From 5d4ed7c4defcbc30a1c10eb0d91887ca055a1419 Mon Sep 17 00:00:00 2001 From: Krisztian Litkey Date: Tue, 24 Sep 2024 15:54:31 +0300 Subject: [PATCH] e2e: pull and save runtime logs after each test. Signed-off-by: Krisztian Litkey --- test/e2e/lib/vm.bash | 16 ++++++++++++++++ test/e2e/run.sh | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/test/e2e/lib/vm.bash b/test/e2e/lib/vm.bash index 04a5edb2e..5981fd5e2 100644 --- a/test/e2e/lib/vm.bash +++ b/test/e2e/lib/vm.bash @@ -588,3 +588,19 @@ vm-stop-log-collection() { local log_file="${log_file:-nri-resource-policy.output.txt}" vm-command "fuser --kill $log_file 2>/dev/null || :" } + +vm-seconds-now() { + vm-command-q "date +%s" +} + +vm-seconds-since() { + echo $(( $(vm-seconds-now) - $1 + 1 )) +} + +vm-pull-journal() { + local _service="${service:+-u} ${service:-} " + local _since="${since:+--since }${since:-}" + + vm-command-q "journalctl $_service $_since" || \ + command-error "failed to pull journal logs (service: ${service:-all}, since: ${since:--}" +} diff --git a/test/e2e/run.sh b/test/e2e/run.sh index e9d438837..820d6f3b1 100755 --- a/test/e2e/run.sh +++ b/test/e2e/run.sh @@ -944,8 +944,14 @@ eval "${yaml_in_defaults}" # Run test/demo TEST_FAILURES="" +test_start_secs=$(vm-seconds-now) + test-user-code +test_span_secs="$(vm-seconds-since $test_start_secs)" +since="-$(( test_span_secs + 5 ))s" +service="${k8scri}" since="$since" vm-pull-journal > "${TEST_OUTPUT_DIR}"/runtime."${k8scri}".log + # If there are any nri-resource-policy logs in the DUT, copy them back to host. host-command "$SCP $VM_HOSTNAME:nri-resource-policy.output.txt \"${TEST_OUTPUT_DIR}/\"" || out "copying \"$nri-resource-policy.output.txt\" from VM failed"