Skip to content

Commit

Permalink
Make sure unknown extensions return 404
Browse files Browse the repository at this point in the history
At the moment, if an extension doens't exist and we call a show method
with wrong id then the exception is not captured. There is a need to
return NOTFOUND exception.
Fixes bug 869153.

Change-Id: Ie0b2c2e87c5a61f6db74bb10a4740add2ab8ea27
  • Loading branch information
Ahmad Hassan authored and viraptor committed Oct 6, 2011
1 parent 72c45bd commit 2915e6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions Authors
@@ -1,6 +1,7 @@
Aaron Lee <aaron.lee@rackspace.com>
Adam Gandelman <adamg@canonical.com>
Adam Johnson <adjohn@gmail.com>
Ahmad Hassan <ahmad.hassan@hp.com>
Alex Meade <alex.meade@rackspace.com>
Alexander Sakhnov <asakhnov@mirantis.com>
Andrey Brindeyev <abrindeyev@griddynamics.com>
Expand Down
8 changes: 6 additions & 2 deletions nova/api/openstack/extensions.py
Expand Up @@ -197,8 +197,12 @@ def index(self, req):
return dict(extensions=extensions)

def show(self, req, id):
# NOTE(dprince): the extensions alias is used as the 'id' for show
ext = self.extension_manager.extensions[id]
try:
# NOTE(dprince): the extensions alias is used as the 'id' for show
ext = self.extension_manager.extensions[id]
except KeyError:
return faults.Fault(webob.exc.HTTPNotFound())

return dict(extension=self._translate(ext))

def delete(self, req, id):
Expand Down
7 changes: 7 additions & 0 deletions nova/tests/api/openstack/test_extensions.py
Expand Up @@ -150,6 +150,13 @@ def test_get_extension_json(self):
"alias": "FOXNSOX",
"links": []})

def test_get_non_existing_extension_json(self):
app = openstack.APIRouterV11()
ext_midware = extensions.ExtensionMiddleware(app)
request = webob.Request.blank("/123/extensions/4")
response = request.get_response(ext_midware)
self.assertEqual(404, response.status_int)

def test_list_extensions_xml(self):
app = openstack.APIRouterV11()
ext_midware = extensions.ExtensionMiddleware(app)
Expand Down

0 comments on commit 2915e6b

Please sign in to comment.