aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2020-04-13 14:19:31 -0400
committerJake Hunsaker <jhunsake@redhat.com>2020-04-22 10:01:01 -0400
commit1e9deb27f90ae5f22e3f5fdcdc6641f49438e662 (patch)
tree5cbbd2725c5afa66ae58e9713a50ffd202f12d9f
parentb0cecd882b6299da01b5b71bda4f55b8d12fb081 (diff)
downloadsos-1e9deb27f90ae5f22e3f5fdcdc6641f49438e662.tar.gz
[PackageManager] Allow for remote execution of package commands
When loading a policy, there is now support for a `remote_exec` parameter, which should be an ssh command, to which will be appended `PackageManager` related commands so that collector can get package data off of the remote nodes, without having to reimplement a subset of `PackageManager` itself. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/policies/__init__.py11
-rw-r--r--sos/policies/amazon.py6
-rw-r--r--sos/policies/debian.py6
-rw-r--r--sos/policies/ibmkvm.py6
-rw-r--r--sos/policies/redhat.py30
-rw-r--r--sos/policies/suse.py6
-rw-r--r--sos/policies/ubuntu.py6
7 files changed, 50 insertions, 21 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 114dd667..7ab1477c 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -336,7 +336,7 @@ class PackageManager(object):
def __init__(self, chroot=None, query_command=None,
verify_command=None, verify_filter=None,
- files_command=None):
+ files_command=None, remote_exec=None):
self.packages = {}
self.files = []
@@ -345,6 +345,15 @@ class PackageManager(object):
self.verify_filter = verify_filter if verify_filter else None
self.files_command = files_command if files_command else None
+
+ # if needed, append the remote command to these so that this returns
+ # the remote package details, not local
+ if remote_exec:
+ for cmd in ['query_command', 'verify_command', 'files_command']:
+ if getattr(self, cmd) is not None:
+ _cmd = getattr(self, cmd)
+ setattr(self, cmd, "%s %s" % (remote_exec, quote(_cmd)))
+
if chroot:
self.chroot = chroot
diff --git a/sos/policies/amazon.py b/sos/policies/amazon.py
index 4e764a9d..8418bf35 100644
--- a/sos/policies/amazon.py
+++ b/sos/policies/amazon.py
@@ -18,9 +18,11 @@ class AmazonPolicy(RedHatPolicy):
vendor = "Amazon"
vendor_url = "https://aws.amazon.com"
- def __init__(self, sysroot=None, init=None, probe_runtime=True):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(AmazonPolicy, self).__init__(sysroot=sysroot, init=init,
- probe_runtime=probe_runtime)
+ probe_runtime=probe_runtime,
+ remote_exec=remote_exec)
@classmethod
def check(cls, remote=''):
diff --git a/sos/policies/debian.py b/sos/policies/debian.py
index 968b96a6..b286e9db 100644
--- a/sos/policies/debian.py
+++ b/sos/policies/debian.py
@@ -17,14 +17,16 @@ class DebianPolicy(LinuxPolicy):
PATH = "/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" \
+ ":/usr/local/sbin:/usr/local/bin"
- def __init__(self, sysroot=None, init=None, probe_runtime=True):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(DebianPolicy, self).__init__(sysroot=sysroot, init=init,
probe_runtime=probe_runtime)
self.ticket_number = ""
self.package_manager = PackageManager(query_command=self._debq_cmd,
verify_command=self._debv_cmd,
verify_filter=self._debv_filter,
- chroot=sysroot)
+ chroot=sysroot,
+ remote_exec=remote_exec)
self.valid_subclasses = [DebianPlugin]
diff --git a/sos/policies/ibmkvm.py b/sos/policies/ibmkvm.py
index e1d17ab5..29aa5b9a 100644
--- a/sos/policies/ibmkvm.py
+++ b/sos/policies/ibmkvm.py
@@ -21,9 +21,11 @@ class PowerKVMPolicy(RedHatPolicy):
vendor = "IBM"
vendor_url = "http://www-03.ibm.com/systems/power/software/linux/powerkvm"
- def __init__(self, sysroot=None, init=None, probe_runtime=True):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(PowerKVMPolicy, self).__init__(sysroot=sysroot, init=init,
- probe_runtime=probe_runtime)
+ probe_runtime=probe_runtime,
+ remote_exec=remote_exec)
self.valid_subclasses = [PowerKVMPlugin, RedHatPlugin]
@classmethod
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index de3f5445..336a842f 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -39,7 +39,8 @@ class RedHatPolicy(LinuxPolicy):
upload_directory = '/incoming'
default_container_runtime = 'podman'
- def __init__(self, sysroot=None, init=None, probe_runtime=True):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(RedHatPolicy, self).__init__(sysroot=sysroot, init=init,
probe_runtime=probe_runtime)
self.ticket_number = ""
@@ -55,7 +56,8 @@ class RedHatPolicy(LinuxPolicy):
verify_command=self._rpmv_cmd,
verify_filter=self._rpmv_filter,
files_command=self._rpmql_cmd,
- chroot=sysroot)
+ chroot=sysroot,
+ remote_exec=remote_exec)
self.valid_subclasses = [RedHatPlugin]
@@ -269,9 +271,11 @@ support representative.
_upload_user = 'anonymous'
_upload_directory = '/incoming'
- def __init__(self, sysroot=None, init=None, probe_runtime=True):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(RHELPolicy, self).__init__(sysroot=sysroot, init=init,
- probe_runtime=probe_runtime)
+ probe_runtime=probe_runtime,
+ remote_exec=remote_exec)
self.register_presets(rhel_presets)
@classmethod
@@ -410,9 +414,11 @@ generated in %(tmpdir)s and may be provided to a %(vendor)s \
support representative.
""" + disclaimer_text + "%(vendor_text)s\n")
- def __init__(self, sysroot=None, init=None, probe_runtime=True):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(RedHatAtomicPolicy, self).__init__(sysroot=sysroot, init=init,
- probe_runtime=probe_runtime)
+ probe_runtime=probe_runtime,
+ remote_exec=remote_exec)
self.register_presets(atomic_presets)
@classmethod
@@ -452,9 +458,11 @@ generated in %(tmpdir)s and may be provided to a %(vendor)s \
support representative.
""" + disclaimer_text + "%(vendor_text)s\n")
- def __init__(self, sysroot=None, init=None, probe_runtime=True):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(RedHatCoreOSPolicy, self).__init__(sysroot=sysroot, init=init,
- probe_runtime=probe_runtime)
+ probe_runtime=probe_runtime,
+ remote_exec=remote_exec)
@classmethod
def check(cls, remote=''):
@@ -491,9 +499,11 @@ class FedoraPolicy(RedHatPolicy):
vendor = "the Fedora Project"
vendor_url = "https://fedoraproject.org/"
- def __init__(self, sysroot=None, init=None, probe_runtime=probe_runtime):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(FedoraPolicy, self).__init__(sysroot=sysroot, init=init,
- probe_runtime=probe_runtime)
+ probe_runtime=probe_runtime,
+ remote_exec=remote_exec)
@classmethod
def check(cls, remote=''):
diff --git a/sos/policies/suse.py b/sos/policies/suse.py
index c9c7d29b..9418ead4 100644
--- a/sos/policies/suse.py
+++ b/sos/policies/suse.py
@@ -21,12 +21,14 @@ class SuSEPolicy(LinuxPolicy):
vendor_url = "https://www.suse.com/"
_tmp_dir = "/var/tmp"
- def __init__(self, sysroot=None, init=None, probe_runtime=True):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(SuSEPolicy, self).__init__(sysroot=sysroot, init=init,
probe_runtime=probe_runtime)
self.ticket_number = ""
self.package_manager = PackageManager(
- 'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"')
+ 'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"',
+ remote_exec=remote_exec)
self.valid_subclasses = [SuSEPlugin, RedHatPlugin]
pkgs = self.package_manager.all_pkgs()
diff --git a/sos/policies/ubuntu.py b/sos/policies/ubuntu.py
index e3fdcf24..a4b0de8d 100644
--- a/sos/policies/ubuntu.py
+++ b/sos/policies/ubuntu.py
@@ -15,9 +15,11 @@ class UbuntuPolicy(DebianPolicy):
_upload_password = "ubuntu"
_use_https_streaming = True
- def __init__(self, sysroot=None, init=None, probe_runtime=True):
+ def __init__(self, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None):
super(UbuntuPolicy, self).__init__(sysroot=sysroot, init=init,
- probe_runtime=probe_runtime)
+ probe_runtime=probe_runtime,
+ remote_exec=remote_exec)
self.valid_subclasses = [UbuntuPlugin, DebianPlugin]
@classmethod