mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
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 <kolyshkin@gmail.com>
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runc/internal/testutil"
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
"github.com/opencontainers/runc/libcontainer/cgroups/systemd"
|
||||||
"github.com/opencontainers/runc/libcontainer/configs"
|
"github.com/opencontainers/runc/libcontainer/configs"
|
||||||
@@ -27,7 +27,8 @@ func TestPodSkipDevicesUpdate(t *testing.T) {
|
|||||||
if os.Geteuid() != 0 {
|
if os.Geteuid() != 0 {
|
||||||
t.Skip("Test requires root.")
|
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"
|
podName := "system-runc_test_pod" + t.Name() + ".slice"
|
||||||
podConfig := &configs.Cgroup{
|
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) {
|
func testSkipDevices(t *testing.T, skipDevices bool, expected []string) {
|
||||||
if !systemd.IsRunningSystemd() {
|
if !systemd.IsRunningSystemd() {
|
||||||
t.Skip("Test requires systemd.")
|
t.Skip("Test requires systemd.")
|
||||||
@@ -146,7 +126,8 @@ func testSkipDevices(t *testing.T, skipDevices bool, expected []string) {
|
|||||||
if os.Geteuid() != 0 {
|
if os.Geteuid() != 0 {
|
||||||
t.Skip("Test requires root.")
|
t.Skip("Test requires root.")
|
||||||
}
|
}
|
||||||
skipOnCentOS7(t)
|
// https://github.com/opencontainers/runc/issues/3743.
|
||||||
|
testutil.SkipOnCentOS(t, "Flaky (#3743)", 7)
|
||||||
|
|
||||||
podConfig := &configs.Cgroup{
|
podConfig := &configs.Cgroup{
|
||||||
Parent: "system.slice",
|
Parent: "system.slice",
|
||||||
|
|||||||
Reference in New Issue
Block a user