EC2: Match exception to AWS response when describing non-existent EC2 instance types (#5527)
This commit is contained in:
parent
148de0e562
commit
aefffd7eee
@ -259,11 +259,15 @@ class InvalidInstanceIdError(EC2ClientError):
|
||||
|
||||
|
||||
class InvalidInstanceTypeError(EC2ClientError):
|
||||
def __init__(self, instance_type):
|
||||
super().__init__(
|
||||
"InvalidInstanceType.NotFound",
|
||||
"The instance type '{0}' does not exist".format(instance_type),
|
||||
)
|
||||
def __init__(self, instance_type, error_type="InvalidInstanceType.NotFound"):
|
||||
if isinstance(instance_type, str):
|
||||
msg = f"The instance type '{instance_type}' does not exist"
|
||||
else:
|
||||
msg = (
|
||||
f"The following supplied instance types do not exist: "
|
||||
f"[{', '.join(instance_type)}]"
|
||||
)
|
||||
super().__init__(error_type, msg)
|
||||
|
||||
|
||||
class InvalidAMIIdError(EC2ClientError):
|
||||
|
@ -145,7 +145,9 @@ class InstanceTypeBackend:
|
||||
unknown_ids = set(instance_types) - set(
|
||||
t.get("InstanceType") for t in matches
|
||||
)
|
||||
raise InvalidInstanceTypeError(unknown_ids)
|
||||
raise InvalidInstanceTypeError(
|
||||
unknown_ids, error_type="InvalidInstanceType"
|
||||
)
|
||||
if filters:
|
||||
matches = generic_filter(filters, matches)
|
||||
return matches
|
||||
|
@ -82,13 +82,14 @@ def test_describe_instance_types_gpu_instance_types():
|
||||
def test_describe_instance_types_unknown_type():
|
||||
client = boto3.client("ec2", "us-east-1")
|
||||
|
||||
with pytest.raises(ClientError) as err:
|
||||
with pytest.raises(ClientError) as exc_info:
|
||||
client.describe_instance_types(InstanceTypes=["t1.non_existent"])
|
||||
err.response["Error"]["Code"].should.equal("ValidationException")
|
||||
err.response["Error"]["Message"].split(":")[0].should.look_like(
|
||||
"The instance type '{'t1.non_existent'}' does not exist"
|
||||
)
|
||||
err.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
|
||||
exc_info.value.response["Error"]["Code"].should.equal("InvalidInstanceType")
|
||||
exc_info.value.response["Error"]["Message"].should.equal(
|
||||
"The following supplied instance types do not exist: [t1.non_existent]",
|
||||
)
|
||||
exc_info.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
|
Loading…
Reference in New Issue
Block a user