From 51afd54229c0ccde8b12a5cd671ae5b2d053bf6a Mon Sep 17 00:00:00 2001 From: Tom Elliff Date: Thu, 12 Oct 2017 13:26:19 +0100 Subject: [PATCH 1/2] Fix runningTasksCount ECS container instance attribute ECS container instances have attributes of 'runningTasksCount' and 'pendingTasksCount'. See Boto3 docs here: http://boto3.readthedocs.io/en/latest/reference/services/ecs.html#ECS.Client.describe_container_instances REST API docs here: http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeContainerInstances.html#API_DescribeContainerInstances_ResponseSyntax --- moto/ecs/models.py | 10 +++++----- tests/test_ecs/test_ecs_boto3.py | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/moto/ecs/models.py b/moto/ecs/models.py index bc847b32e..f5a928791 100644 --- a/moto/ecs/models.py +++ b/moto/ecs/models.py @@ -289,7 +289,7 @@ class ContainerInstance(BaseObject): 'type': 'STRINGSET'}] self.container_instance_arn = "arn:aws:ecs:us-east-1:012345678910:container-instance/{0}".format( str(uuid.uuid1())) - self.pending_task_count = 0 + self.pending_tasks_count = 0 self.remaining_resources = [ {'doubleValue': 0.0, 'integerValue': 4096, @@ -314,7 +314,7 @@ class ContainerInstance(BaseObject): 'stringSetValue': [], 'type': 'STRINGSET'} ] - self.running_task_count = 0 + self.running_tasks_count = 0 self.version_info = { 'agentVersion': "1.0.0", 'agentHash': '4023248', @@ -737,7 +737,7 @@ class EC2ContainerServiceBackend(BaseBackend): resource["stringSetValue"].remove(str(port)) else: resource["stringSetValue"].append(str(port)) - container_instance.running_task_count += resource_multiplier * 1 + container_instance.running_tasks_count += resource_multiplier * 1 def deregister_container_instance(self, cluster_str, container_instance_str, force): failures = [] @@ -748,11 +748,11 @@ class EC2ContainerServiceBackend(BaseBackend): container_instance = self.container_instances[cluster_name].get(container_instance_id) if container_instance is None: raise Exception("{0} is not a container id in the cluster") - if not force and container_instance.running_task_count > 0: + if not force and container_instance.running_tasks_count > 0: raise Exception("Found running tasks on the instance.") # Currently assume that people might want to do something based around deregistered instances # with tasks left running on them - but nothing if no tasks were running already - elif force and container_instance.running_task_count > 0: + elif force and container_instance.running_tasks_count > 0: if not self.container_instances.get('orphaned'): self.container_instances['orphaned'] = {} self.container_instances['orphaned'][container_instance_id] = container_instance diff --git a/tests/test_ecs/test_ecs_boto3.py b/tests/test_ecs/test_ecs_boto3.py index 1cc147fc5..990057749 100644 --- a/tests/test_ecs/test_ecs_boto3.py +++ b/tests/test_ecs/test_ecs_boto3.py @@ -1210,6 +1210,7 @@ def test_resource_reservation_and_release(): remaining_resources['MEMORY'].should.equal(registered_resources['MEMORY'] - 400) registered_resources['PORTS'].append('80') remaining_resources['PORTS'].should.equal(registered_resources['PORTS']) + container_instance_description['runningTasksCount'].should.equal(1) client.stop_task( cluster='test_ecs_cluster', task=run_response['tasks'][0].get('taskArn'), @@ -1223,6 +1224,7 @@ def test_resource_reservation_and_release(): remaining_resources['CPU'].should.equal(registered_resources['CPU']) remaining_resources['MEMORY'].should.equal(registered_resources['MEMORY']) remaining_resources['PORTS'].should.equal(registered_resources['PORTS']) + container_instance_description['runningTasksCount'].should.equal(0) @mock_ecs From a6c38913a7a8576c4192b3501620c062f17745cf Mon Sep 17 00:00:00 2001 From: Tom Elliff Date: Fri, 13 Oct 2017 09:37:39 +0100 Subject: [PATCH 2/2] Add more tests for task count of container instance --- tests/test_ecs/test_ecs_boto3.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_ecs/test_ecs_boto3.py b/tests/test_ecs/test_ecs_boto3.py index 990057749..9b6e99b57 100644 --- a/tests/test_ecs/test_ecs_boto3.py +++ b/tests/test_ecs/test_ecs_boto3.py @@ -714,6 +714,9 @@ def test_describe_container_instances(): for ci in response['containerInstances']] for arn in test_instance_arns: response_arns.should.contain(arn) + for instance in response['containerInstances']: + instance.keys().should.contain('runningTasksCount') + instance.keys().should.contain('pendingTasksCount') @mock_ec2