Skip to content

Commit 88bca78

Browse files
committed
stop service instances
Signed-off-by: Ygal Blum <[email protected]>
1 parent 83e65f9 commit 88bca78

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

test/system/252-quadlet.bats

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ load helpers.registry
1111
load helpers.systemd
1212

1313
UNIT_FILES=()
14+
SERVICES_TO_STOP=()
1415

1516
function start_time() {
1617
sleep_to_next_second # Ensure we're on a new second with no previous logging
@@ -26,16 +27,32 @@ function setup() {
2627

2728
start_time
2829

30+
# Clear arrays for each test
31+
SERVICES_TO_STOP=()
32+
2933
basic_setup
3034
}
3135

3236
function teardown() {
37+
# Stop manually specified services
38+
for service in ${SERVICES_TO_STOP[@]}; do
39+
run systemctl stop "$service"
40+
if [ $status -ne 0 ]; then
41+
echo "# WARNING: systemctl stop failed in teardown: $output" >&3
42+
fi
43+
run systemctl reset-failed "$service"
44+
done
45+
3346
for UNIT_FILE in ${UNIT_FILES[@]}; do
3447
if [[ -e "$UNIT_FILE" ]]; then
3548
local service=$(basename "$UNIT_FILE")
36-
run systemctl stop "$service"
37-
if [ $status -ne 0 ]; then
38-
echo "# WARNING: systemctl stop failed in teardown: $output" >&3
49+
# Skip stopping template services (those ending with '@')
50+
# as they cannot be stopped directly without an instance name
51+
if [[ ! "$service" =~ @\.service$ ]]; then
52+
run systemctl stop "$service"
53+
if [ $status -ne 0 ]; then
54+
echo "# WARNING: systemctl stop failed in teardown: $output" >&3
55+
fi
3956
fi
4057
run systemctl reset-failed "$service"
4158
rm -f "$UNIT_FILE"
@@ -503,6 +520,11 @@ EOF
503520
# Start the container service instance which should also trigger the start of the volume service instance
504521
service_setup $container_service_instance
505522

523+
# Add the service instances to SERVICES_TO_STOP for proper cleanup
524+
# SERVICES_TO_STOP+=("$container_service_instance")
525+
SERVICES_TO_STOP+=("$vol_service_instance")
526+
SERVICES_TO_STOP+=("$net_service_instance")
527+
506528
# Volume system unit instance should be active
507529
run systemctl show --property=ActiveState "$vol_service_instance"
508530
assert "$output" = "ActiveState=active" \
@@ -519,19 +541,10 @@ EOF
519541
# Network should exist
520542
run_podman network exists ${network_name_instance}
521543

522-
# The default cleanup stops the services corresponding to the copied unit files.
523-
# However, the test copies the template units while running their instances.
524-
# As a result, the default cleanup fails to stop the services.
525-
# As a workaround, stop the services and delete the unit files manually.
544+
# Clean up the created resources
526545
service_cleanup $container_service_instance failed
527-
service_cleanup $vol_service_instance inactive
528-
service_cleanup $net_service_instance inactive
529546
run_podman volume rm $volume_name_instance
530547
run_podman network rm $network_name_instance
531-
for UNIT_FILE in ${UNIT_FILES[@]}; do
532-
rm $UNIT_FILE
533-
done
534-
UNIT_FILES=()
535548
}
536549

537550
# A quadlet container depends on a named quadlet volume

0 commit comments

Comments
 (0)