summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-09-05 15:17:04 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2018-09-05 15:45:47 +0200
commit9ec639526ed32d4b05168627c5c016fb66b7d008 (patch)
tree325b728fc8b2e5cbadaffcef2eb057b9dfad5cc5
parentfbb0d16e9ccec7f2b543906ff13801d802fecc3f (diff)
Update scenario section in tempest.conf
It's required at least by Barbican tempest plugin. Change-Id: I46a65ee5fee044917c5375adaa8ebb529efe86ec Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/opnfv_tests/openstack/tempest/conf_utils.py18
-rw-r--r--functest/opnfv_tests/openstack/tempest/tempest.py24
-rw-r--r--functest/tests/unit/openstack/tempest/test_conf_utils.py20
3 files changed, 61 insertions, 1 deletions
diff --git a/functest/opnfv_tests/openstack/tempest/conf_utils.py b/functest/opnfv_tests/openstack/tempest/conf_utils.py
index 8a4bb9386..80f78e979 100644
--- a/functest/opnfv_tests/openstack/tempest/conf_utils.py
+++ b/functest/opnfv_tests/openstack/tempest/conf_utils.py
@@ -19,6 +19,7 @@ import os
import subprocess
import pkg_resources
+import six
from six.moves import configparser
import yaml
@@ -210,7 +211,9 @@ def configure_tempest_update_params(
else:
auth_version = 'v2'
if env.get("NEW_USER_ROLE").lower() != "member":
- rconfig.set('auth', 'tempest_roles', env.get("NEW_USER_ROLE"))
+ rconfig.set(
+ 'auth', 'tempest_roles',
+ convert_list_to_ini([env.get("NEW_USER_ROLE")]))
if not json.loads(env.get("USE_DYNAMIC_CREDENTIALS").lower()):
rconfig.set('auth', 'use_dynamic_credentials', False)
account_file = os.path.join(
@@ -262,3 +265,16 @@ def configure_verifier(deployment_dir):
% tempest_conf_file)
else:
return tempest_conf_file
+
+
+def convert_dict_to_ini(value):
+ "Convert dict to oslo.conf input"
+ assert isinstance(value, dict)
+ return ",".join("{}={}".format(
+ key, val) for (key, val) in six.iteritems(value))
+
+
+def convert_list_to_ini(value):
+ "Convert list to oslo.conf input"
+ assert isinstance(value, list)
+ return ",".join("{}".format(val) for val in value)
diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py
index 329e6b917..f30bbc552 100644
--- a/functest/opnfv_tests/openstack/tempest/tempest.py
+++ b/functest/opnfv_tests/openstack/tempest/tempest.py
@@ -353,6 +353,29 @@ class TempestCommon(singlevm.VmReady2):
with open(rally_conf, 'wb') as config_file:
rconfig.write(config_file)
+ def update_scenario_section(self):
+ """Update scenario section in tempest.conf"""
+ rconfig = configparser.RawConfigParser()
+ rconfig.read(self.conf_file)
+ filename = getattr(
+ config.CONF, '{}_image'.format(self.case_name), self.filename)
+ if not rconfig.has_section('scenario'):
+ rconfig.add_section('scenario')
+ rconfig.set('scenario', 'img_file', os.path.basename(filename))
+ rconfig.set('scenario', 'img_dir', os.path.dirname(filename))
+ rconfig.set('scenario', 'img_disk_format', getattr(
+ config.CONF, '{}_image_format'.format(self.case_name),
+ self.image_format))
+ extra_properties = self.extra_properties.copy()
+ extra_properties.update(
+ getattr(config.CONF, '{}_extra_properties'.format(
+ self.case_name), {}))
+ rconfig.set(
+ 'scenario', 'img_properties',
+ conf_utils.convert_dict_to_ini(extra_properties))
+ with open(self.conf_file, 'wb') as config_file:
+ rconfig.write(config_file)
+
def configure(self, **kwargs): # pylint: disable=unused-argument
"""
Create all openstack resources for tempest-based testcases and write
@@ -375,6 +398,7 @@ class TempestCommon(singlevm.VmReady2):
image_alt_id=self.image_alt.id,
flavor_alt_id=self.flavor_alt.id,
domain_name=self.cloud.auth.get("project_domain_name", "Default"))
+ self.update_scenario_section()
self.backup_tempest_config(self.conf_file, self.res_dir)
def run(self, **kwargs):
diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py
index 7d94b88cc..7c493372f 100644
--- a/functest/tests/unit/openstack/tempest/test_conf_utils.py
+++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py
@@ -182,6 +182,26 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
['rally', 'verify', 'configure-verifier', '--reconfigure',
'--id', str(getattr(config.CONF, 'tempest_verifier_name'))])
+ def test_convert_dict_to_ini(self):
+ self.assertEqual(
+ conf_utils.convert_dict_to_ini({}), "")
+ self.assertEqual(
+ conf_utils.convert_dict_to_ini({"a": "b"}), "a=b")
+ value = conf_utils.convert_dict_to_ini({"a": "b", "c": "d"})
+ self.assertTrue(value == "a=b,c=d" or value == "c=d,a=b")
+ with self.assertRaises(AssertionError):
+ conf_utils.convert_list_to_ini("")
+
+ def test_convert_list_to_ini(self):
+ self.assertEqual(
+ conf_utils.convert_list_to_ini([]), "")
+ self.assertEqual(
+ conf_utils.convert_list_to_ini(["a"]), "a")
+ self.assertEqual(
+ conf_utils.convert_list_to_ini(["a", "b"]), "a,b")
+ with self.assertRaises(AssertionError):
+ conf_utils.convert_list_to_ini("")
+
if __name__ == "__main__":
logging.disable(logging.CRITICAL)