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