summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/api/openstack/compute/contrib/keypairs.py5
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_keypairs.py5
2 files changed, 9 insertions, 1 deletions
diff --git a/nova/api/openstack/compute/contrib/keypairs.py b/nova/api/openstack/compute/contrib/keypairs.py
index 4f6ad6b18..a79b39aae 100644
--- a/nova/api/openstack/compute/contrib/keypairs.py
+++ b/nova/api/openstack/compute/contrib/keypairs.py
@@ -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)
diff --git a/nova/tests/api/openstack/compute/contrib/test_keypairs.py b/nova/tests/api/openstack/compute/contrib/test_keypairs.py
index 06454b123..025845637 100644
--- a/nova/tests/api/openstack/compute/contrib/test_keypairs.py
+++ b/nova/tests/api/openstack/compute/contrib/test_keypairs.py
@@ -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):