Don't traceback in the API on invalid keypair.

When trying to get a keypair that did not exist, a traceback would end
up in the nova-api log.  Handle this exception in the API extension so
that it doesn't make a mess of the log.

Also add a unit test for this particular scenario.

Fix bug 1145545.

Change-Id: Id1647d4ac56629c2931099320d271e34fc2f99b9
This commit is contained in:
Russell Bryant
2013-03-05 10:13:44 -05:00
parent c7684046fe
commit adbccac10a
2 changed files with 9 additions and 1 deletions

View File

@@ -119,7 +119,10 @@ class KeypairController(object):
context = req.environ['nova.context']
authorize(context)
keypair = self.api.get_key_pair(context, context.user_id, id)
try:
keypair = self.api.get_key_pair(context, context.user_id, id)
except exception.KeypairNotFound:
raise webob.exc.HTTPNotFound()
return {'keypair': keypair}
@wsgi.serializers(xml=KeypairsTemplate)

View File

@@ -236,6 +236,11 @@ class KeypairsTest(test.TestCase):
res = req.get_response(self.app)
self.assertEqual(res.status_int, 202)
def test_keypair_get_keypair_not_found(self):
req = webob.Request.blank('/v2/fake/os-keypairs/DOESNOTEXIST')
res = req.get_response(self.app)
self.assertEqual(res.status_int, 404)
def test_keypair_delete_not_found(self):
def db_key_pair_get_not_found(context, user_id, name):