Skip to content

Commit 968026b

Browse files
committed
common/rc: introduce _systemctl_start() and _systemctl_stop()
When test cases depend on specific systemctl services, the test cases need to start the service. After the test case completion, it is better to stop the service. However, if the service was already started and active before executing the test cases, stopping the service will affect test systems. To avoid such affect on the test systems, introduce _systemctl_start() and _systemctl_stop(). When _systemctl_start() check if the specified service has already started or not. If the service has not yet started, start it and record it in the global array SYSTEMCTL_UNITS_TO_STOP. When _systemctl_stop() is called, stop the service recorded in the array SYSTEMCTL_UNITS_TO_STOP. Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
1 parent 7c26543 commit 968026b

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

common/rc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ shopt -s extglob
1313
. common/dm
1414

1515
declare IO_URING_DISABLED
16+
declare -a SYSTEMCTL_UNITS_TO_STOP
1617

1718
# If a test runs multiple "subtests", then each subtest should typically run
1819
# for TIMEOUT / number of subtests.
@@ -511,6 +512,26 @@ _have_systemctl_unit() {
511512
return 0
512513
}
513514

515+
_systemctl_start() {
516+
local unit="$1"
517+
518+
if systemctl is-active --quiet "$unit"; then
519+
return
520+
fi
521+
522+
if systemctl start "$unit"; then
523+
SYSTEMCTL_UNITS_TO_STOP+=("$unit")
524+
fi
525+
}
526+
527+
_systemctl_stop() {
528+
local unit
529+
530+
for unit in "${SYSTEMCTL_UNITS_TO_STOP[@]}"; do
531+
systemctl stop "$unit"
532+
done
533+
}
534+
514535
# Run the given command as NORMAL_USER
515536
_run_user() {
516537
su "$NORMAL_USER" -c "$1"

0 commit comments

Comments
 (0)