forked from aws-controllers-k8s/sagemaker-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_endpoint_config.py
97 lines (82 loc) · 3.44 KB
/
test_endpoint_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may
# not use this file except in compliance with the License. A copy of the
# License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
"""Integration tests for the SageMaker EndpointConfig API.
"""
import pytest
import logging
from typing import Dict
import time
from acktest.resources import random_suffix_name
from acktest.k8s import resource as k8s
from e2e import (
service_marker,
create_sagemaker_resource,
delete_custom_resource,
assert_tags_in_sync,
get_sagemaker_endpoint_config,
)
from e2e.replacement_values import REPLACEMENT_VALUES
from e2e.common import config as cfg
@pytest.fixture(scope="module")
def single_variant_config():
config_resource_name = random_suffix_name("single-variant-config", 32)
model_resource_name = config_resource_name + "-model"
replacements = REPLACEMENT_VALUES.copy()
replacements["ENDPOINT_CONFIG_NAME"] = config_resource_name
replacements["MODEL_NAME"] = model_resource_name
model_reference, model_spec, model_resource = create_sagemaker_resource(
resource_plural=cfg.MODEL_RESOURCE_PLURAL,
resource_name=model_resource_name,
spec_file="xgboost_model",
replacements=replacements,
)
assert model_resource is not None
if k8s.get_resource_arn(model_resource) is None:
logging.error(
f"ARN for this resource is None, resource status is: {model_resource['status']}"
)
assert k8s.get_resource_arn(model_resource) is not None
config_reference, config_spec, config_resource = create_sagemaker_resource(
resource_plural=cfg.ENDPOINT_CONFIG_RESOURCE_PLURAL,
resource_name=config_resource_name,
spec_file="endpoint_config_single_variant",
replacements=replacements,
)
assert config_resource is not None
yield (config_reference, config_resource)
k8s.delete_custom_resource(
model_reference, cfg.DELETE_WAIT_PERIOD, cfg.DELETE_WAIT_LENGTH
)
# Delete the k8s resource if not already deleted by tests
assert delete_custom_resource(
config_reference, cfg.DELETE_WAIT_PERIOD, cfg.DELETE_WAIT_LENGTH
)
@service_marker
@pytest.mark.canary
class TestEndpointConfig:
def test_create_endpoint_config(self, single_variant_config):
(reference, resource) = single_variant_config
assert k8s.get_resource_exists(reference)
config_name = resource["spec"].get("endpointConfigName", None)
endpoint_config_desc = get_sagemaker_endpoint_config(config_name)
endpoint_arn = endpoint_config_desc["EndpointConfigArn"]
assert k8s.get_resource_arn(resource) == endpoint_arn
# random sleep before we check for tags to reduce test flakyness
time.sleep(cfg.TAG_DELAY_SLEEP)
resource_tags = resource["spec"].get("tags", None)
assert_tags_in_sync(endpoint_arn, resource_tags)
# Delete the k8s resource.
assert delete_custom_resource(
reference, cfg.DELETE_WAIT_PERIOD, cfg.DELETE_WAIT_LENGTH
)
assert get_sagemaker_endpoint_config(config_name) is None