From 1714dfea7bb89e50315c03c216355c9f3c98a188 Mon Sep 17 00:00:00 2001 From: Julia Yakovlev Date: Sun, 8 Dec 2024 17:15:43 +0200 Subject: [PATCH] fix(logcollection): save schema info output This commit brings 2 fixes: 1. use 'remote_file' context manager to save schema output it may improve command performance 2. use silence decorator for every run of schema info command. It's to prevent stop info collection on failure --- sdcm/cluster.py | 12 +++++++++--- sdcm/logcollector.py | 3 ++- sdcm/tester.py | 9 +++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/sdcm/cluster.py b/sdcm/cluster.py index ae55b0fdc8..5cb01b1cf3 100644 --- a/sdcm/cluster.py +++ b/sdcm/cluster.py @@ -311,9 +311,15 @@ def __init__(self, name, parent_cluster, ssh_login_info=None, base_logdir=None, def save_cqlsh_output_in_file(self, cmd: str, log_file: str): self.log.info("Save command '%s' output in the file. Node %s", cmd, self.name) - result_tables = self.run_cqlsh(cmd, split=True) - for line in result_tables: - self.remoter.run(f"echo '{line}' >> {log_file}") + file_path = self.remoter.sudo(f"touch {log_file};realpath {log_file}", + verbose=True, ignore_status=True).stdout.strip() + if not (result_tables := self.run_cqlsh(cmd).stdout): + return + + self.log.debug("Schema file path: %s", file_path) + with remote_file(remoter=self.remoter, remote_path=file_path, sudo=True) as fobj: + fobj.truncate(0) # first clear the file + fobj.write(result_tables.strip()) def _is_node_ready_run_scylla_commands(self) -> bool: """ diff --git a/sdcm/logcollector.py b/sdcm/logcollector.py index fc6643c8d9..f59165abbd 100644 --- a/sdcm/logcollector.py +++ b/sdcm/logcollector.py @@ -626,7 +626,8 @@ def collect_logs_per_node(node): try: log_entity.collect(node, local_node_dir, remote_node_dir, local_search_path=local_search_path) except Exception as details: # pylint: disable=unused-variable, broad-except # noqa: BLE001 - LOGGER.error("Error occured during collecting on host: %s\n%s", node.name, details) + LOGGER.error("Error occured during collecting of %s on host: %s\n%s", + log_entity.name, node.name, details) LOGGER.debug("Nodes list %s", [node.name for node in self.nodes]) diff --git a/sdcm/tester.py b/sdcm/tester.py index 06fcd78dda..c58127a8db 100644 --- a/sdcm/tester.py +++ b/sdcm/tester.py @@ -2961,16 +2961,17 @@ def clean_resources(self): self.destroy_credentials() - @silence(name='Save node schema') def save_nodes_schema(self): if self.db_cluster is None: self.log.info("No nodes found in the Scylla cluster") self.log.info("Save nodes user schema in the files") for node in self.db_cluster.nodes: - node.save_cqlsh_output_in_file(cmd="desc schema", log_file="schema.log") - node.save_cqlsh_output_in_file(cmd="select JSON * from system_schema.tables", - log_file="system_schema_tables.log") + with silence(name=f"Save node '{node.name}' schema", raise_error_event=False): + node.save_cqlsh_output_in_file(cmd="desc schema", log_file="schema.log") + with silence(name=f"Save node '{node.name}' system_schema.tables", raise_error_event=False): + node.save_cqlsh_output_in_file(cmd="select JSON * from system_schema.tables", + log_file="system_schema_tables.log") def tearDown(self): self.teardown_started = True