コード例 #1
0
ファイル: test_snapshot.py プロジェクト: ysrji/serve
def test_replace_mar_file_with_dummy():
    """Validates that torchserve will fail to start in the following scenario:
        1) We use a snapshot file to start torchserve. The snapshot contains reference to "A" model file
        2) "A" model file gets corrupted or is replaced by some dummy mar file with same name"""

    snapshot_created_on_management_api_invoke()

    # Start Torchserve using last snapshot state
    snapshot_cfg = glob.glob('logs/config/*snap*.cfg')[0]
    test_utils.start_torchserve(snapshot_file=snapshot_cfg)
    response = requests.get('http://127.0.0.1:8081/models/')
    assert json.loads(
        response.content)['models'][0]['modelName'] == "densenet161"
    test_utils.stop_torchserve()

    # 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")
    snapshot_cfg = glob.glob('logs/config/*snap*.cfg')[0]
    test_utils.start_torchserve(snapshot_file=snapshot_cfg)
    try:
        response = requests.get('http://127.0.0.1:8081/models/')
        assert json.loads(
            response.content)['models'][0]['modelName'] == "densenet161"
    except:
        assert True, "Correct Model mar file not found"
    else:
        assert False, "Something is not right!! Successfully started Torchserve with a dummy mar file"
    finally:
        test_utils.delete_all_snapshots()
        test_utils.delete_model_store()
コード例 #2
0
ファイル: test_snapshot.py プロジェクト: ysrji/serve
def test_torchserve_init_with_non_existent_model_store():
    """Validates that Torchserve fails to start if the model store directory is non existent """

    test_utils.start_torchserve(model_store="/invalid_model_store",
                                snapshot_file=None,
                                no_config_snapshots=True)
    try:
        response = requests.get('http://127.0.0.1:8081/models/')
    except:
        assert True, "Failed to start Torchserve using non existent model-store directory"
    else:
        assert False, "Something is not right!! Successfully started Torchserve " \
                      "using non existent directory!!"
    finally:
        test_utils.delete_model_store()
        test_utils.delete_all_snapshots()
コード例 #3
0
ファイル: test_snapshot.py プロジェクト: ysrji/serve
def test_restart_torchserve_with_one_of_model_mar_removed():
    """Validates that torchserve will fail to start in the following scenario:
        1) We use a snapshot file to start torchserve. The snapshot contains reference to few model files
        2) One of these model mar files are accidentally deleted from the model store"""
    # Register multiple models
    # 1st model
    test_utils.delete_model_store()
    test_utils.start_torchserve()
    requests.post(
        'http://127.0.0.1:8081/models?url=https://torchserve.pytorch.org/mar_files/densenet161.mar'
    )
    time.sleep(15)
    # 2nd model
    requests.post(
        'http://127.0.0.1:8081/models?url=https://torchserve.pytorch.org/mar_files/mnist.mar'
    )
    time.sleep(15)
    test_utils.stop_torchserve()

    # Start Torchserve
    test_utils.start_torchserve()
    response = requests.get('http://127.0.0.1:8081/models/')
    num_of_regd_models = len(json.loads(response.content)['models'])
    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", model_mar="densenet")

    # Start Torchserve with existing snapshot file containing reference to one of the model mar file
    # which is now missing from the model store
    snapshot_cfg = glob.glob('logs/config/*snap*.cfg')[1]
    test_utils.start_torchserve(snapshot_file=snapshot_cfg)
    try:
        response = requests.get('http://127.0.0.1:8081/models/')
    except:
        assert True, "Failed to start Torchserve as one of reqd model mar file is missing"
    else:
        assert False, "Something is not right!! Started Torchserve successfully with a " \
                      "reqd model mar file missing from the model store!!"
    finally:
        test_utils.torchserve_cleanup()
コード例 #4
0
ファイル: test_snapshot.py プロジェクト: ysrji/serve
def test_restart_torchserve_with_last_snapshot_with_model_mar_removed():
    """Validates that torchserve will fail to start in the following scenario:
        1) We use a snapshot file to start torchserve. The snapshot contains reference to "A" model file
        2) The "A" model mar file is accidentally deleted from the model store"""

    # Register model using mgmt api
    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", model_mar="densenet")

    # Start Torchserve with last generated snapshot file
    snapshot_cfg = glob.glob('logs/config/*snap*.cfg')[0]
    test_utils.start_torchserve(snapshot_file=snapshot_cfg)
    try:
        response = requests.get('http://127.0.0.1:8081/models/')
    except:
        assert True, "Failed to start Torchserve properly as reqd model mar file is missing!!"
    else:
        assert False, "Something is not right!! Successfully started Torchserve without reqd mar file"
    finally:
        test_utils.delete_model_store()
        test_utils.delete_all_snapshots()