diff --git a/tests/rptest/services/cloud_broker.py b/tests/rptest/services/cloud_broker.py index b24b3a636ad4d..9ccf89ebfa71c 100644 --- a/tests/rptest/services/cloud_broker.py +++ b/tests/rptest/services/cloud_broker.py @@ -33,6 +33,8 @@ def __init__(self, pod, kubectl, logger) -> None: # Backward compatibility # Various classes will use this var to hash and compare nodes self.account = self._meta + # Mimic Ducktape cluster node hostname field + self.hostname = f"{self._spec['nodeName']}/{self.name}" def _query_broker(self, path, port=None): """ diff --git a/tests/rptest/services/redpanda.py b/tests/rptest/services/redpanda.py index 20b83fced53af..7fef142c1146c 100644 --- a/tests/rptest/services/redpanda.py +++ b/tests/rptest/services/redpanda.py @@ -2145,7 +2145,7 @@ def raise_on_bad_logs(self, allow_list=None, test_start_time=None): self.logger, self.kubectl, test_start_time=test_start_time) - lsearcher.search_logs(self.get_redpanda_pods()) + lsearcher.search_logs(self.pods) class RedpandaService(RedpandaServiceBase): diff --git a/tests/rptest/services/utils.py b/tests/rptest/services/utils.py index 8453f51dd0f50..520ccd31de4e1 100644 --- a/tests/rptest/services/utils.py +++ b/tests/rptest/services/utils.py @@ -6,12 +6,20 @@ from typing import Generator, Optional from rptest.clients.kubectl import KubectlTool, KubeNodeShell +from rptest.services.cloud_broker import CloudBroker class BadLogLines(Exception): def __init__(self, node_to_lines): self.node_to_lines = node_to_lines + @staticmethod + def _get_hostname(node): + if isinstance(node, CloudBroker): + return node.hostname + else: + return node.account.hostname + def __str__(self): # Pick the first line from the first node as an example, and include it # in the string output so that for single line failures, it isn't necessary @@ -20,7 +28,7 @@ def __str__(self): example = next(iter(example_lines)) summary = ','.join([ - f'{i[0].account.hostname}({len(i[1])})' + f'{self._get_hostname(i[0])}({len(i[1])})' for i in self.node_to_lines.items() ]) return f"" @@ -154,6 +162,7 @@ def search_logs(self, nodes): bad_loglines = self._search(nodes) # If anything, raise exception if bad_loglines: + # Call class overriden method to get proper Exception class raise BadLogLines(bad_loglines) @@ -195,8 +204,7 @@ def parse_k8s_time(logline, tz): # Load log, output is in binary form loglines = [] - pod_name = self._get_hostname(pod) - node_name = pod['spec']['nodeName'] + node_name = pod._spec['nodeName'] tz = "+00:00" with KubeNodeShell(self.kubectl, node_name) as ksh: try: @@ -208,16 +216,16 @@ def parse_k8s_time(logline, tz): # Find all log files for target pod logfiles = ksh(f"find /var/log/pods -type f") for logfile in logfiles: - if pod_name in logfile and \ + if pod.name in logfile and \ 'redpanda-configurator' not in logfile: self.logger.info(f"Inspecting '{logfile}'") lines = ksh(f"cat {logfile} | grep {expr}") loglines += lines except Exception as e: - self.logger.warning(f"Error getting logs for {pod_name}: {e}") + self.logger.warning(f"Error getting logs for {pod.name}: {e}") else: _size = len(loglines) - self.logger.debug(f"Received {_size}B of data from {pod_name}") + self.logger.debug(f"Received {_size}B of data from {pod.name}") # check log lines for proper timing. # Log lines will have two timing objects: @@ -238,4 +246,4 @@ def parse_k8s_time(logline, tz): yield line def _get_hostname(self, host) -> str: - return host['metadata']['name'] + return host.hostname