Skip to content

Commit 5521550

Browse files
author
Sushanth Sathish Kumar
committed
fix: modify the mock boto client so that it correctly raises a ClientError
1 parent bc24f5e commit 5521550

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

tests/integ/test_model_monitor.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,86 @@ def test_default_monitor_create_stop_and_start_monitoring_schedule_with_customiz
958958
my_default_monitor.stop_monitoring_schedule()
959959

960960
_wait_for_schedule_changes_to_apply(monitor=my_default_monitor)
961+
962+
963+
@pytest.mark.skipif(
964+
tests.integ.test_region() in tests.integ.NO_MODEL_MONITORING_REGIONS,
965+
reason="ModelMonitoring is not yet supported in this region.",
966+
)
967+
def test_default_monitor_create_stop_and_start_monitoring_schedule_with_dashboards(
968+
sagemaker_session, output_kms_key, volume_kms_key, predictor
969+
):
970+
971+
my_default_monitor = DefaultModelMonitor(
972+
role=ROLE,
973+
instance_count=INSTANCE_COUNT,
974+
instance_type=INSTANCE_TYPE,
975+
volume_size_in_gb=VOLUME_SIZE_IN_GB,
976+
volume_kms_key=volume_kms_key,
977+
output_kms_key=output_kms_key,
978+
max_runtime_in_seconds=MAX_RUNTIME_IN_SECONDS,
979+
sagemaker_session=sagemaker_session,
980+
env=ENVIRONMENT,
981+
tags=TAGS,
982+
network_config=NETWORK_CONFIG,
983+
)
984+
985+
output_s3_uri = os.path.join(
986+
"s3://",
987+
sagemaker_session.default_bucket(),
988+
INTEG_TEST_MONITORING_OUTPUT_BUCKET,
989+
str(uuid.uuid4()),
990+
)
991+
992+
statistics = Statistics.from_file_path(
993+
statistics_file_path=os.path.join(tests.integ.DATA_DIR, "monitor/statistics.json"),
994+
sagemaker_session=sagemaker_session,
995+
)
996+
997+
constraints = Constraints.from_file_path(
998+
constraints_file_path=os.path.join(tests.integ.DATA_DIR, "monitor/constraints.json"),
999+
sagemaker_session=sagemaker_session,
1000+
)
1001+
1002+
my_default_monitor.create_monitoring_schedule(
1003+
endpoint_input=predictor.endpoint_name,
1004+
output_s3_uri=output_s3_uri,
1005+
statistics=statistics,
1006+
constraints=constraints,
1007+
schedule_cron_expression=CronExpressionGenerator.daily(),
1008+
enable_cloudwatch_metrics=ENABLE_CLOUDWATCH_METRICS,
1009+
)
1010+
1011+
schedule_description = my_default_monitor.describe_schedule()
1012+
_verify_default_monitoring_schedule(
1013+
sagemaker_session=sagemaker_session,
1014+
schedule_description=schedule_description,
1015+
statistics=statistics,
1016+
constraints=constraints,
1017+
output_kms_key=output_kms_key,
1018+
volume_kms_key=volume_kms_key,
1019+
network_config=NETWORK_CONFIG,
1020+
)
1021+
1022+
_wait_for_schedule_changes_to_apply(monitor=my_default_monitor)
1023+
1024+
my_default_monitor.stop_monitoring_schedule()
1025+
1026+
_wait_for_schedule_changes_to_apply(monitor=my_default_monitor)
1027+
1028+
stopped_schedule_description = my_default_monitor.describe_schedule()
1029+
assert stopped_schedule_description["MonitoringScheduleStatus"] == "Stopped"
1030+
1031+
my_default_monitor.start_monitoring_schedule()
1032+
1033+
_wait_for_schedule_changes_to_apply(monitor=my_default_monitor)
1034+
1035+
started_schedule_description = my_default_monitor.describe_schedule()
1036+
assert started_schedule_description["MonitoringScheduleStatus"] == "Scheduled"
1037+
1038+
my_default_monitor.stop_monitoring_schedule()
1039+
1040+
_wait_for_schedule_changes_to_apply(monitor=my_default_monitor)
9611041

9621042

9631043
@pytest.mark.skipif(

tests/unit/sagemaker/monitor/test_model_monitoring.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import sagemaker
2020
import pytest
2121
from mock import Mock, patch, MagicMock
22+
from botocore.exceptions import ClientError
2223

2324
from sagemaker.model_monitor import (
2425
ModelMonitor,
@@ -473,7 +474,12 @@
473474
def mock_get_dashboard(DashboardName):
474475
if DashboardName == EXISTING_DASHBOARD_NAME:
475476
return {"DashboardName": DashboardName, "DashboardBody": "dummy_dashboard_body"}
476-
raise ValueError(f"Dashboard '{DashboardName}' not found.")
477+
raise ClientError(
478+
error_response={
479+
"Error": {},
480+
},
481+
operation_name=f"Dashboard '{DashboardName}' not found.",
482+
)
477483

478484

479485
# TODO-reinvent-2019: Continue to flesh these out.

0 commit comments

Comments
 (0)