From a2f7c6add8e875263b9cb1ff66ef7a3d005b6c97 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Mon, 23 Oct 2023 11:55:12 -0700 Subject: [PATCH 1/2] internal/testutil: create, add SkipOnCentOS CentOS 7 is showing its age and we'd rather skip some tests on it than find out why they are flaky. Add internal/testutil package, and move the generalized version of SkipOnCentOS7 from libcontainer/cgroups/devices to there. Signed-off-by: Kir Kolyshkin --- internal/testutil/testutil.go | 30 ++++++++++++++++++++ libcontainer/cgroups/devices/systemd_test.go | 29 ++++--------------- 2 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 internal/testutil/testutil.go diff --git a/internal/testutil/testutil.go b/internal/testutil/testutil.go new file mode 100644 index 00000000000..9df3ed1f68e --- /dev/null +++ b/internal/testutil/testutil.go @@ -0,0 +1,30 @@ +package testutil + +import ( + "os/exec" + "strconv" + "sync" + "testing" +) + +var ( + centosVer string + centosVerOnce sync.Once +) + +func centosVersion() string { + centosVerOnce.Do(func() { + ver, _ := exec.Command("rpm", "-q", "--qf", "%{version}", "centos-release").CombinedOutput() + centosVer = string(ver) + }) + return centosVer +} + +func SkipOnCentOS(t *testing.T, reason string, versions ...int) { + t.Helper() + for _, v := range versions { + if vstr := strconv.Itoa(v); centosVersion() == vstr { + t.Skip(reason + " on CentOS " + vstr) + } + } +} diff --git a/libcontainer/cgroups/devices/systemd_test.go b/libcontainer/cgroups/devices/systemd_test.go index fc3b635f24f..7bae2f7406a 100644 --- a/libcontainer/cgroups/devices/systemd_test.go +++ b/libcontainer/cgroups/devices/systemd_test.go @@ -6,9 +6,9 @@ import ( "os" "os/exec" "strings" - "sync" "testing" + "github.com/opencontainers/runc/internal/testutil" "github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runc/libcontainer/cgroups/systemd" "github.com/opencontainers/runc/libcontainer/configs" @@ -27,7 +27,8 @@ func TestPodSkipDevicesUpdate(t *testing.T) { if os.Geteuid() != 0 { t.Skip("Test requires root.") } - skipOnCentOS7(t) + // https://github.com/opencontainers/runc/issues/3743. + testutil.SkipOnCentOS(t, "Flaky (#3743)", 7) podName := "system-runc_test_pod" + t.Name() + ".slice" podConfig := &configs.Cgroup{ @@ -118,27 +119,6 @@ func TestPodSkipDevicesUpdate(t *testing.T) { } } -var ( - centosVer string - centosVerOnce sync.Once -) - -func centosVersion() string { - centosVerOnce.Do(func() { - ver, _ := exec.Command("rpm", "-q", "--qf", "%{version}", "centos-release").CombinedOutput() - centosVer = string(ver) - }) - return centosVer -} - -func skipOnCentOS7(t *testing.T) { - t.Helper() - // https://github.com/opencontainers/runc/issues/3743 - if centosVersion() == "7" { - t.Skip("Flaky on CentOS 7") - } -} - func testSkipDevices(t *testing.T, skipDevices bool, expected []string) { if !systemd.IsRunningSystemd() { t.Skip("Test requires systemd.") @@ -146,7 +126,8 @@ func testSkipDevices(t *testing.T, skipDevices bool, expected []string) { if os.Geteuid() != 0 { t.Skip("Test requires root.") } - skipOnCentOS7(t) + // https://github.com/opencontainers/runc/issues/3743. + testutil.SkipOnCentOS(t, "Flaky (#3743)", 7) podConfig := &configs.Cgroup{ Parent: "system.slice", From b2539a7dc3411f68e1bfa418ee6d9ae073729c2e Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 27 Oct 2023 13:31:47 -0700 Subject: [PATCH 2/2] libct/cg: skip TestWriteCgroupFileHandlesInterrupt on CentOS 7 It's flaky (kernel bug?) and there's probably nothing we can do about it. Fixes #3418. Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/file_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libcontainer/cgroups/file_test.go b/libcontainer/cgroups/file_test.go index 94f1a99bff0..6236bb9ec1e 100644 --- a/libcontainer/cgroups/file_test.go +++ b/libcontainer/cgroups/file_test.go @@ -8,9 +8,13 @@ import ( "strconv" "testing" "time" + + "github.com/opencontainers/runc/internal/testutil" ) func TestWriteCgroupFileHandlesInterrupt(t *testing.T) { + testutil.SkipOnCentOS(t, "Flaky (see #3418)", 7) + const ( memoryCgroupMount = "/sys/fs/cgroup/memory" memoryLimit = "memory.limit_in_bytes"