Raise HTTPForbidden from os-floating-ips API rather than 404

The os-floating-ips extension was catching and handling a 404
and 403 in the same block and raising HTTPNotFound for both.

This change separates the 404 and 403 cases so HTTPForbidden
is returned in the 403 case.  For the 404 case, the test is
updated to raise the proper NovaException and a new test is
added for the 403 Forbidden case.

Change-Id: Id0daf2d61c6960d845d3b7980f96228fece41128
This commit is contained in:
Matt Riedemann
2014-03-30 17:59:12 -07:00
parent 89fd077042
commit 50f743d1ee
2 changed files with 15 additions and 3 deletions
@@ -257,10 +257,11 @@ class FloatingIPActionController(wsgi.Controller):
except exception.NoFloatingIpInterface:
msg = _('l3driver call to add floating ip failed')
raise webob.exc.HTTPBadRequest(explanation=msg)
except (exception.FloatingIpNotFoundForAddress,
exception.Forbidden):
except exception.FloatingIpNotFoundForAddress:
msg = _('floating ip not found')
raise webob.exc.HTTPNotFound(explanation=msg)
except exception.Forbidden as e:
raise webob.exc.HTTPForbidden(explanation=e.format_message())
except Exception:
msg = _('Error. Unable to associate floating ip')
LOG.exception(msg)
@@ -17,6 +17,7 @@
import uuid
from lxml import etree
import mock
import webob
from nova.api.openstack.compute.contrib import floating_ips
@@ -406,7 +407,8 @@ class FloatingIpTest(test.TestCase):
def fake_associate_floating_ip(self, context, instance,
floating_address, fixed_address,
affect_auto_assigned=False):
raise exception.Forbidden()
raise exception.FloatingIpNotFoundForAddress(
address=floating_address)
self.stubs.Set(network.api.API, "associate_floating_ip",
fake_associate_floating_ip)
floating_ip = '10.10.10.11'
@@ -421,6 +423,15 @@ class FloatingIpTest(test.TestCase):
self.assertEqual(res_dict['itemNotFound']['message'],
"floating ip not found")
@mock.patch.object(network.api.API, 'associate_floating_ip',
side_effect=exception.Forbidden)
def test_associate_floating_ip_forbidden(self, associate_mock):
body = dict(addFloatingIp=dict(address='10.10.10.11'))
req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
self.assertRaises(webob.exc.HTTPForbidden,
self.manager._add_floating_ip, req, 'test_inst',
body)
def test_floating_ip_disassociate(self):
def get_instance_by_floating_ip_addr(self, context, address):
if address == '10.10.10.10':