From 29baa0ec661c2578ad0aabd138a6b84e5c7a0b40 Mon Sep 17 00:00:00 2001 From: Joe Gordon Date: Wed, 30 May 2012 18:33:24 -0700 Subject: Fix bug 1006664: describe non existent ec2 keypair Change-Id: I92bfd6b51aa31abb06e21893174101da31baffd8 --- nova/api/ec2/cloud.py | 5 +++++ nova/tests/api/ec2/test_cloud.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 723c7fca7..6f0d605ed 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -337,6 +337,11 @@ class CloudController(object): if not key_name is None: key_pairs = [x for x in key_pairs if x['name'] in key_name] + #If looking for non existent key pair + if key_name != None and key_pairs == []: + msg = _('Could not find key pair(s): %s') % ','.join(key_name) + raise exception.EC2APIError(msg) + result = [] for key_pair in key_pairs: # filter out the vpn keys diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py index 58cba6d15..3526f72e6 100644 --- a/nova/tests/api/ec2/test_cloud.py +++ b/nova/tests/api/ec2/test_cloud.py @@ -1525,6 +1525,11 @@ class CloudTestCase(test.TestCase): self.assertTrue(filter(lambda k: k['keyName'] == 'test1', keys)) self.assertTrue(filter(lambda k: k['keyName'] == 'test2', keys)) + def test_describe_bad_key_pairs(self): + self.assertRaises(exception.EC2APIError, + self.cloud.describe_key_pairs, self.context, + key_name=['DoesNotExist']) + def test_import_key_pair(self): pubkey_path = os.path.join(os.path.dirname(__file__), 'public_key') f = open(pubkey_path + '/dummy.pub', 'r') -- cgit