Blame SOURCES/sos-bz2043103-collect_decoded_dynflow_data.patch

71a6d2
From 5f95c24ccd3224d441eb1dcab3e63c33847b18bb Mon Sep 17 00:00:00 2001
71a6d2
From: Barbora Vassova <bvassova@redhat.com>
71a6d2
Date: Tue, 5 Apr 2022 13:01:33 +0200
71a6d2
Subject: [PATCH] In dynflow >=1.6.3, dynflow* tables in postgres are encoded
71a6d2
 by msgpack which makes plain CSV dumps unreadable. In such a case,
71a6d2
 psql-msgpack-decode wrapper tool from dynflow-utils (of any version) must be
71a6d2
 used instead of the plain psql command.
71a6d2
71a6d2
Resolves: #2900
71a6d2
71a6d2
Signed-off-by: Barbora Vassova <bvassova@redhat.com>
71a6d2
---
71a6d2
 sos/plugins/foreman.py | 21 +++++++++++++++------
71a6d2
 1 file changed, 15 insertions(+), 6 deletions(-)
71a6d2
71a6d2
diff --git a/sos/plugins/foreman.py b/sos/plugins/foreman.py
71a6d2
index c742ebcab..e0b6eeb15 100644
71a6d2
--- a/sos/plugins/foreman.py
71a6d2
+++ b/sos/plugins/foreman.py
71a6d2
@@ -244,15 +244,23 @@ def setup(self):
71a6d2
             self.add_cmd_output(_cmd, suggest_filename=table, timeout=600,
71a6d2
                                 sizelimit=100, env=self.env)
71a6d2
 
71a6d2
+        # dynflow* tables on dynflow >=1.6.3 are encoded and hence in that
71a6d2
+        # case, psql-msgpack-decode wrapper tool from dynflow-utils (any
71a6d2
+        # version) must be used instead of plain psql command
71a6d2
+        dynutils = self.is_installed('dynflow-utils')
71a6d2
         for dyn in foremancsv:
71a6d2
-            _cmd = self.build_query_cmd(foremancsv[dyn], csv=True)
71a6d2
+            binary = "psql"
71a6d2
+            if dyn != 'foreman_tasks_tasks' and dynutils:
71a6d2
+                binary = "/usr/libexec/psql-msgpack-decode"
71a6d2
+            _cmd = self.build_query_cmd(foremancsv[dyn], csv=True,
71a6d2
+                                        binary=binary)
71a6d2
             self.add_cmd_output(_cmd, suggest_filename=dyn, timeout=600,
71a6d2
                                 sizelimit=100, env=self.env)
71a6d2
 
71a6d2
         # collect http[|s]_proxy env.variables
71a6d2
         self.add_env_var(["http_proxy", "https_proxy"])
71a6d2
 
71a6d2
-    def build_query_cmd(self, query, csv=False):
71a6d2
+    def build_query_cmd(self, query, csv=False, binary="psql"):
71a6d2
         """
71a6d2
         Builds the command needed to invoke the pgsql query as the postgres
71a6d2
         user.
71a6d2
@@ -260,10 +268,11 @@ def build_query_cmd(self, query, csv=False):
71a6d2
         shell and postgres parsing requirements. Note that this will generate
71a6d2
         a large amount of quoting in sos logs referencing the command being run
71a6d2
         """
71a6d2
-        csvformat = "-A -F , -X" if csv else ""
71a6d2
-        _dbcmd = "psql --no-password -h %s -p 5432 -U foreman -d foreman %s \
71a6d2
-                  -c %s"
71a6d2
-        return _dbcmd % (self.dbhost, csvformat, quote(query))
71a6d2
+        if csv:
71a6d2
+            query = "COPY (%s) TO STDOUT " \
71a6d2
+                    "WITH (FORMAT 'csv', DELIMITER ',', HEADER)" % query
71a6d2
+        _dbcmd = "%s --no-password -h %s -p 5432 -U foreman -d foreman -c %s"
71a6d2
+        return _dbcmd % (binary, self.dbhost, quote(query))
71a6d2
 
71a6d2
     def postproc(self):
71a6d2
         satreg = r"((foreman.*)?(\"::(foreman(.*?)|katello).*)?((::(.*)::.*" \