diff options
| author | Dan Smith <danms@us.ibm.com> | 2012-07-23 08:20:37 -0700 |
|---|---|---|
| committer | Dan Smith <danms@us.ibm.com> | 2012-07-23 09:20:25 -0700 |
| commit | 07105cb78e366d35dd8c8a046c951780c274e9a2 (patch) | |
| tree | 96ea45ec55fe4a28d1cf16a1d8d5230dc66419fa | |
| parent | a9682615879215517231230a87af75ab28a8d974 (diff) | |
| download | nova-07105cb78e366d35dd8c8a046c951780c274e9a2.tar.gz nova-07105cb78e366d35dd8c8a046c951780c274e9a2.tar.xz nova-07105cb78e366d35dd8c8a046c951780c274e9a2.zip | |
Return 404 when attempting to remove a non-existent floating ip
This fixes bug 993774 and returns 404 instead of 202 when trying to
delete a floating ip from an instance to which it is not allocated.
Change-Id: I9538a8a71cbbb9d19e9ebb76f93b180dbf619764
| -rw-r--r-- | nova/api/openstack/compute/contrib/floating_ips.py | 7 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_floating_ips.py | 13 |
2 files changed, 17 insertions, 3 deletions
diff --git a/nova/api/openstack/compute/contrib/floating_ips.py b/nova/api/openstack/compute/contrib/floating_ips.py index b6a6adc9e..4b290bb4c 100644 --- a/nova/api/openstack/compute/contrib/floating_ips.py +++ b/nova/api/openstack/compute/contrib/floating_ips.py @@ -282,10 +282,11 @@ class FloatingIPActionController(wsgi.Controller): instance = get_instance_by_floating_ip_addr(self, context, address) # disassociate if associated - if floating_ip.get('fixed_ip_id'): + if instance and floating_ip.get('fixed_ip_id'): disassociate_floating_ip(self, context, instance, address) - - return webob.Response(status_int=202) + return webob.Response(status_int=202) + else: + return webob.Response(status_int=404) class Floating_ips(extensions.ExtensionDescriptor): 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 bd752b6e5..8a3a2ece1 100644 --- a/nova/tests/api/openstack/compute/contrib/test_floating_ips.py +++ b/nova/tests/api/openstack/compute/contrib/test_floating_ips.py @@ -99,6 +99,10 @@ def stub_nw_info(stubs): return get_nw_info_for_instance +def get_instance_by_floating_ip_addr(self, context, address): + return None + + class FloatingIpTest(test.TestCase): floating_ip = "10.10.10.10" @@ -129,6 +133,8 @@ class FloatingIpTest(test.TestCase): network_api_release) self.stubs.Set(network.api.API, "disassociate_floating_ip", network_api_disassociate) + self.stubs.Set(network.api.API, "get_instance_id_by_floating_address", + get_instance_by_floating_ip_addr) self.stubs.Set(compute_utils, "get_nw_info_for_instance", stub_nw_info(self.stubs)) @@ -275,6 +281,13 @@ class FloatingIpTest(test.TestCase): req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action') self.manager._remove_floating_ip(req, 'test_inst', body) + def test_floating_ip_disassociate_missing(self): + body = dict(removeFloatingIp=dict(address='10.10.10.10')) + + req = fakes.HTTPRequest.blank('/v2/fake/servers/test_inst/action') + rsp = self.manager._remove_floating_ip(req, 'test_inst', body) + self.assertTrue(rsp.status_int == 404) + # these are a few bad param tests def test_bad_address_param_in_remove_floating_ip(self): |
