Blame SOURCES/sos-collector-rhhiv-profile.patch

60a6c7
From fb8c2af36672b5868f504bae0704392f9e9b44a5 Mon Sep 17 00:00:00 2001
60a6c7
From: Jake Hunsaker <jhunsake@redhat.com>
60a6c7
Date: Fri, 12 Apr 2019 14:45:01 -0400
60a6c7
Subject: [PATCH 1/3] [clusters] Add a cluster_name class member for better
60a6c7
 identification
60a6c7
60a6c7
Adds a cluster_name class member to Cluster() so that clusters may
60a6c7
specify a well-defined name beyond the name/acronym used to enable the
60a6c7
cluster manually.
60a6c7
60a6c7
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
60a6c7
---
60a6c7
 soscollector/clusters/__init__.py | 9 +++++++++
60a6c7
 soscollector/sos_collector.py     | 3 +--
60a6c7
 soscollector/sosnode.py           | 1 -
60a6c7
 3 files changed, 10 insertions(+), 3 deletions(-)
60a6c7
60a6c7
diff --git a/soscollector/clusters/__init__.py b/soscollector/clusters/__init__.py
60a6c7
index b9d2418..c1bd360 100644
60a6c7
--- a/soscollector/clusters/__init__.py
60a6c7
+++ b/soscollector/clusters/__init__.py
60a6c7
@@ -26,6 +26,7 @@ class Cluster(object):
60a6c7
     sos_plugins = []
60a6c7
     sos_plugin_options = {}
60a6c7
     sos_preset = ''
60a6c7
+    cluster_name = None
60a6c7
 
60a6c7
     def __init__(self, config):
60a6c7
         '''This is the class that cluster profile should subclass in order to
60a6c7
@@ -50,6 +51,14 @@ class Cluster(object):
60a6c7
         self.options = []
60a6c7
         self._get_options()
60a6c7
 
60a6c7
+    @classmethod
60a6c7
+    def name(cls):
60a6c7
+        '''Returns the cluster's name as a string.
60a6c7
+        '''
60a6c7
+        if cls.cluster_name:
60a6c7
+            return cls.cluster_name
60a6c7
+        return cls.__name__.lower()
60a6c7
+
60a6c7
     def _get_options(self):
60a6c7
         '''Loads the options defined by a cluster and sets the default value'''
60a6c7
         for opt in self.option_list:
60a6c7
diff --git a/soscollector/sos_collector.py b/soscollector/sos_collector.py
60a6c7
index fee48ab..54410a2 100644
60a6c7
--- a/soscollector/sos_collector.py
60a6c7
+++ b/soscollector/sos_collector.py
60a6c7
@@ -554,8 +554,7 @@ this utility or remote systems that it connects to.
60a6c7
                             break
60a6c7
 
60a6c7
                 self.config['cluster'] = cluster
60a6c7
-                name = str(cluster.__class__.__name__).lower()
60a6c7
-                self.config['cluster_type'] = name
60a6c7
+                self.config['cluster_type'] = cluster.name()
60a6c7
                 self.log_info(
60a6c7
                     'Cluster type set to %s' % self.config['cluster_type'])
60a6c7
                 break
60a6c7
diff --git a/soscollector/sosnode.py b/soscollector/sosnode.py
60a6c7
index 405d05d..3aba0bf 100644
60a6c7
--- a/soscollector/sosnode.py
60a6c7
+++ b/soscollector/sosnode.py
60a6c7
@@ -100,7 +100,6 @@ class SosNode():
60a6c7
             return True
60a6c7
         return False
60a6c7
 
60a6c7
-
60a6c7
     def create_sos_container(self):
60a6c7
         '''If the host is containerized, create the container we'll be using
