Skip to content

Commit

Permalink
Add support for ecs task def tagging (#478)
Browse files Browse the repository at this point in the history
* Add support for ecs task def tagging

* Update docs string
  • Loading branch information
stlava authored Apr 16, 2019
1 parent cc7a029 commit 4e80a08
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 17 deletions.
32 changes: 24 additions & 8 deletions kingpin/actors/aws/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ class ServiceNotFound(exceptions.RecoverableActorFailure):
}
}
}
},
'tags': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'key': {'type': 'string'},
'value': {'type': 'string'}
}
}
}
}
}
Expand Down Expand Up @@ -307,15 +317,19 @@ def _describe_task_definition(self, task_definition_name):
task_definition_name: Task Definition string.
Returns:
Task Definition description dict.
Returns a dict containing the task definition dict and task
definition tags list.
"""
self.log.info('Describing task definition {}.'.format(
task_definition_name))
task_definition = yield self.api_call(
resp = yield self.api_call(
self.ecs_conn.describe_task_definition,
taskDefinition=task_definition_name)
taskDefinition=task_definition_name,
include=['TAGS'])

raise gen.Return(task_definition['taskDefinition'])
del resp['ResponseMetadata']

raise gen.Return(resp)

@gen.coroutine
@dry('Would list task definitions')
Expand Down Expand Up @@ -938,10 +952,12 @@ def _is_task_definition_different(self, old_task_definition_name,
old_task_definition_name)
new_task_definition = yield self._describe_task_definition(
new_task_definition_name)
del new_task_definition['revision']
del new_task_definition['taskDefinitionArn']
del old_task_definition['revision']
del old_task_definition['taskDefinitionArn']

del new_task_definition['taskDefinition']['revision']
del new_task_definition['taskDefinition']['taskDefinitionArn']
del old_task_definition['taskDefinition']['revision']
del old_task_definition['taskDefinition']['taskDefinitionArn']

raise gen.Return(old_task_definition != new_task_definition)

@gen.coroutine
Expand Down
56 changes: 48 additions & 8 deletions kingpin/actors/aws/test/test_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,26 @@ def setUp(self):
@testing.gen_test
def test_call(self):
task_definition = {'family': 'family'}
task_tags = [
{
'key': 'foo',
'value': 'bar'
}
]
task_definition_name = 'task_definition'
self.actor.ecs_conn.describe_task_definition.return_value = {
'taskDefinition': task_definition}
'taskDefinition': task_definition,
'tags': task_tags,
'ResponseMetadata': 'metadata'}
result = yield self.actor._describe_task_definition(
task_definition_name)
self.assertEqual(result, task_definition)
self.assertEqual(result, {
'taskDefinition': task_definition,
'tags': task_tags})

call_args = self.actor.ecs_conn.describe_task_definition.call_args
expected = ({'taskDefinition': task_definition_name},)
expected = ({'taskDefinition': task_definition_name,
'include': ['TAGS'], },)
self.assertEqual(call_args, expected)


Expand Down Expand Up @@ -831,16 +842,18 @@ def test_same(self):
def mock_describe_task_definition(*args, **kwargs):
mock_describe_task_definition.call_count += 1
if mock_describe_task_definition.call_count == 1:
raise gen.Return({
raise gen.Return({'taskDefinition': {
'revision': 0,
'taskDefinitionArn': 'arn/family:1',
'family': 'family'
}, 'tags': [{'key': 'foo', 'value': 'bar'}]
})
if mock_describe_task_definition.call_count == 2:
raise gen.Return({
raise gen.Return({'taskDefinition': {
'revision': 0,
'taskDefinitionArn': 'arn/family:2',
'family': 'family'
}, 'tags': [{'key': 'foo', 'value': 'bar'}]
})
if mock_describe_task_definition.call_count > 2:
self.fail('Called more than twice.')
Expand All @@ -856,16 +869,43 @@ def test_different(self):
def mock_describe_task_definition(*args, **kwargs):
mock_describe_task_definition.call_count += 1
if mock_describe_task_definition.call_count == 1:
raise gen.Return({
raise gen.Return({'taskDefinition': {
'revision': 0,
'taskDefinitionArn': 'arn/family:1',
'family': 'family1'
})
}})
if mock_describe_task_definition.call_count == 2:
raise gen.Return({
raise gen.Return({'taskDefinition': {
'revision': 0,
'taskDefinitionArn': 'arn/family:2',
'family': 'family2'
}})
if mock_describe_task_definition.call_count > 2:
self.fail('Called more than twice.')

mock_describe_task_definition.call_count = 0
self.actor._describe_task_definition = mock_describe_task_definition
diff = yield self.actor._is_task_definition_different('a', 'b')
self.assertEquals(diff, True)

@testing.gen_test
def test_different_tags(self):
@gen.coroutine
def mock_describe_task_definition(*args, **kwargs):
mock_describe_task_definition.call_count += 1
if mock_describe_task_definition.call_count == 1:
raise gen.Return({'taskDefinition': {
'revision': 0,
'taskDefinitionArn': 'arn/family:1',
'family': 'family'
}, 'tags': [{'key': 'foo', 'value': 'bar'}]
})
if mock_describe_task_definition.call_count == 2:
raise gen.Return({'taskDefinition': {
'revision': 0,
'taskDefinitionArn': 'arn/family:2',
'family': 'family'
}, 'tags': [{'key': 'foo', 'value': 'baz'}]
})
if mock_describe_task_definition.call_count > 2:
self.fail('Called more than twice.')
Expand Down
2 changes: 1 addition & 1 deletion kingpin/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# Copyright 2018 Nextdoor.com, Inc


__version__ = '0.5.8'
__version__ = '0.5.9'

0 comments on commit 4e80a08

Please sign in to comment.