Merge pull request #26207 from giuseppe/fix-flake-kmsg

test: fix race conditions in /dev/kmsg tests
This commit is contained in:
openshift-merge-bot[bot] 2025-05-28 21:14:39 +00:00 • committed by GitHub
commit 23ded8bcee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,7 +50,10 @@ var _ = Describe("Podman run device", func() {
Expect(session).Should(ExitCleanly())
if !isRootless() {
// Kernel 6.9.0 (2024-03) requires SYSLOG
session = podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg", "--cap-add", "SYS_ADMIN,SYSLOG", ALPINE, "head", "-n", "1", "/dev/kmsg"})
// Do not read any data from the device (thus the -n 0), because there is a rare race condition that happens
// when another writes to the ring buffer when the device is already opened and that causes the following test
// to fail: https://github.com/containers/podman/issues/23882.
session = podmanTest.Podman([]string{"run", "-q", "--security-opt", "label=disable", "--device", "/dev/kmsg", "--cap-add", "SYS_ADMIN,SYSLOG", ALPINE, "head", "-n", "0", "/dev/kmsg"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
}
@ -152,9 +155,12 @@ var _ = Describe("Podman run device", func() {
})
It("podman run cannot access non default devices", func() {
session := podmanTest.Podman([]string{"run", "-v /dev:/dev-host", ALPINE, "head", "-1", "/dev-host/kmsg"})
// Unlikely to happen but do not read any data from the device (thus the -n 0), because there is a rare
// race condition that happens so the test would fail for the rare race condition instead of a failure
// reported by open(). More details: https://github.com/containers/podman/issues/23882.
session := podmanTest.Podman([]string{"run", "-v", "/dev:/dev-host", ALPINE, "head", "-n0", "/dev-host/kmsg"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Not(ExitCleanly()))
Expect(session).To(ExitWithErrorRegex(1, "head: /dev-host/kmsg: (Operation not permitted|Permission denied)"))
})
})