Wait for instance deletion 35/62035/2
authorStamatis Katsaounis <mokats@intracom-telecom.com>
Mon, 10 Sep 2018 08:11:49 +0000 (11:11 +0300)
committerStamatis Katsaounis <mokats@intracom-telecom.com>
Thu, 27 Sep 2018 09:08:41 +0000 (12:08 +0300)
JIRA: SDNVPN-222

Confirm the deletion of instance in order to prevent its port
existence when trying to delete relevant subnet in a later stage.

Change-Id: Iace0fbbd90d50f05764ac09682caae59baba22fa
Signed-off-by: Stamatis Katsaounis <mokats@intracom-telecom.com>
sdnvpn/lib/utils.py

index e43750c..9f4c883 100644 (file)
@@ -371,6 +371,21 @@ def async_Wait_for_instances(instances, tries=40):
         logger.error("one or more instances is not yet booted up")
 
 
+def wait_for_instance_delete(nova_client, instance_id, tries=30):
+    sleep_time = 2
+    instances = [instance_id]
+    logger.debug("Waiting for instance %s to be deleted"
+                 % (instance_id))
+    while tries > 0 and instance_id in instances:
+        instances = [instance.id for instance in
+                     os_utils.get_instances(nova_client)]
+        time.sleep(sleep_time)
+        tries -= 1
+    if instance_id in instances:
+        logger.error("Deletion of instance %s failed" %
+                     (instance_id))
+
+
 def wait_for_bgp_net_assoc(neutron_client, bgpvpn_id, net_id):
     tries = 30
     sleep_time = 1
@@ -702,7 +717,8 @@ def cleanup_nova(nova_client, instance_ids, flavor_ids=None):
                 logger.error('Fail to delete all instances. '
                              'Instance with id {} was not deleted.'.
                              format(instance_id))
-                return False
+            else:
+                wait_for_instance_delete(nova_client, instance_id)
     return True