Skip to content

Commit

Permalink
Fix bug 1006664: describe non existent ec2 keypair
Browse files Browse the repository at this point in the history
Change-Id: I92bfd6b51aa31abb06e21893174101da31baffd8
  • Loading branch information
jogo committed Jun 6, 2012
1 parent 7626472 commit 29baa0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nova/api/ec2/cloud.py
Expand Up @@ -337,6 +337,11 @@ def describe_key_pairs(self, context, key_name=None, **kwargs):
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
Expand Down
5 changes: 5 additions & 0 deletions nova/tests/api/ec2/test_cloud.py
Expand Up @@ -1525,6 +1525,11 @@ def test_describe_key_pairs(self):
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')
Expand Down

0 comments on commit 29baa0e

Please sign in to comment.