Sandro Bonazzola has uploaded a new change for review.

Change subject: sos: add sos 3.1 support
......................................................................

sos: add sos 3.1 support

- conditional install sos plugins based on sos version
- use sos-3 plugins if available
- requires sos > 3.1 on RHEL >= 7 and Fedora >= 20;
  plugins have been moved on sos upstream.

Change-Id: I47fb7817727ed88a1b9c7bb91cb5055a2e8d7565
Bug-Url: https://bugzilla.redhat.com/1037663
Signed-off-by: Sandro Bonazzola <[email protected]>
(cherry picked from commit 48ddaad8c39142f494fb5c1fc12c64c84535487a)
---
M .gitignore
M configure.ac
M ovirt-log-collector.spec.in
M src/Makefile.am
M src/__main__.py
M src/sos/plugins/Makefile.am
6 files changed, 78 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector 
refs/changes/47/27847/1

diff --git a/.gitignore b/.gitignore
index aa2f740..87d110a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,5 @@
 src/logrotate.d/ovirt-log-collector
 src/config.py
 src/config.py.in
-ovirt-log-collector-*.tar.gz
 .idea
-.gitreview
\ No newline at end of file
+.gitreview
diff --git a/configure.ac b/configure.ac
index 5f648a1..4539ab2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,6 +64,13 @@
 esac
 
 AX_PYTHON_MODULE([ovirtsdk])
+AX_PYTHON_MODULE([sos], [fatal])
+AC_MSG_CHECKING(sos version)
+    AC_ARG_VAR([SOS_VERSION], [SOS utility version])
+    SOS_VERSION=`$PYTHON -c "import sos; print(sos.__version__)" |cut -c1 
2>/dev/null`
+    AC_MSG_RESULT($SOS_VERSION)
+
+AM_CONDITIONAL([SOS2], [test x"${SOS_VERSION}" == x2])
 
 engineconfigdir="\$(sysconfdir)/ovirt-engine"
 ovirtlogcollectorlibdir="\$(pythondir)/ovirt_log_collector"
diff --git a/ovirt-log-collector.spec.in b/ovirt-log-collector.spec.in
index 21990aa..ba91b12 100644
--- a/ovirt-log-collector.spec.in
+++ b/ovirt-log-collector.spec.in
@@ -34,10 +34,17 @@
 Requires:      ovirt-engine-sdk-python >= 3.4.0.7
 Requires:      ovirt-engine-lib
 Requires:      logrotate
-Requires:      sos
 Requires:      openssh-clients
+
+%if 0%{fedora} >= 20 || 0%{?rhel} >= 7
+Requires:   sos >= 3.1
+%else
+Requires:   sos < 3
+%endif
+
 BuildRequires: python2-devel
 BuildRequires: gettext
+BuildRequires: sos
 
 %description
 Log Collector tool for oVirt Engine
@@ -55,6 +62,7 @@
 rm -rf "%{buildroot}"
 make %{?_smp_mflags} install DESTDIR="%{buildroot}"
 
+
 %files
 %doc AUTHORS
 %doc COPYING
@@ -62,9 +70,20 @@
 %dir %{_sysconfdir}/ovirt-engine/logcollector.conf.d
 %config(noreplace) %{_sysconfdir}/ovirt-engine/logcollector.conf
 %config(noreplace) %{_sysconfdir}/logrotate.d/%{package_name}
