1313"""Integration tests for the SageMaker Endpoint API.
1414"""
1515
16- import botocore
17- from botocore import endpoint
1816import pytest
1917import logging
20- import time
18+
2119from typing import Dict
2220
2321from acktest .aws import s3
2927 create_sagemaker_resource ,
3028 assert_endpoint_status_in_sync ,
3129 assert_tags_in_sync ,
30+ get_sagemaker_endpoint ,
3231)
3332from e2e .replacement_values import REPLACEMENT_VALUES
3433from e2e .common import config as cfg
3534
3635FAIL_UPDATE_ERROR_MESSAGE = "EndpointUpdateError: unable to update endpoint. check FailureReason. latest EndpointConfigName is "
3736# 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+
3941
4042@pytest .fixture (scope = "module" )
4143def name_suffix ():
@@ -212,35 +214,17 @@ def faulty_config(name_suffix, single_container_model):
212214@service_marker
213215@pytest .mark .canary
214216class 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 ):
232218 (reference , resource , _ ) = xgboost_endpoint
233219 assert k8s .get_resource_exists (reference )
234220
235221 # endpoint has correct arn and status
236222 endpoint_name = resource ["spec" ].get ("endpointName" , None )
237223 assert endpoint_name is not None
238224
239- endpoint_desc = self ._describe_sagemaker_endpoint (
240- sagemaker_client , endpoint_name
241- )
225+ endpoint_desc = get_sagemaker_endpoint (endpoint_name )
242226 endpoint_arn = endpoint_desc ["EndpointArn" ]
243- assert self . _get_resource_endpoint_arn (resource ) == endpoint_arn
227+ assert k8s . get_resource_arn (resource ) == endpoint_arn
244228
245229 # endpoint transitions Creating -> InService state
246230 assert_endpoint_status_in_sync (
@@ -257,7 +241,7 @@ def create_endpoint_test(self, sagemaker_client, xgboost_endpoint):
257241 assert_tags_in_sync (endpoint_arn , resource_tags )
258242
259243 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
261245 ):
262246 (endpoint_reference , _ , endpoint_spec ) = xgboost_endpoint
263247 (_ , faulty_config_resource ) = faulty_config
@@ -284,25 +268,28 @@ def update_endpoint_failed_test(
284268 )
285269
286270 assert k8s .wait_on_condition (endpoint_reference , "ACK.ResourceSynced" , "False" )
287-
271+
288272 (_ , 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+ )
290276 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 ,
292281 )
293282
294283 endpoint_resource = k8s .get_resource (endpoint_reference )
295284 assert endpoint_resource ["status" ].get ("failureReason" , None ) is not None
296285
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 ):
300287 (endpoint_reference , endpoint_resource , endpoint_spec ) = xgboost_endpoint
301288
302289 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+ ]
306293 old_variant_instance_count = production_variants [0 ]["CurrentInstanceCount" ]
307294 old_variant_name = production_variants [0 ]["VariantName" ]
308295
@@ -338,9 +325,9 @@ def update_endpoint_successful_test(
338325 assert endpoint_resource ["status" ].get ("failureReason" , None ) is None
339326
340327 # 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+ ]
344331 assert len (new_production_variants ) > 1
345332 new_variant_instance_count = None
346333 for variant in new_production_variants :
@@ -349,14 +336,16 @@ def update_endpoint_successful_test(
349336
350337 assert new_variant_instance_count == old_variant_instance_count
351338
352- def delete_endpoint_test (self , sagemaker_client , xgboost_endpoint ):
339+ def delete_endpoint_test (self , xgboost_endpoint ):
353340 (reference , resource , _ ) = xgboost_endpoint
354341 endpoint_name = resource ["spec" ].get ("endpointName" , None )
355342
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+ )
357346 assert deleted
358347
359- assert self . _describe_sagemaker_endpoint ( sagemaker_client , endpoint_name ) is None
348+ assert get_sagemaker_endpoint ( endpoint_name ) is None
360349
361350 def test_driver (
362351 self ,
@@ -366,13 +355,11 @@ def test_driver(
366355 multi_variant_config ,
367356 xgboost_endpoint ,
368357 ):
369- self .create_endpoint_test (sagemaker_client , xgboost_endpoint )
358+ self .create_endpoint_test (xgboost_endpoint )
370359 self .update_endpoint_failed_test (
371- sagemaker_client , single_variant_config , faulty_config , xgboost_endpoint
360+ single_variant_config , faulty_config , xgboost_endpoint
372361 )
373362 # Note: the test has been intentionally ordered to run a successful update after a failed update
374363 # 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