Check if rally image already exist and don't create it again if so 67/7467/4
authorjose.lausuch <jose.lausuch@ericsson.com>
Wed, 20 Jan 2016 14:39:29 +0000 (15:39 +0100)
committerjose.lausuch <jose.lausuch@ericsson.com>
Wed, 20 Jan 2016 14:52:42 +0000 (15:52 +0100)
Change-Id: Ib872b7c21449fe4dc9c4331401fbfbff86140f68
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
testcases/VIM/OpenStack/CI/libraries/run_rally-cert.py
testcases/VIM/OpenStack/CI/libraries/run_rally.py

index 13066b3..17a6596 100755 (executable)
@@ -282,20 +282,22 @@ def main():
 
     client_dict['neutron'] = neutron_client
 
-    logger.debug("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, GLANCE_IMAGE_PATH))
-    image_id = functest_utils.create_glance_image(glance_client,
-                                            GLANCE_IMAGE_NAME,GLANCE_IMAGE_PATH)
-    if not image_id:
-        logger.error("Failed to create a Glance image...")
-        exit(-1)
-    # Check if the given image exists
-    try:
-        nova_client.images.find(name=GLANCE_IMAGE_NAME)
-        logger.info("Glance image found '%s'" % GLANCE_IMAGE_NAME)
-    except:
-        logger.error("ERROR: Glance image '%s' not found." % GLANCE_IMAGE_NAME)
-        logger.info("Available images are: ")
-        exit(-1)
+    image_id = functest_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME)
+
+    if image_id == '':
+        logger.debug("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, \
+                                                           GLANCE_IMAGE_PATH))
+        image_id = functest_utils.create_glance_image(glance_client,\
+                                                GLANCE_IMAGE_NAME,GLANCE_IMAGE_PATH)
+        if not image_id:
+            logger.error("Failed to create the Glance image...")
+            exit(-1)
+        else:
+            logger.debug("Image '%s' with ID '%s' created succesfully ." \
+                         % (GLANCE_IMAGE_NAME, image_id))
+    else:
+        logger.debug("Using existing image '%s' with ID '%s'..." \
+                     % (GLANCE_IMAGE_NAME,image_id))
 
     if args.test_name == "all":
         for test_name in tests:
@@ -307,7 +309,8 @@ def main():
         print(args.test_name)
         run_task(args.test_name)
 
-    logger.debug("Deleting image...")
+    logger.debug("Deleting image '%s' with ID '%s'..." \
+                         % (GLANCE_IMAGE_NAME, image_id))
     if not functest_utils.delete_glance_image(nova_client, image_id):
         logger.error("Error deleting the glance image")
 
index b879758..a7f1db1 100644 (file)
@@ -122,16 +122,6 @@ def get_task_id(cmd_raw):
     return None
 
 
-def create_glance_image(path, name, disk_format):
-    """
-    Create a glance image given the absolute path of the image, its name and the disk format
-    """
-    cmd = ("glance image-create --name " + name + "  --visibility public "
-           "--disk-format " + disk_format + " --container-format bare --file " + path)
-    functest_utils.execute_command(cmd, logger)
-    return True
-
-
 def task_succeed(json_raw):
     """
     Parse JSON from rally JSON results
@@ -244,20 +234,24 @@ def main():
     glance_client = glanceclient.Client(1, glance_endpoint,
                                         token=keystone_client.auth_token)
 
-    logger.debug("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, GLANCE_IMAGE_PATH))
-    image_id = functest_utils.create_glance_image(glance_client,
-                                            GLANCE_IMAGE_NAME,GLANCE_IMAGE_PATH)
-    if not image_id:
-        logger.error("Failed to create a Glance image...")
-        exit(-1)
-    # Check if the given image exists
-    try:
-        nova_client.images.find(name=GLANCE_IMAGE_NAME)
-        logger.info("Glance image found '%s'" % GLANCE_IMAGE_NAME)
-    except:
-        logger.error("ERROR: Glance image '%s' not found." % GLANCE_IMAGE_NAME)
-        logger.info("Available images are: ")
-        exit(-1)
+
+    image_id = functest_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME)
+
+    if image_id == '':
+        logger.debug("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME, \
+                                                           GLANCE_IMAGE_PATH))
+        image_id = functest_utils.create_glance_image(glance_client,\
+                                                GLANCE_IMAGE_NAME,GLANCE_IMAGE_PATH)
+        if not image_id:
+            logger.error("Failed to create the Glance image...")
+            exit(-1)
+        else:
+            logger.debug("Image '%s' with ID '%s' created succesfully ." \
+                         % (GLANCE_IMAGE_NAME, image_id))
+    else:
+        logger.debug("Using existing image '%s' with ID '%s'..." \
+                     % (GLANCE_IMAGE_NAME,image_id))
+
 
     if args.test_name == "all":
         for test_name in tests:
@@ -272,6 +266,8 @@ def main():
         print(args.test_name)
         run_task(args.test_name)
 
+    logger.debug("Deleting image '%s' with ID '%s'..." \
+                         % (GLANCE_IMAGE_NAME, image_id))
     if not functest_utils.delete_glance_image(nova_client, image_id):
         logger.error("Error deleting the glance image")