60a6c7
         '''
60a6c7
-- 
60a6c7
2.17.2
60a6c7
60a6c7
60a6c7
From 8d94e9ee9162c1b7676822958a94dfcd727d6dc8 Mon Sep 17 00:00:00 2001
60a6c7
From: Jake Hunsaker <jhunsake@redhat.com>
60a6c7
Date: Fri, 12 Apr 2019 14:47:31 -0400
60a6c7
Subject: [PATCH 2/3] [clusters] Add cluster_name where appropriate
60a6c7
60a6c7
Adds a cluster_name to a few of the existing cluster profiles.
60a6c7
60a6c7
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
60a6c7
---
60a6c7
 soscollector/clusters/kubernetes.py | 1 +
60a6c7
 soscollector/clusters/ovirt.py      | 2 ++
60a6c7
 2 files changed, 3 insertions(+)
60a6c7
60a6c7
diff --git a/soscollector/clusters/kubernetes.py b/soscollector/clusters/kubernetes.py
60a6c7
index c5c2094..e18ee71 100644
60a6c7
--- a/soscollector/clusters/kubernetes.py
60a6c7
+++ b/soscollector/clusters/kubernetes.py
60a6c7
@@ -52,6 +52,7 @@ class kubernetes(Cluster):
60a6c7
 
60a6c7
 class openshift(kubernetes):
60a6c7
 
60a6c7
+    cluster_name = 'OpenShift Container Platform'
60a6c7
     packages = ('atomic-openshift',)
60a6c7
     sos_preset = 'ocp'
60a6c7
     cmd = 'oc'
60a6c7
diff --git a/soscollector/clusters/ovirt.py b/soscollector/clusters/ovirt.py
60a6c7
index 0a074ca..18cbf2e 100644
60a6c7
--- a/soscollector/clusters/ovirt.py
60a6c7
+++ b/soscollector/clusters/ovirt.py
60a6c7
@@ -23,6 +23,7 @@ from getpass import getpass
60a6c7
 
60a6c7
 class ovirt(Cluster):
60a6c7
 
60a6c7
+    cluster_name = 'oVirt'
60a6c7
     packages = ('ovirt-engine',)
60a6c7
 
60a6c7
     option_list = [
60a6c7
@@ -122,6 +123,7 @@ class ovirt(Cluster):
60a6c7
 
60a6c7
 class rhv(ovirt):
60a6c7
 
60a6c7
+    cluster_name = 'Red Hat Virtualization'
60a6c7
     packages = ('rhevm', 'rhvm')
60a6c7
     sos_preset = 'rhv'
60a6c7
 
60a6c7
-- 
60a6c7
2.17.2
60a6c7
60a6c7
60a6c7
From 4606699e9a460ebd6345444ae915ff8384619ed3 Mon Sep 17 00:00:00 2001
60a6c7
From: Jake Hunsaker <jhunsake@redhat.com>
60a6c7
Date: Tue, 16 Apr 2019 15:41:33 -0400
60a6c7
Subject: [PATCH 3/3] [ovirt] Add RHHI-V support
60a6c7
60a6c7
Adds support for RHHI-V environments which are RHV environments that
60a6c7
also use the hypervisors as gluster nodes. The new 'rhhi_virt' cluster
60a6c7
profile will be enabled when sos-collector is run against an environment
60a6c7
that is _both_ RHV and has nodes listed in the 'gluster_server' table in
60a6c7
the RHV database. Note that this means if community oVirt is in use, the
60a6c7
gluster bits enabled by 'rhhi_virt' will not be enabled for the oVirt
60a6c7
cluster type.
60a6c7
60a6c7
Included with this change is making DB queries more programmatic, and
60a6c7
making minor stylistic changes to the main query used by get_nodes() to
60a6c7
allow easier reading of the SQL query being built.
60a6c7
60a6c7
Finally, remove an unused import of getpass.
60a6c7
60a6c7
Resolves: #21
60a6c7
60a6c7
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
60a6c7
---
60a6c7
 soscollector/clusters/ovirt.py | 44 ++++++++++++++++++++++++++--------
60a6c7
 1 file changed, 34 insertions(+), 10 deletions(-)
60a6c7
60a6c7
diff --git a/soscollector/clusters/ovirt.py b/soscollector/clusters/ovirt.py
60a6c7
index 18cbf2e..8697d2e 100644
60a6c7
--- a/soscollector/clusters/ovirt.py
60a6c7
+++ b/soscollector/clusters/ovirt.py
60a6c7
@@ -18,13 +18,13 @@ import fnmatch
60a6c7
 
60a6c7
 from pipes import quote
60a6c7
 from soscollector.clusters import Cluster
60a6c7
-from getpass import getpass
60a6c7
 
60a6c7
 
60a6c7
 class ovirt(Cluster):
60a6c7
 
60a6c7
-    cluster_name = 'oVirt'
60a6c7
+    cluster_name = 'Community oVirt'
60a6c7
     packages = ('ovirt-engine',)
60a6c7
+    db_exec = '/usr/share/ovirt-engine/dbscripts/engine-psql.sh -c'
60a6c7
 
60a6c7
     option_list = [
60a6c7
         ('no-database', False, 'Do not collect a database dump'),
60a6c7
@@ -33,6 +33,14 @@ class ovirt(Cluster):
60a6c7
         ('no-hypervisors', False, 'Do not collect from hypervisors')
60a6c7
     ]
60a6c7
 
60a6c7
+    def _run_db_query(self, query):
60a6c7
+        '''
60a6c7
+        Wrapper for running DB queries on the master. Any scrubbing of the
60a6c7
+        query should be done _before_ passing the query to this method.
60a6c7
+        '''
60a6c7
+        cmd = "%s %s" % (self.db_exec, quote(query))
60a6c7
+        return self.exec_master_cmd(cmd, need_root=True)
60a6c7
+
60a6c7
     def _sql_scrub(self, val):
60a6c7
         '''
