44from devtools_testutils import AzureRecordedTestCase
55
66from 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
98
109
1110@pytest .mark .e2etest
11+ @pytest .mark .usefixtures ("recorded_test" , "mock_asset_name" , "mock_component_hash" , "mock_code_hash" )
1212@pytest .mark .production_experiences_test
1313class 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 (
1815 self , client : MLClient , rand_online_name : Callable [[], str ], rand_online_deployment_name : Callable [[], str ]
1916 ) -> None :
2017 endpoint_yaml = "tests/test_configs/deployments/online/simple_online_endpoint_mir.yaml"
2118 deployment_yaml = "tests/test_configs/deployments/online/online_deployment_1.yaml"
22- name = rand_online_name ("name " )
19+ name = rand_online_name ("endpoint_name " )
2320 endpoint = load_online_endpoint (endpoint_yaml )
2421 endpoint .name = name
2522
@@ -53,7 +50,42 @@ def test_online_deployment(
5350 finally :
5451 client .online_endpoints .begin_delete (name = endpoint .name )
5552
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+
5789 def test_online_deployment_skip_script_validation (
5890 self , client : MLClient , rand_online_name : Callable [[], str ], rand_online_deployment_name : Callable [[], str ]
5991 ) -> None :
@@ -74,21 +106,31 @@ def test_online_deployment_skip_script_validation(
74106 # create a blue deployment
75107 model = Model (
76108 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" ,
80110 description = "my sample mlflow model" ,
81111 )
82112
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+
83123 blue_deployment = ManagedOnlineDeployment (
84124 name = online_deployment_name ,
85125 endpoint_name = online_endpoint_name ,
126+ code_configuration = code_config ,
127+ environment = environment ,
86128 model = model ,
87- instance_type = "Standard_F4s_v2 " ,
129+ instance_type = "Standard_DS3_v2 " ,
88130 instance_count = 1 ,
89131 )
90132
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 ()
92134 except Exception as ex :
93135 raise ex
94136 finally :
0 commit comments