Skip to content

Commit 67112aa

Browse files
authored
Merge pull request #4825 from cyphar/test-bfq-policy
tests: bfq: skip tests on misbehaving udev systems
2 parents 32593a4 + e6b4b5a commit 67112aa

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

tests/integration/cgroups.bats

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load helpers
44

55
function teardown() {
66
teardown_bundle
7+
teardown_loopdevs
78
}
89

910
function setup() {
@@ -153,16 +154,28 @@ function setup() {
153154
@test "runc run (per-device io weight for bfq)" {
154155
requires root # to create a loop device
155156

156-
dd if=/dev/zero of=backing.img bs=4096 count=1
157-
dev=$(losetup --find --show backing.img) || skip "unable to create a loop device"
157+
dev="$(setup_loopdev)"
158+
159+
# Some distributions (like openSUSE) have udev configured to forcefully
160+
# reset the scheduler for loopN devices to be "none", which breaks this
161+
# test. We cannot modify the udev behaviour of the host, but since this is
162+
# usually triggered by the "change" event from losetup, we can wait for a
163+
# little bit before continuing the test. For more details, see
164+
# <https://github.com/opencontainers/runc/issues/4781>.
165+
sleep 2s
158166

159167
# See if BFQ scheduler is available.
160168
if ! { grep -qw bfq "/sys/block/${dev#/dev/}/queue/scheduler" &&
161169
echo bfq >"/sys/block/${dev#/dev/}/queue/scheduler"; }; then
162-
losetup -d "$dev"
163170
skip "BFQ scheduler not available"
164171
fi
165172

173+
# Check that the device still has the right scheduler, in case we lost the
174+
# race above...
175+
if ! grep -qw '\[bfq\]' "/sys/block/${dev#/dev/}/queue/scheduler"; then
176+
skip "udev is configured to reset loop device io scheduler"
177+
fi
178+
166179
set_cgroups_path
167180

168181
IFS=$' \t:' read -r major minor <<<"$(lsblk -nd -o MAJ:MIN "$dev")"
@@ -198,9 +211,6 @@ function setup() {
198211
EOF
199212
weights2=$(get_cgroup_value $file)
200213

201-
# The loop device itself is no longer needed.
202-
losetup -d "$dev"
203-
204214
# Check original values.
205215
grep '^default 333$' <<<"$weights1"
206216
grep "^$major:$minor 444$" <<<"$weights1"
@@ -213,12 +223,8 @@ EOF
213223
@test "runc run (per-device multiple iops via unified)" {
214224
requires root cgroups_v2
215225

216-
dd if=/dev/zero of=backing1.img bs=4096 count=1
217-
dev1=$(losetup --find --show backing1.img) || skip "unable to create a loop device"
218-
219-
# Second device.
220-
dd if=/dev/zero of=backing2.img bs=4096 count=1
221-
dev2=$(losetup --find --show backing2.img) || skip "unable to create a loop device"
226+
dev1="$(setup_loopdev)"
227+
dev2="$(setup_loopdev)"
222228

223229
set_cgroups_path
224230

@@ -233,10 +239,6 @@ EOF
233239
runc run -d --console-socket "$CONSOLE_SOCKET" test_dev_weight
234240
[ "$status" -eq 0 ]
235241

236-
# The loop devices are no longer needed.
237-
losetup -d "$dev1"
238-
losetup -d "$dev2"
239-
240242
weights=$(get_cgroup_value "io.max")
241243
grep "^$major1:$minor1 .* riops=333 wiops=444$" <<<"$weights"
242244
grep "^$major2:$minor2 .* riops=555 wiops=666$" <<<"$weights"

tests/integration/helpers.bash

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,29 @@ function teardown_seccompagent() {
791791
rm -f "$SECCCOMP_AGENT_SOCKET"
792792
}
793793

794+
LOOPBACK_DEVICE_LIST="$(mktemp "$BATS_TMPDIR/losetup.XXXXXX")"
795+
796+
function setup_loopdev() {
797+
local backing dev
798+
backing="$(mktemp "$BATS_RUN_TMPDIR/backing.img.XXXXXX")"
799+
truncate --size=4K "$backing"
800+
801+
dev="$(losetup --find --show "$backing")" || skip "unable to create a loop device"
802+
echo "$dev" >>"$LOOPBACK_DEVICE_LIST"
803+
804+
unlink "$backing"
805+
echo "$dev"
806+
}
807+
808+
function teardown_loopdevs() {
809+
[ -s "$LOOPBACK_DEVICE_LIST" ] || return 0
810+
while IFS= read -r dev; do
811+
echo "losetup -d '$dev'" >&2
812+
losetup -d "$dev"
813+
done <"$LOOPBACK_DEVICE_LIST"
814+
truncate --size=0 "$LOOPBACK_DEVICE_LIST"
815+
}
816+
794817
function setup_bundle() {
795818
local image="$1"
796819

0 commit comments

Comments
 (0)