diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-10-14 12:08:03 +0200 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-10-14 12:32:19 +0200 |
commit | 904377462f58464937d4cafeb8c432f024a85bd4 (patch) | |
tree | e60fabfa4c9ae175e2797d2900c7b201267b9005 /functest/utils | |
parent | d0d471502ff7b5dfabf4a2ede79782c5708a463c (diff) |
Fix image properties parsing
It removes useless spaces and now conforms with oslo.conf dict.
New helpers and unit tests are available.
Change-Id: I20335c5e5c3840cc872e158c6072d97a3f2cb98c
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/utils')
-rw-r--r-- | functest/utils/functest_utils.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py index dd2bf1932..7ae74393d 100644 --- a/functest/utils/functest_utils.py +++ b/functest/utils/functest_utils.py @@ -15,6 +15,8 @@ import subprocess import sys import yaml +import six + LOGGER = logging.getLogger(__name__) @@ -134,3 +136,33 @@ def get_openstack_version(cloud): except AssertionError: LOGGER.exception("Cannot detect OpenStack version") return "Unknown" + + +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) + + +def convert_ini_to_dict(value): + "Convert oslo.conf input to dict" + assert isinstance(value, str) + try: + return {k: v for k, v in (x.split(':') for x in value.split(','))} + except ValueError: + return {} + + +def convert_ini_to_list(value): + "Convert list to oslo.conf input" + assert isinstance(value, str) + if not value: + return [] + return [x for x in value.split(',')] |