From a429e9c0fba4dbec716be45a7fa2e55c37aac2ac Mon Sep 17 00:00:00 2001 From: Kerim Gokarslan Date: Thu, 7 Sep 2017 16:09:33 -0700 Subject: [PATCH] Added try loop for floating ip association and deletion, and port deletion Change-Id: I94eb3c934a97f951893444c83f8a8dd55e9b8d29 --- vmtp/instance.py | 9 ++++++++- vmtp/network.py | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/vmtp/instance.py b/vmtp/instance.py index a876374..511600f 100644 --- a/vmtp/instance.py +++ b/vmtp/instance.py @@ -18,7 +18,9 @@ import re from log import LOG import monitor import netaddr +from novaclient.exceptions import BadRequest import sshutils +import time # a dictionary of sequence number indexed by a name prefix @@ -193,7 +195,12 @@ class Instance(object): self.ssh_access.host = fip['floatingip']['floating_ip_address'] self.ssh_ip_id = fip['floatingip']['id'] self.display('Associating floating IP %s', self.ssh_access.host) - self.instance.add_floating_ip(self.ssh_access.host, ipv4_fixed_address) + for _ in range(1, 5): + try: + self.instance.add_floating_ip(self.ssh_access.host, ipv4_fixed_address) + break + except BadRequest: + time.sleep(1) # extract the IP for the data network self.display('Internal network IP: %s', self.internal_ip) diff --git a/vmtp/network.py b/vmtp/network.py index 25d2545..ea28f79 100644 --- a/vmtp/network.py +++ b/vmtp/network.py @@ -17,8 +17,10 @@ import time from log import LOG # Module containing a helper class for operating on OpenStack networks +from neutronclient.common.exceptions import IpAddressInUseClient from neutronclient.common.exceptions import NetworkInUseClient from neutronclient.common.exceptions import NeutronException +from neutronclient.common.exceptions import PortInUseClient import vmtp class Network(object): @@ -320,7 +322,13 @@ class Network(object): def delete_port(self, port): LOG.debug('Deleting port ' + port['id']) - self.neutron_client.delete_port(port['id']) + for _ in range(1, 5): + try: + self.neutron_client.delete_port(port['id']) + break + except PortInUseClient: + time.sleep(1) + # Create a floating ip on the external network and return it def create_floating_ip(self): @@ -334,7 +342,13 @@ class Network(object): # Delete floating ip given a floating ip ad def delete_floating_ip(self, floatingip): - self.neutron_client.delete_floatingip(floatingip) + LOG.info("Deleting floating ip " + floatingip) + for _ in range(1, 5): + try: + self.neutron_client.delete_floatingip(floatingip) + break + except IpAddressInUseClient: + time.sleep(1) # Dispose all network resources, call after all VM have been deleted def dispose(self):