Skip to content

Commit

Permalink
ECS: add pidMode validation for FARGATE (getmoto#6825)
Browse files Browse the repository at this point in the history
  • Loading branch information
cm-iwata authored and toshyak committed Oct 26, 2023
1 parent 82fa5ed commit acef73d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions moto/ecs/models.py
Expand Up @@ -1138,6 +1138,14 @@ def register_task_definition(
pid_mode: Optional[str] = None,
ephemeral_storage: Optional[Dict[str, int]] = None,
) -> TaskDefinition:

if requires_compatibilities and "FARGATE" in requires_compatibilities:
# TODO need more validation for Fargate
if pid_mode and pid_mode != "task":
raise EcsClientException(
f"Tasks using the Fargate launch type do not support pidMode '{pid_mode}'. The supported value for pidMode is 'task'."
)

if family in self.task_definitions:
last_id = self._get_last_task_definition_revision_id(family)
revision = (last_id or 0) + 1
Expand Down
27 changes: 27 additions & 0 deletions tests/test_ecs/test_ecs_boto3.py
Expand Up @@ -293,6 +293,33 @@ def test_register_task_definition():
)


@mock_ecs
def test_register_task_definition_fargate_with_pid_mode():
client = boto3.client("ecs", region_name="us-east-1")
definition = dict(
family="test_ecs_task",
containerDefinitions=[
{"name": "hello_world", "image": "hello-world:latest", "memory": 400}
],
requiresCompatibilities=["FARGATE"],
pidMode="host",
networkMode="awsvpc",
cpu="256",
memory="512",
)

with pytest.raises(ClientError) as exc:
client.register_task_definition(**definition)
ex = exc.value
assert ex.operation_name == "RegisterTaskDefinition"
assert ex.response["ResponseMetadata"]["HTTPStatusCode"] == 400
assert ex.response["Error"]["Code"] == "ClientException"
assert (
ex.response["Error"]["Message"]
== "Tasks using the Fargate launch type do not support pidMode 'host'. The supported value for pidMode is 'task'."
)


@mock_ecs
def test_list_task_definitions():
client = boto3.client("ecs", region_name="us-east-1")
Expand Down

0 comments on commit acef73d

Please sign in to comment.