Skip to content

Commit

Permalink
Handle kepair delete when not found
Browse files Browse the repository at this point in the history
Fixes bug 900924

Change-Id: Icd0a1f69c0fb7c15110bbf0c416e38cdc1147f4d
  • Loading branch information
bcwaldon committed Jan 30, 2012
1 parent 3146044 commit 271acd8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
10 changes: 5 additions & 5 deletions nova/api/openstack/compute/contrib/keypairs.py
Expand Up @@ -17,11 +17,8 @@

""" Keypair management extension"""

import os
import shutil
import tempfile

import webob
import webob.exc

from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
Expand Down Expand Up @@ -122,7 +119,10 @@ def delete(self, req, id):
"""
context = req.environ['nova.context']
authorize(context)
db.key_pair_destroy(context, context.user_id, id)
try:
db.key_pair_destroy(context, context.user_id, id)
except exception.KeypairNotFound:
raise webob.exc.HTTPNotFound()
return webob.Response(status_int=202)

@wsgi.serializers(xml=KeypairsTemplate)
Expand Down
19 changes: 14 additions & 5 deletions nova/tests/api/openstack/compute/contrib/test_keypairs.py
Expand Up @@ -22,6 +22,7 @@
from nova.api.openstack.compute.contrib import keypairs
from nova import context
from nova import db
from nova import exception
from nova import test
from nova.tests.api.openstack import fakes

Expand Down Expand Up @@ -92,11 +93,7 @@ def test_keypair_create_with_empty_name(self):
def test_keypair_create_with_invalid_name(self):
body = {
'keypair': {
'name': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
'name': 'a' * 256
}
}
req = webob.Request.blank('/v2/fake/os-keypairs')
Expand Down Expand Up @@ -155,6 +152,18 @@ def test_keypair_delete(self):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 202)

def test_keypair_delete_not_found(self):

def db_key_pair_get_not_found(context, user_id, name):
raise exception.KeyPairNotFound()

self.stubs.Set(db, "key_pair_get",
db_key_pair_get_not_found)
req = webob.Request.blank('/v2/fake/os-keypairs/WHAT')
res = req.get_response(fakes.wsgi_app())
print res
self.assertEqual(res.status_int, 404)


class KeypairsXMLSerializerTest(test.TestCase):
def setUp(self):
Expand Down

0 comments on commit 271acd8

Please sign in to comment.