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

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