Merge "Remove get_repo_tag"
[functest.git] / functest / utils / openstack_clean.py
old mode 100755 (executable)
new mode 100644 (file)
index 29ebb33..d7df8f8
@@ -23,7 +23,6 @@
 #
 
 import logging
-import sys
 import time
 import yaml
 
@@ -138,9 +137,9 @@ def remove_volumes(cinder_client, default_volumes):
                          "NOT be deleted.")
 
 
-def remove_floatingips(nova_client, default_floatingips):
+def remove_floatingips(neutron_client, default_floatingips):
     logger.debug("Removing floating IPs...")
-    floatingips = os_utils.get_floating_ips(nova_client)
+    floatingips = os_utils.get_floating_ips(neutron_client)
     if floatingips is None or len(floatingips) == 0:
         logger.debug("No floating IPs found.")
         return
@@ -148,13 +147,13 @@ def remove_floatingips(nova_client, default_floatingips):
     init_len = len(floatingips)
     deleted = 0
     for fip in floatingips:
-        fip_id = getattr(fip, 'id')
-        fip_ip = getattr(fip, 'ip')
+        fip_id = fip['id']
+        fip_ip = fip['floating_ip_address']
         logger.debug("'%s', ID=%s " % (fip_ip, fip_id))
         if (fip_id not in default_floatingips and
                 fip_ip not in default_floatingips.values()):
             logger.debug("Removing floating IP %s ..." % fip_id)
-            if os_utils.delete_floating_ip(nova_client, fip_id):
+            if os_utils.delete_floating_ip(neutron_client, fip_id):
                 logger.debug("  > Done!")
                 deleted += 1
             else:
@@ -166,7 +165,7 @@ def remove_floatingips(nova_client, default_floatingips):
 
     timeout = 50
     while timeout > 0:
-        floatingips = os_utils.get_floating_ips(nova_client)
+        floatingips = os_utils.get_floating_ips(neutron_client)
         if floatingips is None or len(floatingips) == (init_len - deleted):
             break
         else:
@@ -382,6 +381,7 @@ def remove_tenants(keystone_client, default_tenants):
 
 
 def main():
+    logging.basicConfig()
     logger.info("Cleaning OpenStack resources...")
 
     nova_client = os_utils.get_nova_client()
@@ -419,7 +419,7 @@ def main():
     separator()
     remove_volumes(cinder_client, default_volumes)
     separator()
-    remove_floatingips(nova_client, default_floatingips)
+    remove_floatingips(neutron_client, default_floatingips)
     separator()
     remove_networks(neutron_client, default_networks, default_routers)
     separator()
@@ -430,8 +430,3 @@ def main():
     remove_tenants(keystone_client, default_tenants)
     separator()
     return 0
-
-
-if __name__ == '__main__':
-    logging.basicConfig()
-    sys.exit(main())