13
13
"""Integration tests for the SageMaker Endpoint API.
14
14
"""
15
15
16
- import botocore
17
- from botocore import endpoint
18
16
import pytest
19
17
import logging
20
- import time
18
+
21
19
from typing import Dict
22
20
23
21
from acktest .aws import s3
29
27
create_sagemaker_resource ,
30
28
assert_endpoint_status_in_sync ,
31
29
assert_tags_in_sync ,
30
+ get_sagemaker_endpoint ,
32
31
)
33
32
from e2e .replacement_values import REPLACEMENT_VALUES
34
33
from e2e .common import config as cfg
35
34
36
35
FAIL_UPDATE_ERROR_MESSAGE = "EndpointUpdateError: unable to update endpoint. check FailureReason. latest EndpointConfigName is "
37
36
# annontation key for last endpoint config name used for update
38
- LAST_ENDPOINTCONFIG_UPDATE_ANNOTATION = "sagemaker.services.k8s.aws/last-endpoint-config-for-update"
37
+ LAST_ENDPOINTCONFIG_UPDATE_ANNOTATION = (
38
+ "sagemaker.services.k8s.aws/last-endpoint-config-for-update"
39
+ )
40
+
39
41
40
42
@pytest .fixture (scope = "module" )
41
43
def name_suffix ():
@@ -212,35 +214,17 @@ def faulty_config(name_suffix, single_container_model):
212
214
@service_marker
213
215
@pytest .mark .canary
214
216
class TestEndpoint :
215
- def _get_resource_endpoint_arn (self , resource : Dict ):
216
- assert (
217
- "ackResourceMetadata" in resource ["status" ]
218
- and "arn" in resource ["status" ]["ackResourceMetadata" ]
219
- )
220
- return resource ["status" ]["ackResourceMetadata" ]["arn" ]
221
-
222
- def _describe_sagemaker_endpoint (self , sagemaker_client , endpoint_name : str ):
223
- try :
224
- return sagemaker_client .describe_endpoint (EndpointName = endpoint_name )
225
- except botocore .exceptions .ClientError as error :
226
- logging .error (
227
- f"SageMaker could not find a endpoint with the name { endpoint_name } . Error { error } "
228
- )
229
- return None
230
-
231
- def create_endpoint_test (self , sagemaker_client , xgboost_endpoint ):
217
+ def create_endpoint_test (self , xgboost_endpoint ):
232
218
(reference , resource , _ ) = xgboost_endpoint
233
219
assert k8s .get_resource_exists (reference )
234
220
235
221
# endpoint has correct arn and status
236
222
endpoint_name = resource ["spec" ].get ("endpointName" , None )
237
223
assert endpoint_name is not None
238
224
239
- endpoint_desc = self ._describe_sagemaker_endpoint (
240
- sagemaker_client , endpoint_name
241
- )
225
+ endpoint_desc = get_sagemaker_endpoint (endpoint_name )
242
226
endpoint_arn = endpoint_desc ["EndpointArn" ]
243
- assert self . _get_resource_endpoint_arn (resource ) == endpoint_arn
227
+ assert k8s . get_resource_arn (resource ) == endpoint_arn
244
228
245
229
# endpoint transitions Creating -> InService state
246
230
assert_endpoint_status_in_sync (
@@ -257,7 +241,7 @@ def create_endpoint_test(self, sagemaker_client, xgboost_endpoint):
257
241
assert_tags_in_sync (endpoint_arn , resource_tags )
258
242
259
243
def update_endpoint_failed_test (
260
- self , sagemaker_client , single_variant_config , faulty_config , xgboost_endpoint
244
+ self , single_variant_config , faulty_config , xgboost_endpoint
261
245
):
262
246
(endpoint_reference , _ , endpoint_spec ) = xgboost_endpoint
263
247
(_ , faulty_config_resource ) = faulty_config
@@ -284,25 +268,28 @@ def update_endpoint_failed_test(
284
268
)
285
269
286
270
assert k8s .wait_on_condition (endpoint_reference , "ACK.ResourceSynced" , "False" )
287
-
271
+
288
272
(_ , old_config_resource ) = single_variant_config
289
- current_config_name = old_config_resource ["spec" ].get ("endpointConfigName" , None )
273
+ current_config_name = old_config_resource ["spec" ].get (
274
+ "endpointConfigName" , None
275
+ )
290
276
assert k8s .assert_condition_state_message (
291
- endpoint_reference , "ACK.Terminal" , "True" , FAIL_UPDATE_ERROR_MESSAGE + current_config_name ,
277
+ endpoint_reference ,
278
+ "ACK.Terminal" ,
279
+ "True" ,
280
+ FAIL_UPDATE_ERROR_MESSAGE + current_config_name ,
292
281
)
293
282
294
283
endpoint_resource = k8s .get_resource (endpoint_reference )
295
284
assert endpoint_resource ["status" ].get ("failureReason" , None ) is not None
296
285
297
- def update_endpoint_successful_test (
298
- self , sagemaker_client , multi_variant_config , xgboost_endpoint
299
- ):
286
+ def update_endpoint_successful_test (self , multi_variant_config , xgboost_endpoint ):
300
287
(endpoint_reference , endpoint_resource , endpoint_spec ) = xgboost_endpoint
301
288
302
289
endpoint_name = endpoint_resource ["spec" ].get ("endpointName" , None )
303
- production_variants = self . _describe_sagemaker_endpoint (
304
- sagemaker_client , endpoint_name
305
- )[ "ProductionVariants" ]
290
+ production_variants = get_sagemaker_endpoint ( endpoint_name )[
291
+ "ProductionVariants"
292
+ ]
306
293
old_variant_instance_count = production_variants [0 ]["CurrentInstanceCount" ]
307
294
old_variant_name = production_variants [0 ]["VariantName" ]
308
295
@@ -338,9 +325,9 @@ def update_endpoint_successful_test(
338
325
assert endpoint_resource ["status" ].get ("failureReason" , None ) is None
339
326
340
327
# RetainAllVariantProperties - variant properties were retained + is a multi-variant endpoint
341
- new_production_variants = self . _describe_sagemaker_endpoint (
342
- sagemaker_client , endpoint_name
343
- )[ "ProductionVariants" ]
328
+ new_production_variants = get_sagemaker_endpoint ( endpoint_name )[
329
+ "ProductionVariants"
330
+ ]
344
331
assert len (new_production_variants ) > 1
345
332
new_variant_instance_count = None
346
333
for variant in new_production_variants :
@@ -349,14 +336,16 @@ def update_endpoint_successful_test(
349
336
350
337
assert new_variant_instance_count == old_variant_instance_count
351
338
352
- def delete_endpoint_test (self , sagemaker_client , xgboost_endpoint ):
339
+ def delete_endpoint_test (self , xgboost_endpoint ):
353
340
(reference , resource , _ ) = xgboost_endpoint
354
341
endpoint_name = resource ["spec" ].get ("endpointName" , None )
355
342
356
- _ , deleted = k8s .delete_custom_resource (reference , cfg .DELETE_WAIT_PERIOD , cfg .DELETE_WAIT_LENGTH )
343
+ _ , deleted = k8s .delete_custom_resource (
344
+ reference , cfg .DELETE_WAIT_PERIOD , cfg .DELETE_WAIT_LENGTH
345
+ )
357
346
assert deleted
358
347
359
- assert self . _describe_sagemaker_endpoint ( sagemaker_client , endpoint_name ) is None
348
+ assert get_sagemaker_endpoint ( endpoint_name ) is None
360
349
361
350
def test_driver (
362
351
self ,
@@ -366,13 +355,11 @@ def test_driver(
366
355
multi_variant_config ,
367
356
xgboost_endpoint ,
368
357
):
369
- self .create_endpoint_test (sagemaker_client , xgboost_endpoint )
358
+ self .create_endpoint_test (xgboost_endpoint )
370
359
self .update_endpoint_failed_test (
371
- sagemaker_client , single_variant_config , faulty_config , xgboost_endpoint
360
+ single_variant_config , faulty_config , xgboost_endpoint
372
361
)
373
362
# Note: the test has been intentionally ordered to run a successful update after a failed update
374
363
# check that controller updates the endpoint, removes the terminal condition and clears the failure reason
375
- self .update_endpoint_successful_test (
376
- sagemaker_client , multi_variant_config , xgboost_endpoint
377
- )
378
- self .delete_endpoint_test (sagemaker_client , xgboost_endpoint )
364
+ self .update_endpoint_successful_test (multi_variant_config , xgboost_endpoint )
365
+ self .delete_endpoint_test (xgboost_endpoint )
0 commit comments