summaryrefslogtreecommitdiffstats
path: root/roles/lib_utils/library
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2017-03-24 13:07:24 -0400
committerKenny Woodson <kwoodson@redhat.com>2017-03-28 15:28:34 -0400
commitaa9e19c20b745f91a47292f8754a8cf52017c3e4 (patch)
tree4bb2dd64e3adc6483c5e76cad76d9f211ecffd50 /roles/lib_utils/library
parenta69a84339e1bf187aa970316a4148138cb7f82fb (diff)
downloadopenshift-aa9e19c20b745f91a47292f8754a8cf52017c3e4.tar.gz
openshift-aa9e19c20b745f91a47292f8754a8cf52017c3e4.tar.bz2
openshift-aa9e19c20b745f91a47292f8754a8cf52017c3e4.tar.xz
openshift-aa9e19c20b745f91a47292f8754a8cf52017c3e4.zip
Adding a few more test cases. Fixed a bug when key was empty. Safeguard against yedit module being passed an empty key
Diffstat (limited to 'roles/lib_utils/library')
-rw-r--r--roles/lib_utils/library/yedit.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/roles/lib_utils/library/yedit.py b/roles/lib_utils/library/yedit.py
index b311354da..48d5a411b 100644
--- a/roles/lib_utils/library/yedit.py
+++ b/roles/lib_utils/library/yedit.py
@@ -201,8 +201,6 @@ EXAMPLES = '''
# -*- -*- -*- End included fragment: doc/yedit -*- -*- -*-
# -*- -*- -*- Begin included fragment: class/yedit.py -*- -*- -*-
-# pylint: disable=undefined-variable,missing-docstring
-# noqa: E301,E302
class YeditException(Exception):
@@ -236,13 +234,13 @@ class Yedit(object):
@property
def separator(self):
- ''' getter method for yaml_dict '''
+ ''' getter method for separator '''
return self._separator
@separator.setter
- def separator(self):
- ''' getter method for yaml_dict '''
- return self._separator
+ def separator(self, inc_sep):
+ ''' setter method for separator '''
+ self._separator = inc_sep
@property
def yaml_dict(self):
@@ -656,7 +654,17 @@ class Yedit(object):
pass
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
- if not result:
+ if result is None:
+ return (False, self.yaml_dict)
+
+ # When path equals "" it is a special case.
+ # "" refers to the root of the document
+ # Only update the root path (entire document) when its a list or dict
+ if path == '':
+ if isinstance(result, list) or isinstance(result, dict):
+ self.yaml_dict = result
+ return (True, self.yaml_dict)
+
return (False, self.yaml_dict)
self.yaml_dict = tmp_copy
@@ -682,7 +690,7 @@ class Yedit(object):
pass
result = Yedit.add_entry(tmp_copy, path, value, self.separator)
- if result:
+ if result is not None:
self.yaml_dict = tmp_copy
return (True, self.yaml_dict)
@@ -724,7 +732,7 @@ class Yedit(object):
# If vtype is not str then go ahead and attempt to yaml load it.
elif isinstance(inc_value, str) and 'str' not in vtype:
try:
- inc_value = yaml.load(inc_value)
+ inc_value = yaml.safe_load(inc_value)
except Exception:
raise YeditException('Could not determine type of incoming ' +
'value. value=[%s] vtype=[%s]'
@@ -856,6 +864,8 @@ class Yedit(object):
'result': rval[1],
'state': state}
+ # We were passed content but no src, key or value, or edits. Return contents in memory
+ return {'changed': False, 'result': yamlfile.yaml_dict, 'state': state}
return {'failed': True, 'msg': 'Unkown state passed'}
# -*- -*- -*- End included fragment: class/yedit.py -*- -*- -*-
@@ -893,6 +903,9 @@ def main():
required_one_of=[["content", "src"]],
)
+ if module.params['src'] is not None and module.params['key'] in [None, '']:
+ module.fail_json(failed=True, msg='Empty value for parameter key not allowed.')
+
rval = Yedit.run_ansible(module.params)
if 'failed' in rval and rval['failed']:
module.fail_json(**rval)