aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2020-04-14 12:49:30 -0400
committerJake Hunsaker <jhunsake@redhat.com>2020-04-22 10:01:01 -0400
commitf1e27634bfac0f0a28d1a754bb89f7844df405b2 (patch)
tree49213595933ae546ce3f3f97fad96cdb8e05060b
parent80180b736d00d3f12a1413eb0861efa24853d2e0 (diff)
downloadsos-f1e27634bfac0f0a28d1a754bb89f7844df405b2.tar.gz
[sos] Do not require collect to be available for base sos runs
Not all distributions want to add a dependency on pexpect as a default for the installation of sos, as report does not require it. As such, if we fail to import the collector module, add placeholder psuedo-components so that --help output (and attempts to run the command outright) still indicate that the functionality is available in some manner, just with an additional step from the user. This covers two distinct failures during the collector import: 1. The collector module is not present. This implies that the module has been split into sub-packages. The user will need to install the appropriate sub-package for their distro. 2. The pexpect package is not present. The user will just need to install the python3 pexpect package. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/__init__.py28
-rw-r--r--sos/missing.py36
2 files changed, 61 insertions, 3 deletions
diff --git a/sos/__init__.py b/sos/__init__.py
index c0ac67a3..1ab4501d 100644
--- a/sos/__init__.py
+++ b/sos/__init__.py
@@ -33,6 +33,12 @@ def _default(msg):
_sos = _default
+# py3 < 3.6 compat
+try:
+ ModuleNotFoundError
+except NameError:
+ ModuleNotFoundError = ImportError
+
class SoS():
"""Main entrypoint for sos from the command line
@@ -51,11 +57,27 @@ class SoS():
# of shorthand names to accept in place of the full subcommand
# if no aliases are desired, pass an empty list
import sos.report
- import sos.collector
self._components = {
- 'report': (sos.report.SoSReport, ['rep']),
- 'collect': (sos.collector.SoSCollector, ['collector'])
+ 'report': (sos.report.SoSReport, ['rep'])
}
+ # some distros do not want pexpect as a default dep, so try to load
+ # collector here, and if it fails add an entry that implies it is at
+ # least present on this installation
+ try:
+ import sos.collector
+ self._components['collect'] = (sos.collector.SoSCollector,
+ ['collector'])
+ except ModuleNotFoundError as err:
+ import sos.missing
+ if 'sos.collector' in err.msg:
+ # is not locally installed - packaged separately
+ self._components['collect'] = (sos.missing.MissingCollect, [])
+ elif 'pexpect' in err.msg:
+ # cannot be imported due to missing the pexpect dep
+ self._components['collect'] = (sos.missing.MissingPexpect, [])
+ else:
+ # we failed elsewhere, re-raise the exception
+ raise
# build the top-level parser
_com_string = ''
for com in self._components:
diff --git a/sos/missing.py b/sos/missing.py
new file mode 100644
index 00000000..f6ad2ceb
--- /dev/null
+++ b/sos/missing.py
@@ -0,0 +1,36 @@
+
+import sys
+from sos.component import SoSComponent
+
+
+class MissingCollect(SoSComponent):
+ """This is used as a placeholder for when the local sos installation
+ attempts to import sos.collector, but that module is not present. In those
+ scenarios, it means that sos has been split into sub-packages. Barring
+ incorrect splitting, this 'sos.missing' module should always be available
+ to the main sos package.
+ """
+
+ load_policy = False
+ configure_logging = False
+ desc = '(unavailable) Collect an sos report from multiple nodes'
+
+ def execute(self):
+ sys.stderr.write(
+ "The collect command is unavailable as it appears to be packaged "
+ "separately for your distribution.\n\nPlease install the latest "
+ "sos-collector package to enable this functionality.\n"
+ )
+
+
+class MissingPexpect(MissingCollect):
+ """This is used as a placeholder for when the collect component is locally
+ installed, but cannot be used due to a missing pexpect dependency.
+ """
+
+ def execute(self):
+ sys.stderr.write(
+ "The collect command is unavailable due to a missing dependency "
+ "on python3-pexpect.\n\nPlease install python3-pexpect to enable "
+ "this functionality.\n"
+ )