diff --git a/tests/rptest/clients/kubectl.py b/tests/rptest/clients/kubectl.py index 4862bc0183ab9..78ab5a9b853bd 100644 --- a/tests/rptest/clients/kubectl.py +++ b/tests/rptest/clients/kubectl.py @@ -142,12 +142,12 @@ def logger(self) -> Logger: def _local_cmd(self, cmd: list[str], timeout=900): """Run the given command locally and return the stdout as bytes. Logs stdout and stderr on failure. - + cmd: list[str]: command to run - + throws CalledProcessError on non-zero exit code - thwows - + thwows + returns: stdout as string if not empty, else stderr """ def _prepare_output(sout: str, serr: str) -> str: @@ -174,9 +174,6 @@ def _prepare_output(sout: str, serr: str) -> str: s_out, s_err = process.communicate() raise subprocess.TimeoutExpired(cmd, timeout, s_out, s_err) - # Log all collected strings, including JSONs collected - self.logger.debug(_prepare_output(s_out, s_err)) - # TODO: Handle s_err output # It will be hard to detect errors as a lot of apps and utils # just uses stderr as normal output. For example, tsh (teleport tunnel) @@ -187,6 +184,9 @@ def _prepare_output(sout: str, serr: str) -> str: f"{_prepare_output(s_out, s_err)}") raise subprocess.CalledProcessError(process.returncode, cmd, s_out, s_err) + else: + # Log all collected strings, including JSONs collected + self.logger.debug(_prepare_output(s_out, s_err)) # Most of the time stdout will hold valuable data # In rare occasions when return code is 0, and and stderr is not empty