diff --git a/nova/api/openstack/compute/plugins/v3/floating_ips.py b/nova/api/openstack/compute/plugins/v3/floating_ips.py index 553b06b2f409..fb41ca899e5f 100644 --- a/nova/api/openstack/compute/plugins/v3/floating_ips.py +++ b/nova/api/openstack/compute/plugins/v3/floating_ips.py @@ -247,19 +247,13 @@ class FloatingIPActionController(wsgi.Controller): @extensions.expected_errors((400, 403, 404, 409)) @wsgi.action('removeFloatingIp') + @validation.schema(floating_ips.remove_floating_ip) def _remove_floating_ip(self, req, id, body): """Dissociate floating_ip from an instance.""" context = req.environ['nova.context'] authorize(context) - try: - address = body['removeFloatingIp']['address'] - except TypeError: - msg = _("Missing parameter dict") - raise webob.exc.HTTPBadRequest(explanation=msg) - except KeyError: - msg = _("Address not specified") - raise webob.exc.HTTPBadRequest(explanation=msg) + address = body['removeFloatingIp']['address'] # get the floating ip object try: diff --git a/nova/api/openstack/compute/schemas/v3/floating_ips.py b/nova/api/openstack/compute/schemas/v3/floating_ips.py index d299faf79656..dbc90844b0f2 100644 --- a/nova/api/openstack/compute/schemas/v3/floating_ips.py +++ b/nova/api/openstack/compute/schemas/v3/floating_ips.py @@ -32,3 +32,19 @@ add_floating_ip = { 'required': ['addFloatingIp'], 'additionalProperties': False } + +remove_floating_ip = { + 'type': 'object', + 'properties': { + 'removeFloatingIp': { + 'type': 'object', + 'properties': { + 'address': parameter_types.ip_address + }, + 'required': ['address'], + 'additionalProperties': False + } + }, + 'required': ['removeFloatingIp'], + 'additionalProperties': False +} diff --git a/nova/tests/unit/api/openstack/compute/contrib/test_floating_ips.py b/nova/tests/unit/api/openstack/compute/contrib/test_floating_ips.py index ea52b05f3411..d46a6e57d89b 100644 --- a/nova/tests/unit/api/openstack/compute/contrib/test_floating_ips.py +++ b/nova/tests/unit/api/openstack/compute/contrib/test_floating_ips.py @@ -553,7 +553,7 @@ class FloatingIpTestV21(test.TestCase): body = dict(removeFloatingIp=dict(address='10.10.10.10')) rsp = self.manager._remove_floating_ip(self.fake_req, 'test_inst', - body) + body=body) self.assertEqual(202, rsp.status_int) def test_floating_ip_disassociate_missing(self): @@ -561,7 +561,7 @@ class FloatingIpTestV21(test.TestCase): self.assertRaises(webob.exc.HTTPConflict, self.manager._remove_floating_ip, - self.fake_req, 'test_inst', body) + self.fake_req, 'test_inst', body=body) def test_floating_ip_associate_non_existent_ip(self): def fake_network_api_associate(self, context, instance, @@ -594,7 +594,7 @@ class FloatingIpTestV21(test.TestCase): body = dict(removeFloatingIp=dict(address='1.1.1.1')) self.assertRaises(webob.exc.HTTPNotFound, self.manager._remove_floating_ip, - self.fake_req, 'test_inst', body) + self.fake_req, 'test_inst', body=body) def test_floating_ip_disassociate_wrong_instance_uuid(self): def get_instance_by_floating_ip_addr(self, context, address): @@ -609,7 +609,7 @@ class FloatingIpTestV21(test.TestCase): self.assertRaises(webob.exc.HTTPConflict, self.manager._remove_floating_ip, - self.fake_req, wrong_uuid, body) + self.fake_req, wrong_uuid, body=body) def test_floating_ip_disassociate_wrong_instance_id(self): def get_instance_by_floating_ip_addr(self, context, address): @@ -623,7 +623,7 @@ class FloatingIpTestV21(test.TestCase): self.assertRaises(webob.exc.HTTPConflict, self.manager._remove_floating_ip, - self.fake_req, 'test_inst', body) + self.fake_req, 'test_inst', body=body) def test_floating_ip_disassociate_auto_assigned(self): def fake_get_floating_ip_addr_auto_assigned(self, context, address): @@ -647,7 +647,7 @@ class FloatingIpTestV21(test.TestCase): body = dict(removeFloatingIp=dict(address='10.10.10.10')) self.assertRaises(webob.exc.HTTPForbidden, self.manager._remove_floating_ip, - self.fake_req, 'test_inst', body) + self.fake_req, 'test_inst', body=body) def test_floating_ip_disassociate_map_authorization_exc(self): def fake_get_floating_ip_addr_auto_assigned(self, context, address): @@ -670,23 +670,23 @@ class FloatingIpTestV21(test.TestCase): body = dict(removeFloatingIp=dict(address='10.10.10.10')) self.assertRaises(webob.exc.HTTPForbidden, self.manager._remove_floating_ip, - self.fake_req, 'test_inst', body) + self.fake_req, 'test_inst', body=body) # these are a few bad param tests def test_bad_address_param_in_remove_floating_ip(self): body = dict(removeFloatingIp=dict(badparam='11.0.0.1')) - self.assertRaises(webob.exc.HTTPBadRequest, + self.assertRaises(self.validation_error, self.manager._remove_floating_ip, self.fake_req, - 'test_inst', body) + 'test_inst', body=body) def test_missing_dict_param_in_remove_floating_ip(self): body = dict(removeFloatingIp='11.0.0.1') - self.assertRaises(webob.exc.HTTPBadRequest, + self.assertRaises(self.validation_error, self.manager._remove_floating_ip, self.fake_req, - 'test_inst', body) + 'test_inst', body=body) def test_missing_dict_param_in_add_floating_ip(self): body = dict(addFloatingIp='11.0.0.1')