diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2020-04-13 13:50:23 -0400 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2020-04-22 10:01:00 -0400 |
commit | b9909e5a916540b5f1b8c11c0946309abe6e275e (patch) | |
tree | eeb98caf37a42c4983b8e497821e3940e9407214 | |
parent | 005991275d1f1bae57f5f2627dbb647d8337e0ec (diff) | |
download | sos-b9909e5a916540b5f1b8c11c0946309abe6e275e.tar.gz |
[Policy] Allow check() to inspect remote content
Updates the `check()` method within `Policy` to allow consumers to
specify a `remote` parameter that can be used in place of the locally
available files.
This is the first step in merging `SoSHost` from collector with the
standard `Policy` which is far better defined.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/policies/__init__.py | 6 | ||||
-rw-r--r-- | sos/policies/amazon.py | 6 | ||||
-rw-r--r-- | sos/policies/debian.py | 6 | ||||
-rw-r--r-- | sos/policies/ibmkvm.py | 12 | ||||
-rw-r--r-- | sos/policies/osx.py | 6 | ||||
-rw-r--r-- | sos/policies/redhat.py | 33 | ||||
-rw-r--r-- | sos/policies/suse.py | 8 | ||||
-rw-r--r-- | sos/policies/ubuntu.py | 6 |
8 files changed, 68 insertions, 15 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index 81f995e7..114dd667 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -612,10 +612,14 @@ any third party. "list of subclasses that this policy can " "process") - def check(self): + def check(self, remote=''): """ This function is responsible for determining if the underlying system is supported by this policy. + + If `remote` is provided, it should be the contents of os-release from + a remote host, or a similar vendor-specific file that can be used in + place of a locally available file. """ return False diff --git a/sos/policies/amazon.py b/sos/policies/amazon.py index e573aae0..34160b2a 100644 --- a/sos/policies/amazon.py +++ b/sos/policies/amazon.py @@ -22,7 +22,11 @@ class AmazonPolicy(RedHatPolicy): super(AmazonPolicy, self).__init__(sysroot=sysroot) @classmethod - def check(cls): + def check(cls, remote=''): + + if remote: + return cls.distro in remote + if not os.path.exists(OS_RELEASE): return False diff --git a/sos/policies/debian.py b/sos/policies/debian.py index 1d7bc57f..3d5094aa 100644 --- a/sos/policies/debian.py +++ b/sos/policies/debian.py @@ -34,9 +34,13 @@ class DebianPolicy(LinuxPolicy): }.get(binary, binary) @classmethod - def check(cls): + def check(cls, remote=''): """This method checks to see if we are running on Debian. It returns True or False.""" + + if remote: + return cls.distro in remote + return os.path.isfile('/etc/debian_version') def dist_version(self): diff --git a/sos/policies/ibmkvm.py b/sos/policies/ibmkvm.py index 1990fcd5..b684291c 100644 --- a/sos/policies/ibmkvm.py +++ b/sos/policies/ibmkvm.py @@ -26,9 +26,13 @@ class PowerKVMPolicy(RedHatPolicy): self.valid_subclasses = [PowerKVMPlugin, RedHatPlugin] @classmethod - def check(cls): + def check(cls, remote=''): """This method checks to see if we are running on PowerKVM. It returns True or False.""" + + if remote: + return cls.distro in remote + return os.path.isfile('/etc/ibm_powerkvm-release') def dist_version(self): @@ -50,9 +54,13 @@ class ZKVMPolicy(RedHatPolicy): self.valid_subclasses = [ZKVMPlugin, RedHatPlugin] @classmethod - def check(cls): + def check(cls, remote=''): """This method checks to see if we are running on IBM Z KVM. It returns True or False.""" + + if remote: + return cls.distro in remote + return os.path.isfile('/etc/base-release') def dist_version(self): diff --git a/sos/policies/osx.py b/sos/policies/osx.py index 2228e1e2..434db007 100644 --- a/sos/policies/osx.py +++ b/sos/policies/osx.py @@ -7,7 +7,11 @@ class OSXPolicy(Policy): distro = "Mac OS X" @classmethod - def check(cls): + def check(cls, remote=''): + + if remote: + return cls.distro in remote + try: return "Mac OS X" in shell_out("sw_vers") except Exception: diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py index 0618a420..560339c6 100644 --- a/sos/policies/redhat.py +++ b/sos/policies/redhat.py @@ -77,10 +77,15 @@ class RedHatPolicy(LinuxPolicy): self.load_presets() @classmethod - def check(cls): + def check(cls, remote=''): """This method checks to see if we are running on Red Hat. It must be overriden by concrete subclasses to return True when running on a - Fedora, RHEL or other Red Hat distribution or False otherwise.""" + Fedora, RHEL or other Red Hat distribution or False otherwise. + + If `remote` is provided, it should be the contents of a remote host's + os-release, or comparable, file to be used in place of the locally + available one. + """ return False def check_usrmove(self, pkgs): @@ -268,7 +273,7 @@ support representative. self.register_presets(rhel_presets) @classmethod - def check(cls): + def check(cls, remote=''): """Test to see if the running host is a RHEL installation. Checks for the presence of the "Red Hat Enterprise Linux" @@ -279,6 +284,10 @@ support representative. :returns: ``True`` if the host is running RHEL or ``False`` otherwise. """ + + if remote: + return cls.distro in remote + if not os.path.exists(OS_RELEASE): return False @@ -404,7 +413,11 @@ support representative. self.register_presets(atomic_presets) @classmethod - def check(cls): + def check(cls, remote=''): + + if remote: + return cls.distro in remote + atomic = False if ENV_HOST_SYSROOT not in os.environ: return atomic @@ -440,7 +453,11 @@ support representative. super(RedHatCoreOSPolicy, self).__init__(sysroot=sysroot) @classmethod - def check(cls): + def check(cls, remote=''): + + if remote: + return cls.distro in remote + coreos = False if ENV_HOST_SYSROOT not in os.environ: return coreos @@ -474,9 +491,13 @@ class FedoraPolicy(RedHatPolicy): super(FedoraPolicy, self).__init__(sysroot=sysroot) @classmethod - def check(cls): + def check(cls, remote=''): """This method checks to see if we are running on Fedora. It returns True or False.""" + + if remote: + return cls.distro in remote + return os.path.isfile('/etc/fedora-release') def fedora_version(self): diff --git a/sos/policies/suse.py b/sos/policies/suse.py index 87007fc2..31fa91e2 100644 --- a/sos/policies/suse.py +++ b/sos/policies/suse.py @@ -41,7 +41,7 @@ class SuSEPolicy(LinuxPolicy): self.set_exec_path() @classmethod - def check(cls): + def check(cls, remote=''): """This method checks to see if we are running on SuSE. It must be overriden by concrete subclasses to return True when running on an OpenSuSE, SLES or other Suse distribution and False otherwise.""" @@ -99,7 +99,11 @@ No changes will be made to system configuration. super(OpenSuSEPolicy, self).__init__(sysroot=sysroot) @classmethod - def check(cls): + def check(cls, remote): """This method checks to see if we are running on SuSE. """ + + if remote: + return cls.distro in remote + return (os.path.isfile('/etc/SuSE-release')) diff --git a/sos/policies/ubuntu.py b/sos/policies/ubuntu.py index b7067d14..ad5a4cc9 100644 --- a/sos/policies/ubuntu.py +++ b/sos/policies/ubuntu.py @@ -20,9 +20,13 @@ class UbuntuPolicy(DebianPolicy): self.valid_subclasses = [UbuntuPlugin, DebianPlugin] @classmethod - def check(cls): + def check(cls, remote=''): """This method checks to see if we are running on Ubuntu. It returns True or False.""" + + if remote: + return cls.distro in remote + try: with open('/etc/lsb-release', 'r') as fp: return "Ubuntu" in fp.read() |