summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorDevan Goodwin <dgoodwin@redhat.com>2016-07-28 15:10:10 -0300
committerDevan Goodwin <dgoodwin@redhat.com>2016-08-08 15:59:09 -0300
commitf28826b474df693c45ff59c64e0536bad4e1c35f (patch)
tree1df68c12e79ecfd7e1e20ad89740cdc83a8b7d3d /library
parent4bb6264a131082cc14f4a16e7b118bea2b5263de (diff)
downloadopenshift-f28826b474df693c45ff59c64e0536bad4e1c35f.tar.gz
openshift-f28826b474df693c45ff59c64e0536bad4e1c35f.tar.bz2
openshift-f28826b474df693c45ff59c64e0536bad4e1c35f.tar.xz
openshift-f28826b474df693c45ff59c64e0536bad4e1c35f.zip
Fixed a bug in modify_yaml module.
When adding a property to a section that does not yet exist, the property was being inserted into the section above where it should have due to the pointer not being adjusted for the new section we created. Adds a test sub-directory, would like to eventually move all the ooinstall tests here as well so nosetests just works from top level directory.
Diffstat (limited to 'library')
-rwxr-xr-xlibrary/modify_yaml.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/library/modify_yaml.py b/library/modify_yaml.py
index a4be10ca3..63b507a72 100755
--- a/library/modify_yaml.py
+++ b/library/modify_yaml.py
@@ -20,6 +20,24 @@ EXAMPLES = '''
yaml_value: 2
'''
+
+# pylint: disable=missing-docstring
+def set_key(yaml_data, yaml_key, yaml_value):
+ changes = []
+ ptr = yaml_data
+ for key in yaml_key.split('.'):
+ if key not in ptr and key != yaml_key.split('.')[-1]:
+ ptr[key] = {}
+ ptr = ptr[key]
+ elif key == yaml_key.split('.')[-1]:
+ if (key in ptr and module.safe_eval(ptr[key]) != yaml_value) or (key not in ptr):
+ ptr[key] = yaml_value
+ changes.append((yaml_key, yaml_value))
+ else:
+ ptr = ptr[key]
+ return changes
+
+
def main():
''' Modify key (supplied in jinja2 dot notation) in yaml file, setting
the key to the desired value.
@@ -53,22 +71,12 @@ def main():
yaml.add_representer(type(None), none_representer)
try:
- changes = []
yaml_file = open(dest)
yaml_data = yaml.safe_load(yaml_file.read())
yaml_file.close()
- ptr = yaml_data
- for key in yaml_key.split('.'):
- if key not in ptr and key != yaml_key.split('.')[-1]:
- ptr[key] = {}
- elif key == yaml_key.split('.')[-1]:
- if (key in ptr and module.safe_eval(ptr[key]) != yaml_value) or (key not in ptr):
- ptr[key] = yaml_value
- changes.append((yaml_key, yaml_value))
- else:
- ptr = ptr[key]
+ changes = set_key(yaml_data, yaml_key, yaml_value)
if len(changes) > 0:
if backup: