Add the status field to ECS task definitions (#3723)

Also I found extra tests for describe_task_definition and deregister_task_definition that were not being run,
so I changed their names so they are found by pytest and made them pass.  I also added checks to them for the new
status field.
This commit is contained in:
William Richard 2021-02-24 08:26:26 -05:00 committed by GitHub
parent 6a6c2ffd13
commit 0f4f01bb7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 10 deletions

View File

@ -177,6 +177,7 @@ class TaskDefinition(BaseObject, CloudFormationModel):
self.cpu = cpu self.cpu = cpu
self.memory = memory self.memory = memory
self.status = "ACTIVE"
@property @property
def response_object(self): def response_object(self):
@ -788,7 +789,9 @@ class EC2ContainerServiceBackend(BaseBackend):
family in self.task_definitions family in self.task_definitions
and revision in self.task_definitions[family] and revision in self.task_definitions[family]
): ):
return self.task_definitions[family].pop(revision) task_definition = self.task_definitions[family].pop(revision)
task_definition.status = "INACTIVE"
return task_definition
else: else:
raise TaskDefinitionNotFoundException raise TaskDefinitionNotFoundException

View File

@ -312,7 +312,7 @@ def test_list_task_definitions_with_family_prefix():
@mock_ecs @mock_ecs
def test_describe_task_definition(): def test_describe_task_definitions():
client = boto3.client("ecs", region_name="us-east-1") client = boto3.client("ecs", region_name="us-east-1")
_ = client.register_task_definition( _ = client.register_task_definition(
family="test_ecs_task", family="test_ecs_task",
@ -380,7 +380,7 @@ def test_describe_task_definition():
@mock_ecs @mock_ecs
def test_deregister_task_definition(): def test_deregister_task_definition_1():
client = boto3.client("ecs", region_name="us-east-1") client = boto3.client("ecs", region_name="us-east-1")
_ = client.register_task_definition( _ = client.register_task_definition(
family="test_ecs_task", family="test_ecs_task",
@ -400,8 +400,9 @@ def test_deregister_task_definition():
) )
response = client.deregister_task_definition(taskDefinition="test_ecs_task:1") response = client.deregister_task_definition(taskDefinition="test_ecs_task:1")
type(response["taskDefinition"]).should.be(dict) type(response["taskDefinition"]).should.be(dict)
response["taskDefinition"]["status"].should.equal("INACTIVE")
response["taskDefinition"]["taskDefinitionArn"].should.equal( response["taskDefinition"]["taskDefinitionArn"].should.equal(
"arn:aws:ecs:us-east-1:012345678910:task-definition/test_ecs_task:1" "arn:aws:ecs:us-east-1:{}:task-definition/test_ecs_task:1".format(ACCOUNT_ID)
) )
response["taskDefinition"]["containerDefinitions"][0]["name"].should.equal( response["taskDefinition"]["containerDefinitions"][0]["name"].should.equal(
"hello_world" "hello_world"
@ -426,7 +427,7 @@ def test_deregister_task_definition():
@mock_ecs @mock_ecs
def test_deregister_task_definition(): def test_deregister_task_definition_2():
client = boto3.client("ecs", region_name="us-east-1") client = boto3.client("ecs", region_name="us-east-1")
client.deregister_task_definition.when.called_with( client.deregister_task_definition.when.called_with(
taskDefinition="fake_task" taskDefinition="fake_task"
@ -1814,7 +1815,7 @@ def test_describe_tasks_exceptions():
@mock_ecs @mock_ecs
def describe_task_definition(): def test_describe_task_definition_by_family():
client = boto3.client("ecs", region_name="us-east-1") client = boto3.client("ecs", region_name="us-east-1")
container_definition = { container_definition = {
"name": "hello_world", "name": "hello_world",
@ -1828,13 +1829,19 @@ def describe_task_definition():
task_definition = client.register_task_definition( task_definition = client.register_task_definition(
family="test_ecs_task", containerDefinitions=[container_definition] family="test_ecs_task", containerDefinitions=[container_definition]
) )
family = task_definition["family"] family = task_definition["taskDefinition"]["family"]
task = client.describe_task_definition(taskDefinition=family) task = client.describe_task_definition(taskDefinition=family)["taskDefinition"]
task["containerDefinitions"][0].should.equal(container_definition) task["containerDefinitions"][0].should.equal(
dict(
container_definition,
**{"mountPoints": [], "portMappings": [], "volumesFrom": []}
)
)
task["taskDefinitionArn"].should.equal( task["taskDefinitionArn"].should.equal(
"arn:aws:ecs:us-east-1:012345678910:task-definition/test_ecs_task2:1" "arn:aws:ecs:us-east-1:{}:task-definition/test_ecs_task:1".format(ACCOUNT_ID)
) )
task["volumes"].should.equal([]) task["volumes"].should.equal([])
task["status"].should.equal("ACTIVE")
@mock_ec2 @mock_ec2