Reduce the number of iterations to ten in rally scenarios
[functest.git] / testcases / VIM / OpenStack / CI / libraries / run_rally-cert.py
index d2128d9..0fb6ce7 100755 (executable)
@@ -27,6 +27,7 @@ from novaclient import client as novaclient
 from glanceclient import client as glanceclient
 from keystoneclient.v2_0 import client as keystoneclient
 from neutronclient.v2_0 import client as neutronclient
+from cinderclient import client as cinderclient
 
 """ tests configuration """
 tests = ['authenticate', 'glance', 'cinder', 'heat', 'keystone',
@@ -100,7 +101,9 @@ SUPPORT_DIR = SCENARIOS_DIR + "scenario/support"
 FLAVOR_NAME = "m1.tiny"
 USERS_AMOUNT = 2
 TENANTS_AMOUNT = 3
-CONTROLLERS_AMOUNT = 2
+ITERATIONS_AMOUNT = 10
+CONCURRENCY = 4
+
 ###
 RESULTS_DIR = functest_yaml.get("general").get("directories"). \
     get("dir_rally_res")
@@ -119,6 +122,8 @@ GLANCE_IMAGE_FORMAT = functest_yaml.get("general"). \
 GLANCE_IMAGE_PATH = functest_yaml.get("general"). \
     get("directories").get("dir_functest_data") + "/" + GLANCE_IMAGE_FILENAME
 
+CINDER_VOLUME_TYPE_NAME = "volume_test"
+
 
 def push_results_to_db(payload):
 
@@ -158,16 +163,14 @@ def task_succeed(json_raw):
     :return: Bool
     """
     rally_report = json.loads(json_raw)
-    rally_report = rally_report[0]
-    if rally_report is None:
-        return False
-    if rally_report.get('result') is None:
-        return False
-
-    for result in rally_report.get('result'):
-        if len(result.get('error')) > 0:
+    for report in rally_report:
+        if report is None or report.get('result') is None:
             return False
 
+        for result in report.get('result'):
+            if result is None or len(result.get('error')) > 0:
+                return False
+
     return True
 
 
@@ -184,11 +187,38 @@ def build_task_args(test_file_name):
     task_args['sup_dir'] = SUPPORT_DIR
     task_args['users_amount'] = USERS_AMOUNT
     task_args['tenants_amount'] = TENANTS_AMOUNT
-    task_args['controllers_amount'] = CONTROLLERS_AMOUNT
+    task_args['iterations'] = ITERATIONS_AMOUNT
+    task_args['concurrency'] = CONCURRENCY
 
     return task_args
 
 
+def get_output(proc):
+    result = ""
+    if args.verbose:
+        while proc.poll() is None:
+            line = proc.stdout.readline()
+            print line.replace('\n', '')
+            result += line
+    else:
+        while proc.poll() is None:
+            line = proc.stdout.readline()
+            if "Load duration" in line or \
+               "started" in line or \
+               "finished" in line or \
+               " Preparing" in line or \
+               "+-" in line or \
+               "|" in line:
+                result += line
+            elif "test scenario" in line:
+                result += "\n" + line
+            elif "Full duration" in line:
+                result += line + "\n\n"
+        logger.info("\n" + result)
+
+    return result
+
+
 def run_task(test_name):
     #
     # the "main" function of the script who launch rally for a task
@@ -196,7 +226,7 @@ def run_task(test_name):
     # :return: void
     #
 
-    logger.info('starting {} test ...'.format(test_name))
+    logger.info('Starting test scenario "{}" ...'.format(test_name))
 
     task_file = '{}task.yaml'.format(SCENARIOS_DIR)
     if not os.path.exists(task_file):
@@ -216,13 +246,8 @@ def run_task(test_name):
     logger.debug('running command line : {}'.format(cmd_line))
 
     p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, stderr=RALLY_STDERR, shell=True)
-    result = ""
-    while p.poll() is None:
-        l = p.stdout.readline()
-        print l.replace('\n', '')
-        result += l
-
-    task_id = get_task_id(result)
+    output = get_output(p)
+    task_id = get_task_id(output)
     logger.debug('task_id : {}'.format(task_id))
 
     if task_id is None:
@@ -262,9 +287,9 @@ def run_task(test_name):
 
     """ parse JSON operation result """
     if task_succeed(json_results):
-        print 'Test OK'
+        logger.info('Test scenario: "{}" OK.'.format(test_name) + "\n")
     else:
-        print 'Test KO'
+        logger.info('Test scenario: "{}" Failed.'.format(test_name) + "\n")
 
 
 def main():
@@ -283,9 +308,28 @@ def main():
                                                    endpoint_type='publicURL')
     glance_client = glanceclient.Client(1, glance_endpoint,
                                         token=keystone_client.auth_token)
+    creds_cinder = functest_utils.get_credentials("cinder")
+    cinder_client = cinderclient.Client('2',creds_cinder['username'],
+                                        creds_cinder['api_key'],
+                                        creds_cinder['project_id'],
+                                        creds_cinder['auth_url'],
+                                        service_type="volume")
 
     client_dict['neutron'] = neutron_client
 
+    volume_types = functest_utils.list_volume_types(cinder_client, private=False)
+    if not volume_types:
+        volume_type = functest_utils.create_volume_type(cinder_client, \
+                                                        CINDER_VOLUME_TYPE_NAME)
+        if not volume_type:
+            logger.error("Failed to create volume type...")
+            exit(-1)
+        else:
+            logger.debug("Volume type '%s' created succesfully..." \
+                         % CINDER_VOLUME_TYPE_NAME)
+    else:
+        logger.debug("Using existing volume type(s)...")
+
     image_id = functest_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME)
 
     if image_id == '':
@@ -307,7 +351,6 @@ def main():
         for test_name in tests:
             if not (test_name == 'all' or
                     test_name == 'vm'):
-                print(test_name)
                 run_task(test_name)
     else:
         print(args.test_name)
@@ -318,5 +361,12 @@ def main():
     if not functest_utils.delete_glance_image(nova_client, image_id):
         logger.error("Error deleting the glance image")
 
+    if not volume_types:
+        logger.debug("Deleting volume type '%s'..." \
+                             % CINDER_VOLUME_TYPE_NAME)
+        if not functest_utils.delete_volume_type(cinder_client, volume_type):
+            logger.error("Error in deleting volume type...")
+
+
 if __name__ == '__main__':
     main()