aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2018-05-26 20:41:52 +0100
committerBryn M. Reeves <bmr@redhat.com>2018-05-29 11:38:40 +0100
commit1ec69db8fd4b4f66ede0164f335ce588310acfd1 (patch)
tree40f0eb6e2eb566df787aedf90a79e8ff5c2ee19e
parent11bcab18563d2286cec712890f8942e591946eaa (diff)
downloadsos-1ec69db8fd4b4f66ede0164f335ce588310acfd1.tar.gz
[policies/redhat] use os-release instead of redhat|fedora-release
Rather than testing for the presence of /etc/redhat-release and the absence of /etc/fedora-release, open /etc/os-release and check for the presence of the RHEL release string in the NAME field. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/policies/redhat.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index d5c1df8b..a6d314f1 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -26,6 +26,8 @@ except:
# might fail if non-RHEL
pass
+OS_RELEASE = "/etc/os-release"
+
class RedHatPolicy(LinuxPolicy):
distro = "Red Hat"
@@ -138,9 +140,11 @@ class RedHatPolicy(LinuxPolicy):
ENV_CONTAINER = 'container'
ENV_HOST_SYSROOT = 'HOST'
+RHEL_RELEASE_STR = "Red Hat Enterprise Linux"
+
class RHELPolicy(RedHatPolicy):
- distro = "Red Hat Enterprise Linux"
+ distro = RHEL_RELEASE_STR
vendor = "Red Hat"
vendor_url = "https://access.redhat.com/support/"
msg = _("""\
@@ -169,10 +173,27 @@ No changes will be made to system configuration.
@classmethod
def check(cls):
- """This method checks to see if we are running on RHEL. It returns True
- or False."""
- return (os.path.isfile(cls._redhat_release) and not
- os.path.isfile('/etc/fedora-release'))
+ """Test to see if the running host is a RHEL installation.
+
+ Checks for the presence of the "Red Hat Enterprise Linux"
+ release string at the beginning of the NAME field in the
+ `/etc/os-release` file and returns ``True`` if it is
+ found, and ``False`` otherwise.
+
+ :returns: ``True`` if the host is running RHEL or ``False``
+ otherwise.
+ """
+ if not os.path.exists(OS_RELEASE):
+ return False
+
+ with open(OS_RELEASE, "r") as f:
+ for line in f:
+ if line.startswith("NAME"):
+ (name, value) = line.split("=")
+ value = value.strip("\"'")
+ if value.startswith(RHEL_RELEASE_STR):
+ return True
+ return False
def dist_version(self):
try: