Blame SOURCES/sos-bz2043102-foreman-tasks-msgpack.patch

315fce
From 5634f7dd77eff821f37daa953fa86cc783d3b937 Mon Sep 17 00:00:00 2001
315fce
From: Pavel Moravec <pmoravec@redhat.com>
315fce
Date: Fri, 21 Jan 2022 16:27:33 +0100
315fce
Subject: [PATCH] [foreman] Use psql-msgpack-decode wrapper for dynflow >= 1.6
315fce
315fce
In dynflow >=1.6.3, dynflow* tables in postgres are encoded by
315fce
msgpack which makes plain CSV dumps unreadable. In such a case,
315fce
psql-msgpack-decode wrapper tool from dynflow-utils (of any
315fce
version) must be used instead of the plain psql command.
315fce
315fce
Resolves: #2830
315fce
315fce
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
315fce
---
315fce
 sos/report/plugins/foreman.py | 16 ++++++++++++----
315fce
 1 file changed, 12 insertions(+), 4 deletions(-)
315fce
315fce
diff --git a/sos/report/plugins/foreman.py b/sos/report/plugins/foreman.py
315fce
index 314a651d1..3fd80e6a8 100644
315fce
--- a/sos/report/plugins/foreman.py
315fce
+++ b/sos/report/plugins/foreman.py
315fce
@@ -244,8 +244,16 @@ def setup(self):
315fce
             self.add_cmd_output(_cmd, suggest_filename=table, timeout=600,
315fce
                                 sizelimit=100, env=self.env)
315fce
 
315fce
+        # dynflow* tables on dynflow >=1.6.3 are encoded and hence in that
315fce
+        # case, psql-msgpack-decode wrapper tool from dynflow-utils (any
315fce
+        # version) must be used instead of plain psql command
315fce
+        dynutils = self.is_installed('dynflow-utils')
315fce
         for dyn in foremancsv:
315fce
-            _cmd = self.build_query_cmd(foremancsv[dyn], csv=True)
315fce
+            binary = "psql"
315fce
+            if dyn != 'foreman_tasks_tasks' and dynutils:
315fce
+                binary = "/usr/libexec/psql-msgpack-decode"
315fce
+            _cmd = self.build_query_cmd(foremancsv[dyn], csv=True,
315fce
+                                        binary=binary)
315fce
             self.add_cmd_output(_cmd, suggest_filename=dyn, timeout=600,
315fce
                                 sizelimit=100, env=self.env)
315fce
 
315fce
@@ -270,7 +278,7 @@ def setup(self):
315fce
         # collect http[|s]_proxy env.variables
315fce
         self.add_env_var(["http_proxy", "https_proxy"])
315fce
 
315fce
-    def build_query_cmd(self, query, csv=False):
315fce
+    def build_query_cmd(self, query, csv=False, binary="psql"):
315fce
         """
315fce
         Builds the command needed to invoke the pgsql query as the postgres
315fce
         user.
315fce
@@ -281,8 +289,8 @@ def build_query_cmd(self, query, csv=False):
315fce
         if csv:
315fce
             query = "COPY (%s) TO STDOUT " \
315fce
                     "WITH (FORMAT 'csv', DELIMITER ',', HEADER)" % query
315fce
-        _dbcmd = "psql --no-password -h %s -p 5432 -U foreman -d foreman -c %s"
315fce
-        return _dbcmd % (self.dbhost, quote(query))
315fce
+        _dbcmd = "%s --no-password -h %s -p 5432 -U foreman -d foreman -c %s"
315fce
+        return _dbcmd % (binary, self.dbhost, quote(query))
315fce
 
315fce
     def postproc(self):
315fce
         self.do_path_regex_sub(