From 8160e02459c06257724f895766030cfd9152e79f Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 30 Apr 2025 11:05:09 +0200 Subject: [PATCH] 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 --- test/e2e/common_test.go | 11 +++++++++++ test/e2e/run_test.go | 22 ++++++++++++++-------- test/e2e/update_test.go | 9 +++++---- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index e97b5b471b..9d081087a7 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -942,6 +942,13 @@ func SkipIfNotRootless(reason string) { } } +func SkipIfNotExist(reason, path string) { + checkReason(reason) + if _, err := os.Stat(path); err != nil { + Skip("[doesNotExist]: " + path + " does not exist: " + reason) + } +} + func SkipIfSystemdNotRunning(reason string) { checkReason(reason) @@ -1648,3 +1655,7 @@ func makeTempDirInDir(dir string) string { Expect(err).ToNot(HaveOccurred()) return path } + +func skipWithoutDevNullb0() { + SkipIfNotExist("use modprobe null_blk nr_devices=1 to create it", "/dev/nullb0") +} diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index a7c9f99e51..cc281f0c78 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -848,13 +848,14 @@ USER bin`, BB) It("podman run device-read-bps test", func() { SkipIfRootless("Setting device-read-bps not supported for rootless users") + skipWithoutDevNullb0() var session *PodmanSessionIntegration if CGROUPSV2 { - 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"}) + 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"}) } else { - session = podmanTest.Podman([]string{"run", "--rm", "--device-read-bps=/dev/zero:1mb", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.read_bps_device"}) + session = podmanTest.Podman([]string{"run", "--rm", "--device-read-bps=/dev/nullb0:1mb", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.read_bps_device"}) } session.WaitWithDefaultTimeout() @@ -866,13 +867,14 @@ USER bin`, BB) It("podman run device-write-bps test", func() { SkipIfRootless("Setting device-write-bps not supported for rootless users") + skipWithoutDevNullb0() var session *PodmanSessionIntegration if CGROUPSV2 { - 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"}) + 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"}) } else { - session = podmanTest.Podman([]string{"run", "--rm", "--device-write-bps=/dev/zero:1mb", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.write_bps_device"}) + session = podmanTest.Podman([]string{"run", "--rm", "--device-write-bps=/dev/nullb0:1mb", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.write_bps_device"}) } session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) @@ -883,12 +885,14 @@ USER bin`, BB) It("podman run device-read-iops test", func() { SkipIfRootless("Setting device-read-iops not supported for rootless users") + skipWithoutDevNullb0() + var session *PodmanSessionIntegration if CGROUPSV2 { - 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"}) + 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"}) } else { - session = podmanTest.Podman([]string{"run", "--rm", "--device-read-iops=/dev/zero:100", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.read_iops_device"}) + session = podmanTest.Podman([]string{"run", "--rm", "--device-read-iops=/dev/nullb0:100", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.read_iops_device"}) } session.WaitWithDefaultTimeout() @@ -900,12 +904,14 @@ USER bin`, BB) It("podman run device-write-iops test", func() { SkipIfRootless("Setting device-write-iops not supported for rootless users") + skipWithoutDevNullb0() + var session *PodmanSessionIntegration if CGROUPSV2 { - 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"}) + 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"}) } else { - session = podmanTest.Podman([]string{"run", "--rm", "--device-write-iops=/dev/zero:100", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.write_iops_device"}) + session = podmanTest.Podman([]string{"run", "--rm", "--device-write-iops=/dev/nullb0:100", ALPINE, "cat", "/sys/fs/cgroup/blkio/blkio.throttle.write_iops_device"}) } session.WaitWithDefaultTimeout() diff --git a/test/e2e/update_test.go b/test/e2e/update_test.go index 7950b1ffe6..e442b7b36d 100644 --- a/test/e2e/update_test.go +++ b/test/e2e/update_test.go @@ -87,6 +87,7 @@ var _ = Describe("Podman update", func() { It("podman update container all options v2", func() { SkipIfCgroupV1("testing flags that only work in cgroup v2") SkipIfRootless("many of these handlers are not enabled while rootless in CI") + skipWithoutDevNullb0() session := podmanTest.Podman([]string{"run", "-dt", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(ExitCleanly()) @@ -103,10 +104,10 @@ var _ = Describe("Podman update", func() { "--memory-swap", "2G", "--memory-reservation", "2G", "--blkio-weight", "123", - "--device-read-bps", "/dev/zero:10mb", - "--device-write-bps", "/dev/zero:10mb", - "--device-read-iops", "/dev/zero:1000", - "--device-write-iops", "/dev/zero:1000", + "--device-read-bps", "/dev/nullb0:10mb", + "--device-write-bps", "/dev/nullb0:10mb", + "--device-read-iops", "/dev/nullb0:1000", + "--device-write-iops", "/dev/nullb0:1000", "--pids-limit", "123", ctrID}