From 9390dde943915da9fe0e21b8d4822a3f31a347cf Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 7 Jan 2016 15:40:27 -0800 Subject: [PATCH] make floating IP specification test robust to races The get_unused_ip function returns an address that isn't in use on the network at the time it's called. However, by the time the caller uses it, it may have been allocated to another concurrent test if the network is shared or external. The test_create_floatingip_with_specified_ip_address test creates a floating IP with an unused IP on the external network, which has lots of activity on it from other tests so it would occasionally have its address taken by another test. This patch just catches the in use error and tries again with a new IP. Change-Id: I5a2f78a6da1e400dea07949f35964abb767edbb2 Closes-Bug: #1532033 --- .../admin/test_floating_ips_admin_actions.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/neutron/tests/api/admin/test_floating_ips_admin_actions.py b/neutron/tests/api/admin/test_floating_ips_admin_actions.py index 45bd5c99c..b95cfe4aa 100644 --- a/neutron/tests/api/admin/test_floating_ips_admin_actions.py +++ b/neutron/tests/api/admin/test_floating_ips_admin_actions.py @@ -140,10 +140,20 @@ class FloatingIPAdminTestJSON(base.BaseAdminNetworkTest): @test.attr(type='smoke') @test.idempotent_id('332a8ae4-402e-4b98-bb6f-532e5a87b8e0') def test_create_floatingip_with_specified_ip_address(self): - fip = self.get_unused_ip(self.ext_net_id, ip_version=4) - body = self.admin_client.create_floatingip( - floating_network_id=self.ext_net_id, - floating_ip_address=fip) + # other tests may end up stealing the IP before we can use it + # since it's on the external network so we need to retry if it's + # in use. + for i in range(100): + fip = self.get_unused_ip(self.ext_net_id, ip_version=4) + try: + body = self.admin_client.create_floatingip( + floating_network_id=self.ext_net_id, + floating_ip_address=fip) + break + except lib_exc.Conflict: + pass + else: + self.fail("Could not get an unused IP after 100 attempts") created_floating_ip = body['floatingip'] self.addCleanup(self.admin_client.delete_floatingip, created_floating_ip['id']) -- 2.45.2