From 5cce71baaa13fc651d76b6b26a29effbf879f1b1 Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Thu, 3 Jan 2013 09:04:58 -0600 Subject: Refactor EC2 keypairs exception According to the following document: http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/api-error-codes.html The EC2 API sends specific error codes when keypair listing or keypair generation fails, specifically the error codes are InvalidKeyPair.Duplicate - duplicate keypair InvalidKeyPair.Format - keypair format invalid InvalidKeyPair.NotFound - keypair not found ResourceLimitExceeded - keypair quota exceeded Refactored create_key_pair and describe_key_pair so that it throws the correct EC2 error codes according to the public EC2 API specs. Also removed some duplicate exceptions as well. Fixes LP: 1072318 DocImpact Change-Id: Ib7045e49211d9300e9cb6ca0bfe80e569d635c9b Signed-off-by: Chuck Short --- nova/tests/api/ec2/test_cloud.py | 4 ++-- nova/tests/test_api.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index 562473121..a00dceff1 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -1440,7 +1440,7 @@ class CloudTestCase(test.TestCase): self.assertTrue(filter(lambda k: k['keyName'] == 'test2', keys)) def test_describe_bad_key_pairs(self): - self.assertRaises(exception.EC2APIError, + self.assertRaises(exception.KeypairNotFound, self.cloud.describe_key_pairs, self.context, key_name=['DoesNotExist']) @@ -1490,7 +1490,7 @@ class CloudTestCase(test.TestCase): self.assertEqual(result['keyName'], key_name) for key_name in bad_names: - self.assertRaises(exception.EC2APIError, + self.assertRaises(exception.InvalidKeypair, self.cloud.create_key_pair, self.context, key_name) diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py index 829a98334..fb2e76e45 100644 --- a/nova/tests/test_api.py +++ b/nova/tests/test_api.py @@ -309,11 +309,10 @@ class ApiEc2TestCase(test.TestCase): try: self.ec2.create_key_pair('test') except boto_exc.EC2ResponseError, e: - if e.code == 'KeyPairExists': + if e.code == 'InvalidKeyPair.Duplicate': pass else: - self.fail("Unexpected EC2ResponseError: %s " - "(expected KeyPairExists)" % e.code) + self.assertEqual('InvalidKeyPair.Duplicate', e.code) else: self.fail('Exception not raised.') -- cgit