aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2020-04-13 14:39:31 -0400
committerJake Hunsaker <jhunsake@redhat.com>2020-04-22 10:01:01 -0400
commit43b8700118a8e20d622737977717c5dd1634b9ed (patch)
treeb5e2c5b1a6d1aa63848ff25821006392fc7e8b54
parent1e9deb27f90ae5f22e3f5fdcdc6641f49438e662 (diff)
downloadsos-43b8700118a8e20d622737977717c5dd1634b9ed.tar.gz
[collector|Policies] Load a Policy rather than SoSHost within SoSNode
Rather than load a `SoSHost` instance, `SoSNode` will now load a `Policy` that is determined by the content of `/etc/os-release` on the remote node, as this is a standardized file for Linux-based systems and allows for reliable identification of the host. Each per-node policy will load the host-side package information for use by collector in determining cluster profile and sos capabilities. This per-node policy will not however load an `InitSystem()` or a `ContainerRuntime()`. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/collector/sosnode.py20
-rw-r--r--sos/policies/__init__.py9
2 files changed, 15 insertions, 14 deletions
diff --git a/sos/collector/sosnode.py b/sos/collector/sosnode.py
index 5f86f656..c603e556 100644
--- a/sos/collector/sosnode.py
+++ b/sos/collector/sosnode.py
@@ -18,6 +18,7 @@ import shutil
from distutils.version import LooseVersion
from pipes import quote
+from sos.policies import load, InitSystem
from sos.collector.exceptions import *
@@ -63,7 +64,7 @@ class SosNode():
self.connected = True
self.local = True
if self.connected and load_facts:
- self.host = self.determine_host()
+ self.host = self.determine_host_policy()
if not self.host:
self.connected = False
self.close_ssh_session()
@@ -71,8 +72,6 @@ class SosNode():
if self.local:
if self.check_in_container():
self.host.containerized = False
- self.log_debug("Host facts found to be %s" %
- self.host.report_facts())
self.get_hostname()
if self.host.containerized:
self.create_sos_container()
@@ -291,17 +290,16 @@ class SosNode():
self.log_error("Exception while reading %s: %s" % (to_read, err))
return ''
- def determine_host(self):
+ def determine_host_policy(self):
'''Attempts to identify the host installation against supported
distributions
'''
- for host_type in self.host_types:
- host = self.host_types[host_type](self.address)
- rel_string = self.read_file(host.release_file)
- if host._check_enabled(rel_string):
- self.log_debug("Host installation found to be %s" %
- host.distribution)
- return host
+ host = load(cache={}, sysroot=self.opts.sysroot, init=InitSystem(),
+ probe_runtime=False, remote_exec=self.ssh_cmd,
+ remote_check=self.read_file('/etc/os-release'))
+ if host:
+ self.log_debug("loaded policy %s for host" % host.distro)
+ return host
self.log_error('Unable to determine host installation. Ignoring node')
raise UnsupportedHostException
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 7ab1477c..97624052 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -48,7 +48,8 @@ def import_policy(name):
return None
-def load(cache={}, sysroot=None):
+def load(cache={}, sysroot=None, init=None, probe_runtime=True,
+ remote_exec=None, remote_check=''):
if 'policy' in cache:
return cache.get('policy')
@@ -56,8 +57,10 @@ def load(cache={}, sysroot=None):
helper = ImporterHelper(sos.policies)
for module in helper.get_modules():
for policy in import_policy(module):
- if policy.check():
- cache['policy'] = policy(sysroot=sysroot)
+ if policy.check(remote=remote_check):
+ cache['policy'] = policy(sysroot=sysroot, init=init,
+ probe_runtime=probe_runtime,
+ remote_exec=remote_exec)
if 'policy' not in cache:
cache['policy'] = GenericPolicy()