Sandro Bonazzola has uploaded a new change for review.

Change subject: WIP: sos: add sos 3.0 support
......................................................................

WIP: sos: add sos 3.0 support

- conditional install sos 2 or sos 3 plugins based on sos version
- renamed postgresql plugin to ovirt-postgresql.

TODO:
- fix sos 3 jobs for using new API
- fix log-collector for using right plugins with sos-3.0

Change-Id: I47fb7817727ed88a1b9c7bb91cb5055a2e8d7565
Bug-Url: https://bugzilla.redhat.com/1037663
Signed-off-by: Sandro Bonazzola <[email protected]>
---
M .gitignore
M configure.ac
M ovirt-log-collector.spec.in
M po/POTFILES.in
M src/Makefile.am
R src/sos2/Makefile.am
R src/sos2/plugins/Makefile.am
R src/sos2/plugins/engine.py
R src/sos2/plugins/postgresql.py
C src/sos3/Makefile.am
C src/sos3/plugins/Makefile.am
C src/sos3/plugins/engine.py
A src/sos3/plugins/ovirt-postgresql.py
13 files changed, 192 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector 
refs/changes/93/23793/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 400739e..869813f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,6 +64,14 @@
 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])
+AM_CONDITIONAL([SOS3], [test x"${SOS_VERSION}" == x3])
 
 engineconfigdir="\$(sysconfdir)/ovirt-engine"
 ovirtlogcollectorlibdir="\$(pythondir)/ovirt_log_collector"
@@ -78,8 +86,10 @@
        ovirt-log-collector.spec
        src/config.py.in
        src/Makefile
-       src/sos/Makefile
-       src/sos/plugins/Makefile
+       src/sos2/Makefile
+       src/sos2/plugins/Makefile
+       src/sos3/Makefile
+       src/sos3/plugins/Makefile
        src/helper/Makefile
        src/logrotate.d/Makefile
        po/Makefile.in
diff --git a/ovirt-log-collector.spec.in b/ovirt-log-collector.spec.in
index 81c23e4..0c6947c 100644
--- a/ovirt-log-collector.spec.in
+++ b/ovirt-log-collector.spec.in
@@ -17,6 +17,7 @@
 
 %global                package_version @PACKAGE_VERSION@
 %global                package_name @PACKAGE_NAME@
+%global                sos_version @SOS_VERSION@
 
 Summary:       Log Collector for oVirt Engine
 Name:          %{package_name}
@@ -34,10 +35,11 @@
 Requires:      ovirt-engine-sdk-python >= 3.4.0.2
 Requires:      ovirt-engine-lib
 Requires:      logrotate
-Requires:      sos
+Requires:      sos >= %{sos_version}
 Requires:      openssh-clients
 BuildRequires: python2-devel
 BuildRequires: gettext
+BuildRequires: sos
 
 %description
 Log Collector tool for oVirt Engine
@@ -55,6 +57,7 @@
 rm -rf "%{buildroot}"
 make %{?_smp_mflags} install DESTDIR="%{buildroot}"
 
+
 %files
 %doc AUTHORS
 %doc COPYING
