[PATCH] testsuite: cleanup qemu machines left running

7 views
Skip to first unread message

Uladzimir Bely

unread,
Aug 23, 2024, 1:27:17 AM8/23/24
to isar-...@googlegroups.com
Parameter "keep=True" in `vm_start` function allows to share the same
qemu process between different tests.

In case the machine is forgotten to be closed by the last test or in
case avocado skips some tests (due to internal error or other reason)
such qemu processes stay running after the testsuite completed.

This change allows to terminate these processes.

Signed-off-by: Uladzimir Bely <ub...@ilbers.de>
---
scripts/ci_build.sh | 5 ++++-
testsuite/cleanup.py | 26 ++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
create mode 100755 testsuite/cleanup.py

diff --git a/scripts/ci_build.sh b/scripts/ci_build.sh
index 0aa2403d..b643b5a6 100755
--- a/scripts/ci_build.sh
+++ b/scripts/ci_build.sh
@@ -147,4 +147,7 @@ set -x

avocado ${VERBOSE} run "${TESTSUITE_DIR}/citest.py" \
-t "${TAGS}" --max-parallel-tasks=1 --disable-sysinfo \
- ${SSTATE} ${TIMEOUT}
+ ${SSTATE} ${TIMEOUT} \
+ || true
+
+python3 ${TESTSUITE_DIR}/cleanup.py
diff --git a/testsuite/cleanup.py b/testsuite/cleanup.py
new file mode 100755
index 00000000..c81397d2
--- /dev/null
+++ b/testsuite/cleanup.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+import os
+import pickle
+import signal
+
+build_dir = os.path.join(os.path.dirname(__file__), '..', 'build')
+
+vm_dict_file = f"{build_dir}/vm_dict_file"
+vm_dict = {}
+
+if os.path.isfile(vm_dict_file):
+ with open(vm_dict_file, 'rb') as f:
+ data = f.read()
+ if data:
+ vm_dict = pickle.loads(data)
+
+for vm in vm_dict:
+ pid = vm_dict[vm][0]
+ name = vm_dict[vm][1][0]
+ print(f"Killing {name} process with pid {pid}", end ="... ")
+ try:
+ os.kill(pid, signal.SIGKILL)
+ print("OK")
+ except ProcessLookupError:
+ print("Not found")
--
2.44.2

Anton Mikanovich

unread,
Aug 23, 2024, 5:30:59 AM8/23/24
to Uladzimir Bely, isar-...@googlegroups.com
23/08/2024 08:26, Uladzimir Bely wrote:
> Parameter "keep=True" in `vm_start` function allows to share the same
> qemu process between different tests.
>
> In case the machine is forgotten to be closed by the last test or in
> case avocado skips some tests (due to internal error or other reason)
> such qemu processes stay running after the testsuite completed.
>
> This change allows to terminate these processes.
>
> Signed-off-by: Uladzimir Bely <ub...@ilbers.de>
> ---
> scripts/ci_build.sh | 5 ++++-
> testsuite/cleanup.py | 26 ++++++++++++++++++++++++++
> 2 files changed, 30 insertions(+), 1 deletion(-)
> create mode 100755 testsuite/cleanup.py
>
> diff --git a/scripts/ci_build.sh b/scripts/ci_build.sh
> index 0aa2403d..b643b5a6 100755
> --- a/scripts/ci_build.sh
> +++ b/scripts/ci_build.sh
> @@ -147,4 +147,7 @@ set -x
>
> avocado ${VERBOSE} run "${TESTSUITE_DIR}/citest.py" \
> -t "${TAGS}" --max-parallel-tasks=1 --disable-sysinfo \
> - ${SSTATE} ${TIMEOUT}
> + ${SSTATE} ${TIMEOUT} \
> + || true
Why not just 'set +e' before avocado call?

Uladzimir Bely

unread,
Aug 26, 2024, 1:17:52 AM8/26/24
to isar-...@googlegroups.com
Parameter "keep=True" in `vm_start` function allows to share the same
qemu process between different tests.

In case the machine is forgotten to be closed by the last test or in
case avocado skips some tests (due to internal error or other reason)
such qemu processes stay running after the testsuite completed.

This change allows to terminate these processes.

Signed-off-by: Uladzimir Bely <ub...@ilbers.de>
---
scripts/ci_build.sh | 9 ++++++++-
testsuite/cleanup.py | 26 ++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 1 deletion(-)
create mode 100755 testsuite/cleanup.py

Changes since v1:
- Preserve avocado return code on exiting ci_build.sh.

diff --git a/scripts/ci_build.sh b/scripts/ci_build.sh
index 0aa2403d..338557ad 100755
--- a/scripts/ci_build.sh
+++ b/scripts/ci_build.sh
@@ -142,9 +142,16 @@ logs_dir = $(realpath "${BASE_DIR}")/job-results
EOF
export VIRTUAL_ENV="./"

+ret=0
+
# the real stuff starts here, trace commands from now on
set -x

avocado ${VERBOSE} run "${TESTSUITE_DIR}/citest.py" \
-t "${TAGS}" --max-parallel-tasks=1 --disable-sysinfo \
- ${SSTATE} ${TIMEOUT}
+ ${SSTATE} ${TIMEOUT} \
+ || ret=$?
+
+python3 ${TESTSUITE_DIR}/cleanup.py
+
+exit ${ret}
--
2.44.2

Uladzimir Bely

unread,
Aug 29, 2024, 1:53:40 AM8/29/24
to isar-...@googlegroups.com
Applied to next.

--
Best regards,
Uladzimir.
Reply all
Reply to author
Forward
0 new messages