Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions tests/integration/local/invoke/test_integrations_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,16 +799,35 @@ def _create_cred_file(self, profile):
return custom_cred


# These tests require to remove all sam cli images and can't be run in parallel
class TestLayerVersionBase(InvokeIntegBase):
region = "us-west-2"
layer_utils = LayerUtils(region=region)

def setUp(self):
self.layer_cache = Path().home().joinpath("integ_layer_cache")

@staticmethod
def _cleanup_samcli_images(docker_client):
"""Remove all samcli/lambda-* images.

Docker's images.list(name="samcli/lambda") does exact repository matching
and won't match repositories like "samcli/lambda-python". We list all images
and filter by tag prefix instead.
"""
try:
all_images = docker_client.images.list()
for image in all_images:
for tag in image.tags:
if tag.startswith("samcli/lambda-"):
docker_client.remove_image_safely(image.id, force=True)
break
except Exception:
pass

def tearDown(self):
# Only clean the layer cache between test methods, not Docker images.
# Docker images are shared across tests and cleaned up by CI runner.
docker_client = get_validated_container_client()
self._cleanup_samcli_images(docker_client)
shutil.rmtree(str(self.layer_cache), ignore_errors=True)

@classmethod
Expand Down Expand Up @@ -1066,7 +1085,16 @@ def setUp(self):
self.layer_cache = Path().home().joinpath("integ_layer_cache")

def tearDown(self):
pass
docker_client = get_validated_container_client()
try:
all_images = docker_client.images.list()
for image in all_images:
for tag in image.tags:
if tag.startswith("samcli/lambda-"):
docker_client.remove_image_safely(image.id, force=True)
break
except Exception:
pass

def test_layer_does_not_exist(self):
self.layer_utils.upsert_layer(LayerUtils.generate_layer_name(), "LayerOneArn", "layer1.zip")
Expand Down
Loading