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 <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2019-12-11 20:21:38 +05:30 committed by GitHub
parent 4da87fb3ee
commit e82b28a920
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- Handle write_files option in cgroup_perf_recap callback plugin (https://github.com/ansible/ansible/issues/64936).

View file

@ -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,6 +297,7 @@ class CallbackModule(CallbackBase):
except Exception:
pass
if self.write_files:
filename = self._file_name_format % data
self._files[feature] = open(os.path.join(output_dir, filename), 'w+')
@ -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':