Return proper error messages while disassociating floating IP
Currently, when a floating IP is not associated with an instance, and if we try to disassociate it, a response likes "HTTP/1.1 404 Not Found" will be returned, it is not proper, so change it to "HTTP/1.1 422 Unprocessable Entity" with body likes '{"computeFault": {"message": "Floating ip 172.24.4.225 is not associated with instance a33857af-b18b-4b88-a5cc-7d84c7fd41c8.", "code": 422}}'. Fixes bug: #1129719 Change-Id: I18194ccf59edb5eb2bcd52a65f38d5632fef95d3
This commit is contained in:
parent
f86f9a8cb5
commit
5b38c5c6fe
@ -294,7 +294,9 @@ class FloatingIPActionController(wsgi.Controller):
|
|||||||
disassociate_floating_ip(self, context, instance, address)
|
disassociate_floating_ip(self, context, instance, address)
|
||||||
return webob.Response(status_int=202)
|
return webob.Response(status_int=202)
|
||||||
else:
|
else:
|
||||||
return webob.Response(status_int=404)
|
msg = _("Floating ip %(address)s is not associated with instance "
|
||||||
|
"%(id)s.") % locals()
|
||||||
|
raise webob.exc.HTTPUnprocessableEntity(explanation=msg)
|
||||||
|
|
||||||
|
|
||||||
class Floating_ips(extensions.ExtensionDescriptor):
|
class Floating_ips(extensions.ExtensionDescriptor):
|
||||||
|
@ -364,8 +364,9 @@ class FloatingIpTest(test.TestCase):
|
|||||||
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
|
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
|
req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
|
||||||
rsp = self.manager._remove_floating_ip(req, 'test_inst', body)
|
self.assertRaises(webob.exc.HTTPUnprocessableEntity,
|
||||||
self.assertTrue(rsp.status_int == 404)
|
self.manager._remove_floating_ip,
|
||||||
|
req, 'test_inst', body)
|
||||||
|
|
||||||
def test_floating_ip_associate_non_existent_ip(self):
|
def test_floating_ip_associate_non_existent_ip(self):
|
||||||
def fake_network_api_associate(self, context, instance,
|
def fake_network_api_associate(self, context, instance,
|
||||||
@ -414,8 +415,9 @@ class FloatingIpTest(test.TestCase):
|
|||||||
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
|
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
|
req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
|
||||||
rsp = self.manager._remove_floating_ip(req, wrong_uuid, body)
|
self.assertRaises(webob.exc.HTTPUnprocessableEntity,
|
||||||
self.assertTrue(rsp.status_int == 404)
|
self.manager._remove_floating_ip,
|
||||||
|
req, wrong_uuid, body)
|
||||||
|
|
||||||
def test_floating_ip_disassociate_wrong_instance_id(self):
|
def test_floating_ip_disassociate_wrong_instance_id(self):
|
||||||
def get_instance_by_floating_ip_addr(self, context, address):
|
def get_instance_by_floating_ip_addr(self, context, address):
|
||||||
@ -428,8 +430,9 @@ class FloatingIpTest(test.TestCase):
|
|||||||
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
|
body = dict(removeFloatingIp=dict(address='10.10.10.10'))
|
||||||
|
|
||||||
req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
|
req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action')
|
||||||
rsp = self.manager._remove_floating_ip(req, 'test_inst', body)
|
self.assertRaises(webob.exc.HTTPUnprocessableEntity,
|
||||||
self.assertTrue(rsp.status_int == 404)
|
self.manager._remove_floating_ip,
|
||||||
|
req, 'test_inst', body)
|
||||||
|
|
||||||
def test_floating_ip_disassociate_auto_assigned(self):
|
def test_floating_ip_disassociate_auto_assigned(self):
|
||||||
def fake_get_floating_ip_addr_auto_assigned(self, context, address):
|
def fake_get_floating_ip_addr_auto_assigned(self, context, address):
|
||||||
|
Loading…
Reference in New Issue
Block a user