From e82b28a92012863f34c407e5df8f24dbc73f630c Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Wed, 11 Dec 2019 20:21:38 +0530 Subject: [PATCH] cgroup_perf_recap: Check if user wants to write to files or not (#64988) if user sets 'write_files' to False or does not set value, then handle file write related operations. Fixes: #64936 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/cgroup_fix_write.yml | 2 ++ .../plugins/callback/cgroup_perf_recap.py | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/cgroup_fix_write.yml diff --git a/changelogs/fragments/cgroup_fix_write.yml b/changelogs/fragments/cgroup_fix_write.yml new file mode 100644 index 00000000000..2461b17c3a5 --- /dev/null +++ b/changelogs/fragments/cgroup_fix_write.yml @@ -0,0 +1,2 @@ +bugfixes: +- Handle write_files option in cgroup_perf_recap callback plugin (https://github.com/ansible/ansible/issues/64936). diff --git a/lib/ansible/plugins/callback/cgroup_perf_recap.py b/lib/ansible/plugins/callback/cgroup_perf_recap.py index c21d3e2f81e..678503dc664 100644 --- a/lib/ansible/plugins/callback/cgroup_perf_recap.py +++ b/lib/ansible/plugins/callback/cgroup_perf_recap.py @@ -277,6 +277,7 @@ class CallbackModule(CallbackBase): self._file_per_task = False self._counter = 0 + self.write_files = False def _open_files(self, task_uuid=None): output_format = self._output_format @@ -296,13 +297,14 @@ class CallbackModule(CallbackBase): except Exception: pass - filename = self._file_name_format % data + if self.write_files: + filename = self._file_name_format % data - self._files[feature] = open(os.path.join(output_dir, filename), 'w+') - if output_format == b'csv': - self._writers[feature] = partial(csv_writer, csv.writer(self._files[feature])) - elif output_format == b'json': - self._writers[feature] = partial(json_writer, self._files[feature]) + self._files[feature] = open(os.path.join(output_dir, filename), 'w+') + if output_format == b'csv': + self._writers[feature] = partial(csv_writer, csv.writer(self._files[feature])) + elif output_format == b'json': + self._writers[feature] = partial(json_writer, self._files[feature]) def set_options(self, task_keys=None, var_options=None, direct=None): super(CallbackModule, self).set_options(task_keys=task_keys, var_options=var_options, direct=direct) @@ -355,7 +357,7 @@ class CallbackModule(CallbackBase): 'pids': partial(PidsProf, pid_current_file, poll_interval=pid_poll_interval), } - write_files = self.get_option('write_files') + self.write_files = self.get_option('write_files') file_per_task = self.get_option('file_per_task') self._output_format = to_bytes(self.get_option('output_format')) output_dir = to_bytes(self.get_option('output_dir'), errors='surrogate_or_strict') @@ -368,7 +370,7 @@ class CallbackModule(CallbackBase): file_name_format = to_bytes(self.get_option('file_name_format')) - if write_files: + if self.write_files: if file_per_task: self._file_per_task = True if file_name_format == b'%(feature)s.%(ext)s':