From 544f261433a6632911e98ce806390fca04598201 Mon Sep 17 00:00:00 2001 From: David Esparza Date: Fri, 13 Oct 2023 18:02:00 +0000 Subject: [PATCH] metrics: skips docker restart when it is not installed or is masked. To avoid errors when initializing the test environment, the kill_processes_before_start() helper function needs to verify that docker is installed before attempting to stop it. Fixes: #8218 Signed-off-by: David Esparza (cherry picked from commit 908519db9d49eb55d8d5d16a9dc65d576f78d364) Signed-off-by: Greg Kurz --- tests/metrics/lib/common.bash | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/metrics/lib/common.bash b/tests/metrics/lib/common.bash index 8528d2c7b0..8ec227a80d 100755 --- a/tests/metrics/lib/common.bash +++ b/tests/metrics/lib/common.bash @@ -168,15 +168,18 @@ function init_env() cmd=("docker" "ctr") - sudo systemctl restart docker - # check dependencies check_cmds "${cmd[@]}" # Remove all stopped containers - clean_env clean_env_ctr + # restart docker only if it is not masked by systemd + docker_masked="$(systemctl list-unit-files --state=masked | grep -c docker)" + if [ "${docker_masked}" -eq 0 ]; then + sudo systemctl restart docker + fi + # This clean up is more aggressive, this is in order to # decrease the factors that could affect the metrics results. kill_processes_before_start @@ -188,8 +191,12 @@ function init_env() # killed to start test with clean environment. function kill_processes_before_start() { - DOCKER_PROCS=$(sudo "${DOCKER_EXE}" ps -q) - [[ -n "${DOCKER_PROCS}" ]] && clean_env + docker_masked="$(systemctl list-unit-files --state=masked | grep -c "${DOCKER_EXE}")" + + if [ "${docker_masked}" -eq 0 ]; then + DOCKER_PROCS=$(sudo "${DOCKER_EXE}" ps -q) + [[ -n "${DOCKER_PROCS}" ]] && clean_env + fi CTR_PROCS=$(sudo "${CTR_EXE}" t list -q) [[ -n "${CTR_PROCS}" ]] && clean_env_ctr