diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2020-06-09 10:32:36 -0400 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2020-06-17 12:11:29 -0400 |
commit | e7b91722b20a51555cf86dbaa36ba840fe6d6350 (patch) | |
tree | 8892fa2a3f7cf622d03f2d5dede2cc2c5461ff33 | |
parent | b11b80b5c4c4c783f0d4d7ea4cb3d70623d9f8f5 (diff) | |
download | sos-e7b91722b20a51555cf86dbaa36ba840fe6d6350.tar.gz |
[report|collect] Handle exceptions raised by SoSCleaner
Updates SoSReport and SoSCollector to better handle any exceptions
raised by SoSCleaner when `--clean` is used, so that we no longer try to
use `SoSCleaner` in subsequent renaming methods (when that object is
likely uninstantiated now due to the exception)
-rw-r--r-- | sos/collector/__init__.py | 8 | ||||
-rw-r--r-- | sos/report/__init__.py | 12 |
2 files changed, 13 insertions, 7 deletions
diff --git a/sos/collector/__init__.py b/sos/collector/__init__.py index 04789ef9..57c767ac 100644 --- a/sos/collector/__init__.py +++ b/sos/collector/__init__.py @@ -1118,6 +1118,7 @@ this utility or remote systems that it connects to. for fname in host.file_list: arc_paths.append(fname) + do_clean = False if self.opts.clean: hook_commons = { 'policy': self.policy, @@ -1132,6 +1133,7 @@ this utility or remote systems that it connects to. hook_commons=hook_commons) cleaner.set_target_path(self.tmpdir) map_file, arc_paths = cleaner.execute() + do_clean = True except Exception as err: self.ui_log.error("ERROR: unable to obfuscate reports: %s" % err) @@ -1142,7 +1144,7 @@ this utility or remote systems that it connects to. dest = fname.split('/')[-1] if fname.endswith(('.md5',)): dest = os.path.join('checksums', fname.split('/')[-1]) - if self.opts.clean: + if do_clean: dest = cleaner.obfuscate_string(dest) name = os.path.join(self.tmpdir, fname) self.archive.add_file(name, dest=dest) @@ -1162,7 +1164,7 @@ this utility or remote systems that it connects to. self.archive.add_final_manifest_data( self.opts.compression_type ) - if self.opts.clean: + if do_clean: _dir = os.path.join(self.tmpdir, self.archive._name) cleaner.obfuscate_file( os.path.join(_dir, 'sos_logs', 'sos.log'), @@ -1179,7 +1181,7 @@ this utility or remote systems that it connects to. arc_name = self.archive.finalize(self.opts.compression_type) final_name = os.path.join(self.sys_tmp, os.path.basename(arc_name)) - if self.opts.clean: + if do_clean: final_name = cleaner.obfuscate_string( final_name.replace('.tar', '-obfuscated.tar') ) diff --git a/sos/report/__init__.py b/sos/report/__init__.py index 0d36fe8f..1cc10f0b 100644 --- a/sos/report/__init__.py +++ b/sos/report/__init__.py @@ -1121,6 +1121,9 @@ class SoSReport(SoSComponent): directory = None # report directory path (--build) map_file = None # path of the map file generated for the report + # use this instead of self.opts.clean beyond the initial check if + # cleaning was requested in case SoSCleaner fails for some reason + do_clean = False if self.opts.clean: try: hook_commons = { @@ -1134,6 +1137,7 @@ class SoSReport(SoSComponent): cleaner.set_target_path(self.archive.get_archive_path()) # ignore the returned paths here map_file, _paths = cleaner.execute() + do_clean = True except Exception as err: print(_("ERROR: Unable to obfuscate report: %s" % err)) @@ -1141,7 +1145,7 @@ class SoSReport(SoSComponent): if self.manifest is not None: self.archive.add_final_manifest_data(self.opts.compression_type) # Now, separately clean the log files that cleaner also wrote to - if self.opts.clean: + if do_clean: _dir = os.path.join(self.tmpdir, self.archive._name) cleaner.obfuscate_file(os.path.join(_dir, 'sos_logs', 'sos.log'), short_name='sos.log') @@ -1159,7 +1163,7 @@ class SoSReport(SoSComponent): print(_("Creating compressed archive...")) # compression could fail for a number of reasons try: - if self.opts.clean: + if do_clean: self.archive.rename_archive_root(cleaner) archive = self.archive.finalize( self.opts.compression_type) @@ -1183,7 +1187,7 @@ class SoSReport(SoSComponent): dir_name = os.path.basename(directory) try: final_dir = os.path.join(self.sys_tmp, dir_name) - if self.opts.clean: + if do_clean: final_dir = cleaner.obfuscate_string(final_dir) os.rename(directory, final_dir) directory = final_dir @@ -1211,7 +1215,7 @@ class SoSReport(SoSComponent): # containing directory. final_name = os.path.join(self.sys_tmp, os.path.basename(archive)) - if self.opts.clean: + if do_clean: final_name = cleaner.obfuscate_string( final_name.replace('.tar', '-obfuscated.tar') ) |