ECS:run_task - persist launchType (#4733)

This commit is contained in:
Bert Blommers 2021-12-31 15:55:48 -01:00 committed by GitHub
parent 3f79f7f6c7
commit 307104417b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 5 deletions

View File

@ -289,6 +289,7 @@ class Task(BaseObject):
container_instance_arn,
resource_requirements,
backend,
launch_type="",
overrides=None,
started_by="",
tags=None,
@ -304,6 +305,7 @@ class Task(BaseObject):
self.containers = []
self.started_by = started_by
self.tags = tags or []
self.launch_type = launch_type
self.stopped_reason = ""
self.resource_requirements = resource_requirements
self.region_name = cluster.region_name
@ -887,7 +889,14 @@ class EC2ContainerServiceBackend(BaseBackend):
raise TaskDefinitionNotFoundException
def run_task(
self, cluster_str, task_definition_str, count, overrides, started_by, tags
self,
cluster_str,
task_definition_str,
count,
overrides,
started_by,
tags,
launch_type,
):
cluster = self._get_cluster(cluster_str)
@ -930,6 +939,7 @@ class EC2ContainerServiceBackend(BaseBackend):
overrides=overrides or {},
started_by=started_by or "",
tags=tags or [],
launch_type=launch_type or "",
)
self.update_container_instance_resources(
container_instance, resource_requirements

View File

@ -118,8 +118,15 @@ class EC2ContainerServiceResponse(BaseResponse):
count = self._get_int_param("count")
started_by = self._get_param("startedBy")
tags = self._get_param("tags")
launch_type = self._get_param("launchType")
tasks = self.ecs_backend.run_task(
cluster_str, task_definition_str, count, overrides, started_by, tags
cluster_str,
task_definition_str,
count,
overrides,
started_by,
tags,
launch_type,
)
return json.dumps(
{"tasks": [task.response_object for task in tasks], "failures": []}

View File

@ -1611,7 +1611,7 @@ def test_run_task_default_cluster():
ec2_utils.generate_instance_identity_document(test_instance)
)
response = client.register_container_instance(
client.register_container_instance(
cluster=test_cluster_name, instanceIdentityDocument=instance_id_document
)
@ -1639,6 +1639,7 @@ def test_run_task_default_cluster():
startedBy="moto",
)
len(response["tasks"]).should.equal(2)
response["tasks"][0].should.have.key("launchType").equals("FARGATE")
response["tasks"][0]["taskArn"].should.match(
"arn:aws:ecs:us-east-1:{}:task/[a-z0-9-]+$".format(ACCOUNT_ID)
)
@ -1744,7 +1745,7 @@ def test_start_task():
ec2_utils.generate_instance_identity_document(test_instance)
)
response = client.register_container_instance(
client.register_container_instance(
cluster=test_cluster_name, instanceIdentityDocument=instance_id_document
)
@ -1913,7 +1914,7 @@ def test_describe_tasks():
ec2_utils.generate_instance_identity_document(test_instance)
)
response = client.register_container_instance(
client.register_container_instance(
cluster=test_cluster_name, instanceIdentityDocument=instance_id_document
)