Skip to content

Commit 09b9ae6

Browse files
Yadan-WeiYadan Wei
andauthored
Add Deep Canary For Public Registry (#5045)
* add public registry deep canary * reformat * fix typo * handle lookup function issue * remove unuseful assert --------- Co-authored-by: Yadan Wei <yadanwei@amazon.com>
1 parent f49bd01 commit 09b9ae6

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

test/dlc_tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,13 @@ def lookup_condition(lookup, image):
17991799
def pytest_generate_tests(metafunc):
18001800
images = metafunc.config.getoption("--images")
18011801

1802+
# Check for public registry canary first
1803+
if os.getenv("IS_PUBLIC_REGISTRY_CANARY", "false").lower() == "true":
1804+
# Only handle framework agnostic tests for public registry
1805+
if "image" in metafunc.fixturenames:
1806+
metafunc.parametrize("image", images)
1807+
return
1808+
18021809
# Parametrize framework specific tests
18031810
for fixture in FRAMEWORK_FIXTURES:
18041811
if fixture in metafunc.fixturenames:

test/dlc_tests/sanity/test_canary_integration.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,25 @@
2525
@pytest.mark.integration("deep_canary")
2626
def test_deep_canary_integration(image, region):
2727
ctx = Context()
28-
image_account_id = get_account_id_from_image_uri(image)
29-
image_region = get_region_from_image_uri(image)
30-
assert image_region == region, f"Problem: Test region {region} != canary region {image_region}"
28+
if os.getenv("IS_PUBLIC_REGISTRY_CANARY", "false").lower() == "true":
29+
# If the image is a public registry canary, we don't need to login to ECR
30+
LOGGER.info(f"Deep Canary pull test for public registry canary {image}")
31+
try:
32+
ctx.run(f"docker pull {image}", hide="out")
33+
LOGGER.info(f"Deep Canary pull test succeeded for {image}")
34+
finally:
35+
ctx.run(f"docker rmi {image}", warn=True, hide="out")
36+
return
37+
else:
38+
image_account_id = get_account_id_from_image_uri(image)
39+
image_region = get_region_from_image_uri(image)
40+
assert (
41+
image_region == region
42+
), f"Problem: Test region {region} != canary region {image_region}"
3143

32-
try:
33-
login_to_ecr_registry(ctx, image_account_id, region)
34-
ctx.run(f"docker pull {image}", hide="out")
35-
LOGGER.info(f"Deep Canary pull test succeeded for {image}")
36-
finally:
37-
ctx.run(f"docker rmi {image}", warn=True, hide="out")
44+
try:
45+
login_to_ecr_registry(ctx, image_account_id, region)
46+
ctx.run(f"docker pull {image}", hide="out")
47+
LOGGER.info(f"Deep Canary pull test succeeded for {image}")
48+
finally:
49+
ctx.run(f"docker rmi {image}", warn=True, hide="out")

test/test_utils/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ def get_ami_id_ssm(region_name, parameter_path):
239239
SAGEMAKER_REMOTE_TEST_TYPE = "sagemaker"
240240

241241
PUBLIC_DLC_REGISTRY = "763104351884"
242+
DLC_PUBLIC_REGISTRY_ALIAS = "public.ecr.aws/deep-learning-containers"
242243

243244
SAGEMAKER_EXECUTION_REGIONS = ["us-west-2", "us-east-1", "eu-west-1"]
244245
# Before SM GA with Trn1, they support launch of ml.trn1 instance only in us-east-1. After SM GA this can be removed
@@ -1318,6 +1319,7 @@ def get_dlc_images():
13181319
canary_arch_type=get_test_job_arch_type(),
13191320
canary_region=os.getenv("AWS_REGION"),
13201321
canary_region_prod_account=os.getenv("REGIONAL_PROD_ACCOUNT", PUBLIC_DLC_REGISTRY),
1322+
is_public_registry=os.getenv("IS_PUBLIC_REGISTRY_CANARY", "false").lower() == "true",
13211323
)
13221324
return " ".join(deep_canary_images)
13231325
elif is_pr_context() or is_empty_build_context():
@@ -1345,6 +1347,7 @@ def get_deep_canary_images(
13451347
canary_arch_type,
13461348
canary_region,
13471349
canary_region_prod_account,
1350+
is_public_registry=False,
13481351
):
13491352
"""
13501353
For an input combination of canary job specs, find a matching list of image uris to be tested
@@ -1382,9 +1385,17 @@ def get_deep_canary_images(
13821385
and canary_image_type == image_type
13831386
and canary_arch_type == image_arch_type
13841387
):
1385-
regionalized_image_uri = image_uri.replace(image_region, canary_region).replace(
1386-
image_account_id, canary_region_prod_account
1387-
)
1388+
if is_public_registry:
1389+
# For public registry, we use the public account ID
1390+
image_repository = image_uri.split("/")[-1].split(":")[0]
1391+
image_tag = image_uri.split(":")[-1]
1392+
regionalized_image_uri = (
1393+
f"{DLC_PUBLIC_REGISTRY_ALIAS}/{image_repository}:{image_tag}"
1394+
)
1395+
else:
1396+
regionalized_image_uri = image_uri.replace(image_region, canary_region).replace(
1397+
image_account_id, canary_region_prod_account
1398+
)
13881399
matching_images.append(regionalized_image_uri)
13891400
return matching_images
13901401

0 commit comments

Comments
 (0)