60a6c7
         Manually sanitize SQL queries since we can't leave this up to the
60a6c7
@@ -58,18 +66,16 @@ class ovirt(Cluster):
60a6c7
     def format_db_cmd(self):
60a6c7
         cluster = self._sql_scrub(self.get_option('cluster'))
60a6c7
         datacenter = self._sql_scrub(self.get_option('datacenter'))
60a6c7
-        query = ("select host_name from vds_static where cluster_id in "
60a6c7
-                 "(select cluster_id from cluster where name like '%s'"
60a6c7
-                 " and storage_pool_id in (select id from storage_pool "
60a6c7
-                 "where name like '%s'))" % (cluster, datacenter))
60a6c7
-        self.dbcmd = ('/usr/share/ovirt-engine/dbscripts/engine-psql.sh '
60a6c7
-                      '-c {}'.format(quote(query)))
60a6c7
-        self.log_debug('Query command for ovirt DB set to: %s' % self.dbcmd)
60a6c7
+        self.dbquery = ("SELECT host_name from vds_static where cluster_id in "
60a6c7
+                        "(select cluster_id FROM cluster WHERE name like '%s'"
60a6c7
+                        " and storage_pool_id in (SELECT id FROM storage_pool "
60a6c7
+                        "WHERE name like '%s'))" % (cluster, datacenter))
60a6c7
+        self.log_debug('Query command for ovirt DB set to: %s' % self.dbquery)
60a6c7
 
60a6c7
     def get_nodes(self):
60a6c7
         if self.get_option('no-hypervisors'):
60a6c7
             return []
60a6c7
-        res = self.exec_master_cmd(self.dbcmd, need_root=True)
60a6c7
+        res = self._run_db_query(self.dbquery)
60a6c7
         if res['status'] == 0:
60a6c7
             nodes = res['stdout'].splitlines()[2:-1]
60a6c7
             return [n.split('(')[0].strip() for n in nodes]
60a6c7
@@ -134,3 +140,21 @@ class rhv(ovirt):
60a6c7
             return 'rhvh'
60a6c7
         else:
60a6c7
             return 'rhelh'
60a6c7
+
60a6c7
+
60a6c7
+class rhhi_virt(rhv):
60a6c7
+
60a6c7
+    cluster_name = 'Red Hat Hyperconverged Infrastructure - Virtualization'
60a6c7
+    sos_plugins = ('gluster',)
60a6c7
+    sos_plugin_options = {'gluster.dump': 'on'}
60a6c7
+    sos_preset = 'rhv'
60a6c7
+
60a6c7
+    def check_enabled(self):
60a6c7
+        return (self.master.is_installed('rhvm') and self._check_for_rhhiv())
60a6c7
+
60a6c7
+    def _check_for_rhhiv(self):
60a6c7
+        ret = self._run_db_query('SELECT count(server_id) FROM gluster_server')
60a6c7
+        if ret['status'] == 0:
60a6c7
+            # if there are any entries in this table, RHHI-V is in use
60a6c7
+            return ret['stdout'].splitlines()[2].strip() != '0'
60a6c7
+        return False
60a6c7
-- 
60a6c7
2.17.2
60a6c7