Skip to content

Commit 8160e02

Browse files
committed
test/e2e: Use nullb0 for IO limit tests
The tests for device I/O limits were using `/dev/zero`, which is not a block device suitable for these cgroup controls. Update the tests to use `/dev/nullb0` if it exists. Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 3b61e56 commit 8160e02

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

test/e2e/common_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,13 @@ func SkipIfNotRootless(reason string) {
942942
}
943943
}
944944

945+
func SkipIfNotExist(reason, path string) {
946+
checkReason(reason)
947+
if _, err := os.Stat(path); err != nil {
948+
Skip("[doesNotExist]: " + path + " does not exist: " + reason)
949+
}
950+
}
951+
945952
func SkipIfSystemdNotRunning(reason string) {
946953
checkReason(reason)
947954

@@ -1648,3 +1655,7 @@ func makeTempDirInDir(dir string) string {
16481655
Expect(err).ToNot(HaveOccurred())
16491656
return path
16501657
}
1658+
1659+
func skipWithoutDevNullb0() {
1660+
SkipIfNotExist("use modprobe null_blk nr_devices=1 to create it", "/dev/nullb0")
1661+
}

test/e2e/run_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -848,13 +848,14 @@ USER bin`, BB)
848848

849849
It("podman run device-read-bps test", func() {
850850
SkipIfRootless("Setting device-read-bps not supported for rootless users")
851+
skipWithoutDevNullb0()
851852

852853
var session *PodmanSessionIntegration
853854

854855
if CGROUPSV2 {
855-
session = podmanTest.Podman([]string{"run", "--rm", "--device-read-bps=/dev/zero:1mb", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/io.max"})
856+
session = podmanTest.Podman([]string{"run", "--rm", "--device-read-bps=/dev/nullb0:1mb", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/io.max"})
856857
} else {
857-
session = podmanTest.Podman([]string{"run", "--rm", "--device-read-bps=/dev/zero:1mb", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.read_bps_device"})
858+
session = podmanTest.Podman([]string{"run", "--rm", "--device-read-bps=/dev/nullb0:1mb", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.read_bps_device"})
858859
}
859860

860861
session.WaitWithDefaultTimeout()
@@ -866,13 +867,14 @@ USER bin`, BB)
866867

867868
It("podman run device-write-bps test", func() {
868869
SkipIfRootless("Setting device-write-bps not supported for rootless users")
870+
skipWithoutDevNullb0()
869871

870872
var session *PodmanSessionIntegration
871873

872874
if CGROUPSV2 {
873-
session = podmanTest.Podman([]string{"run", "--rm", "--device-write-bps=/dev/zero:1mb", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/io.max"})
875+
session = podmanTest.Podman([]string{"run", "--rm", "--device-write-bps=/dev/nullb0:1mb", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/io.max"})
874876
} else {
875-
session = podmanTest.Podman([]string{"run", "--rm", "--device-write-bps=/dev/zero:1mb", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.write_bps_device"})
877+
session = podmanTest.Podman([]string{"run", "--rm", "--device-write-bps=/dev/nullb0:1mb", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.write_bps_device"})
876878
}
877879
session.WaitWithDefaultTimeout()
878880
Expect(session).Should(ExitCleanly())
@@ -883,12 +885,14 @@ USER bin`, BB)
883885

884886
It("podman run device-read-iops test", func() {
885887
SkipIfRootless("Setting device-read-iops not supported for rootless users")
888+
skipWithoutDevNullb0()
889+
886890
var session *PodmanSessionIntegration
887891

888892
if CGROUPSV2 {
889-
session = podmanTest.Podman([]string{"run", "--rm", "--device-read-iops=/dev/zero:100", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/io.max"})
893+
session = podmanTest.Podman([]string{"run", "--rm", "--device-read-iops=/dev/nullb0:100", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/io.max"})
890894
} else {
891-
session = podmanTest.Podman([]string{"run", "--rm", "--device-read-iops=/dev/zero:100", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.read_iops_device"})
895+
session = podmanTest.Podman([]string{"run", "--rm", "--device-read-iops=/dev/nullb0:100", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.read_iops_device"})
892896
}
893897

894898
session.WaitWithDefaultTimeout()
@@ -900,12 +904,14 @@ USER bin`, BB)
900904

901905
It("podman run device-write-iops test", func() {
902906
SkipIfRootless("Setting device-write-iops not supported for rootless users")
907+
skipWithoutDevNullb0()
908+
903909
var session *PodmanSessionIntegration
904910

905911
if CGROUPSV2 {
906-
session = podmanTest.Podman([]string{"run", "--rm", "--device-write-iops=/dev/zero:100", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/io.max"})
912+
session = podmanTest.Podman([]string{"run", "--rm", "--device-write-iops=/dev/nullb0:100", ALPINE, "sh", "-c", "cat /sys/fs/cgroup/$(sed -e 's|0::||' < /proc/self/cgroup)/io.max"})
907913
} else {
908-
session = podmanTest.Podman([]string{"run", "--rm", "--device-write-iops=/dev/zero:100", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.write_iops_device"})
914+
session = podmanTest.Podman([]string{"run", "--rm", "--device-write-iops=/dev/nullb0:100", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.write_iops_device"})
909915
}
910916

911917
session.WaitWithDefaultTimeout()

test/e2e/update_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ var _ = Describe("Podman update", func() {
8787
It("podman update container all options v2", func() {
8888
SkipIfCgroupV1("testing flags that only work in cgroup v2")
8989
SkipIfRootless("many of these handlers are not enabled while rootless in CI")
90+
skipWithoutDevNullb0()
9091
session := podmanTest.Podman([]string{"run", "-dt", ALPINE})
9192
session.WaitWithDefaultTimeout()
9293
Expect(session).Should(ExitCleanly())
@@ -103,10 +104,10 @@ var _ = Describe("Podman update", func() {
103104
"--memory-swap", "2G",
104105
"--memory-reservation", "2G",
105106
"--blkio-weight", "123",
106-
"--device-read-bps", "/dev/zero:10mb",
107-
"--device-write-bps", "/dev/zero:10mb",
108-
"--device-read-iops", "/dev/zero:1000",
109-
"--device-write-iops", "/dev/zero:1000",
107+
"--device-read-bps", "/dev/nullb0:10mb",
108+
"--device-write-bps", "/dev/nullb0:10mb",
109+
"--device-read-iops", "/dev/nullb0:1000",
110+
"--device-write-iops", "/dev/nullb0:1000",
110111
"--pids-limit", "123",
111112
ctrID}
112113

0 commit comments

Comments
 (0)