Batch: create_compute_environment() now validates instanceRole and minvCpu (#6470)
This commit is contained in:
parent
bf3c9768b2
commit
8e35eedc3d
@ -1272,6 +1272,10 @@ class BatchBackend(BaseBackend):
|
|||||||
if "FARGATE" not in cr["type"]:
|
if "FARGATE" not in cr["type"]:
|
||||||
# Most parameters are not applicable to jobs that are running on Fargate resources:
|
# Most parameters are not applicable to jobs that are running on Fargate resources:
|
||||||
# non exhaustive list: minvCpus, instanceTypes, imageId, ec2KeyPair, instanceRole, tags
|
# non exhaustive list: minvCpus, instanceTypes, imageId, ec2KeyPair, instanceRole, tags
|
||||||
|
if "instanceRole" not in cr:
|
||||||
|
raise ClientException(
|
||||||
|
"Error executing request, Exception : Instance role is required."
|
||||||
|
)
|
||||||
for profile in self.iam_backend.get_instance_profiles():
|
for profile in self.iam_backend.get_instance_profiles():
|
||||||
if profile.arn == cr["instanceRole"]:
|
if profile.arn == cr["instanceRole"]:
|
||||||
break
|
break
|
||||||
@ -1280,6 +1284,10 @@ class BatchBackend(BaseBackend):
|
|||||||
f"could not find instanceRole {cr['instanceRole']}"
|
f"could not find instanceRole {cr['instanceRole']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if "minvCpus" not in cr:
|
||||||
|
raise ClientException(
|
||||||
|
"Error executing request, Exception : Resource minvCpus is required."
|
||||||
|
)
|
||||||
if int(cr["minvCpus"]) < 0:
|
if int(cr["minvCpus"]) < 0:
|
||||||
raise InvalidParameterValueException("minvCpus must be positive")
|
raise InvalidParameterValueException("minvCpus must be positive")
|
||||||
if int(cr["maxvCpus"]) < int(cr["minvCpus"]):
|
if int(cr["maxvCpus"]) < int(cr["minvCpus"]):
|
||||||
|
@ -395,3 +395,47 @@ def test_create_fargate_managed_compute_environment(compute_env_type):
|
|||||||
# Should have created 1 ECS cluster
|
# Should have created 1 ECS cluster
|
||||||
all_clusters = ecs_client.list_clusters()["clusterArns"]
|
all_clusters = ecs_client.list_clusters()["clusterArns"]
|
||||||
assert our_env["ecsClusterArn"] in all_clusters
|
assert our_env["ecsClusterArn"] in all_clusters
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
@mock_ecs
|
||||||
|
@mock_iam
|
||||||
|
@mock_batch
|
||||||
|
def test_create_ec2_managed_compute_environment__without_required_params():
|
||||||
|
ec2_client, iam_client, _, _, batch_client = _get_clients()
|
||||||
|
_, subnet_id, _, iam_arn = _setup(ec2_client, iam_client)
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
batch_client.create_compute_environment(
|
||||||
|
computeEnvironmentName="ec2-env",
|
||||||
|
type="MANAGED",
|
||||||
|
state="ENABLED",
|
||||||
|
computeResources={"type": "EC2", "maxvCpus": 1, "subnets": [subnet_id]},
|
||||||
|
serviceRole=iam_arn,
|
||||||
|
)
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
assert err["Code"] == "ClientException"
|
||||||
|
assert (
|
||||||
|
"Error executing request, Exception : Instance role is required."
|
||||||
|
in err["Message"]
|
||||||
|
)
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
batch_client.create_compute_environment(
|
||||||
|
computeEnvironmentName="ec2-env",
|
||||||
|
type="MANAGED",
|
||||||
|
state="ENABLED",
|
||||||
|
computeResources={
|
||||||
|
"type": "EC2",
|
||||||
|
"maxvCpus": 1,
|
||||||
|
"subnets": [subnet_id],
|
||||||
|
"instanceRole": iam_arn.replace("role", "instance-profile"),
|
||||||
|
},
|
||||||
|
serviceRole=iam_arn,
|
||||||
|
)
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
assert err["Code"] == "ClientException"
|
||||||
|
assert (
|
||||||
|
"Error executing request, Exception : Resource minvCpus is required."
|
||||||
|
in err["Message"]
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user