Merge "Add sfc in thirdparty-requirements.txt"
[functest.git] / functest / utils / openstack_utils.py
index f155449..e7cdfc8 100644 (file)
@@ -82,7 +82,8 @@ def get_env_cred_dict():
         'OS_PROJECT_NAME': 'project_name',
         'OS_ENDPOINT_TYPE': 'endpoint_type',
         'OS_REGION_NAME': 'region_name',
-        'OS_CACERT': 'https_cacert'
+        'OS_CACERT': 'https_cacert',
+        'OS_INSECURE': 'https_insecure'
     }
     return env_cred_dict
 
@@ -150,10 +151,12 @@ def get_credentials_for_rally():
         cred_key = env_cred_dict.get('OS_REGION_NAME')
         rally_conf[cred_key] = region_name
 
-    cacert = os.getenv('OS_CACERT')
-    if cacert is not None:
-        cred_key = env_cred_dict.get('OS_CACERT')
-        rally_conf[cred_key] = cacert
+    cred_key = env_cred_dict.get('OS_CACERT')
+    rally_conf[cred_key] = os.getenv('OS_CACERT', '')
+
+    insecure_key = env_cred_dict.get('OS_INSECURE')
+    rally_conf[insecure_key] = os.getenv('OS_INSECURE', '').lower() == 'true'
+
     return rally_conf
 
 
@@ -181,14 +184,10 @@ def get_endpoint(service_type, endpoint_type='publicURL'):
 
 def get_session(other_creds={}):
     auth = get_session_auth(other_creds)
-    cacert = os.getenv('OS_CACERT')
-    if cacert is not None:
-        if not os.path.isfile(cacert):
-            raise Exception("The 'OS_CACERT' environment"
-                            "variable is set to %s but the file"
-                            "does not exist.", cacert)
-
-    return session.Session(auth=auth, verify=cacert)
+    https_cacert = os.getenv('OS_CACERT', '')
+    https_insecure = os.getenv('OS_INSECURE', '').lower() == 'true'
+    return session.Session(auth=auth,
+                           verify=(https_cacert or not https_insecure))
 
 
 # *********************************************
@@ -426,12 +425,12 @@ def get_or_create_flavor(flavor_name, ram, disk, vcpus, public=True):
     return flavor_exists, flavor_id
 
 
-def get_floating_ips(nova_client):
+def get_floating_ips(neutron_client):
     try:
-        floating_ips = nova_client.floating_ips.list()
-        return floating_ips
+        floating_ips = neutron_client.list_floatingips()
+        return floating_ips['floatingips']
     except Exception as e:
-        logger.error("Error [get_floating_ips(nova_client)]: %s" % e)
+        logger.error("Error [get_floating_ips(neutron_client)]: %s" % e)
         return None
 
 
@@ -594,12 +593,12 @@ def delete_instance(nova_client, instance_id):
         return False
 
 
-def delete_floating_ip(nova_client, floatingip_id):
+def delete_floating_ip(neutron_client, floatingip_id):
     try:
-        nova_client.floating_ips.delete(floatingip_id)
+        neutron_client.delete_floatingip(floatingip_id)
         return True
     except Exception as e:
-        logger.error("Error [delete_floating_ip(nova_client, '%s')]: %s"
+        logger.error("Error [delete_floating_ip(neutron_client, '%s')]: %s"
                      % (floatingip_id, e))
         return False
 
@@ -1192,9 +1191,9 @@ def delete_security_group(neutron_client, secgroup_id):
 # *********************************************
 #   GLANCE
 # *********************************************
-def get_images(nova_client):
+def get_images(glance_client):
     try:
-        images = nova_client.images.list()
+        images = glance_client.images.list()
         return images
     except Exception as e:
         logger.error("Error [get_images]: %s" % e)
@@ -1258,12 +1257,12 @@ def get_or_create_image(name, path, format):
     return image_exists, image_id
 
 
-def delete_glance_image(nova_client, image_id):
+def delete_glance_image(glance_client, image_id):
     try:
-        nova_client.images.delete(image_id)
+        glance_client.images.delete(image_id)
         return True
     except Exception as e:
-        logger.error("Error [delete_glance_image(nova_client, '%s')]: %s"
+        logger.error("Error [delete_glance_image(glance_client, '%s')]: %s"
                      % (image_id, e))
         return False