@@ -62,8 +65,7 @@
 %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/
 %{python_sitelib}/sos/plugins/*.py*
 %{_bindir}/engine-log-collector
 %{_mandir}/man8/*
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 60e3427..42e28f8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,8 @@
 ./src/helper/__init__.py
 ./src/__init__.py
 ./src/__main__.py
-./src/sos/plugins/engine.py
-./src/sos/plugins/postgresql.py
+./src/sos2/plugins/engine.py
+./src/sos2/plugins/postgresql.py
+./src/sos3/plugins/engine.py
+./src/sos3/plugins/ovirt-postgresql.py
 ./src/tests.py
diff --git a/src/Makefile.am b/src/Makefile.am
index 49cd324..2856792 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -37,9 +37,10 @@
        $(NULL)
 
 SUBDIRS = \
-       sos \
        helper \
        logrotate.d \
+       sos2 \
+       sos3 \
        $(NULL)
 
 ovirtlogcollectorlib_PYTHON = \
diff --git a/src/sos/Makefile.am b/src/sos2/Makefile.am
similarity index 100%
rename from src/sos/Makefile.am
rename to src/sos2/Makefile.am
diff --git a/src/sos/plugins/Makefile.am b/src/sos2/plugins/Makefile.am
similarity index 92%
rename from src/sos/plugins/Makefile.am
rename to src/sos2/plugins/Makefile.am
index 8f1d910..f1fc54a 100644
--- a/src/sos/plugins/Makefile.am
+++ b/src/sos2/plugins/Makefile.am
@@ -21,10 +21,17 @@
        $(srcdir)/Makefile.in \
        $(NULL)
 
+if SOS2
 dist_sosplugins_PYTHON = \
        engine.py \
        postgresql.py \
        $(NULL)
+else
+dist_noinst_PYTHON = \
+       engine.py \
+       postgresql.py \
+       $(NULL)
+endif
 
 all-local: \
        python-syntax-check \
diff --git a/src/sos/plugins/engine.py b/src/sos2/plugins/engine.py
similarity index 100%
rename from src/sos/plugins/engine.py
rename to src/sos2/plugins/engine.py
diff --git a/src/sos/plugins/postgresql.py b/src/sos2/plugins/postgresql.py
similarity index 100%
rename from src/sos/plugins/postgresql.py
rename to src/sos2/plugins/postgresql.py
diff --git a/src/sos/Makefile.am b/src/sos3/Makefile.am
similarity index 100%
copy from src/sos/Makefile.am
copy to src/sos3/Makefile.am
diff --git a/src/sos/plugins/Makefile.am b/src/sos3/plugins/Makefile.am
similarity index 90%
copy from src/sos/plugins/Makefile.am
copy to src/sos3/plugins/Makefile.am
index 8f1d910..003a7a9 100644
--- a/src/sos/plugins/Makefile.am
+++ b/src/sos3/plugins/Makefile.am
@@ -21,10 +21,18 @@
        $(srcdir)/Makefile.in \
        $(NULL)
 
+if SOS3
 dist_sosplugins_PYTHON = \
        engine.py \
-       postgresql.py \
+       ovirt-postgresql.py \
        $(NULL)
+else
+dist_noinst_PYTHON = \
+       engine.py \
+       ovirt-postgresql.py \
+       $(NULL)
+endif
+
 
 all-local: \
        python-syntax-check \
diff --git a/src/sos/plugins/engine.py b/src/sos3/plugins/engine.py
similarity index 100%
copy from src/sos/plugins/engine.py
copy to src/sos3/plugins/engine.py
diff --git a/src/sos3/plugins/ovirt-postgresql.py 
b/src/sos3/plugins/ovirt-postgresql.py
new file mode 100644
index 0000000..7b1defb
--- /dev/null
+++ b/src/sos3/plugins/ovirt-postgresql.py
@@ -0,0 +1,152 @@
+import os
+import tempfile
+
+from sos.plugins import Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin
+from sos.utilities import find
+
+
+class PostgreSQL(Plugin):
+    """PostgreSQL related information"""
+
+    __pghome = '/var/lib/pgsql'
+    __username = 'postgres'
+    __dbport = 5432
+
+    plugin_name = "ovirt-postgresql"
+
+    packages = ('postgresql',)
+
+    tmp_dir = None
+
+    option_list = [
+        (
+            'pghome',
+            'PostgreSQL server home directory (default=/var/lib/pgsql)',
+            '',
+            False
+        ),
+        ('username', 'username for pg_dump (default=postgres)', '', False),
+        ('password', 'password for pg_dump (default=None)', '', False),
+        (
+            'dbname',
+            'database name to dump for pg_dump (default=None)',
+            '',
+            False
+        ),
+        (
+            'dbhost',
+            'hostname/IP of the server upon which the DB is running \
+(default=localhost)',
+            '',
+            False
+        ),
+        ('dbport', 'database server port number (default=5432)', '', False)
+    ]
+
+    def pg_dump(self):
+        dest_file = os.path.join(self.tmp_dir, "sos_pgdump.tar")
+        old_env_pgpassword = os.environ.get("PGPASSWORD")
+        os.environ["PGPASSWORD"] = self.get_option("password")
+        if (
+            self.get_option("dbhost") and
+            self.get_option("dbhost") is not True
+        ):
+            cmd = "pg_dump -U %s -h %s -p %s -w -f %s -F t %s" % (
+                self.__username,
+                self.get_option("dbhost"),
+                self.__dbport,
+                dest_file,
+                self.get_option("dbname")
+            )
+        else:
+            cmd = "pg_dump -C -U %s -w -f %s -F t %s " % (
+                self.__username,
+                dest_file,
+                self.get_option("dbname")
+            )
+        self.soslog.debug("calling %s" % cmd)
+        (status, output, rtime) = self.call_ext_prog(cmd)
+        if old_env_pgpassword is not None:
+            os.environ["PGPASSWORD"] = str(old_env_pgpassword)
+        if (status == 0):
+            self.add_copy_spec(dest_file)
+        else:
+            self.soslog.error(
+                "Unable to execute pg_dump. Error(%s)" % (output)
+            )
+            self.add_alert(
+                "ERROR: Unable to execute pg_dump.  Error(%s)" % (output)
+            )
+
+    def setup(self):
+        if (
+            self.get_option("pghome") and
+            self.get_option("pghome") is not True
+        ):
+            self.__pghome = self.get_option("pghome")
+        self.soslog.debug("using pghome=%s" % self.__pghome)
+
+        if (
+            self.get_option("dbname") and
+            self.get_option("dbname") is not True
+        ):
+            if (
+                self.get_option("password") and
+                self.get_option("password") is not True
+            ):
+                if (
+                    self.get_option("username") and
+                    self.get_option("username") is not True
+                ):
+                    self.__username = self.get_option("username")
+                if (
+                    self.get_option("dbport") and
+                    self.get_option("dbport") is not True
+                ):
+                    self.__dbport = self.get_option("dbport")
+                self.tmp_dir = tempfile.mkdtemp()
+                self.pg_dump()
+            else:
+                self.soslog.warning(
+                    "password must be supplied to dump a database."
+                )
+                self.add_alert(
+                    "WARN: password must be supplied to dump a database."
+                )
+        else:
+            self.soslog.warning(
+                "dbname must be supplied to dump a database."
+            )
+            self.add_alert(
+                "WARN: dbname must be supplied to dump a database."
+            )
+
+        # Copy PostgreSQL log files.
+        for filename in find("*.log", self.__pghome):
+            self.add_copy_spec(filename)
+        # Copy PostgreSQL config files.
+        for filename in find("*.conf", self.__pghome):
+            self.add_copy_spec(filename)
+
+        self.add_copy_spec(os.path.join(self.__pghome, "data", "PG_VERSION"))
+        self.add_copy_spec(
+            os.path.join(self.__pghome, "data", "postmaster.opts")
+        )
+
+    def postproc(self):
+        if self.tmp_dir:
+            import shutil
+            try:
+                shutil.rmtree(self.tmp_dir)
+            except shutil.Error:
+                self.soslog.exception(
+                    "Unable to remove %s." % (self.tmp_dir)
+                )
+                self.add_alert("ERROR: Unable to remove %s." % (self.tmp_dir))
+
+
+class RedHatPostgreSQL(PostgreSQL, RedHatPlugin):
+    """PostgreSQL related information for Red Hat distributions"""
+
+    def setup(self):
+        super(RedHatPostgreSQL, self).setup()


-- 
To view, visit http://gerrit.ovirt.org/23793
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: master
Gerrit-Owner: Sandro Bonazzola <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to