From 544745f9da3245a71d771cff26dc6d0255bb0470 Mon Sep 17 00:00:00 2001 From: Haiwei Xu Date: Wed, 19 Feb 2014 04:32:38 +0900 Subject: [PATCH] Change exception type from HTTPBadRequest to HTTPForbidden When user without admin permission wants to get a list of servers which are in 'deleted' state, currently it raises HTTPBadRequest. This should be changed to HTTPForbidden exception. Change-Id: I29da5f055c69e8aba66ffb068a3601ae69b2fc94 Closes-Bug: #1281904 --- nova/api/openstack/compute/plugins/v3/servers.py | 2 +- nova/api/openstack/compute/servers.py | 2 +- nova/tests/api/openstack/compute/plugins/v3/test_servers.py | 2 +- nova/tests/api/openstack/compute/test_servers.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nova/api/openstack/compute/plugins/v3/servers.py b/nova/api/openstack/compute/plugins/v3/servers.py index 3e3233dcb7c9..4a20e021b60c 100644 --- a/nova/api/openstack/compute/plugins/v3/servers.py +++ b/nova/api/openstack/compute/plugins/v3/servers.py @@ -233,7 +233,7 @@ class ServersController(wsgi.Controller): search_opts['deleted'] = True else: msg = _("Only administrators may list deleted instances") - raise exc.HTTPBadRequest(explanation=msg) + raise exc.HTTPForbidden(explanation=msg) # If tenant_id is passed as a search parameter this should # imply that all_tenants is also enabled unless explicitly diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 6d4974fc2187..7d133f0d39b0 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -560,7 +560,7 @@ class Controller(wsgi.Controller): search_opts['deleted'] = True else: msg = _("Only administrators may list deleted instances") - raise exc.HTTPBadRequest(explanation=msg) + raise exc.HTTPForbidden(explanation=msg) # If all tenants is passed with 0 or false as the value # then remove it from the search options. Nothing passed as diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_servers.py b/nova/tests/api/openstack/compute/plugins/v3/test_servers.py index 8eebf6764676..c0db6fb56749 100644 --- a/nova/tests/api/openstack/compute/plugins/v3/test_servers.py +++ b/nova/tests/api/openstack/compute/plugins/v3/test_servers.py @@ -1003,7 +1003,7 @@ class ServersControllerTest(ControllerTest): def test_get_servers_deleted_status_as_user(self): req = fakes.HTTPRequestV3.blank('/servers?status=deleted', use_admin_context=False) - self.assertRaises(webob.exc.HTTPBadRequest, + self.assertRaises(webob.exc.HTTPForbidden, self.controller.detail, req) def test_get_servers_deleted_status_as_admin(self): diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 22dc9d41030a..1708ec4b2893 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -923,7 +923,7 @@ class ServersControllerTest(ControllerTest): def test_get_servers_deleted_status_as_user(self): req = fakes.HTTPRequest.blank('/fake/servers?status=deleted', use_admin_context=False) - self.assertRaises(webob.exc.HTTPBadRequest, + self.assertRaises(webob.exc.HTTPForbidden, self.controller.detail, req) def test_get_servers_deleted_status_as_admin(self):