ECS: add pidMode validation for FARGATE (#6825)
This commit is contained in:
parent
281b0f1caf
commit
2ada07ff44
@ -1138,6 +1138,14 @@ class EC2ContainerServiceBackend(BaseBackend):
|
||||
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
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user