Fix config file name setting
[functest.git] / functest / opnfv_tests / openstack / tempest / conf_utils.py
index 91a5bb4..028b085 100644 (file)
@@ -13,8 +13,6 @@ import re
 import shutil
 import subprocess
 
-import opnfv.utils.constants as releng_constants
-
 from functest.utils.constants import CONST
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as ft_utils
@@ -110,24 +108,19 @@ def get_verifier_deployment_dir(verifier_id, deployment_id):
 
 def configure_tempest(deployment_dir, IMAGE_ID=None, FLAVOR_ID=None):
     """
-    Add/update needed parameters into tempest.conf file generated by Rally
+    Calls rally verify and updates the generated tempest.conf with
+    given parameters
     """
-    tempest_conf_file = os.path.join(deployment_dir, "tempest.conf")
-    if os.path.isfile(tempest_conf_file):
-        logger.debug("Verifier is already configured.")
-        logger.debug("Reconfiguring the current verifier...")
-        cmd = "rally verify configure-verifier --reconfigure"
-    else:
-        logger.info("Configuring the verifier...")
-        cmd = "rally verify configure-verifier"
-    ft_utils.execute_command(cmd)
+    conf_file = configure_verifier(deployment_dir)
+    configure_tempest_update_params(conf_file,
+                                    IMAGE_ID, FLAVOR_ID)
 
-    logger.debug("Looking for tempest.conf file...")
-    if not os.path.isfile(tempest_conf_file):
-        logger.error("Tempest configuration file %s NOT found."
-                     % tempest_conf_file)
-        return releng_constants.EXIT_RUN_ERROR
 
+def configure_tempest_update_params(tempest_conf_file,
+                                    IMAGE_ID=None, FLAVOR_ID=None):
+    """
+    Add/update needed parameters into tempest.conf file
+    """
     logger.debug("Updating selected tempest.conf parameters...")
     config = ConfigParser.RawConfigParser()
     config.read(tempest_conf_file)
@@ -178,7 +171,29 @@ def configure_tempest(deployment_dir, IMAGE_ID=None, FLAVOR_ID=None):
     shutil.copyfile(tempest_conf_file,
                     os.path.join(TEMPEST_RESULTS_DIR, 'tempest.conf'))
 
-    return releng_constants.EXIT_OK
+
+def configure_verifier(deployment_dir):
+    """
+    Execute rally verify configure-verifier, which generates tempest.conf
+    """
+    tempest_conf_file = os.path.join(deployment_dir, "tempest.conf")
+    if os.path.isfile(tempest_conf_file):
+        logger.debug("Verifier is already configured.")
+        logger.debug("Reconfiguring the current verifier...")
+        cmd = "rally verify configure-verifier --reconfigure"
+    else:
+        logger.info("Configuring the verifier...")
+        cmd = "rally verify configure-verifier"
+    ft_utils.execute_command(cmd)
+
+    logger.debug("Looking for tempest.conf file...")
+    if not os.path.isfile(tempest_conf_file):
+        logger.error("Tempest configuration file %s NOT found."
+                     % tempest_conf_file)
+        raise Exception("Tempest configuration file %s NOT found."
+                        % tempest_conf_file)
+    else:
+        return tempest_conf_file
 
 
 def configure_tempest_multisite(deployment_dir):
@@ -191,9 +206,8 @@ def configure_tempest_multisite(deployment_dir):
     logger.debug("Finding tempest.conf file...")
     tempest_conf_old = os.path.join(deployment_dir, 'tempest.conf')
     if not os.path.isfile(tempest_conf_old):
-        logger.error("Tempest configuration file %s NOT found."
-                     % tempest_conf_old)
-        return releng_constants.EXIT_RUN_ERROR
+        raise Exception("Tempest configuration file %s NOT found."
+                        % tempest_conf_old)
 
     # Copy tempest.conf to /home/opnfv/functest/results/tempest/
     cur_path = os.path.split(os.path.realpath(__file__))[0]
@@ -265,5 +279,3 @@ def configure_tempest_multisite(deployment_dir):
     config.set('kingbird', 'api_version', kingbird_api_version)
     with open(tempest_conf_file, 'wb') as config_file:
         config.write(config_file)
-
-    return releng_constants.EXIT_OK