diff --git a/.circleci/config.yml b/.circleci/config.yml index 7a063152f5..3e1045403b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,7 +59,7 @@ commands: steps: - run: name: Start torchserve, Execute << parameters.collection >> API Tests, Stop torchserve - command: python ts_scripts/test_api.py << parameters.collection >> + command: python ts_scripts/api_utils.py << parameters.collection >> when: always @@ -102,7 +102,7 @@ jobs: - install-dependencies - run: name: Execute frontend gradle tests - command: python ts_scripts/test_frontend.py + command: python ts_scripts/frontend_utils.py - store_artifacts: name: Store frontend gradle test results path: frontend/server/build/reports/tests/test @@ -117,7 +117,7 @@ jobs: - install-dependencies - run: name: Execute python lint and unit tests - command: python ts_scripts/test_torchserve.py + command: python ts_scripts/torchserve_install_utils.py - store_artifacts: name: Store python Test results path: result_units @@ -134,7 +134,7 @@ jobs: - install-torchserve - run: name: Execute sanity tests - command: python ts_scripts/test_sanity.py + command: python ts_scripts/sanity_utils.py - store_artifacts: name: Store TS logs from sanity tests path: logs/ @@ -171,7 +171,7 @@ jobs: - install-torchserve - run: name: Execute regression suite - command: python ts_scripts/test_regression.py + command: python ts_scripts/regression_utils.py - store_artifacts: name: Store server logs from regression tests path: test/pytest/logs/ @@ -232,7 +232,7 @@ jobs: - install-torchserve - run: name: Execute python lint, unit and integration tests - command: python ts_scripts/test_modelarchiver.py + command: python ts_scripts/modelarchiver_utils.py - store_artifacts: name: Store unit tests results from model archiver tests path: model-archiver/result_units diff --git a/.circleci/scripts/linux_test_sanity.sh b/.circleci/scripts/linux_test_sanity.sh index 01d22495be..ffb2f3ba29 100755 --- a/.circleci/scripts/linux_test_sanity.sh +++ b/.circleci/scripts/linux_test_sanity.sh @@ -1,6 +1,6 @@ #!/bin/bash -source scripts/install_utils +source ts_scripts/install_utils MODELS=("fastrcnn" "fcn_resnet_101" "my_text_classifier_v2" "resnet-18" "my_text_classifier_scripted_v2" "alexnet_scripted" "fcn_resnet_101_scripted" "roberta_qa_no_torchscript" "bert_token_classification_no_torchscript" "bert_seqc_without_torchscript") diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 569e60acd9..45e1e49811 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ If you are interested in contributing to TorchServe, your contributions will fal - To ensure your changes doesn't break any of the existing features run the sanity suite as follows from serve directory: - Install dependencies (if not already installed) ```bash - python scripts/install_dependencies.py + python ts_scripts/install_dependencies.py ``` > For GPU with Cuda 10.1, make sure add the `cu101` arg to the above command - Execute sanity suite diff --git a/README.md b/README.md index 98ca64ff40..3bf2fcf09d 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ NOTE: This script uninstalls existing `torchserve` and `torch-model-archiver` in #### For Debian Based Systems/ MacOS ``` +python ./ts_scripts/install_dependencies.py python ./ts_scripts/install_from_src.py ``` diff --git a/benchmarks/windows_install_dependencies.py b/benchmarks/windows_install_dependencies.py index d431431e74..c7e153f02d 100644 --- a/benchmarks/windows_install_dependencies.py +++ b/benchmarks/windows_install_dependencies.py @@ -1,6 +1,6 @@ import sys -sys.path.append("../scripts") -from scripts.shell_utils import download_save, unzip, rm_file, rm_dir +sys.path.append("../ts_scripts") +from ts_scripts.shell_utils import download_save, unzip, rm_file, rm_dir import os import subprocess import locale diff --git a/binaries/README.md b/binaries/README.md index f2dce68af1..d0ce5f3e9e 100644 --- a/binaries/README.md +++ b/binaries/README.md @@ -1,7 +1,7 @@ # Building TorchServe and Torch-Model-Archiver release binaries 1. Make sure all the dependencies are installed ```bash - python scripts/install_dependencies.py + python ts_scripts/install_dependencies.py ``` > For GPU with Cuda 10.1, make sure add the `cu101` arg to the above command diff --git a/binaries/pip/build_wheels.sh b/binaries/pip/build_wheels.sh index a24eb9ea3d..245c63fcc1 100755 --- a/binaries/pip/build_wheels.sh +++ b/binaries/pip/build_wheels.sh @@ -2,7 +2,7 @@ set -eou pipefail -source ../../scripts/install_utils +source ../../ts_scripts/install_utils cleanup() { diff --git a/ci/buildspec.yml b/ci/buildspec.yml index 672e92ba18..16dc66b17a 100644 --- a/ci/buildspec.yml +++ b/ci/buildspec.yml @@ -5,6 +5,8 @@ version: 0.2 phases: install: commands: + - apt-get update + - apt-get install sudo -y - python ts_scripts/install_dependencies.py --cuda=cu101 build: diff --git a/ci/buildspec_windows.yml b/ci/buildspec_windows.yml new file mode 100644 index 0000000000..1d9e37054f --- /dev/null +++ b/ci/buildspec_windows.yml @@ -0,0 +1,13 @@ +# Build Spec for AWS CodeBuild CI + +version: 0.2 + +phases: + install: + commands: + - python ts_scripts/install_dependencies.py + + build: + commands: + - python torchserve_sanity.py + - cd serving-sdk/ && mvn clean install -q && cd ../ \ No newline at end of file diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 6d65828250..c6baf88c6d 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -27,6 +27,7 @@ RUN --mount=type=cache,id=apt-dev,target=/var/cache/apt \ fakeroot \ ca-certificates \ dpkg-dev \ + sudo \ g++ \ git \ python3-dev \ @@ -52,7 +53,8 @@ RUN if [ "$MACHINE_TYPE" = "gpu" ]; then export USE_CUDA=1; fi \ && git clone https://github.com/pytorch/serve.git \ && cd serve \ && git checkout ${BRANCH_NAME} \ - && ./scripts/install_from_src $CUDA_VERSION \ + && python ts_scripts/install_dependencies.py --cuda $CUDA_VERSION \ + && python ts_scripts/install_from_src.py \ && useradd -m model-server \ && mkdir -p /home/model-server/tmp \ && cp docker/dockerd-entrypoint.sh /usr/local/bin/dockerd-entrypoint.sh \ diff --git a/docker/README.md b/docker/README.md index 65ee3a5895..68401b150f 100644 --- a/docker/README.md +++ b/docker/README.md @@ -141,7 +141,7 @@ To create a Docker image for a GPU device with a specific branch, use following To create a Docker image for a GPU device with Cuda 10.1, use following command: ```bash -./build_image.sh --gpu --cudaversion cuda101 +./build_image.sh --gpu --cudaversion cu101 ``` To run your TorchServe Docker image and start TorchServe inside the container with a pre-registered `resnet-18` image classification model, use the following command: diff --git a/docs/code_coverage.md b/docs/code_coverage.md index 85c3d0f1bd..9e98686b68 100644 --- a/docs/code_coverage.md +++ b/docs/code_coverage.md @@ -1,7 +1,7 @@ ## To check branch stability run the sanity suite as follows - Install dependencies (if not already installed) ```bash - python scripts/install_dependencies.py + python ts_scripts/install_dependencies.py ``` > For GPU with Cuda 10.1, make sure add the `cu101` argument to the above command - Execute sanity suite diff --git a/docs/torchserve_on_wsl.md b/docs/torchserve_on_wsl.md index 6ddc776df5..b49edd43e0 100644 --- a/docs/torchserve_on_wsl.md +++ b/docs/torchserve_on_wsl.md @@ -18,7 +18,7 @@ 1. Setup Ubuntu Environment ```bash -wget -O - https://raw.githubusercontent.com/pytorch/serve/master/scripts/setup_wsl_ubuntu | bash +wget -O - https://raw.githubusercontent.com/pytorch/serve/master/ts_scripts/setup_wsl_ubuntu | bash echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc source ~/.bashrc ``` @@ -45,7 +45,7 @@ pip install torchserve torch-model-archiver git clone https://github.com/pytorch/serve.git cd serve -./scripts/setup_wsl_ubuntu +./ts_scripts/setup_wsl_ubuntu export PATH=$HOME/.local/bin:$PATH python ./ts_scripts/install_from_src.py echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.bashrc diff --git a/examples/text_to_speech_synthesizer/create_mar.py b/examples/text_to_speech_synthesizer/create_mar.py index d012455958..5ef6d65a80 100644 --- a/examples/text_to_speech_synthesizer/create_mar.py +++ b/examples/text_to_speech_synthesizer/create_mar.py @@ -1,7 +1,7 @@ import tempfile import sys -sys.path.append('../../scripts') -from scripts.shell_utils import rm_dir, rm_file, download_save +sys.path.append('../../ts_scripts') +from ts_scripts.shell_utils import rm_dir, rm_file, download_save import os import shutil import subprocess diff --git a/setup.py b/setup.py index 36cb6219c9..3d7b28620f 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ import ts -pkgs = find_packages() +pkgs = find_packages(exclude=["ts_scripts"]) build_frontend_command = {"Windows": ".\\frontend\\gradlew.bat -p frontend clean assemble", "Darwin": "frontend/gradlew -p frontend clean assemble", diff --git a/test/README.md b/test/README.md index 1ce65d4afb..64a09b956e 100644 --- a/test/README.md +++ b/test/README.md @@ -62,9 +62,9 @@ git checkout ``` Install dependencies (if not already installed) ```bash -python scripts/install_dependencies.py +python ts_scripts/install_dependencies.py ``` -> For GPU with Cuda 10.1, make sure add the `--cu101` flag to the above command +> For GPU with Cuda 10.1, make sure to use argument `--cuda=cu101` to to the above command Execute regression suite To execute regression tests: diff --git a/test/buildspec.yml b/test/buildspec.yml index ea97e91073..7c018facd0 100644 --- a/test/buildspec.yml +++ b/test/buildspec.yml @@ -5,6 +5,8 @@ version: 0.2 phases: install: commands: + - apt-get update + - apt-get install sudo -y - python ts_scripts/install_dependencies.py --cuda=cu101 build: diff --git a/test/buildspec_windows.yml b/test/buildspec_windows.yml new file mode 100644 index 0000000000..ea97e91073 --- /dev/null +++ b/test/buildspec_windows.yml @@ -0,0 +1,12 @@ +# Build Spec for AWS CodeBuild CI + +version: 0.2 + +phases: + install: + commands: + - python ts_scripts/install_dependencies.py --cuda=cu101 + + build: + commands: + - python test/regression_tests.py diff --git a/test/pytest/test_snapshot.py b/test/pytest/test_snapshot.py index 9f8859b3f5..9895a4fa73 100644 --- a/test/pytest/test_snapshot.py +++ b/test/pytest/test_snapshot.py @@ -16,7 +16,7 @@ def teardown_module(module): def replace_mar_file_with_dummy_mar_in_model_store(model_store=None, model_mar=None): - model_store = model_store if (model_store != None) else "/workspace/model_store/" + model_store = model_store if (model_store != None) else f"{test_utils.ROOT_DIR}/model_store/" if model_mar != None: myfilepath = model_store + "/" + model_mar if os.path.exists(model_store + "/" + model_mar): @@ -155,7 +155,7 @@ def test_restart_torchserve_with_last_snapshot_with_model_mar_removed(): snapshot_created_on_management_api_invoke() # Now remove the registered model mar file (delete_mar_ fn) - test_utils.delete_mar_file_from_model_store(model_store="/workspace/model_store", + test_utils.delete_mar_file_from_model_store(model_store=f"{test_utils.ROOT_DIR}/model_store", model_mar="densenet") # Start Torchserve with last generated snapshot file @@ -188,7 +188,7 @@ def test_replace_mar_file_with_dummy(): # Now replace the registered model mar with dummy file replace_mar_file_with_dummy_mar_in_model_store( - model_store="/workspace/model_store", model_mar="densenet161.mar") + model_store=f"{test_utils.ROOT_DIR}/model_store", model_mar="densenet161.mar") snapshot_cfg = glob.glob('logs/config/*snap*.cfg')[0] test_utils.start_torchserve(snapshot_file=snapshot_cfg) try: @@ -227,7 +227,7 @@ def test_restart_torchserve_with_one_of_model_mar_removed(): test_utils.stop_torchserve() # Now remove the registered model mar file (delete_mar_ fn) - test_utils.delete_mar_file_from_model_store(model_store="/workspace/model_store", + test_utils.delete_mar_file_from_model_store(model_store=f"{test_utils.ROOT_DIR}/model_store", model_mar="densenet") # Start Torchserve with existing snapshot file containing reference to one of the model mar file diff --git a/test/pytest/test_utils.py b/test/pytest/test_utils.py index 7eea937021..108d8984ef 100644 --- a/test/pytest/test_utils.py +++ b/test/pytest/test_utils.py @@ -4,16 +4,14 @@ import glob import os import requests -import platform import tempfile -ROOT_DIR = "/workspace/" -if platform.system() == "Windows": - ROOT_DIR = "C:\\workspace\\" +ROOT_DIR = f"{tempfile.gettempdir()}/workspace/" MODEL_STORE = path.join(ROOT_DIR, "model_store/") CODEBUILD_WD = path.abspath(path.join(__file__, "../../..")) + def start_torchserve(model_store=None, snapshot_file=None, no_config_snapshots=False): stop_torchserve() cmd = ["torchserve", "--start"] @@ -69,7 +67,7 @@ def unregister_model(model_name): def delete_mar_file_from_model_store(model_store=None, model_mar=None): - model_store = model_store if (model_store != None) else "/workspace/model_store/" - if model_mar != None: + model_store = model_store if (model_store is not None) else f"{ROOT_DIR}/model_store/" + if model_mar is not None: for f in glob.glob(path.join(model_store, model_mar + "*")): os.remove(f) \ No newline at end of file diff --git a/test/regression_tests.py b/test/regression_tests.py index ee7eb010e2..574527ed1b 100644 --- a/test/regression_tests.py +++ b/test/regression_tests.py @@ -7,8 +7,8 @@ sys.path.append(REPO_ROOT) from ts_scripts.install_from_src import install_from_src -from ts_scripts.test_regression import test_regression -from ts_scripts.test_api import test_api +from ts_scripts.regression_utils import test_regression +from ts_scripts.api_utils import test_api from pygit2 import Repository git_branch = Repository('.').head.shorthand diff --git a/torchserve_sanity.py b/torchserve_sanity.py index 43b822aae1..7d44c7d509 100644 --- a/torchserve_sanity.py +++ b/torchserve_sanity.py @@ -1,9 +1,9 @@ -from ts_scripts.test_modelarchiver import test_modelarchiver -from ts_scripts.test_torchserve import test_torchserve +from ts_scripts.modelarchiver_utils import test_modelarchiver +from ts_scripts.backend_utils import test_torchserve from ts_scripts.install_from_src import install_from_src -from ts_scripts.test_sanity import test_sanity +from ts_scripts.sanity_utils import test_sanity from ts_scripts.shell_utils import rm_dir -from ts_scripts.test_frontend import test_frontend +from ts_scripts.frontend_utils import test_frontend import ts_scripts.tsutils as ts import test.print_env_info as build_hdr_printer diff --git a/ts_scripts/Readme.md b/ts_scripts/Readme.md deleted file mode 100644 index d334fc57eb..0000000000 --- a/ts_scripts/Readme.md +++ /dev/null @@ -1,24 +0,0 @@ -The scripts listed here execute on all of the supported platforms(Linux, Windows, OSX) -The scripts are designed to execute independent of each other. - - -1. [install_dependencies.py](install_dependencies.py) : Helps you install build and test dependencies for torchserve (like java, torch packages, newman, etc) - ``` - # Example - python ts_scripts/install_dependencies.py - -2. [tsutils.py](tsutils.py.py) : Import this module in your scripts to have access to utility methods like start\stop torchserve, register\infer\unregister models, etc. -3. [shell_utils.py](shell_utils.py) : Import this module in your scripts to have access to utility methods like download file, remove directory, unzip files, etc -4. [install_from_src.py](install_from_src.py) : Installs torch and torch-model-archiver from source. -5. [test_frontend.py](test_frontend.py) : Executes gradle tests -6. [test_torchserve.py](test_torchserve.py) : Executes liniting in `ts` directory and executes pytests -7. [test_modelarchiver.py](test_modelarchiver.py) : Executes liniting in `model-archiver` directory and executes pytests (unit & integration tests) -8. [test_sanity.py](test_sanity.py) : Executes sanity tests (selected few models are registered\infered\unregistered) and markdown files are checked for broken links -9. [test_api.py](test_api.py) : Executes newman api collections (management\inference\increased_timeout_inference\https\all) - ``` - # Example - python ts_scripts/test_api.py management - python ts_scripts/test_api.py inference - python ts_scripts/test_api.py all - ``` -10. [test_regression.py](test_regression.py) : Executes regression pytests. \ No newline at end of file diff --git a/ts_scripts/test_api.py b/ts_scripts/api_utils.py similarity index 95% rename from ts_scripts/test_api.py rename to ts_scripts/api_utils.py index 782a2b87d9..f274ee8839 100755 --- a/ts_scripts/test_api.py +++ b/ts_scripts/api_utils.py @@ -1,11 +1,13 @@ import glob import os +import shutil import sys -import argparse -from ts_scripts import tsutils as ts - REPO_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") +sys.path.append(REPO_ROOT) + +from ts_scripts import tsutils as ts + TEST_DIR = os.path.join("test") MODEL_STORE_DIR = os.path.join("model_store") @@ -99,6 +101,7 @@ def trigger_all(): def test_api(collection): os.chdir(TEST_DIR) for DIR in [MODEL_STORE_DIR, ARTIFACTS_MANAGEMENT_DIR, ARTIFACTS_INFERENCE_DIR, ARTIFACTS_INCRSD_TIMEOUT_INFERENCE_DIR, ARTIFACTS_HTTPS_DIR] : + shutil.rmtree(DIR, True) os.makedirs(DIR, exist_ok=True) switcher = { @@ -114,11 +117,3 @@ def test_api(collection): if exit_code != 0: sys.exit("## Newman API Tests Failed !") - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Execute newman API test suite") - parser.add_argument("collection", type=str, help="Collection Name") - args = parser.parse_args() - - test_api(args.collection) \ No newline at end of file diff --git a/ts_scripts/test_torchserve.py b/ts_scripts/backend_utils.py similarity index 95% rename from ts_scripts/test_torchserve.py rename to ts_scripts/backend_utils.py index 3c31b43d0f..cc87837ada 100755 --- a/ts_scripts/test_torchserve.py +++ b/ts_scripts/backend_utils.py @@ -25,7 +25,3 @@ def test_torchserve(): sys.exit("## TorchServe Linting Failed !") if py_test_exit_code != 0: sys.exit("## TorchServe Pytests Failed !") - - -if __name__ == "__main__": - test_torchserve() diff --git a/ts_scripts/test_frontend.py b/ts_scripts/frontend_utils.py similarity index 90% rename from ts_scripts/test_frontend.py rename to ts_scripts/frontend_utils.py index 30ac432eff..a8eddc6ca1 100755 --- a/ts_scripts/test_frontend.py +++ b/ts_scripts/frontend_utils.py @@ -11,7 +11,3 @@ def test_frontend(): if frontend_gradlew_exit_code != 0: sys.exit("## Frontend Gradle Tests Failed !") - - -if __name__ == "__main__": - test_frontend() \ No newline at end of file diff --git a/ts_scripts/install_dependencies.py b/ts_scripts/install_dependencies.py index 735fcc5ee0..e14ea1381b 100644 --- a/ts_scripts/install_dependencies.py +++ b/ts_scripts/install_dependencies.py @@ -4,11 +4,11 @@ class Common(): - def __init__(self, sudo_cmd): + def __init__(self): # Assumption is nvidia-smi is installed on systems with gpu self.is_gpu_instance = True if os.system("nvidia-smi") == 0 else False self.torch_stable_url = "https://download.pytorch.org/whl/torch_stable.html" - self.sudo_cmd = sudo_cmd + self.sudo_cmd = 'sudo ' def install_java(self): pass @@ -32,7 +32,6 @@ def install_python_packages(self, cuda_version): os.system("conda install -y conda-build") def install_node_packages(self): - os.system(f"{self.sudo_cmd}apt-get update") os.system(f"{self.sudo_cmd}npm install -g newman newman-reporter-html markdown-link-check") def install_jmeter(self): @@ -40,13 +39,17 @@ def install_jmeter(self): class Linux(Common): - def __init__(self, sudo_cmd): - super().__init__(sudo_cmd) + def __init__(self): + super().__init__() def install_java(self): os.system(f"{self.sudo_cmd}apt-get update") os.system(f"{self.sudo_cmd}apt-get install -y openjdk-11-jdk") + def install_node_packages(self): + os.system(f"{self.sudo_cmd}apt-get update") + os.system(f"{self.sudo_cmd}npm install -g newman newman-reporter-html markdown-link-check") + def install_nodejs(self): os.system(f"{self.sudo_cmd}apt-get update") os.system(f"{self.sudo_cmd}curl -sL https://deb.nodesource.com/setup_14.x | {self.sudo_cmd}bash -") @@ -54,8 +57,9 @@ def install_nodejs(self): class Windows(Common): - def __init__(self, sudo_cmd): - super().__init__(sudo_cmd) + def __init__(self): + super().__init__() + self.sudo_cmd = '' def install_java(self): pass @@ -65,8 +69,8 @@ def install_nodejs(self): class Darwin(Common): - def __init__(self, sudo_cmd): - super().__init__(sudo_cmd) + def __init__(self): + super().__init__() def install_java(self): os.system("brew tap AdoptOpenJDK/openjdk") @@ -79,25 +83,24 @@ def install_torch_packages(self, cuda_version=''): os.system(f"pip install -U -r requirements/torch.txt -f {self.torch_stable_url}") -def install_dependencies(sudo_cmd='sudo ', cuda_version=None): +def install_dependencies(cuda_version=None): os_map = { "Linux": Linux, "Windows": Windows, "Darwin": Darwin } - system = os_map[platform.system()](sudo_cmd) + system = os_map[platform.system()]() - import sys # Sequence of installation to be maintained system.install_java() system.install_nodejs() system.install_python_packages(cuda_version) system.install_node_packages() + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Install various build and test dependencies of TorchServe") - parser.add_argument('--cuda', default=None, choices=['cu101'], help="CUDA version for torch") + parser.add_argument('--cuda', default=None, choices=['cu101', 'latest'], help="CUDA version for torch") args = parser.parse_args() - install_dependencies('', cuda_version=args.cuda) - + install_dependencies(cuda_version=args.cuda) diff --git a/ts_scripts/install_from_src.py b/ts_scripts/install_from_src.py index afe7b5f0fc..dfc7bbfc23 100644 --- a/ts_scripts/install_from_src.py +++ b/ts_scripts/install_from_src.py @@ -9,7 +9,6 @@ sys.path.append(REPO_ROOT) from ts_scripts import tsutils as ts -from ts_scripts import install_dependencies as idep def clean_slate(): @@ -57,5 +56,4 @@ def install_from_src(): if __name__ == '__main__': - idep.install_dependencies() install_from_src() diff --git a/ts_scripts/test_modelarchiver.py b/ts_scripts/modelarchiver_utils.py similarity index 97% rename from ts_scripts/test_modelarchiver.py rename to ts_scripts/modelarchiver_utils.py index 022f3a44e5..f1b5e6a3c5 100644 --- a/ts_scripts/test_modelarchiver.py +++ b/ts_scripts/modelarchiver_utils.py @@ -3,6 +3,8 @@ REPO_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") +sys.path.append(REPO_ROOT) + def test_modelarchiver(): os.chdir("model-archiver") @@ -40,7 +42,3 @@ def test_modelarchiver(): sys.exit("## Model archiver Integration Pytests Failed !") os.chdir(REPO_ROOT) - - -if __name__ == "__main__": - test_modelarchiver() diff --git a/ts_scripts/test_regression.py b/ts_scripts/regression_utils.py similarity index 89% rename from ts_scripts/test_regression.py rename to ts_scripts/regression_utils.py index 4fa3e6dfbe..645ebbe788 100644 --- a/ts_scripts/test_regression.py +++ b/ts_scripts/regression_utils.py @@ -1,17 +1,17 @@ import os -import platform +import tempfile import sys import urllib.request - REPO_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") +sys.path.append(REPO_ROOT) + +ROOT_DIR = f"{tempfile.gettempdir()}/workspace/" + def generate_densenet_test_model_archive(): print("## Started densenet mar creation") - if platform.system() == "Windows": - model_store_dir = os.path.join("C:\\workspace", "model_store") - else: - model_store_dir = os.path.join("/", "workspace", "model_store") + model_store_dir = os.path.join(ROOT_DIR, "model_store") model_name = "densenet161_v1" version = "1.1" model_file = os.path.join(REPO_ROOT, "examples", "image_classifier", "densenet_161", "model.py") @@ -48,6 +48,7 @@ def run_pytest(): print(f"## In directory: {os.getcwd()} | Executing command: {cmd}") return os.system(cmd) + def test_regression(): print("## Started regression tests") # generate_densenet_test_model_archive $MODEL_STORE @@ -59,7 +60,3 @@ def test_regression(): sys.exit("## Densenet mar creation failed !") if py_test_exit_code != 0: sys.exit("## TorchServe Regression Pytests Failed") - - -if __name__ == "__main__": - test_regression() \ No newline at end of file diff --git a/ts_scripts/test_sanity.py b/ts_scripts/sanity_utils.py similarity index 95% rename from ts_scripts/test_sanity.py rename to ts_scripts/sanity_utils.py index 0c78e420aa..2c30d60340 100755 --- a/ts_scripts/test_sanity.py +++ b/ts_scripts/sanity_utils.py @@ -3,6 +3,10 @@ import nvgpu import glob + +REPO_ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..") +sys.path.append(REPO_ROOT) + from ts_scripts import tsutils as ts @@ -125,9 +129,9 @@ def test_sanity(): response = ts.run_inference(resnet18_model["name"], resnet18_model["inputs"][0]) if response and response.status_code == 200: - print(f"## Successfully ran inference on {model_name} model.") + print(f"## Successfully ran inference on {resnet18_model['name']} model.") else: - print(f"## Failed to run inference on {model_name} model") + print(f"## Failed to run inference on {resnet18_model['name']} model") sys.exit(1) stopped = ts.stop_torchserve() @@ -137,7 +141,3 @@ def test_sanity(): #links_ok = run_markdown_link_checker() #if not links_ok: # sys.exit("## Markdown Link Checker Failed !") - - -if __name__ == "__main__": - test_sanity() diff --git a/ts_scripts/tsutils.py b/ts_scripts/tsutils.py index fc3826e7bb..5a14c2b612 100644 --- a/ts_scripts/tsutils.py +++ b/ts_scripts/tsutils.py @@ -1,5 +1,4 @@ import os -import sys import platform import time import requests