Batch: improve parameter validation (#7505)
This commit is contained in:
parent
3edc0c751c
commit
59ce86c5c7
@ -1219,6 +1219,12 @@ class BatchBackend(BaseBackend):
|
|||||||
f"A compute environment already exists with the name {compute_environment_name}"
|
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
|
# Look for IAM role
|
||||||
try:
|
try:
|
||||||
self.iam_backend.get_role_by_arn(service_role)
|
self.iam_backend.get_role_by_arn(service_role)
|
||||||
|
@ -374,9 +374,11 @@ def test_create_ec2_managed_compute_environment__without_required_params():
|
|||||||
ec2_client, iam_client, _, _, batch_client = _get_clients()
|
ec2_client, iam_client, _, _, batch_client = _get_clients()
|
||||||
_, subnet_id, _, iam_arn = _setup(ec2_client, iam_client)
|
_, subnet_id, _, iam_arn = _setup(ec2_client, iam_client)
|
||||||
|
|
||||||
|
env_name = "ec2-env"
|
||||||
|
|
||||||
with pytest.raises(ClientError) as exc:
|
with pytest.raises(ClientError) as exc:
|
||||||
batch_client.create_compute_environment(
|
batch_client.create_compute_environment(
|
||||||
computeEnvironmentName="ec2-env",
|
computeEnvironmentName=env_name,
|
||||||
type="MANAGED",
|
type="MANAGED",
|
||||||
state="ENABLED",
|
state="ENABLED",
|
||||||
computeResources={"type": "EC2", "maxvCpus": 1, "subnets": [subnet_id]},
|
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:
|
with pytest.raises(ClientError) as exc:
|
||||||
batch_client.create_compute_environment(
|
batch_client.create_compute_environment(
|
||||||
computeEnvironmentName="ec2-env",
|
computeEnvironmentName=env_name,
|
||||||
type="MANAGED",
|
type="MANAGED",
|
||||||
state="ENABLED",
|
state="ENABLED",
|
||||||
computeResources={
|
computeResources={
|
||||||
@ -408,3 +410,16 @@ def test_create_ec2_managed_compute_environment__without_required_params():
|
|||||||
"Error executing request, Exception : Resource minvCpus is required."
|
"Error executing request, Exception : Resource minvCpus is required."
|
||||||
in err["Message"]
|
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"]
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user