Merge "Create API to run a test case"
[functest.git] / functest / utils / openstack_snapshot.py
old mode 100755 (executable)
new mode 100644 (file)
index a03c503..3dc6f80
@@ -22,7 +22,6 @@
 
 import logging
 import yaml
-import sys
 
 import functest.utils.openstack_utils as os_utils
 from functest.utils.constants import CONST
@@ -48,13 +47,13 @@ def get_instances(nova_client):
     return {'instances': dic_instances}
 
 
-def get_images(nova_client):
+def get_images(glance_client):
     logger.debug("Getting images...")
     dic_images = {}
-    images = os_utils.get_images(nova_client)
-    if not (images is None or len(images) == 0):
-        for image in images:
-            dic_images.update({getattr(image, 'id'): getattr(image, 'name')})
+    images = os_utils.get_images(glance_client)
+    if images is None:
+        return -1
+    dic_images.update({image.id: image.name for image in images})
     return {'images': dic_images}
 
 
@@ -131,12 +130,14 @@ def get_tenants(keystone_client):
 
 
 def main():
+    logging.basicConfig()
     logger.info("Generating OpenStack snapshot...")
 
     nova_client = os_utils.get_nova_client()
     neutron_client = os_utils.get_neutron_client()
     keystone_client = os_utils.get_keystone_client()
     cinder_client = os_utils.get_cinder_client()
+    glance_client = os_utils.get_glance_client()
 
     if not os_utils.check_credentials():
         logger.error("Please source the openrc credentials and run the" +
@@ -145,7 +146,7 @@ def main():
 
     snapshot = {}
     snapshot.update(get_instances(nova_client))
-    snapshot.update(get_images(nova_client))
+    snapshot.update(get_images(glance_client))
     snapshot.update(get_volumes(cinder_client))
     snapshot.update(get_networks(neutron_client))
     snapshot.update(get_routers(neutron_client))
@@ -162,8 +163,3 @@ def main():
         logger.debug("NOTE: These objects will NOT be deleted after " +
                      "running the test.")
     return 0
-
-
-if __name__ == '__main__':
-    logging.basicConfig()
-    sys.exit(main())