diff --git a/src/warnet/control.py b/src/warnet/control.py index 85680ac36..981bd724a 100644 --- a/src/warnet/control.py +++ b/src/warnet/control.py @@ -430,6 +430,7 @@ def format_pods(pods: list[V1Pod], namespace: Optional[str]) -> list[str]: if not namespaces: click.echo(f"Could not find pod in any namespaces: {pod_name}") + return namespace = namespaces[0] diff --git a/test/namespace_admin_test.py b/test/namespace_admin_test.py index 5ca77e90b..baec605e7 100755 --- a/test/namespace_admin_test.py +++ b/test/namespace_admin_test.py @@ -201,6 +201,11 @@ def bob_checks_logs(self): ) self.sut.expect(bitcoin_version_slug, timeout=10) self.sut.close() + self.sut = pexpect.spawn("warnet logs this_does_not_exist", maxread=4096 * 10) + assert expect_without_traceback( + "Could not find pod in any namespaces", self.sut, timeout=10 + ) + self.sut.close() self.log.info("Bob has checked the logs") assert self.this_is_the_current_context(self.bob_context) @@ -226,6 +231,11 @@ def admin_checks_logs(self): ) self.sut.expect(bitcoin_version_slug, timeout=10) self.sut.close() + self.sut = pexpect.spawn("warnet logs this_does_not_exist", maxread=4096 * 10) + assert expect_without_traceback( + "Could not find pod in any namespaces", self.sut, timeout=10 + ) + self.sut.close() self.log.info("The admin has checked the logs") assert self.this_is_the_current_context(self.initial_context) @@ -244,6 +254,27 @@ def remove_context(kubeconfig_data: dict, context_name: str) -> dict: return kubeconfig_data +class StackTraceFoundException(Exception): + """Custom exception raised when a stack trace is found in the output.""" + + pass + + +def expect_without_traceback(expectation: str, sut: pexpect.spawn, timeout: int = 10) -> bool: + expectation_found = False + while True: + try: + sut.expect("\n", timeout=timeout) + line = sut.before.decode("utf-8") + if "Traceback (" in line: + raise StackTraceFoundException + if expectation in line: + expectation_found = True + except pexpect.exceptions.EOF: + break + return expectation_found + + if __name__ == "__main__": test = NamespaceAdminTest() test.run_test()