From 1993e3f4ec70c6b5bf9abc65b030406abb7401e7 Mon Sep 17 00:00:00 2001 From: Dominik Schubert Date: Fri, 3 Dec 2021 15:46:24 +0100 Subject: [PATCH] ECS - Fix tag/untag for with multiple services in cluster (#4649) --- moto/ecs/models.py | 4 ++-- tests/test_ecs/test_ecs_boto3.py | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/moto/ecs/models.py b/moto/ecs/models.py index 149c38b24..79c823698 100644 --- a/moto/ecs/models.py +++ b/moto/ecs/models.py @@ -1568,7 +1568,7 @@ class EC2ContainerServiceBackend(BaseBackend): for service in self.services.values(): if service.arn == resource_arn: service.tags = self._merge_tags(service.tags, tags) - return {} + return {} else: raise ServiceNotFoundException raise NotImplementedError() @@ -1594,7 +1594,7 @@ class EC2ContainerServiceBackend(BaseBackend): service.tags = [ tag for tag in service.tags if tag["key"] not in tag_keys ] - return {} + return {} else: raise ServiceNotFoundException raise NotImplementedError() diff --git a/tests/test_ecs/test_ecs_boto3.py b/tests/test_ecs/test_ecs_boto3.py index 04daf7e34..80aa63211 100644 --- a/tests/test_ecs/test_ecs_boto3.py +++ b/tests/test_ecs/test_ecs_boto3.py @@ -2766,26 +2766,50 @@ def test_ecs_service_tag_resource(): } ], ) - response = client.create_service( + create_response2 = client.create_service( + cluster="test_ecs_cluster", + serviceName="test_ecs_service_2", + taskDefinition="test_ecs_task", + desiredCount=1, + ) + create_response = client.create_service( cluster="test_ecs_cluster", serviceName="test_ecs_service", taskDefinition="test_ecs_task", desiredCount=2, ) + client.tag_resource( - resourceArn=response["service"]["serviceArn"], + resourceArn=create_response["service"]["serviceArn"], tags=[ {"key": "createdBy", "value": "moto-unittest"}, {"key": "foo", "value": "bar"}, ], ) + client.tag_resource( + resourceArn=create_response2["service"]["serviceArn"], + tags=[ + {"key": "createdBy-2", "value": "moto-unittest-2"}, + {"key": "foo-2", "value": "bar-2"}, + ], + ) response = client.list_tags_for_resource( - resourceArn=response["service"]["serviceArn"] + resourceArn=create_response["service"]["serviceArn"] ) type(response["tags"]).should.be(list) response["tags"].should.equal( [{"key": "createdBy", "value": "moto-unittest"}, {"key": "foo", "value": "bar"}] ) + response2 = client.list_tags_for_resource( + resourceArn=create_response2["service"]["serviceArn"] + ) + type(response2["tags"]).should.be(list) + response2["tags"].should.equal( + [ + {"key": "createdBy-2", "value": "moto-unittest-2"}, + {"key": "foo-2", "value": "bar-2"}, + ] + ) @mock_ecs