From 6bd77c893a0ce42562647c42ecbcbf12aedb4bf2 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Thu, 22 Feb 2024 01:24:44 +0000 Subject: [PATCH] Even more logging fixes (#757) Hopefully the last one for a bit. This only output the cmdline if log_file is present (ie, not to stdout). It also fixes a bug where the log_file was not passed in one line. Reviewed-on: https://git.vdb.to/cerc-io/stack-orchestrator/pulls/757 Co-authored-by: Thomas E Lackey Co-committed-by: Thomas E Lackey --- stack_orchestrator/deploy/webapp/util.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/stack_orchestrator/deploy/webapp/util.py b/stack_orchestrator/deploy/webapp/util.py index 6cfdb118..959d5d31 100644 --- a/stack_orchestrator/deploy/webapp/util.py +++ b/stack_orchestrator/deploy/webapp/util.py @@ -40,13 +40,18 @@ class AttrDict(dict): def logged_cmd(log_file, *vargs): + result = None try: - print(" ".join(vargs), file=log_file) - result = subprocess.run(vargs, capture_output=True, stdout=log_file, stderr=log_file) + if log_file: + print(" ".join(vargs), file=log_file) + result = subprocess.run(vargs, capture_output=True) result.check_returncode() return result.stdout.decode() except Exception as err: - print(str(err), file=log_file) + if result: + print(result.stderr.decode(), file=log_file) + else: + print(str(err), file=log_file) raise err @@ -184,7 +189,7 @@ class LaconicRegistryClient: self.set_name(name, new_record_id) return new_record_id finally: - logged_cmd("rm", "-rf", tmpdir) + logged_cmd(self.log_file, "rm", "-rf", tmpdir) def set_name(self, name, record_id): logged_cmd(self.log_file, "laconic", "-c", self.config_file, "cns", "name", "set", name, record_id)