diff mbox series

[OSSTEST,6/6] ts-logs-capture: Fish some logs out of guest filesystem

Message ID 20200327181526.19412-6-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show
Series [OSSTEST,1/6] TestSupport: export guest_find_lv | expand

Commit Message

Ian Jackson March 27, 2020, 6:15 p.m. UTC
This involves shutting the guests down.  We use this shell rune
because xl doesn't provide a good way to ensure there are no guests
running.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 ts-logs-capture | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
diff mbox series

Patch

diff --git a/ts-logs-capture b/ts-logs-capture
index 6be77676..c67856cd 100755
--- a/ts-logs-capture
+++ b/ts-logs-capture
@@ -261,10 +261,40 @@  sub fetch_logs_guest ($) {
     }
 }
 
+sub shutdown_guests () {
+    target_cmd_root($ho, <<'END', 180);
+        set -x
+        (
+            ( exec 2>/dev/null; sleep 30 ; echo y ) &
+            ( xl shutdown -a -F -w ; echo y ) &
+        ) | (
+            read x
+            xl list | awk '!/^Domain-0 |^Name / {print $2}' \
+            | xargs -t -r -n1 xl destroy ||:
+        )
+END
+}
+
+sub extract_logs_guest ($) {
+    my ($gho) = @_;
+    if (!eval {
+	guest_find_lv($gho);
+	target_cmd_root($ho, "umount /mnt ||:");
+	target_cmd_root($ho, "mount -r ".$gho->{Lvdev}." /mnt");
+	try_fetch_logs($ho, \@general_logs, '/mnt', "$gho->{Guest}-");
+	target_cmd_root($ho, "umount /mnt ||:");
+	1;
+    }) {
+	logm("failure extracting logs out of guest fs: $@");
+    }
+}
+
 power_state($ho,1);
 find_guests();
 fetch_xenctx_guest($_) foreach @guests;
 serial_fetch_logs($ho);
 fetch_logs_host();
 fetch_logs_guest($_) foreach @guests;
+shutdown_guests();
+extract_logs_guest($_) foreach @allguests;
 logm("logs captured to $stash");