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 <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2025-04-30 11:05:09 +02:00
committed by openshift-cherrypick-robot
parent 1c82abd17b
commit b85c312bc6
3 changed files with 30 additions and 12 deletions

View File

@ -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) { func SkipIfSystemdNotRunning(reason string) {
checkReason(reason) checkReason(reason)
@ -1648,3 +1655,7 @@ func makeTempDirInDir(dir string) string {
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
return path return path
} }
func skipWithoutDevNullb0() {
SkipIfNotExist("use modprobe null_blk nr_devices=1 to create it", "/dev/nullb0")
}

View File

@ -848,13 +848,14 @@ USER bin`, BB)
It("podman run device-read-bps test", func() { It("podman run device-read-bps test", func() {
SkipIfRootless("Setting device-read-bps not supported for rootless users") SkipIfRootless("Setting device-read-bps not supported for rootless users")
skipWithoutDevNullb0()
var session *PodmanSessionIntegration var session *PodmanSessionIntegration
if CGROUPSV2 { 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 { } 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() session.WaitWithDefaultTimeout()
@ -866,13 +867,14 @@ USER bin`, BB)
It("podman run device-write-bps test", func() { It("podman run device-write-bps test", func() {
SkipIfRootless("Setting device-write-bps not supported for rootless users") SkipIfRootless("Setting device-write-bps not supported for rootless users")
skipWithoutDevNullb0()
var session *PodmanSessionIntegration var session *PodmanSessionIntegration
if CGROUPSV2 { 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 { } 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() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
@ -883,12 +885,14 @@ USER bin`, BB)
It("podman run device-read-iops test", func() { It("podman run device-read-iops test", func() {
SkipIfRootless("Setting device-read-iops not supported for rootless users") SkipIfRootless("Setting device-read-iops not supported for rootless users")
skipWithoutDevNullb0()
var session *PodmanSessionIntegration var session *PodmanSessionIntegration
if CGROUPSV2 { 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 { } 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() session.WaitWithDefaultTimeout()
@ -900,12 +904,14 @@ USER bin`, BB)
It("podman run device-write-iops test", func() { It("podman run device-write-iops test", func() {
SkipIfRootless("Setting device-write-iops not supported for rootless users") SkipIfRootless("Setting device-write-iops not supported for rootless users")
skipWithoutDevNullb0()
var session *PodmanSessionIntegration var session *PodmanSessionIntegration
if CGROUPSV2 { 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 { } 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() session.WaitWithDefaultTimeout()

View File

@ -87,6 +87,7 @@ var _ = Describe("Podman update", func() {
It("podman update container all options v2", func() { It("podman update container all options v2", func() {
SkipIfCgroupV1("testing flags that only work in cgroup v2") SkipIfCgroupV1("testing flags that only work in cgroup v2")
SkipIfRootless("many of these handlers are not enabled while rootless in CI") SkipIfRootless("many of these handlers are not enabled while rootless in CI")
skipWithoutDevNullb0()
session := podmanTest.Podman([]string{"run", "-dt", ALPINE}) session := podmanTest.Podman([]string{"run", "-dt", ALPINE})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
@ -103,10 +104,10 @@ var _ = Describe("Podman update", func() {
"--memory-swap", "2G", "--memory-swap", "2G",
"--memory-reservation", "2G", "--memory-reservation", "2G",
"--blkio-weight", "123", "--blkio-weight", "123",
"--device-read-bps", "/dev/zero:10mb", "--device-read-bps", "/dev/nullb0:10mb",
"--device-write-bps", "/dev/zero:10mb", "--device-write-bps", "/dev/nullb0:10mb",
"--device-read-iops", "/dev/zero:1000", "--device-read-iops", "/dev/nullb0:1000",
"--device-write-iops", "/dev/zero:1000", "--device-write-iops", "/dev/nullb0:1000",
"--pids-limit", "123", "--pids-limit", "123",
ctrID} ctrID}