mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Merge pull request #2600 from kolyshkin/libct-int-wut
libcontainer/integration: fix cgroupv1 + systemd tests
This commit is contained in:
@@ -41,12 +41,10 @@ func testExecPS(t *testing.T, userns bool) {
|
||||
rootfs, err := newRootfs()
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
config := newTemplateConfig(rootfs)
|
||||
if userns {
|
||||
config.UidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
|
||||
config.GidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
|
||||
config.Namespaces = append(config.Namespaces, configs.Namespace{Type: configs.NEWUSER})
|
||||
}
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
userns: userns,
|
||||
})
|
||||
|
||||
buffers, exitCode, err := runContainer(config, "", "ps", "-o", "pid,user,comm")
|
||||
if err != nil {
|
||||
@@ -78,7 +76,7 @@ func TestIPCPrivate(t *testing.T) {
|
||||
l, err := os.Readlink("/proc/1/ns/ipc")
|
||||
ok(t, err)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/ipc")
|
||||
ok(t, err)
|
||||
|
||||
@@ -103,7 +101,7 @@ func TestIPCHost(t *testing.T) {
|
||||
l, err := os.Readlink("/proc/1/ns/ipc")
|
||||
ok(t, err)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.Namespaces.Remove(configs.NEWIPC)
|
||||
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/ipc")
|
||||
ok(t, err)
|
||||
@@ -129,7 +127,7 @@ func TestIPCJoinPath(t *testing.T) {
|
||||
l, err := os.Readlink("/proc/1/ns/ipc")
|
||||
ok(t, err)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.Namespaces.Add(configs.NEWIPC, "/proc/1/ns/ipc")
|
||||
|
||||
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/ipc")
|
||||
@@ -153,7 +151,7 @@ func TestIPCBadPath(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.Namespaces.Add(configs.NEWIPC, "/proc/1/ns/ipcc")
|
||||
|
||||
_, _, err = runContainer(config, "", "true")
|
||||
@@ -183,12 +181,10 @@ func testRlimit(t *testing.T, userns bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
if userns {
|
||||
config.UidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
|
||||
config.GidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
|
||||
config.Namespaces = append(config.Namespaces, configs.Namespace{Type: configs.NEWUSER})
|
||||
}
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
userns: userns,
|
||||
})
|
||||
|
||||
// ensure limit is lower than what the config requests to test that in a user namespace
|
||||
// the Setrlimit call happens early enough that we still have permissions to raise the limit.
|
||||
@@ -213,7 +209,7 @@ func TestEnter(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
|
||||
container, err := newContainerWithName("test", config)
|
||||
ok(t, err)
|
||||
@@ -300,7 +296,7 @@ func TestProcessEnv(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
|
||||
container, err := newContainerWithName("test", config)
|
||||
ok(t, err)
|
||||
@@ -348,7 +344,7 @@ func TestProcessEmptyCaps(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.Capabilities = nil
|
||||
|
||||
container, err := newContainerWithName("test", config)
|
||||
@@ -397,7 +393,7 @@ func TestProcessCaps(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
|
||||
container, err := newContainerWithName("test", config)
|
||||
ok(t, err)
|
||||
@@ -465,7 +461,7 @@ func TestAdditionalGroups(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
|
||||
container, err := newContainerWithName("test", config)
|
||||
ok(t, err)
|
||||
@@ -519,7 +515,10 @@ func testFreeze(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
container, err := newContainerWithName("test", config)
|
||||
ok(t, err)
|
||||
defer container.Destroy()
|
||||
@@ -576,10 +575,10 @@ func testCpuShares(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
if systemd {
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
}
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
config.Cgroups.Resources.CpuShares = 1
|
||||
|
||||
_, _, err = runContainer(config, "", "ps")
|
||||
@@ -608,10 +607,10 @@ func testPids(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
if systemd {
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
}
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
config.Cgroups.Resources.PidsLimit = -1
|
||||
|
||||
// Running multiple processes.
|
||||
@@ -694,10 +693,10 @@ func testRunWithKernelMemory(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
if systemd {
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
}
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
config.Cgroups.Resources.KernelMemory = 52428800
|
||||
|
||||
_, _, err = runContainer(config, "", "ps")
|
||||
@@ -728,10 +727,10 @@ func testCgroupResourcesUnifiedErrorOnV1(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
if systemd {
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
}
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
config.Cgroups.Resources.Unified = map[string]string{
|
||||
"memory.min": "10240",
|
||||
}
|
||||
@@ -763,18 +762,13 @@ func testCgroupResourcesUnified(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
config.Cgroups.Resources.Memory = 536870912 // 512M
|
||||
config.Cgroups.Resources.MemorySwap = 536870912 // 512M, i.e. no swap
|
||||
config.Namespaces.Add(configs.NEWCGROUP, "")
|
||||
config.Mounts = append(config.Mounts, &configs.Mount{
|
||||
Destination: "/sys/fs/cgroup",
|
||||
Device: "cgroup",
|
||||
Flags: defaultMountFlags | unix.MS_RDONLY,
|
||||
})
|
||||
if systemd {
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
@@ -871,7 +865,7 @@ func TestContainerState(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.Namespaces = configs.Namespaces([]configs.Namespace{
|
||||
{Type: configs.NEWNS},
|
||||
{Type: configs.NEWUTS},
|
||||
@@ -932,7 +926,7 @@ func TestPassExtraFiles(t *testing.T) {
|
||||
}
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
|
||||
container, err := newContainerWithName("test", config)
|
||||
if err != nil {
|
||||
@@ -1007,7 +1001,7 @@ func TestMountCmds(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.Mounts = append(config.Mounts, &configs.Mount{
|
||||
Source: tmpDir,
|
||||
Destination: "/tmp",
|
||||
@@ -1064,7 +1058,7 @@ func TestSysctl(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.Sysctl = map[string]string{
|
||||
"kernel.shmmni": "8192",
|
||||
}
|
||||
@@ -1101,14 +1095,7 @@ func TestMountCgroupRO(t *testing.T) {
|
||||
rootfs, err := newRootfs()
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
config := newTemplateConfig(rootfs)
|
||||
|
||||
config.Mounts = append(config.Mounts, &configs.Mount{
|
||||
Destination: "/sys/fs/cgroup",
|
||||
Device: "cgroup",
|
||||
Flags: defaultMountFlags | unix.MS_RDONLY,
|
||||
})
|
||||
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
buffers, exitCode, err := runContainer(config, "", "mount")
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %s", buffers, err)
|
||||
@@ -1150,13 +1137,14 @@ func TestMountCgroupRW(t *testing.T) {
|
||||
rootfs, err := newRootfs()
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
config := newTemplateConfig(rootfs)
|
||||
|
||||
config.Mounts = append(config.Mounts, &configs.Mount{
|
||||
Destination: "/sys/fs/cgroup",
|
||||
Device: "cgroup",
|
||||
Flags: defaultMountFlags,
|
||||
})
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
// clear the RO flag from cgroup mount
|
||||
for _, m := range config.Mounts {
|
||||
if m.Device == "cgroup" {
|
||||
m.Flags = defaultMountFlags
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
buffers, exitCode, err := runContainer(config, "", "mount")
|
||||
if err != nil {
|
||||
@@ -1201,7 +1189,7 @@ func TestOomScoreAdj(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.OomScoreAdj = ptrInt(200)
|
||||
|
||||
container, err := newContainerWithName("test", config)
|
||||
@@ -1243,7 +1231,7 @@ func TestHook(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
expectedBundle := bundle
|
||||
config.Labels = append(config.Labels, "bundle="+expectedBundle)
|
||||
|
||||
@@ -1389,7 +1377,7 @@ func TestSTDIOPermissions(t *testing.T) {
|
||||
rootfs, err := newRootfs()
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
buffers, exitCode, err := runContainer(config, "", "sh", "-c", "echo hi > /dev/stderr")
|
||||
ok(t, err)
|
||||
if exitCode != 0 {
|
||||
@@ -1422,7 +1410,7 @@ func TestRootfsPropagationSlaveMount(t *testing.T) {
|
||||
rootfs, err := newRootfs()
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
|
||||
config.RootPropagation = unix.MS_SLAVE | unix.MS_REC
|
||||
|
||||
@@ -1538,7 +1526,7 @@ func TestRootfsPropagationSharedMount(t *testing.T) {
|
||||
rootfs, err := newRootfs()
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.RootPropagation = unix.MS_PRIVATE
|
||||
|
||||
// Bind mount a volume
|
||||
@@ -1647,7 +1635,7 @@ func TestPIDHost(t *testing.T) {
|
||||
l, err := os.Readlink("/proc/1/ns/pid")
|
||||
ok(t, err)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.Namespaces.Remove(configs.NEWPID)
|
||||
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/pid")
|
||||
ok(t, err)
|
||||
@@ -1723,7 +1711,7 @@ func TestInitJoinPID(t *testing.T) {
|
||||
defer remove(rootfs)
|
||||
|
||||
// Execute a long-running container
|
||||
container1, err := newContainer(newTemplateConfig(rootfs))
|
||||
container1, err := newContainer(newTemplateConfig(&tParam{rootfs: rootfs}))
|
||||
ok(t, err)
|
||||
defer container1.Destroy()
|
||||
|
||||
@@ -1747,7 +1735,7 @@ func TestInitJoinPID(t *testing.T) {
|
||||
pidns1 := state1.NamespacePaths[configs.NEWPID]
|
||||
|
||||
// Run a container inside the existing pidns but with different cgroups
|
||||
config2 := newTemplateConfig(rootfs)
|
||||
config2 := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config2.Namespaces.Add(configs.NEWPID, pidns1)
|
||||
config2.Cgroups.Path = "integration/test2"
|
||||
container2, err := newContainerWithName("testCT2", config2)
|
||||
@@ -1826,10 +1814,10 @@ func TestInitJoinNetworkAndUser(t *testing.T) {
|
||||
defer remove(rootfs)
|
||||
|
||||
// Execute a long-running container
|
||||
config1 := newTemplateConfig(rootfs)
|
||||
config1.UidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
|
||||
config1.GidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
|
||||
config1.Namespaces = append(config1.Namespaces, configs.Namespace{Type: configs.NEWUSER})
|
||||
config1 := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
userns: true,
|
||||
})
|
||||
container1, err := newContainer(config1)
|
||||
ok(t, err)
|
||||
defer container1.Destroy()
|
||||
@@ -1859,9 +1847,10 @@ func TestInitJoinNetworkAndUser(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs2)
|
||||
|
||||
config2 := newTemplateConfig(rootfs2)
|
||||
config2.UidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
|
||||
config2.GidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
|
||||
config2 := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs2,
|
||||
userns: true,
|
||||
})
|
||||
config2.Namespaces.Add(configs.NEWNET, netns1)
|
||||
config2.Namespaces.Add(configs.NEWUSER, userns1)
|
||||
config2.Cgroups.Path = "integration/test2"
|
||||
@@ -1919,7 +1908,7 @@ func TestTmpfsCopyUp(t *testing.T) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
|
||||
config.Mounts = append(config.Mounts, &configs.Mount{
|
||||
Source: "tmpfs",
|
||||
@@ -1969,7 +1958,7 @@ func TestCGROUPPrivate(t *testing.T) {
|
||||
l, err := os.Readlink("/proc/1/ns/cgroup")
|
||||
ok(t, err)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config.Namespaces.Add(configs.NEWCGROUP, "")
|
||||
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/cgroup")
|
||||
ok(t, err)
|
||||
@@ -1998,7 +1987,7 @@ func TestCGROUPHost(t *testing.T) {
|
||||
l, err := os.Readlink("/proc/1/ns/cgroup")
|
||||
ok(t, err)
|
||||
|
||||
config := newTemplateConfig(rootfs)
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/cgroup")
|
||||
ok(t, err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user