diff options
Diffstat (limited to 'roles/lib_openshift/library/oc_serviceaccount.py')
-rw-r--r-- | roles/lib_openshift/library/oc_serviceaccount.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/roles/lib_openshift/library/oc_serviceaccount.py b/roles/lib_openshift/library/oc_serviceaccount.py index 55ab099f8..0db0d1219 100644 --- a/roles/lib_openshift/library/oc_serviceaccount.py +++ b/roles/lib_openshift/library/oc_serviceaccount.py @@ -290,6 +290,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: @@ -298,15 +309,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) @@ -1516,7 +1523,7 @@ class OCServiceAccount(OpenShiftCLI): def main(): ''' - ansible oc module for route + ansible oc module for service accounts ''' module = AnsibleModule( |