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

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