summaryrefslogtreecommitdiffstats
path: root/roles/lib_utils/library
diff options
context:
space:
mode:
authorThomas Wiest <twiest@redhat.com>2017-01-29 14:47:07 -0500
committerThomas Wiest <twiest@redhat.com>2017-02-06 17:03:48 -0500
commitd508ec24877a743c6d79dac0574c859e14d40218 (patch)
treeba462f616ca507e33cfbf4dc18e3764eb1aad4a1 /roles/lib_utils/library
parent76d0a4538baa3b59085d6dd57b92ffd145c76f93 (diff)
downloadopenshift-d508ec24877a743c6d79dac0574c859e14d40218.tar.gz
openshift-d508ec24877a743c6d79dac0574c859e14d40218.tar.bz2
openshift-d508ec24877a743c6d79dac0574c859e14d40218.tar.xz
openshift-d508ec24877a743c6d79dac0574c859e14d40218.zip
Added oc_serviceaccount_secret to lib_openshift.
Diffstat (limited to 'roles/lib_utils/library')
-rw-r--r--roles/lib_utils/library/yedit.py23
1 files changed, 15 insertions, 8 deletions
diff --git a/roles/lib_utils/library/yedit.py b/roles/lib_utils/library/yedit.py
index 7ad2b7181..1c74b4d3f 100644
--- a/roles/lib_utils/library/yedit.py
+++ b/roles/lib_utils/library/yedit.py
@@ -356,6 +356,17 @@ class Yedit(object):
return data
+ @staticmethod
+ def _write(filename, contents):
+ ''' Actually write the file contents to disk. This helps with mocking. '''
+
+ tmp_filename = filename + '.yedit'
+
+ with open(tmp_filename, 'w') as yfd:
+ yfd.write(contents)
+
+ os.rename(tmp_filename, filename)
+
def write(self):
''' write to file '''
if not self.filename:
@@ -364,15 +375,11 @@ class Yedit(object):
if self.backup and self.file_exists():
shutil.copy(self.filename, self.filename + '.orig')
- tmp_filename = self.filename + '.yedit'
- with open(tmp_filename, 'w') as yfd:
- # pylint: disable=no-member
- if hasattr(self.yaml_dict, 'fa'):
- self.yaml_dict.fa.set_block_style()
-
- yfd.write(yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
+ # pylint: disable=no-member
+ if hasattr(self.yaml_dict, 'fa'):
+ self.yaml_dict.fa.set_block_style()
- os.rename(tmp_filename, self.filename)
+ Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
return (True, self.yaml_dict)