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

This commit is contained in:
Jenkins 2014-05-05 22:02:07 +00:00 committed by Gerrit Code Review
commit 325657801e
2 changed files with 15 additions and 3 deletions

View File

@ -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)

View File

@ -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':