Merge "Make delete_unattached_floating_ips return a count"

This commit is contained in:
Zuul 2018-10-31 00:39:18 +00:00 committed by Gerrit Code Review
commit 6cf265488f
3 changed files with 25 additions and 5 deletions

View File

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

View File

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

View File

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