mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
libct/int/newTemplateConfig: add systemd support
... and properly set ScopePrefix, Name and Parent for a systemd case. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -514,7 +514,10 @@ func testFreeze(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
container, err := newContainerWithName("test", config)
|
||||
ok(t, err)
|
||||
defer container.Destroy()
|
||||
@@ -571,10 +574,10 @@ func testCpuShares(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
if systemd {
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
}
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
config.Cgroups.Resources.CpuShares = 1
|
||||
|
||||
_, _, err = runContainer(config, "", "ps")
|
||||
@@ -603,10 +606,10 @@ func testPids(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
if systemd {
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
}
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
config.Cgroups.Resources.PidsLimit = -1
|
||||
|
||||
// Running multiple processes.
|
||||
@@ -689,10 +692,10 @@ func testRunWithKernelMemory(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(&tParam{rootfs: rootfs})
|
||||
if systemd {
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
}
|
||||
config := newTemplateConfig(&tParam{
|
||||
rootfs: rootfs,
|
||||
systemd: systemd,
|
||||
})
|
||||
config.Cgroups.Resources.KernelMemory = 52428800
|
||||
|
||||
_, _, err = runContainer(config, "", "ps")
|
||||
@@ -723,10 +726,10 @@ func testCgroupResourcesUnifiedErrorOnV1(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(&tParam{rootfs: 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",
|
||||
}
|
||||
@@ -758,13 +761,13 @@ func testCgroupResourcesUnified(t *testing.T, systemd bool) {
|
||||
ok(t, err)
|
||||
defer remove(rootfs)
|
||||
|
||||
config := newTemplateConfig(&tParam{rootfs: 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, "")
|
||||
if systemd {
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"strconv"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer/configs"
|
||||
"github.com/opencontainers/runc/libcontainer/specconv"
|
||||
|
||||
@@ -17,8 +20,9 @@ var standardEnvironment = []string{
|
||||
const defaultMountFlags = unix.MS_NOEXEC | unix.MS_NOSUID | unix.MS_NODEV
|
||||
|
||||
type tParam struct {
|
||||
rootfs string
|
||||
userns bool
|
||||
rootfs string
|
||||
userns bool
|
||||
systemd bool
|
||||
}
|
||||
|
||||
// newTemplateConfig returns a base template for running a container
|
||||
@@ -122,7 +126,6 @@ func newTemplateConfig(p *tParam) *configs.Config {
|
||||
{Type: configs.NEWNET},
|
||||
}),
|
||||
Cgroups: &configs.Cgroup{
|
||||
Path: "/sys/fs/cgroup/",
|
||||
Resources: &configs.Resources{
|
||||
MemorySwappiness: nil,
|
||||
Devices: allowedDevices,
|
||||
@@ -209,5 +212,15 @@ func newTemplateConfig(p *tParam) *configs.Config {
|
||||
})
|
||||
}
|
||||
|
||||
if p.systemd {
|
||||
id := strconv.FormatUint(rand.Uint64(), 36)
|
||||
config.Cgroups.Name = "test" + id
|
||||
// do not change Parent (see newContainerWithName)
|
||||
config.Cgroups.Parent = "system.slice"
|
||||
config.Cgroups.ScopePrefix = "runc-test"
|
||||
} else {
|
||||
config.Cgroups.Path = "/test/integration"
|
||||
}
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user