Blame SOURCES/sos-collector-deb-support.patch

42837f
From 998b7596c8aa7cccbcb94ebffe9fb72a4609bce4 Mon Sep 17 00:00:00 2001
42837f
From: Bryan Quigley <bryan.quigley@canonical.com>
42837f
Date: Mon, 15 Oct 2018 16:52:50 -0700
42837f
Subject: [PATCH] [Hosts] Add Debian and Ubuntu as hosts
42837f
42837f
Currently Debian and Ubuntu share a hosts file but we can further
42837f
split them out if needed.
42837f
42837f
Needed to define both a package name and bin path variable
42837f
so that the differences between RH and U/D could be handled.
42837f
42837f
Signed-off-by: Bryan Quigley <bryan.quigley@canonical.com>
42837f
---
42837f
 soscollector/hosts/__init__.py |  2 ++
42837f
 soscollector/hosts/debian.py   | 36 ++++++++++++++++++++++++++++++++++++
42837f
 soscollector/hosts/redhat.py   |  2 ++
42837f
 soscollector/sosnode.py        |  4 ++--
42837f
 4 files changed, 42 insertions(+), 2 deletions(-)
42837f
 create mode 100644 soscollector/hosts/debian.py
42837f
42837f
diff --git a/soscollector/hosts/__init__.py b/soscollector/hosts/__init__.py
42837f
index 02b1d71..2e93094 100644
42837f
--- a/soscollector/hosts/__init__.py
42837f
+++ b/soscollector/hosts/__init__.py
42837f
@@ -41,6 +41,8 @@ class SosHost():
42837f
     container_runtime = None
42837f
     container_image = None
42837f
     sos_path_strip = None
42837f
+    sos_pkg_name = None  # package name in deb/rpm/etc
42837f
+    sos_bin_path = None  # path to sosreport binary
42837f
 
42837f
     def __init__(self, address):
42837f
         self.address = address
42837f
diff --git a/soscollector/hosts/debian.py b/soscollector/hosts/debian.py
42837f
new file mode 100644
42837f
index 0000000..7b67c83
42837f
--- /dev/null
42837f
+++ b/soscollector/hosts/debian.py
42837f
@@ -0,0 +1,36 @@
42837f
+# Copyright Canonical 2018, Bryan Quigley <bryan.quigley@canonical.com>
42837f
+# This program is free software; you can redistribute it and/or modify
42837f
+# it under the terms of the GNU General Public License as published by
42837f
+# the Free Software Foundation; either version 2 of the License, or
42837f
+# (at your option) any later version.
42837f
+
42837f
+# This program is distributed in the hope that it will be useful,
42837f
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
42837f
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42837f
+# GNU General Public License for more details.
42837f
+
42837f
+# You should have received a copy of the GNU General Public License along
42837f
+# with this program; if not, write to the Free Software Foundation, Inc.,
42837f
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
42837f
+
42837f
+from soscollector.hosts import SosHost
42837f
+
42837f
+
42837f
+class DebianHost(SosHost):
42837f
+    '''Base class for defining Debian based systems'''
42837f
+
42837f
+    distribution = 'Debian'
42837f
+    releases = ['ubuntu', 'debian']
42837f
+    package_manager = {
42837f
+        'name': 'dpkg',
42837f
+        'query': "dpkg-query -W -f='${Package}-${Version}\\\n' "
42837f
+    }
42837f
+    sos_pkg_name = 'sosreport'
42837f
+    sos_bin_path = '/usr/bin/sosreport'
42837f
+
42837f
+    def check_enabled(self, rel_string):
42837f
+        for release in self.releases:
42837f
+            if release in rel_string:
42837f
+                return True
42837f
+        return False
42837f
+# vim:ts=4 et sw=4
42837f
diff --git a/soscollector/hosts/redhat.py b/soscollector/hosts/redhat.py
42837f
index 20db16a..f077d03 100644
42837f
--- a/soscollector/hosts/redhat.py
42837f
+++ b/soscollector/hosts/redhat.py
42837f
@@ -26,6 +26,8 @@ class RedHatHost(SosHost):
42837f
         'name': 'rpm',
42837f
         'query': 'rpm -q'
42837f
     }
42837f
+    sos_pkg_name = 'sos'
42837f
+    sos_bin_path = '/usr/sbin/sosreport'
42837f
 
42837f
     def check_enabled(self, rel_string):
42837f
         for release in self.releases:
42837f
diff --git a/soscollector/sosnode.py b/soscollector/sosnode.py
42837f
index 98f1765..fc674b0 100644
42837f
--- a/soscollector/sosnode.py
42837f
+++ b/soscollector/sosnode.py
42837f
@@ -154,7 +154,7 @@ class SosNode():
42837f
     def _load_sos_info(self):
42837f
         '''Queries the node for information about the installed version of sos
42837f
         '''
42837f
-        cmd = self.host.prefix + self.host.pkg_query('sos')
42837f
+        cmd = self.host.prefix + self.host.pkg_query(self.host.sos_pkg_name)
42837f
         res = self.run_command(cmd)
42837f
         if res['status'] == 0:
42837f
             ver = res['stdout'].splitlines()[-1].split('-')[1]
42837f
@@ -275,7 +275,7 @@ class SosNode():
42837f
     def run_command(self, cmd, timeout=180, get_pty=False, need_root=False):
42837f
         '''Runs a given cmd, either via the SSH session or locally'''
42837f
         if cmd.startswith('sosreport'):
42837f
-            cmd = cmd.replace('sosreport', '/usr/sbin/sosreport')
42837f
+            cmd = cmd.replace('sosreport', self.host.sos_bin_path)
42837f
             need_root = True
42837f
         if need_root:
42837f
             get_pty = True
42837f
-- 
42837f
2.14.4
42837f