Make delete_unattached_floating_ips return a count

This modifies delete_unattached_floating_ips to return either a count
of how many floating IPs were cleaned, or False if none were cleaned.

Although this is an API change, from searching both codesearch and
google it seems very likely that nodepool only user of this.  However,
since a positive integer value will evaluate True anyway extant code
should continue to work.

The neturon test-case is updated with an extra floating-ip to make
sure the count works.  The nova test-case is updated to ensure it
returns False to indicate nothing was done.

Sort-of-Needed-By: https://review.openstack.org/614074
Change-Id: I7bd709bd83f352c58203c767779acbe66ecfc10e
This commit is contained in:
Ian Wienand 2018-10-30 15:33:05 +11:00
parent 66c94fd083
commit 61468af124
3 changed files with 25 additions and 5 deletions

View File

@ -6163,7 +6163,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.
"""
@ -6173,7 +6173,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())