diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 34954297b..68bbcf41b 100755 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -6164,7 +6164,7 @@ class _OpenStackCloudMixin(_normalize.Normalizer): A value of 0 will also cause no checking of results to occur. - :returns: True if Floating IPs have been deleted, False if not + :returns: Number of Floating IPs deleted, False if none :raises: ``OpenStackCloudException``, on operation error. """ @@ -6174,7 +6174,7 @@ class _OpenStackCloudMixin(_normalize.Normalizer): if not ip['attached']: processed.append(self.delete_floating_ip( floating_ip_id=ip['id'], retry=retry)) - return all(processed) if processed else False + return len(processed) if all(processed) else False def _attach_ip_to_server( self, server, floating_ip, diff --git a/openstack/tests/unit/cloud/test_floating_ip_neutron.py b/openstack/tests/unit/cloud/test_floating_ip_neutron.py index bf4871f2c..94c06bdc0 100644 --- a/openstack/tests/unit/cloud/test_floating_ip_neutron.py +++ b/openstack/tests/unit/cloud/test_floating_ip_neutron.py @@ -928,6 +928,14 @@ class TestFloatingIP(base.TestCase): "network": "this-is-a-net-or-pool-id", "port_id": None, "status": "ACTIVE" + }, { + "id": "this-is-a-second-floating-ip-id", + "fixed_ip_address": None, + "internal_network": None, + "floating_ip_address": "203.0.113.30", + "network": "this-is-a-net-or-pool-id", + "port_id": None, + "status": "ACTIVE" }, { "id": "this-is-an-attached-floating-ip-id", "fixed_ip_address": None, @@ -949,12 +957,24 @@ class TestFloatingIP(base.TestCase): append=['v2.0', 'floatingips/{0}.json'.format( floating_ips[0]['id'])]), json={}), + # First IP has been deleted now, return just the second dict(method='GET', uri=self.get_mock_url( 'network', 'public', append=['v2.0', 'floatingips.json']), - json={'floatingips': [floating_ips[1]]}), + json={'floatingips': floating_ips[1:]}), + dict(method='DELETE', + uri=self.get_mock_url( + 'network', 'public', + append=['v2.0', 'floatingips/{0}.json'.format( + floating_ips[1]['id'])]), + json={}), + dict(method='GET', + uri=self.get_mock_url( + 'network', 'public', append=['v2.0', 'floatingips.json']), + json={'floatingips': [floating_ips[2]]}), ]) - self.cloud.delete_unattached_floating_ips() + cleaned_up = self.cloud.delete_unattached_floating_ips() + self.assertEqual(cleaned_up, 2) self.assert_calls() def test_create_floating_ip_no_port(self): diff --git a/openstack/tests/unit/cloud/test_floating_ip_nova.py b/openstack/tests/unit/cloud/test_floating_ip_nova.py index 1ca9a68a3..7d49e19d8 100644 --- a/openstack/tests/unit/cloud/test_floating_ip_nova.py +++ b/openstack/tests/unit/cloud/test_floating_ip_nova.py @@ -318,4 +318,4 @@ class TestFloatingIP(base.TestCase): def test_cleanup_floating_ips(self): # This should not call anything because it's unsafe on nova. - self.cloud.delete_unattached_floating_ips() + self.assertFalse(self.cloud.delete_unattached_floating_ips())