Re-generating tempest.conf file before starting tests
[functest.git] / testcases / OpenStack / tempest / run_tempest.py
index 8d23b74..4a8a3d0 100755 (executable)
@@ -21,11 +21,11 @@ import shutil
 import subprocess
 import sys
 import time
-import yaml
 
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as ft_utils
 import functest.utils.openstack_utils as os_utils
+import yaml
 
 
 modes = ['full', 'smoke', 'baremetal', 'compute', 'data_processing',
@@ -176,12 +176,16 @@ def configure_tempest(deployment_dir):
     Add/update needed parameters into tempest.conf file generated by Rally
     """
 
-    logger.debug("Generating tempest.conf file...")
+    tempest_conf_file = deployment_dir + "/tempest.conf"
+    if os.path.isfile(tempest_conf_file):
+        logger.debug("Deleting old tempest.conf file...")
+        os.remove(tempest_conf_file)
+
+    logger.debug("Generating new tempest.conf file...")
     cmd = "rally verify genconfig"
     ft_utils.execute_command(cmd, logger)
 
     logger.debug("Finding tempest.conf file...")
-    tempest_conf_file = deployment_dir + "/tempest.conf"
     if not os.path.isfile(tempest_conf_file):
         logger.error("Tempest configuration file %s NOT found."
                      % tempest_conf_file)
@@ -214,8 +218,8 @@ def configure_tempest(deployment_dir):
 
 
 def configure_tempest_feature(deployment_dir, mode):
-    """
-    Add/update needed parameters into tempest.conf file generated by Rally
+    """Add/update needed parameters into tempest.conf file generated by Rally
+
     """
 
     logger.debug("Finding tempest.conf file...")
@@ -231,56 +235,11 @@ def configure_tempest_feature(deployment_dir, mode):
     if mode == 'feature_multisite':
         config.set('service_available', 'kingbird', 'true')
         cmd = "openstack endpoint show kingbird | grep publicurl |\
-               awk '{print $4}' | awk -F '/' '{print $4}'"
-        kingbird_api_version = os.popen(cmd).read()
-        if os.environ.get("INSTALLER_TYPE") == 'fuel':
-            # For MOS based setup, the service is accessible
-            # via bind host
-            kingbird_conf_path = "/etc/kingbird/kingbird.conf"
-            installer_type = os.getenv('INSTALLER_TYPE', 'Unknown')
-            installer_ip = os.getenv('INSTALLER_IP', 'Unknown')
-            installer_username = ft_utils.get_parameter_from_yaml(
-                "multisite." + installer_type +
-                "_environment.installer_username")
-            installer_password = ft_utils.get_parameter_from_yaml(
-                "multisite." + installer_type +
-                "_environment.installer_password")
-
-            ssh_options = "-o UserKnownHostsFile=/dev/null -o \
-                StrictHostKeyChecking=no"
-
-            # Get the controller IP from the fuel node
-            cmd = 'sshpass -p %s ssh 2>/dev/null %s %s@%s \
-                    \'fuel node --env 1| grep controller | grep "True\|  1" \
-                    | awk -F\| "{print \$5}"\'' % (installer_password,
-                                                   ssh_options,
-                                                   installer_username,
-                                                   installer_ip)
-            multisite_controller_ip = \
-                "".join(os.popen(cmd).read().split())
-
-            # Login to controller and get bind host details
-            cmd = 'sshpass -p %s ssh 2>/dev/null  %s %s@%s "ssh %s \\" \
-                grep -e "^bind_" %s  \\""' % (installer_password,
-                                              ssh_options,
-                                              installer_username,
-                                              installer_ip,
-                                              multisite_controller_ip,
-                                              kingbird_conf_path)
-            bind_details = os.popen(cmd).read()
-            bind_details = "".join(bind_details.split())
-            # Extract port number from the bind details
-            bind_port = re.findall(r"\D(\d{4})", bind_details)[0]
-            # Extract ip address from the bind details
-            bind_host = re.findall(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",
-                                   bind_details)[0]
-            kingbird_endpoint_url = "http://" + bind_host + ":" + bind_port + \
-                                    "/"
-        else:
-            cmd = "openstack endpoint show kingbird | grep publicurl |\
-                   awk '{print $4}' | awk -F '/' '{print $3}'"
-            kingbird_endpoint_url = os.popen(cmd).read()
-
+               awk '{print $4}'"
+        kingbird_endpoint_details = "".join(os.popen(cmd).read().split())
+        kingbird_endpoint_url = kingbird_endpoint_details.rsplit('/', 1)[0] + \
+            '/'
+        kingbird_api_version = kingbird_endpoint_details.rsplit('/', 1)[1]
         try:
             config.add_section("kingbird")
         except Exception:
@@ -341,7 +300,7 @@ def apply_tempest_blacklist():
             black_list_yaml = yaml.safe_load(black_list_file)
             black_list_file.close()
             for item in black_list_yaml:
-                scenarios = item['sceanrios']
+                scenarios = item['scenarios']
                 installers = item['installers']
                 if (deploy_scenario in scenarios and
                         installer_type in installers):
@@ -353,9 +312,12 @@ def apply_tempest_blacklist():
         black_tests = []
         logger.debug("Tempest blacklist file does not exist.")
 
-    for line in cases_file:
-        if line not in black_tests:
-            result_file.write(str(line) + '\n')
+    for cases_line in cases_file:
+        for black_tests_line in black_tests:
+            if black_tests_line in cases_line:
+                break
+        else:
+            result_file.write(str(cases_line) + '\n')
     result_file.close()
 
 
@@ -427,34 +389,20 @@ def run_tempest(OPTION):
     dur_sec_int = dur_sec_int + 60 * dur_min
     stop_time = time.time()
 
-    status = "FAIL"
     try:
         diff = (int(num_tests) - int(num_failures))
         success_rate = 100 * diff / int(num_tests)
     except:
         success_rate = 0
 
-    # For Tempest we assume that the success rate is above 90%
-    if "smoke" in args.mode:
-        case_name = "tempest_smoke_serial"
-        # Note criteria hardcoded...TODO read it from testcases.yaml
-        success_criteria = 100
-        if success_rate >= success_criteria:
-            status = "PASS"
-        else:
-            logger.info("Tempest success rate: %s%%. The success criteria to "
-                        "pass this test is %s%%. Marking the test as FAILED." %
-                        (success_rate, success_criteria))
+    if 'smoke' in args.mode:
+        case_name = 'tempest_smoke_serial'
     else:
-        case_name = "tempest_full_parallel"
-        # Note criteria hardcoded...TODO read it from testcases.yaml
-        success_criteria = 80
-        if success_rate >= success_criteria:
-            status = "PASS"
-        else:
-            logger.info("Tempest success rate: %s%%. The success criteria to "
-                        "pass this test is %s%%. Marking the test as FAILED." %
-                        (success_rate, success_criteria))
+        case_name = 'tempest_full_parallel'
+
+    status = ft_utils.check_success_rate(case_name, success_rate)
+    logger.info("Tempest %s success_rate is %s%%, is marked as %s"
+                % (case_name, success_rate, status))
 
     # Push results in payload of testcase
     if args.report: