diff options
author | amitg.b14@gmail.com <amitg.b14@gmail.com> | 2016-01-15 20:36:49 +0530 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2016-10-21 17:47:30 +0100 |
commit | 7ed39691a7744758615eb000f78c464202d3e5a5 (patch) | |
tree | a075b9ef23fef4caf660c3e4172ecc07d1c6c8fa | |
parent | 069932fe5d1eb9f7b1aba632bb587c73064fd238 (diff) | |
download | sos-7ed39691a7744758615eb000f78c464202d3e5a5.tar.gz |
[sosreport] handle SIGTERM correctly in plugin setup()/collect() phases
Added "self.exit_process" statements to stop process with SIGTERM
signal. Added "self.handle_exception()" function to handle plugin
exception and SIGTERM signal.
Closes:#689
-rw-r--r-- | sos/sosreport.py | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/sos/sosreport.py b/sos/sosreport.py index 30c2b057..62942e82 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -682,6 +682,7 @@ class SoSReport(object): self._args = args self.sysroot = "/" self.sys_tmp = None + self.exit_process = False try: import signal @@ -810,9 +811,16 @@ class SoSReport(object): def get_exit_handler(self): def exit_handler(signum, frame): + self.exit_process = True self._exit() return exit_handler + def handle_exception(self, plugname=None, func=None): + if self.raise_plugins or self.exit_process: + raise + if plugname and func: + self._log_plugin_exception(plugname, func) + def _read_config(self): self.config = ConfigParser() if self.opts.config_file: @@ -962,6 +970,7 @@ class SoSReport(object): continue plugin_class = self.policy.match_plugin(plugin_classes) + if not validate_plugin(plugin_class, experimental=self.opts.experimental): self.soslog.warning( @@ -1009,13 +1018,11 @@ class SoSReport(object): for i in plugin_class.profiles: if i in remaining_profiles: remaining_profiles.remove(i) - self._load(plugin_class) except Exception as e: self.soslog.warning(_("plugin %s does not install, " "skipping: %s") % (plug, e)) - if self.raise_plugins: - raise + self.handle_exception() if len(remaining_profiles) > 0: self.soslog.error(_("Unknown or inactive profile(s) provided:" " %s") % ", ".join(remaining_profiles)) @@ -1254,13 +1261,9 @@ class SoSReport(object): % e.strerror) self.ui_log.error("") self._exit(1) - if self.raise_plugins: - raise - self._log_plugin_exception(plugname, "setup") + self.handle_exception(plugname, "setup") except: - if self.raise_plugins: - raise - self._log_plugin_exception(plugname, "setup") + self.handle_exception(plugname, "setup") def version(self): """Fetch version information from all plugins and store in the report @@ -1268,8 +1271,10 @@ class SoSReport(object): versions = [] versions.append("sosreport: %s" % __version__) + for plugname, plug in self.loaded_plugins: versions.append("%s: %s" % (plugname, plug.version)) + self.archive.add_string(content="\n".join(versions), dest='version.txt') @@ -1302,13 +1307,9 @@ class SoSReport(object): % e.strerror) self.ui_log.error("") self._exit(1) - if self.raise_plugins: - raise - self._log_plugin_exception(plugname, "collect") + self.handle_exception(plugname, "collect") except: - if self.raise_plugins: - raise - self._log_plugin_exception(plugname, "collect") + self.handle_exception(plugname, "collect") self.ui_log.info("") def report(self): @@ -1432,8 +1433,7 @@ class SoSReport(object): try: html = plug.report() except: - if self.raise_plugins: - raise + self.handle_exception() else: rfd.write(html) rfd.write("</body></html>") @@ -1452,13 +1452,9 @@ class SoSReport(object): % e.strerror) self.ui_log.error("") self._exit(1) - if self.raise_plugins: - raise - self._log_plugin_exception(plugname, "postproc") + self.handle_exception(plugname, "postproc") except: - if self.raise_plugins: - raise - self._log_plugin_exception(plugname, "postproc") + self.handle_exception(plugname, "postproc") def _create_checksum(self, archive, hash_name): if not archive: |