Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECS: add pidMode validation for FARGATE #6825

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions moto/ecs/models.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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