Skip to content

Commit 655ff65

Browse files
committed
refactor(test): unify debug info dumping routines
We have two places where the test framework dumps a bunch of debug info: When something fails via SSH, and when we fail to kill a microVM because it's already dead. Let's unify both of these to dump the _same_ debug information, by having both call _dump_debug_information (generalized slightly so that it no longer hardcodes "SSH gone wrong" as the error message, and extended to also print uffd logs). Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
1 parent f5198f0 commit 655ff65

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

tests/framework/microvm.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,14 @@ def kill(self):
313313
if self.screen_pid:
314314
os.kill(self.screen_pid, signal.SIGKILL)
315315
except:
316-
if self.uffd_handler:
317-
LOG.error(
318-
"Failed to kill Firecracker Process. Did it already die (or did the UFFD handler process die and take it down)?"
319-
)
320-
LOG.error("UFFD Handler Logs:\n" + self.uffd_handler.log_data)
321-
else:
322-
LOG.error("Failed to kill Firecracker Process. Did it already die?")
323-
LOG.error("Firecracker Logs:\n" + self.log_data)
316+
msg = (
317+
"Failed to kill Firecracker Process. Did it already die (or did the UFFD handler process die and take it down)?"
318+
if self.uffd_handler
319+
else "Failed to kill Firecracker Process. Did it already die?"
320+
)
321+
322+
self._dump_debug_information(msg)
323+
324324
raise
325325

326326
# if microvm was spawned then check if it gets killed
@@ -1062,7 +1062,9 @@ def ssh_iface(self, iface_idx=0):
10621062
user="root",
10631063
host=guest_ip,
10641064
control_path=Path(self.chroot()) / f"ssh-{iface_idx}.sock",
1065-
on_error=self._dump_debug_information,
1065+
on_error=lambda exc: self._dump_debug_information(
1066+
f"Failure executing command via SSH in microVM: {exc}"
1067+
),
10661068
)
10671069
self._connections.append(connection)
10681070
return connection
@@ -1084,17 +1086,18 @@ def thread_backtraces(self):
10841086
)
10851087
return "\n".join(backtraces)
10861088

1087-
def _dump_debug_information(self, exc: Exception):
1089+
def _dump_debug_information(self, what: str):
10881090
"""
10891091
Dumps debug information about this microvm
10901092
10911093
Used for example when running a command inside the guest via `SSHConnection.check_output` fails.
10921094
"""
1093-
print(
1094-
f"Failure executing command via SSH in microVM: {exc}\n\n"
1095-
f"Firecracker logs:\n{self.log_data}\n"
1096-
f"Thread backtraces:\n{self.thread_backtraces}"
1097-
)
1095+
LOG.error(what)
1096+
LOG.error("Firecracker logs:\n %s", self.log_data)
1097+
if self.uffd_handler:
1098+
LOG.error("Uffd logs: %s", self.uffd_handler.log_data)
1099+
if not self._killed:
1100+
LOG.error("Thread backtraces: %s", self.thread_backtraces)
10981101

10991102
def wait_for_ssh_up(self):
11001103
"""Wait for guest running inside the microVM to come up and respond."""

0 commit comments

Comments
 (0)