Batch: improve parameter validation (#7505)

This commit is contained in:
rafcio19 2024-03-21 21:23:26 +01:00 committed by GitHub
parent 3edc0c751c
commit 59ce86c5c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -1219,6 +1219,12 @@ class BatchBackend(BaseBackend):
f"A compute environment already exists with the name {compute_environment_name}"
)
if not service_role:
raise ClientException(
f"Error executing request, Exception : ServiceRole is required.,"
f" RequestId: {mock_random.uuid4()}"
)
# Look for IAM role
try:
self.iam_backend.get_role_by_arn(service_role)

View File

@ -374,9 +374,11 @@ 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)
env_name = "ec2-env"
with pytest.raises(ClientError) as exc:
batch_client.create_compute_environment(
computeEnvironmentName="ec2-env",
computeEnvironmentName=env_name,
type="MANAGED",
state="ENABLED",
computeResources={"type": "EC2", "maxvCpus": 1, "subnets": [subnet_id]},
@ -391,7 +393,7 @@ def test_create_ec2_managed_compute_environment__without_required_params():
with pytest.raises(ClientError) as exc:
batch_client.create_compute_environment(
computeEnvironmentName="ec2-env",
computeEnvironmentName=env_name,
type="MANAGED",
state="ENABLED",
computeResources={
@ -408,3 +410,16 @@ def test_create_ec2_managed_compute_environment__without_required_params():
"Error executing request, Exception : Resource minvCpus is required."
in err["Message"]
)
with pytest.raises(ClientError) as exc:
batch_client.create_compute_environment(
computeEnvironmentName=env_name,
type="UNMANGED",
state="ENABLED",
)
err = exc.value.response["Error"]
assert err["Code"] == "ClientException"
assert (
"Error executing request, Exception : ServiceRole is required.,"
in err["Message"]
)