diff --git a/ecs_deploy/ecs.py b/ecs_deploy/ecs.py index 0036624..5d03396 100644 --- a/ecs_deploy/ecs.py +++ b/ecs_deploy/ecs.py @@ -40,7 +40,10 @@ def describe_services(self, cluster_name, service_name): def describe_task_definition(self, task_definition_arn): try: return self.boto.describe_task_definition( - taskDefinition=task_definition_arn + taskDefinition=task_definition_arn, + include=[ + 'TAGS', + ] ) except ClientError: raise UnknownTaskDefinitionError( @@ -57,13 +60,14 @@ def describe_tasks(self, cluster_name, task_arns): return self.boto.describe_tasks(cluster=cluster_name, tasks=task_arns) def register_task_definition(self, family, containers, volumes, role_arn, - execution_role_arn, additional_properties): + execution_role_arn, tags, additional_properties): return self.boto.register_task_definition( family=family, containerDefinitions=containers, volumes=volumes, taskRoleArn=role_arn, executionRoleArn=execution_role_arn, + tags=tags, **additional_properties ) @@ -202,7 +206,7 @@ class EcsTaskDefinition(object): def __init__(self, containerDefinitions, volumes, family, revision, status, taskDefinitionArn, requiresAttributes=None, taskRoleArn=None, executionRoleArn=None, compatibilities=None, - **kwargs): + tags=None, **kwargs): self.containers = containerDefinitions self.volumes = volumes self.family = family @@ -212,6 +216,7 @@ def __init__(self, containerDefinitions, volumes, family, revision, self.requires_attributes = requiresAttributes or {} self.role_arn = taskRoleArn or u'' self.execution_role_arn = executionRoleArn or u'' + self.tags = tags self.additional_properties = kwargs self._diff = [] @@ -585,6 +590,7 @@ def get_task_definition(self, task_definition): ) task_definition = EcsTaskDefinition( + tags=task_definition_payload.get('tags', None), **task_definition_payload[u'taskDefinition'] ) return task_definition @@ -596,6 +602,7 @@ def update_task_definition(self, task_definition): volumes=task_definition.volumes, role_arn=task_definition.role_arn, execution_role_arn=task_definition.execution_role_arn, + tags=task_definition.tags, additional_properties=task_definition.additional_properties ) new_task_definition = EcsTaskDefinition(**response[u'taskDefinition']) diff --git a/tests/test_ecs.py b/tests/test_ecs.py index 1cf81e7..f931747 100644 --- a/tests/test_ecs.py +++ b/tests/test_ecs.py @@ -543,7 +543,7 @@ def test_client_describe_services(client): def test_client_describe_task_definition(client): client.describe_task_definition(u'task_definition_arn') - client.boto.describe_task_definition.assert_called_once_with(taskDefinition=u'task_definition_arn') + client.boto.describe_task_definition.assert_called_once_with(include=['TAGS'], taskDefinition=u'task_definition_arn') def test_client_describe_unknown_task_definition(client): @@ -575,6 +575,9 @@ def test_client_register_task_definition(client): revision=1, taskRoleArn=role_arn, executionRoleArn=execution_role_arn, + tags={ + 'Name': 'test_client_register_task_definition' + }, status='active', taskDefinitionArn='arn:task', requiresAttributes={}, @@ -587,6 +590,7 @@ def test_client_register_task_definition(client): volumes=task_definition.volumes, role_arn=task_definition.role_arn, execution_role_arn=execution_role_arn, + tags=task_definition.tags, additional_properties=task_definition.additional_properties ) @@ -596,6 +600,7 @@ def test_client_register_task_definition(client): volumes=volumes, taskRoleArn=role_arn, executionRoleArn=execution_role_arn, + tags=task_definition.tags, unkownProperty='foobar' ) @@ -711,6 +716,7 @@ def test_update_task_definition(client, task_definition): volumes=task_definition.volumes, role_arn=task_definition.role_arn, execution_role_arn=task_definition.execution_role_arn, + tags=task_definition.tags, additional_properties={ u'networkMode': u'host', u'placementConstraints': {}, @@ -943,7 +949,7 @@ def describe_tasks(self, cluster_name, task_arns): return deepcopy(RESPONSE_DESCRIBE_TASKS) def register_task_definition(self, family, containers, volumes, role_arn, - execution_role_arn, additional_properties): + execution_role_arn, tags, additional_properties): if not self.access_key_id or not self.secret_access_key: raise EcsConnectionError(u'Unable to locate credentials. Configure credentials by running "aws configure".') return deepcopy(RESPONSE_TASK_DEFINITION_2)