From 064948eb96cd6f585ed18af3966aaba0ff190ae1 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Fri, 2 Nov 2012 15:44:07 -0700 Subject: Map NotAuthorized to 403 in floating ips extension When a NotAuthorized exception is raised in the network manager, it would be presented as an HTTP 401 exception through the floating ips extension. This patch presents it as a 403 instead. Fixes bug 1074505 Change-Id: Idb45c78755a182635ef353bb9ec8b557c8ea9b16 --- nova/api/openstack/compute/contrib/floating_ips.py | 2 +- .../openstack/compute/contrib/test_floating_ips.py | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/nova/api/openstack/compute/contrib/floating_ips.py b/nova/api/openstack/compute/contrib/floating_ips.py index 56a6a8fad..1d987d5ad 100644 --- a/nova/api/openstack/compute/contrib/floating_ips.py +++ b/nova/api/openstack/compute/contrib/floating_ips.py @@ -92,7 +92,7 @@ def disassociate_floating_ip(self, context, instance, address): try: self.network_api.disassociate_floating_ip(context, instance, address) except exception.NotAuthorized: - raise webob.exc.HTTPUnauthorized() + raise webob.exc.HTTPForbidden() except exception.FloatingIpNotAssociated: msg = _('Floating ip is not associated') raise webob.exc.HTTPBadRequest(explanation=msg) diff --git a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py index fad602c0b..171b0900e 100644 --- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py +++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py @@ -458,6 +458,30 @@ class FloatingIpTest(test.TestCase): self.manager._remove_floating_ip, req, 'test_inst', body) + def test_floating_ip_disassociate_map_authorization_exc(self): + def fake_get_floating_ip_addr_auto_assigned(self, context, address): + return {'id': 1, 'address': '10.10.10.10', 'pool': 'nova', + 'fixed_ip_id': 10, 'auto_assigned': 1} + + def get_instance_by_floating_ip_addr(self, context, address): + if address == '10.10.10.10': + return 'test_inst' + + def network_api_disassociate(self, context, instance, address): + raise exception.NotAuthorized() + + self.stubs.Set(network.api.API, "get_floating_ip_by_address", + fake_get_floating_ip_addr_auto_assigned) + self.stubs.Set(network.api.API, "get_instance_id_by_floating_address", + get_instance_by_floating_ip_addr) + self.stubs.Set(network.api.API, "disassociate_floating_ip", + network_api_disassociate) + body = dict(removeFloatingIp=dict(address='10.10.10.10')) + req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action') + self.assertRaises(webob.exc.HTTPForbidden, + self.manager._remove_floating_ip, + req, 'test_inst', body) + # these are a few bad param tests def test_bad_address_param_in_remove_floating_ip(self): -- cgit