From 852ab822622928f20d963f7ffb450bcce72c5a69 Mon Sep 17 00:00:00 2001 From: Kevin Carter Date: Mon, 8 Feb 2016 14:26:45 -0600 Subject: [PATCH] Updated config parsing for listOPS This change updates the list parsing for all list options passed through the config_template module using the INI configuration type. This change is needed so that when passing a list into a configuration file for use within an OpenStack service oslo.config properlly handles the lists as a comma seperated value when rendered. Closes-Bug: #1543588 Change-Id: If8055b3362f1d9d1f274baa447fac094a6a91481 Signed-off-by: Kevin Carter --- actions/config_template.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/actions/config_template.py b/actions/config_template.py index fdb8d5d..60a9c3e 100644 --- a/actions/config_template.py +++ b/actions/config_template.py @@ -67,6 +67,8 @@ class ActionModule(object): # If the items value is not a dictionary it is assumed that the # value is a default item for this config type. if not isinstance(items, dict): + if isinstance(items, list): + items = ','.join(items) config.set('DEFAULT', str(section), str(items)) else: # Attempt to add a section to the config file passing if @@ -77,6 +79,8 @@ class ActionModule(object): except (ConfigParser.DuplicateSectionError, ValueError): pass for key, value in items.items(): + if isinstance(value, list): + value = ','.join(value) config.set(str(section), str(key), str(value)) else: config_object.close() @@ -140,11 +144,11 @@ class ActionModule(object): base_items.get(key, {}), value ) + elif ',' in value or '\n' in value: + base_items[key] = re.split(', |,|\n', value) + base_items[key] = [i.strip() for i in base_items[key] if i] elif isinstance(value, list): - if key in base_items and isinstance(base_items[key], list): - base_items[key].extend(value) - else: - base_items[key] = value + base_items[key] = value else: base_items[key] = new_items[key] return base_items