Merge pull request #2948 from rifqifatih/ecs-placement-constraints
ECS: add placement constraints
This commit is contained in:
commit
067b7f3f5b
@ -121,6 +121,7 @@ class TaskDefinition(BaseObject):
|
||||
network_mode=None,
|
||||
volumes=None,
|
||||
tags=None,
|
||||
placement_constraints=None,
|
||||
):
|
||||
self.family = family
|
||||
self.revision = revision
|
||||
@ -137,6 +138,9 @@ class TaskDefinition(BaseObject):
|
||||
self.network_mode = "bridge"
|
||||
else:
|
||||
self.network_mode = network_mode
|
||||
self.placement_constraints = (
|
||||
placement_constraints if placement_constraints is not None else []
|
||||
)
|
||||
|
||||
@property
|
||||
def response_object(self):
|
||||
@ -558,7 +562,13 @@ class EC2ContainerServiceBackend(BaseBackend):
|
||||
raise Exception("{0} is not a cluster".format(cluster_name))
|
||||
|
||||
def register_task_definition(
|
||||
self, family, container_definitions, volumes=None, network_mode=None, tags=None
|
||||
self,
|
||||
family,
|
||||
container_definitions,
|
||||
volumes=None,
|
||||
network_mode=None,
|
||||
tags=None,
|
||||
placement_constraints=None,
|
||||
):
|
||||
if family in self.task_definitions:
|
||||
last_id = self._get_last_task_definition_revision_id(family)
|
||||
@ -574,6 +584,7 @@ class EC2ContainerServiceBackend(BaseBackend):
|
||||
volumes=volumes,
|
||||
network_mode=network_mode,
|
||||
tags=tags,
|
||||
placement_constraints=placement_constraints,
|
||||
)
|
||||
self.task_definitions[family][revision] = task_definition
|
||||
|
||||
|
@ -63,12 +63,14 @@ class EC2ContainerServiceResponse(BaseResponse):
|
||||
volumes = self._get_param("volumes")
|
||||
tags = self._get_param("tags")
|
||||
network_mode = self._get_param("networkMode")
|
||||
placement_constraints = self._get_param("placementConstraints")
|
||||
task_definition = self.ecs_backend.register_task_definition(
|
||||
family,
|
||||
container_definitions,
|
||||
volumes=volumes,
|
||||
network_mode=network_mode,
|
||||
tags=tags,
|
||||
placement_constraints=placement_constraints,
|
||||
)
|
||||
return json.dumps({"taskDefinition": task_definition.response_object})
|
||||
|
||||
|
@ -2604,3 +2604,36 @@ def test_ecs_service_untag_resource_multiple_tags():
|
||||
resourceArn=response["service"]["serviceArn"]
|
||||
)
|
||||
response["tags"].should.equal([{"key": "hello", "value": "world"}])
|
||||
|
||||
|
||||
@mock_ecs
|
||||
def test_ecs_task_definition_placement_constraints():
|
||||
client = boto3.client("ecs", region_name="us-east-1")
|
||||
response = client.register_task_definition(
|
||||
family="test_ecs_task",
|
||||
containerDefinitions=[
|
||||
{
|
||||
"name": "hello_world",
|
||||
"image": "docker/hello-world:latest",
|
||||
"cpu": 1024,
|
||||
"memory": 400,
|
||||
"essential": True,
|
||||
"environment": [
|
||||
{"name": "AWS_ACCESS_KEY_ID", "value": "SOME_ACCESS_KEY"}
|
||||
],
|
||||
"logConfiguration": {"logDriver": "json-file"},
|
||||
}
|
||||
],
|
||||
networkMode="bridge",
|
||||
tags=[
|
||||
{"key": "createdBy", "value": "moto-unittest"},
|
||||
{"key": "foo", "value": "bar"},
|
||||
],
|
||||
placementConstraints=[
|
||||
{"type": "memberOf", "expression": "attribute:ecs.instance-type =~ t2.*"}
|
||||
],
|
||||
)
|
||||
type(response["taskDefinition"]["placementConstraints"]).should.be(list)
|
||||
response["taskDefinition"]["placementConstraints"].should.equal(
|
||||
[{"type": "memberOf", "expression": "attribute:ecs.instance-type =~ t2.*"}]
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user