|
2 | 2 |
|
3 | 3 | import pytest
|
4 | 4 | from devtools_testutils import AzureRecordedTestCase
|
5 |
| - |
6 |
| -from azure.ai.ml import MLClient, load_online_deployment, load_online_endpoint |
| 5 | +from pathlib import Path |
| 6 | +from azure.ai.ml import MLClient, load_online_deployment, load_online_endpoint, load_model |
7 | 7 | from azure.ai.ml.entities import ManagedOnlineDeployment, ManagedOnlineEndpoint, Model, CodeConfiguration, Environment
|
8 | 8 |
|
9 | 9 |
|
@@ -50,6 +50,54 @@ def test_online_deployment_create(
|
50 | 50 | finally:
|
51 | 51 | client.online_endpoints.begin_delete(name=endpoint.name)
|
52 | 52 |
|
| 53 | + def test_online_deployment_create_when_registry_assets( |
| 54 | + self, |
| 55 | + sdkv2_registry_client: MLClient, |
| 56 | + client: MLClient, |
| 57 | + randstr: Callable[[], str], |
| 58 | + rand_online_name: Callable[[], str], |
| 59 | + rand_online_deployment_name: Callable[[], str], |
| 60 | + ) -> None: |
| 61 | + # create a model in registry |
| 62 | + model_name = randstr("test-registry-model") |
| 63 | + model = Model(name=model_name, path="./tests/test_configs/deployments/model-1/model") |
| 64 | + model = sdkv2_registry_client.models.create_or_update(model) |
| 65 | + assert model.name == model_name |
| 66 | + |
| 67 | + # create a endpoint |
| 68 | + endpoint_yaml = "tests/test_configs/deployments/online/simple_online_endpoint_mir.yaml" |
| 69 | + endpoint = load_online_endpoint(endpoint_yaml) |
| 70 | + endpoint_name = rand_online_name("endpoint_name") |
| 71 | + endpoint.name = endpoint_name |
| 72 | + endpoint = client.online_endpoints.begin_create_or_update(endpoint).result() |
| 73 | + assert endpoint.name == endpoint_name |
| 74 | + |
| 75 | + # create a deployment |
| 76 | + deployment_yaml = "tests/test_configs/deployments/online/online_deployment_1.yaml" |
| 77 | + deployment = load_online_deployment(deployment_yaml) |
| 78 | + deployment.endpoint_name = endpoint.name |
| 79 | + deployment.name = rand_online_deployment_name("deployment_name") |
| 80 | + deployment.model = model |
| 81 | + |
| 82 | + try: |
| 83 | + client.online_deployments.begin_create_or_update(deployment).result() |
| 84 | + dep = client.online_deployments.get(name=deployment.name, endpoint_name=endpoint.name) |
| 85 | + assert dep.name == deployment.name |
| 86 | + |
| 87 | + deps = client.online_deployments.list(endpoint_name=endpoint.name) |
| 88 | + assert len(list(deps)) > 0 |
| 89 | + |
| 90 | + endpoint.traffic = {deployment.name: 100} |
| 91 | + client.online_endpoints.begin_create_or_update(endpoint).result() |
| 92 | + endpoint_updated = client.online_endpoints.get(endpoint.name) |
| 93 | + assert endpoint_updated.traffic[deployment.name] == 100 |
| 94 | + client.online_endpoints.invoke( |
| 95 | + endpoint_name=endpoint.name, |
| 96 | + request_file="tests/test_configs/deployments/model-1/sample-request.json", |
| 97 | + ) |
| 98 | + finally: |
| 99 | + client.online_endpoints.begin_delete(name=endpoint.name) |
| 100 | + |
53 | 101 | def test_online_deployment_update(
|
54 | 102 | self, client: MLClient, rand_online_name: Callable[[], str], rand_online_deployment_name: Callable[[], str]
|
55 | 103 | ) -> None:
|
|
0 commit comments