4
4
from devtools_testutils import AzureRecordedTestCase
5
5
6
6
from azure .ai .ml import MLClient , load_online_deployment , load_online_endpoint
7
- from azure .ai .ml .constants import AssetTypes
8
- from azure .ai .ml .entities import ManagedOnlineDeployment , ManagedOnlineEndpoint , Model
7
+ from azure .ai .ml .entities import ManagedOnlineDeployment , ManagedOnlineEndpoint , Model , CodeConfiguration , Environment
9
8
10
9
11
10
@pytest .mark .e2etest
11
+ @pytest .mark .usefixtures ("recorded_test" , "mock_asset_name" , "mock_component_hash" , "mock_code_hash" )
12
12
@pytest .mark .production_experiences_test
13
13
class TestOnlineDeployment (AzureRecordedTestCase ):
14
- @pytest .mark .skip (
15
- reason = "Tests failing in internal automation due to lack of quota. Cannot record or run in live mode."
16
- )
17
- def test_online_deployment (
14
+ def test_online_deployment_create (
18
15
self , client : MLClient , rand_online_name : Callable [[], str ], rand_online_deployment_name : Callable [[], str ]
19
16
) -> None :
20
17
endpoint_yaml = "tests/test_configs/deployments/online/simple_online_endpoint_mir.yaml"
21
18
deployment_yaml = "tests/test_configs/deployments/online/online_deployment_1.yaml"
22
- name = rand_online_name ("name " )
19
+ name = rand_online_name ("endpoint_name " )
23
20
endpoint = load_online_endpoint (endpoint_yaml )
24
21
endpoint .name = name
25
22
@@ -53,7 +50,42 @@ def test_online_deployment(
53
50
finally :
54
51
client .online_endpoints .begin_delete (name = endpoint .name )
55
52
56
- @pytest .mark .skip (reason = "Known failure" )
53
+ def test_online_deployment_update (
54
+ self , client : MLClient , rand_online_name : Callable [[], str ], rand_online_deployment_name : Callable [[], str ]
55
+ ) -> None :
56
+ endpoint_yaml = "tests/test_configs/deployments/online/simple_online_endpoint_mir.yaml"
57
+ deployment_yaml = "tests/test_configs/deployments/online/online_deployment_1.yaml"
58
+ endpoint = load_online_endpoint (endpoint_yaml )
59
+ endpoint_name = rand_online_name ("endpoint-name" )
60
+ endpoint .name = endpoint_name
61
+ deployment = load_online_deployment (deployment_yaml )
62
+ deployment_name = rand_online_deployment_name ("deployment_name" )
63
+ deployment .name = deployment_name
64
+ deployment .endpoint_name = endpoint_name
65
+
66
+ # create a endpoint
67
+ client .online_endpoints .begin_create_or_update (endpoint ).result ()
68
+
69
+ try :
70
+ # create a deployment
71
+ client .online_deployments .begin_create_or_update (deployment ).result ()
72
+ dep = client .online_deployments .get (name = deployment .name , endpoint_name = endpoint .name )
73
+ assert dep .name == deployment .name
74
+
75
+ deps = client .online_deployments .list (endpoint_name = endpoint .name )
76
+ deps = list (deps )
77
+ assert len (deps ) == 1
78
+ assert deps [0 ].name == deployment .name
79
+
80
+ dep .instance_count = 3
81
+ updated_deploymwnt = client .online_deployments .begin_create_or_update (dep ).result ()
82
+ assert updated_deploymwnt .instance_count == 3
83
+
84
+ except Exception as ex :
85
+ raise ex
86
+ finally :
87
+ client .online_endpoints .begin_delete (name = endpoint .name )
88
+
57
89
def test_online_deployment_skip_script_validation (
58
90
self , client : MLClient , rand_online_name : Callable [[], str ], rand_online_deployment_name : Callable [[], str ]
59
91
) -> None :
@@ -74,21 +106,31 @@ def test_online_deployment_skip_script_validation(
74
106
# create a blue deployment
75
107
model = Model (
76
108
name = "test-model" ,
77
- version = "4" ,
78
- path = "tests/test_configs/deployments/sklearn-diabetes/model" ,
79
- type = AssetTypes .MLFLOW_MODEL ,
109
+ path = "tests/test_configs/deployments/model-1/model" ,
80
110
description = "my sample mlflow model" ,
81
111
)
82
112
113
+ code_config = CodeConfiguration (
114
+ code = "tests/test_configs/deployments/model-1/onlinescoring/" ,
115
+ scoring_script = "score.py" ,
116
+ )
117
+
118
+ environment = Environment (
119
+ conda_file = "tests/test_configs/deployments/model-1/environment/conda.yml" ,
120
+ image = "mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest" ,
121
+ )
122
+
83
123
blue_deployment = ManagedOnlineDeployment (
84
124
name = online_deployment_name ,
85
125
endpoint_name = online_endpoint_name ,
126
+ code_configuration = code_config ,
127
+ environment = environment ,
86
128
model = model ,
87
- instance_type = "Standard_F4s_v2 " ,
129
+ instance_type = "Standard_DS3_v2 " ,
88
130
instance_count = 1 ,
89
131
)
90
132
91
- client .online_deployments .begin_create_or_update (blue_deployment ).result ()
133
+ client .online_deployments .begin_create_or_update (blue_deployment , skip_script_validation = True ).result ()
92
134
except Exception as ex :
93
135
raise ex
94
136
finally :
0 commit comments