diff options
author | 2018-10-14 12:08:03 +0200 | |
---|---|---|
committer | 2018-10-14 13:27:59 +0200 | |
commit | 06a1649e11007ee4d8f61562839cdb58fe0ed783 (patch) | |
tree | 11defd46c41e0715a4d60c7b4f53309f9b2056b1 /functest/utils | |
parent | 19a00e2eb8f6cb0aa0ed6d18f41b006857e22550 (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>
(cherry picked from commit 904377462f58464937d4cafeb8c432f024a85bd4)
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(',')] |