Skip to content

Commit fb415d7

Browse files
committed
Refactored test.
1 parent 7f167c9 commit fb415d7

File tree

1 file changed

+45
-185
lines changed

1 file changed

+45
-185
lines changed

tests/unitary/default_setup/model_deployment/test_model_deployment_v2.py

Lines changed: 45 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
model_deployment_instance_shape_config_details=ModelDeploymentInstanceShapeConfigDetails(
8080
ocpus=10, memory_in_gbs=36
8181
),
82-
subnet_id="fakeid.subnet.oc1.iad.xxx"
8382
),
8483
scaling_policy=FixedSizeScalingPolicy(instance_count=5),
8584
bandwidth_mbps=5,
@@ -129,7 +128,6 @@
129128
"replica": 5,
130129
"shape_name": "VM.Standard.E4.Flex",
131130
"shape_config_details": {"ocpus": 10, "memoryInGBs": 36},
132-
"subnet_id": "fakeid.subnet.oc1.iad.xxx",
133131
"web_concurrency": 10,
134132
"access_log": {
135133
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
@@ -150,7 +148,7 @@
150148
"entrypoint": ["python", "/opt/ds/model/deployed_model/api.py"],
151149
"server_port": 5000,
152150
"health_check_port": 5000,
153-
"env": {"WEB_CONCURRENCY": 10},
151+
"env": {"WEB_CONCURRENCY": "10"},
154152
"input_stream_ids": ["123", "456"],
155153
"output_stream_ids": ["321", "654"],
156154
"model_uri": "fakeid.datasciencemodel.oc1.iad.xxx",
@@ -186,10 +184,9 @@
186184
shapeConfigDetails:
187185
memoryInGBs: 36
188186
ocpus: 10
189-
subnetId: fakeid.subnet.oc1.iad.xxx
190187
replica: 5
191188
bandwidthMbps: 5
192-
webConcurrency: 5
189+
webConcurrency: 10
193190
runtime:
194191
kind: runtime
195192
type: container
@@ -200,56 +197,48 @@
200197
entrypoint: ["python", "/opt/ds/model/deployed_model/api.py"]
201198
serverPort: 5000
202199
healthCheckPort: 5000
203-
env:
204-
key: value
205200
inputStreamIds: ["123", "456"]
206201
outputStreamIds: ["321", "654"]
207202
deploymentMode: STREAM_ONLY
208203
"""
209204

205+
infrastructure = (
206+
ModelDeploymentInfrastructure()
207+
.with_bandwidth_mbps(5)
208+
.with_compartment_id("fakeid.compartment.oc1..xxx")
209+
.with_project_id("fakeid.datascienceproject.oc1.iad.xxx")
210+
.with_replica(5)
211+
.with_shape_name("VM.Standard.E4.Flex")
212+
.with_shape_config_details(ocpus=10, memory_in_gbs=36)
213+
.with_web_concurrency(10)
214+
.with_access_log(
215+
log_group_id="fakeid.loggroup.oc1.iad.xxx",
216+
log_id="fakeid.log.oc1.iad.xxx",
217+
)
218+
.with_predict_log(
219+
log_group_id="fakeid.loggroup.oc1.iad.xxx",
220+
log_id="fakeid.log.oc1.iad.xxx",
221+
)
222+
)
210223

211-
class ModelDeploymentBYOCTestCase(unittest.TestCase):
212-
def initialize_model_deployment(self):
213-
infrastructure = (
214-
ModelDeploymentInfrastructure()
215-
.with_bandwidth_mbps(5)
216-
.with_compartment_id("fakeid.compartment.oc1..xxx")
217-
.with_project_id("fakeid.datascienceproject.oc1.iad.xxx")
218-
.with_replica(5)
219-
.with_shape_name("VM.Standard.E4.Flex")
220-
.with_shape_config_details(ocpus=10, memory_in_gbs=36)
221-
.with_subnet_id("fakeid.subnet.oc1.iad.xxx")
222-
.with_web_concurrency(10)
223-
.with_access_log(
224-
log_group_id="fakeid.loggroup.oc1.iad.xxx",
225-
log_id="fakeid.log.oc1.iad.xxx",
226-
)
227-
.with_predict_log(
228-
log_group_id="fakeid.loggroup.oc1.iad.xxx",
229-
log_id="fakeid.log.oc1.iad.xxx",
230-
)
231-
)
224+
runtime = (
225+
ModelDeploymentContainerRuntime()
226+
.with_image("iad.ocir.io/ociodscdev/ml_flask_app_demo:1.0.0")
227+
.with_image_digest(
228+
"sha256:243590ea099af4019b6afc104b8a70b9552f0b001b37d0442f8b5a399244681c"
229+
)
230+
.with_entrypoint(["python", "/opt/ds/model/deployed_model/api.py"])
231+
.with_server_port(5000)
232+
.with_health_check_port(5000)
233+
.with_input_stream_ids(["123", "456"])
234+
.with_output_stream_ids(["321", "654"])
235+
.with_model_uri("fakeid.datasciencemodel.oc1.iad.xxx")
236+
.with_deployment_mode("STREAM_ONLY")
237+
)
232238

233-
runtime = (
234-
ModelDeploymentContainerRuntime()
235-
.with_image("iad.ocir.io/ociodscdev/ml_flask_app_demo:1.0.0")
236-
.with_image_digest(
237-
"sha256:243590ea099af4019b6afc104b8a70b9552f0b001b37d0442f8b5a399244681c"
238-
)
239-
.with_entrypoint(["python", "/opt/ds/model/deployed_model/api.py"])
240-
.with_server_port(5000)
241-
.with_health_check_port(5000)
242-
.with_env(
243-
{
244-
"WEB_CONCURRENCY": 10,
245-
}
246-
)
247-
.with_input_stream_ids(["123", "456"])
248-
.with_output_stream_ids(["321", "654"])
249-
.with_model_uri("fakeid.datasciencemodel.oc1.iad.xxx")
250-
.with_deployment_mode("STREAM_ONLY")
251-
)
252239

240+
class ModelDeploymentBYOCTestCase(unittest.TestCase):
241+
def initialize_model_deployment(self):
253242
model_deployment = (
254243
ModelDeployment()
255244
.with_display_name("Generic Model Deployment With Small Artifact")
@@ -263,46 +252,6 @@ def initialize_model_deployment(self):
263252
return model_deployment
264253

265254
def initialize_model_deployment_from_spec(self):
266-
infrastructure = (
267-
ModelDeploymentInfrastructure()
268-
.with_bandwidth_mbps(5)
269-
.with_compartment_id("fakeid.compartment.oc1..xxx")
270-
.with_project_id("fakeid.datascienceproject.oc1.iad.xxx")
271-
.with_replica(5)
272-
.with_shape_name("VM.Standard.E4.Flex")
273-
.with_shape_config_details(ocpus=10, memory_in_gbs=36)
274-
.with_subnet_id("fakeid.subnet.oc1.iad.xxx")
275-
.with_web_concurrency(10)
276-
.with_access_log(
277-
log_group_id="fakeid.loggroup.oc1.iad.xxx",
278-
log_id="fakeid.log.oc1.iad.xxx",
279-
)
280-
.with_predict_log(
281-
log_group_id="fakeid.loggroup.oc1.iad.xxx",
282-
log_id="fakeid.log.oc1.iad.xxx",
283-
)
284-
)
285-
286-
runtime = (
287-
ModelDeploymentContainerRuntime()
288-
.with_image("iad.ocir.io/ociodscdev/ml_flask_app_demo:1.0.0")
289-
.with_image_digest(
290-
"sha256:243590ea099af4019b6afc104b8a70b9552f0b001b37d0442f8b5a399244681c"
291-
)
292-
.with_entrypoint(["python", "/opt/ds/model/deployed_model/api.py"])
293-
.with_server_port(5000)
294-
.with_health_check_port(5000)
295-
.with_env(
296-
{
297-
"WEB_CONCURRENCY": 10,
298-
}
299-
)
300-
.with_input_stream_ids(["123", "456"])
301-
.with_output_stream_ids(["321", "654"])
302-
.with_model_uri("fakeid.datasciencemodel.oc1.iad.xxx")
303-
.with_deployment_mode("STREAM_ONLY")
304-
)
305-
306255
return ModelDeployment(
307256
spec={
308257
"display_name": "Generic Model Deployment With Small Artifact",
@@ -315,46 +264,6 @@ def initialize_model_deployment_from_spec(self):
315264
)
316265

317266
def initialize_model_deployment_from_kwargs(self):
318-
infrastructure = (
319-
ModelDeploymentInfrastructure()
320-
.with_bandwidth_mbps(5)
321-
.with_compartment_id("fakeid.compartment.oc1..xxx")
322-
.with_project_id("fakeid.datascienceproject.oc1.iad.xxx")
323-
.with_replica(5)
324-
.with_shape_name("VM.Standard.E4.Flex")
325-
.with_shape_config_details(ocpus=10, memory_in_gbs=36)
326-
.with_subnet_id("fakeid.subnet.oc1.iad.xxx")
327-
.with_web_concurrency(10)
328-
.with_access_log(
329-
log_group_id="fakeid.loggroup.oc1.iad.xxx",
330-
log_id="fakeid.log.oc1.iad.xxx",
331-
)
332-
.with_predict_log(
333-
log_group_id="fakeid.loggroup.oc1.iad.xxx",
334-
log_id="fakeid.log.oc1.iad.xxx",
335-
)
336-
)
337-
338-
runtime = (
339-
ModelDeploymentContainerRuntime()
340-
.with_image("iad.ocir.io/ociodscdev/ml_flask_app_demo:1.0.0")
341-
.with_image_digest(
342-
"sha256:243590ea099af4019b6afc104b8a70b9552f0b001b37d0442f8b5a399244681c"
343-
)
344-
.with_entrypoint(["python", "/opt/ds/model/deployed_model/api.py"])
345-
.with_server_port(5000)
346-
.with_health_check_port(5000)
347-
.with_env(
348-
{
349-
"WEB_CONCURRENCY": 10,
350-
}
351-
)
352-
.with_input_stream_ids(["123", "456"])
353-
.with_output_stream_ids(["321", "654"])
354-
.with_model_uri("fakeid.datasciencemodel.oc1.iad.xxx")
355-
.with_deployment_mode("STREAM_ONLY")
356-
)
357-
358267
return ModelDeployment(
359268
display_name="Generic Model Deployment With Small Artifact",
360269
description="The model deployment description",
@@ -383,7 +292,7 @@ def test_initialize_model_deployment(self):
383292

384293
temp_runtime = temp_model_deployment.runtime
385294
assert temp_runtime.environment_config_type == "OCIR_CONTAINER"
386-
assert temp_runtime.env == {"WEB_CONCURRENCY": 10}
295+
assert temp_runtime.env == {"WEB_CONCURRENCY": "10"}
387296
assert temp_runtime.deployment_mode == "STREAM_ONLY"
388297
assert temp_runtime.input_stream_ids == ["123", "456"]
389298
assert temp_runtime.output_stream_ids == ["321", "654"]
@@ -410,7 +319,6 @@ def test_initialize_model_deployment(self):
410319
"ocpus": 10,
411320
"memoryInGBs": 36,
412321
}
413-
assert temp_infrastructure.subnet_id == "fakeid.subnet.oc1.iad.xxx"
414322
assert temp_infrastructure.replica == 5
415323
assert temp_infrastructure.access_log == {
416324
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
@@ -468,7 +376,6 @@ def test_model_deployment_to_dict(self):
468376
"replica": 5,
469377
"shapeName": "VM.Standard.E4.Flex",
470378
"shapeConfigDetails": {"ocpus": 10, "memoryInGBs": 36},
471-
"subnetId": "fakeid.subnet.oc1.iad.xxx",
472379
"webConcurrency": 10,
473380
"accessLog": {
474381
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
@@ -489,7 +396,7 @@ def test_model_deployment_to_dict(self):
489396
"entrypoint": ["python", "/opt/ds/model/deployed_model/api.py"],
490397
"serverPort": 5000,
491398
"healthCheckPort": 5000,
492-
"env": {"WEB_CONCURRENCY": 10},
399+
"env": {"WEB_CONCURRENCY": "10"},
493400
"inputStreamIds": ["123", "456"],
494401
"outputStreamIds": ["321", "654"],
495402
"modelUri": "fakeid.datasciencemodel.oc1.iad.xxx",
@@ -525,7 +432,6 @@ def test_build_model_deployment_configuration_details(self, mock_prepare_artifac
525432
"ocpus": 10,
526433
"memoryInGBs": 36,
527434
},
528-
"subnetId": "fakeid.subnet.oc1.iad.xxx",
529435
},
530436
"modelId": "fakeid.datasciencemodel.oc1.iad.xxx",
531437
"scalingPolicy": {"policyType": "FIXED_SIZE", "instanceCount": 5},
@@ -689,7 +595,6 @@ def test_build_model_deployment_details(self, mock_prepare_artifact):
689595
instance_configuration.model_deployment_instance_shape_config_details.memory_in_gbs
690596
== model_deployment.infrastructure.shape_config_details["memoryInGBs"]
691597
)
692-
assert instance_configuration.subnet_id == model_deployment.infrastructure.subnet_id
693598

694599
scaling_policy = model_configuration_details.scaling_policy
695600
assert isinstance(scaling_policy, FixedSizeScalingPolicy)
@@ -790,7 +695,6 @@ def test_update_from_oci_model(self):
790695
infrastructure.shape_config_details["memoryInGBs"]
791696
== instance_configuration.model_deployment_instance_shape_config_details.memory_in_gbs
792697
)
793-
assert infrastructure.subnet_id == instance_configuration.subnet_id
794698
assert infrastructure.replica == scaling_policy.instance_count
795699

796700
category_log_details = OCI_MODEL_DEPLOYMENT_RESPONSE.category_log_details
@@ -853,55 +757,6 @@ def test_model_deployment_from_yaml(self):
853757
)
854758
assert isinstance(model_deployment_from_yaml.runtime, ModelDeploymentRuntime)
855759

856-
assert model_deployment_from_yaml.to_dict() == {
857-
"kind": "deployment",
858-
"type": "modelDeployment",
859-
"spec": {
860-
"displayName": "Generic Model Deployment With Small Artifact",
861-
"description": "The model deployment description",
862-
"definedTags": {"key1": {"skey1": "value1"}},
863-
"freeformTags": {"key1": "value1"},
864-
"infrastructure": {
865-
"kind": "infrastructure",
866-
"type": "datascienceModelDeployment",
867-
"spec": {
868-
"bandwidthMbps": 5,
869-
"compartmentId": "fakeid.compartment.oc1..xxx",
870-
"projectId": "fakeid.datascienceproject.oc1.iad.xxx",
871-
"replica": 5,
872-
"shapeName": "VM.Standard.E4.Flex",
873-
"shapeConfigDetails": {"ocpus": 10, "memoryInGBs": 36},
874-
"subnetId": "fakeid.subnet.oc1.iad.xxx",
875-
"accessLog": {
876-
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
877-
"logId": "fakeid.log.oc1.iad.xxx",
878-
},
879-
"predictLog": {
880-
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
881-
"logId": "fakeid.log.oc1.iad.xxx",
882-
},
883-
"webConcurrency": 5,
884-
},
885-
},
886-
"runtime": {
887-
"kind": "runtime",
888-
"type": "container",
889-
"spec": {
890-
"image": "iad.ocir.io/ociodscdev/ml_flask_app_demo:1.0.0",
891-
"imageDigest": "sha256:243590ea099af4019b6afc104b8a70b9552f0b001b37d0442f8b5a399244681c",
892-
"entrypoint": ["python", "/opt/ds/model/deployed_model/api.py"],
893-
"serverPort": 5000,
894-
"healthCheckPort": 5000,
895-
"env": {"key": "value"},
896-
"inputStreamIds": ["123", "456"],
897-
"outputStreamIds": ["321", "654"],
898-
"modelUri": "fakeid.datasciencemodel.oc1.iad.xxx",
899-
"deploymentMode": "STREAM_ONLY",
900-
},
901-
},
902-
},
903-
}
904-
905760
def test_model_deployment_from_dict(self):
906761
new_model_deployment = ModelDeployment.from_dict(
907762
copy.deepcopy(OCI_MODEL_DEPLOYMENT_DICT)
@@ -1038,7 +893,6 @@ def test_update_model_deployment_details(self, mock_prepare_artifact):
1038893
instance_configuration.model_deployment_instance_shape_config_details.memory_in_gbs
1039894
== model_deployment.infrastructure.shape_config_details["memoryInGBs"]
1040895
)
1041-
assert instance_configuration.subnet_id == model_deployment.infrastructure.subnet_id
1042896

1043897
scaling_policy = model_configuration_details.scaling_policy
1044898
assert isinstance(scaling_policy, FixedSizeScalingPolicy)
@@ -1090,7 +944,6 @@ def test_extract_from_oci_model(self):
1090944
"replica": 5,
1091945
"shapeName": "VM.Standard.E4.Flex",
1092946
"shapeConfigDetails": {"ocpus": 10, "memoryInGBs": 36},
1093-
"subnetId": "fakeid.subnet.oc1.iad.xxx",
1094947
"accessLog": {
1095948
"logGroupId": "fakeid.loggroup.oc1.iad.xxx",
1096949
"logId": "fakeid.log.oc1.iad.xxx",
@@ -1398,3 +1251,10 @@ def test_list_df(self, mock_list):
13981251
project_id="test_project_id",
13991252
)
14001253
assert isinstance(df, pandas.DataFrame)
1254+
1255+
def test_model_deployment_with_subnet_id(self):
1256+
model_deployment = self.initialize_model_deployment()
1257+
assert model_deployment.infrastructure.subnet_id == None
1258+
1259+
model_deployment.infrastructure.with_subnet_id("test_id")
1260+
assert model_deployment.infrastructure.subnet_id == "test_id"

0 commit comments

Comments
 (0)