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: If106ef16349a88f3fcd363927bd4b27d11cbbbf3
Depends-On: If8055b3362f1d9d1f274baa447fac094a6a91481
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
Kevin Carter 2016-02-08 20:30:57 -06:00 committed by Jesse Pretorius (odyssey4me)
parent ec2ef9a020
commit 864ba64c6c
1 changed files with 8 additions and 4 deletions

View File

@ -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