ConfigParser is used for tempest.conf updating 21/12621/1
authorvitikkan <viktor.tikkanen@nokia.com>
Mon, 25 Apr 2016 07:43:29 +0000 (10:43 +0300)
committervitikkan <viktor.tikkanen@nokia.com>
Mon, 25 Apr 2016 07:44:48 +0000 (10:44 +0300)
Bash commands are replaced with python's ConfigParser routines
for configuration file reading/updating.

Removed updating of ssh_user_regex parameter since it is now
into upstream Rally code.

JIRA: FUNCTEST-198

Change-Id: I95f926948a395993e28e993bf7ea2872d6b5c969
Signed-off-by: vitikkan <viktor.tikkanen@nokia.com>
testcases/VIM/OpenStack/CI/libraries/run_tempest.py

index b2240c9..8407da2 100644 (file)
@@ -23,6 +23,7 @@ import shutil
 import subprocess
 import time
 import yaml
+import ConfigParser
 
 import keystoneclient.v2_0.client as ksclient
 from neutronclient.v2_0 import client as neutronclient
@@ -217,7 +218,9 @@ def configure_tempest(mode):
         cmd += "testr list-tests >" + TEMPEST_LIST_FILE + ";cd"
         functest_utils.execute_command(cmd, logger)
 
-    logger.debug("  Updating fixed_network_name...")
+    logger.debug("Updating selected tempest.conf parameters...")
+    config = ConfigParser.RawConfigParser()
+    config.read(tempest_conf_file)
     private_net_name = ""
     creds_neutron = openstack_utils.get_credentials("neutron")
     neutron_client = neutronclient.Client(**creds_neutron)
@@ -226,24 +229,12 @@ def configure_tempest(mode):
         logger.error("No shared private networks found.")
     else:
         private_net_name = private_net['name']
-    cmd = "crudini --set " + tempest_conf_file + \
-          " compute fixed_network_name " + \
-          private_net_name
-    functest_utils.execute_command(cmd, logger)
-
-    logger.debug("  Updating non-admin credentials...")
-    cmd = "crudini --set " + tempest_conf_file + " identity tenant_name " \
-          + TENANT_NAME
-    functest_utils.execute_command(cmd, logger)
-    cmd = "crudini --set " + tempest_conf_file + " identity username " \
-          + USER_NAME
-    functest_utils.execute_command(cmd, logger)
-    cmd = "crudini --set " + tempest_conf_file + " identity password " \
-          + USER_PASSWORD
-    functest_utils.execute_command(cmd, logger)
-    cmd = "sed -i 's/.*ssh_user_regex.*/ssh_user_regex = " + SSH_USER_REGEX + \
-        "/' " + tempest_conf_file
-    functest_utils.execute_command(cmd, logger)
+    config.set('compute', 'fixed_network_name', private_net_name)
+    config.set('identity', 'tenant_name', TENANT_NAME)
+    config.set('identity', 'username', USER_NAME)
+    config.set('identity', 'password', USER_PASSWORD)
+    with open(tempest_conf_file, 'wb') as config_file:
+        config.write(config_file)
 
     # Copy tempest.conf to /home/opnfv/functest/results/tempest/
     shutil.copyfile(tempest_conf_file, TEMPEST_RESULTS_DIR + '/tempest.conf')