Skip to content

Commit 63cbe9b

Browse files
committed
fix: unique resource names for jumpstart integration tests
1 parent ddd06bb commit 63cbe9b

File tree

2 files changed

+6
-49
lines changed

2 files changed

+6
-49
lines changed

tests/integ/sagemaker/jumpstart/retrieve_uri/inference.py

+4-37
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# language governing permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

15-
import time
1615
import boto3
1716
import os
1817
from botocore.config import Config
@@ -23,7 +22,7 @@
2322
get_sm_session,
2423
)
2524

26-
from sagemaker.utils import repack_model
25+
from sagemaker.utils import repack_model, unique_name_from_base
2726
from tests.integ.sagemaker.jumpstart.constants import (
2827
ENV_VAR_JUMPSTART_SDK_TEST_SUITE_ID,
2928
JUMPSTART_TAG,
@@ -38,18 +37,14 @@ def __init__(
3837
model_uri,
3938
instance_type,
4039
environment_variables,
41-
suffix=time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime()),
4240
region=JUMPSTART_DEFAULT_REGION_NAME,
4341
boto_config=Config(retries={"max_attempts": 10, "mode": "standard"}),
44-
base_name="jumpstart-inference-job",
4542
execution_role=None,
4643
) -> None:
4744

48-
self.suffix = suffix
4945
self.test_suite_id = os.environ[ENV_VAR_JUMPSTART_SDK_TEST_SUITE_ID]
5046
self.region = region
5147
self.config = boto_config
52-
self.base_name = base_name
5348
self.execution_role = execution_role or get_sm_session().get_caller_identity_arn()
5449
self.account_id = boto3.client("sts").get_caller_identity()["Account"]
5550
self.image_uri = image_uri
@@ -110,41 +105,13 @@ def get_sagemaker_client(self) -> boto3.client:
110105
return boto3.client(service_name="sagemaker", config=self.config, region_name=self.region)
111106

112107
def get_endpoint_config_name(self) -> str:
113-
timestamp_length = len(self.suffix)
114-
non_timestamped_name = f"{self.base_name}-endpoint-config-"
115-
116-
max_endpoint_config_name_length = 63
117-
118-
if len(non_timestamped_name) > max_endpoint_config_name_length - timestamp_length:
119-
non_timestamped_name = non_timestamped_name[
120-
: max_endpoint_config_name_length - timestamp_length
121-
]
122-
123-
return f"{non_timestamped_name}{self.suffix}"
108+
return unique_name_from_base("endpoint-config")
124109

125110
def get_endpoint_name(self) -> str:
126-
timestamp_length = len(self.suffix)
127-
non_timestamped_name = f"{self.base_name}-endpoint-"
128-
129-
max_endpoint_name_length = 63
130-
131-
if len(non_timestamped_name) > max_endpoint_name_length - timestamp_length:
132-
non_timestamped_name = non_timestamped_name[
133-
: max_endpoint_name_length - timestamp_length
134-
]
135-
136-
return f"{non_timestamped_name}{self.suffix}"
111+
return unique_name_from_base("endpoint")
137112

138113
def get_model_name(self) -> str:
139-
timestamp_length = len(self.suffix)
140-
non_timestamped_name = f"{self.base_name}-model-"
141-
142-
max_model_name_length = 63
143-
144-
if len(non_timestamped_name) > max_model_name_length - timestamp_length:
145-
non_timestamped_name = non_timestamped_name[: max_model_name_length - timestamp_length]
146-
147-
return f"{non_timestamped_name}{self.suffix}"
114+
return unique_name_from_base("model")
148115

149116
def create_model(self) -> None:
150117
self.sagemaker_client.create_model(

tests/integ/sagemaker/jumpstart/retrieve_uri/training.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
from __future__ import absolute_import
1414

1515
import os
16-
import time
1716
import boto3
1817
from botocore.config import Config
1918

2019
from sagemaker.jumpstart.constants import JUMPSTART_DEFAULT_REGION_NAME
20+
from sagemaker.utils import unique_name_from_base
2121
from tests.integ.sagemaker.jumpstart.utils import (
2222
get_test_artifact_bucket,
2323
get_sm_session,
@@ -41,19 +41,15 @@ def __init__(
4141
hyperparameters,
4242
instance_type,
4343
training_dataset_s3_key,
44-
suffix=time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime()),
4544
region=JUMPSTART_DEFAULT_REGION_NAME,
4645
boto_config=Config(retries={"max_attempts": 10, "mode": "standard"}),
47-
base_name="jumpstart-training-job",
4846
execution_role=None,
4947
) -> None:
5048

5149
self.account_id = boto3.client("sts").get_caller_identity()["Account"]
52-
self.suffix = suffix
5350
self.test_suite_id = os.environ[ENV_VAR_JUMPSTART_SDK_TEST_SUITE_ID]
5451
self.region = region
5552
self.config = boto_config
56-
self.base_name = base_name
5753
self.execution_role = execution_role or get_sm_session().get_caller_identity_arn()
5854
self.image_uri = image_uri
5955
self.script_uri = script_uri
@@ -67,13 +63,7 @@ def get_sagemaker_client(self) -> boto3.client:
6763
return boto3.client(service_name="sagemaker", config=self.config, region_name=self.region)
6864

6965
def get_training_job_name(self) -> str:
70-
timestamp_length = len(self.suffix)
71-
non_timestamped_name = f"{self.base_name}-training-job-"
72-
73-
if len(non_timestamped_name) > 63 - timestamp_length:
74-
non_timestamped_name = non_timestamped_name[: 63 - timestamp_length]
75-
76-
return f"{non_timestamped_name}{self.suffix}"
66+
return unique_name_from_base("training-job")
7767

7868
def wait_until_training_job_complete(self):
7969
print("Waiting for training job to complete...")

0 commit comments

Comments
 (0)