-%{python_sitelib}/ovirt_log_collector/*.py*
-%{python_sitelib}/ovirt_log_collector/helper/*.py*
+%{python_sitelib}/ovirt_log_collector/
+%if 0%{fedora}
+%if 0%{fedora} < 20
 %{python_sitelib}/sos/plugins/*.py*
+%endif
+%endif
+
+%if 0%{?rhel}
+%if 0%{rhel} < 7
+%{python_sitelib}/sos/plugins/*.py*
+%endif
+%endif
+
+
 %{_bindir}/engine-log-collector
 %{_mandir}/man8/*
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 49cd324..8518159 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,9 +37,9 @@
        $(NULL)
 
 SUBDIRS = \
-       sos \
        helper \
        logrotate.d \
+       sos \
        $(NULL)
 
 ovirtlogcollectorlib_PYTHON = \
diff --git a/src/__main__.py b/src/__main__.py
index 120600a..e4fb588 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -35,7 +35,7 @@
 import atexit
 import time
 import socket
-
+import sos
 
 from ovirt_engine import configfile
 
@@ -677,7 +677,10 @@
 
         cmd = """%(ssh_cmd)s "
 VERSION=`/bin/rpm -q --qf '[%%{{VERSION}}]' sos | /bin/sed 's/\.//'`;
-if [ "$VERSION" -ge "22" ]; then
+if [ "$VERSION" -ge "30" ]; then
+    /usr/sbin/sosreport {option} --batch \
+        -o %(reports)s
+elif [ "$VERSION" -ge "22" ]; then
     /usr/sbin/sosreport {option} --batch -k general.all_logs=True \
         -o %(reports)s
 elif [ "$VERSION" -ge "17" ]; then
@@ -767,9 +770,14 @@
 
 
 class ENGINEData(CollectorBase):
+    def __init__(self, hostname, configuration=None, **kwargs):
+        super(ENGINEData, self).__init__(hostname, configuration)
+        self._engine_plugin = 'engine'
+        if sos.__version__.replace('.', '') >= '30':
+            self._engine_plugin = 'ovirt-engine'
 
     def prep(self):
-        CollectorBase.prep(self)
+        super(ENGINEData, self).prep()
         engine_service_config = configfile.ConfigFile([
             config.ENGINE_SERVICE_DEFAULTS,
         ])
@@ -793,12 +801,10 @@
         """
         opts = [
             "-k rpm.rpmva=off",
-            "-k general.all_logs=True",
             "-k apache.log=True",
         ]
-
         sensitive_keys = {
-            'engine': 'sensitive_keys',
+            self._engine_plugin: 'sensitive_keys',
             'ovirt_engine_dwh': 'dwh_sensitive_keys',
         }
         for plugin in sensitive_keys:
@@ -818,11 +824,15 @@
         if self.configuration.get("upload"):
             opts.append("--upload=%s" % self.configuration.get("upload"))
 
+        if sos.__version__.replace('.', '') < '30':
+            opts.append('--report')
+            opts.append("-k general.all_logs=True")
+
         return " ".join(opts)
 
     def sosreport(self):
         self.configuration["reports"] = ",".join((
-            "engine",
+            self._engine_plugin,
             "rpm",
             "libvirt",
             "general",
@@ -841,12 +851,16 @@
         ))
         self.configuration["sos_options"] = self.build_options()
         self.caller.call(
-            "sosreport --batch --report --build \
+            "sosreport --batch --build \
             --tmp-dir='%(local_tmp_dir)s' -o %(reports)s %(sos_options)s"
         )
 
 
 class PostgresData(CollectorBase):
+
+    def __init__(self, hostname, configuration=None, **kwargs):
+        super(PostgresData, self).__init__(hostname, configuration)
+        self._postgres_plugin = 'postgresql'
 
     def get_key_file(self):
         """
@@ -867,22 +881,29 @@
 
     def sosreport(self):
         opt = ""
-
         if self.configuration.get("ticket_number"):
-            opt += '--ticket-number=' + self.configuration.get("ticket_number")
+            opt += '--ticket-number=%(ticket_number)s '
+
+        if sos.__version__.replace('.', '') < '30':
+            opt += '--report '
 
         if self.configuration.get('pg_pass'):
             opt = (
-                '-k postgresql.dbname=%(pg_dbname)s '
-                '-k postgresql.dbhost=%(pg_dbhost)s '
-                '-k postgresql.dbport=%(pg_dbport)s '
-                '-k postgresql.username=%(pg_user)s '
-                '-k postgresql.password=%(pg_pass)s '
+                '-k {plugin}.dbname=%(pg_dbname)s '
+                '-k {plugin}.dbhost=%(pg_dbhost)s '
+                '-k {plugin}.dbport=%(pg_dbport)s '
+                '-k {plugin}.username=%(pg_user)s '
+                '-k {plugin}.password=%(pg_pass)s '
+            ).format(
+                plugin=self._postgres_plugin,
             )
-            stdout = self.caller.call(
-                '/usr/sbin/sosreport --batch --report -o postgresql '
+            cmdline = (
+                '/usr/sbin/sosreport --batch -o {plugin} '
                 '--tmp-dir=%(local_scratch_dir)s ' + opt
+            ).format(
+                plugin=self._postgres_plugin,
             )
+            stdout = self.caller.call(cmdline)
             self.parse_sosreport_stdout(stdout)
             # Prepend postgresql- to the .md5 file that is produced by SOS
             # so that it is easy to distinguish from the other N reports
diff --git a/src/sos/plugins/Makefile.am b/src/sos/plugins/Makefile.am
index c3c1da0..43326f4 100644
--- a/src/sos/plugins/Makefile.am
+++ b/src/sos/plugins/Makefile.am
@@ -21,12 +21,21 @@
        $(srcdir)/Makefile.in \
        $(NULL)
 
+if SOS2
 dist_sosplugins_PYTHON = \
        engine.py \
        ovirt_engine_dwh.py \
        ovirt_engine_reports.py \
        postgresql.py \
        $(NULL)
+else
+dist_noinst_PYTHON = \
+       engine.py \
+       ovirt_engine_dwh.py \
+       ovirt_engine_reports.py \
+       postgresql.py \
+       $(NULL)
+endif
 
 all-local: \
        python-syntax-check \


-- 
To view, visit http://gerrit.ovirt.org/27847
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I47fb7817727ed88a1b9c7bb91cb5055a2e8d7565
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-log-collector
Gerrit-Branch: ovirt-log-collector-3.4
Gerrit-Owner: Sandro Bonazzola <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to