aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2022-05-04 12:32:44 -0400
committerJake Hunsaker <jhunsake@redhat.com>2022-05-04 16:40:54 -0400
commite2e3d91167982b63e54603de158e5ab1abc9fe86 (patch)
tree836740e24f6cc8d499ab819ce035b0ee144527f5
parent8c3a252c8a34a780b0edb212d761eef427645f51 (diff)
downloadsos-e2e3d91167982b63e54603de158e5ab1abc9fe86.tar.gz
[GenericPolicy] Fix execution when GenericPolicy is loaded
Over time a lot has changed with `Policy()` implementation. Along with that, the functionality of `GenericPolicy` broke at some point, thus preventing any form of execution of SoS on distributions without explicit policies. Fix this by changing `GenericPolicy` to `GenericLinuxPolicy` (to be more explicit in case we re-add non-Linux support in the future) and having it subclass `LinuxPolicy` instead of the top-level `Policy`. Further, add a platform check to ensure we are not inadvertently loading a Linux-based policy on a non-Linux platform which would likely result in failure to do anything useful. The `GenericLinuxPolicy` will only load `IndependentPlugin`-tagged plugins, does not leverage an init system, and does not provide any default upload functionality. Related: #2928 Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/policies/__init__.py14
-rw-r--r--sos/policies/distros/__init__.py16
2 files changed, 21 insertions, 9 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 8b7ecac8..8212d2c4 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -5,6 +5,7 @@ import json
import tempfile
import random
import string
+import sys
from pwd import getpwuid
from sos.presets import (NO_PRESET, GENERIC_PRESETS, PRESETS_PATH,
@@ -40,8 +41,11 @@ def load(cache={}, sysroot=None, init=None, probe_runtime=True,
probe_runtime=probe_runtime,
remote_exec=remote_exec)
+ if sys.platform != 'linux':
+ raise Exception("SoS is not supported on this platform")
+
if 'policy' not in cache:
- cache['policy'] = GenericPolicy()
+ cache['policy'] = sos.policies.distros.GenericLinuxPolicy()
return cache['policy']
@@ -600,12 +604,4 @@ any third party.
self.presets.pop(name)
-class GenericPolicy(Policy):
- """This Policy will be returned if no other policy can be loaded. This
- should allow for IndependentPlugins to be executed on any system"""
-
- def get_msg(self):
- return self.msg % {'distro': self.system}
-
-
# vim: set et ts=4 sw=4 :
diff --git a/sos/policies/distros/__init__.py b/sos/policies/distros/__init__.py
index f459689b..8fbc0de4 100644
--- a/sos/policies/distros/__init__.py
+++ b/sos/policies/distros/__init__.py
@@ -791,3 +791,19 @@ class LinuxPolicy(Policy):
cmd)
else:
return cmd
+
+
+class GenericLinuxPolicy(LinuxPolicy):
+ """This Policy will be returned if no other policy can be loaded. This
+ should allow for IndependentPlugins to be executed on any system"""
+
+ vendor_urls = [('Upstream Project', 'https://github.com/sosreport/sos')]
+ vendor = 'SoS'
+ vendor_text = ('SoS was unable to determine that the distribution of this '
+ 'system is supported, and has loaded a generic '
+ 'configuration. This may not provide desired behavior, and '
+ 'users are encouraged to request a new distribution-specifc'
+ ' policy at the GitHub project above.\n')
+
+
+# vim: set et ts=4 sw=4 :