libct/int: better test container names

1. Do not create the same container named "test" over and over.

2. Fix randomization issues when generating container and cgroup names.
   The issues were:

    * math/rand used without seeding
    * complex rand/md5/hexencode sequence

   In both cases, replace with nanosecond time encoded with digits and
   lowercase letters.

3. Add test name to container and cgroup names. For example, this is
   how systemd log has changed:

   Before: Started libcontainer container test16ddfwutxgjte.
   After: Started libcontainer container TestPidsSystemd-4oaqvr.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-04-14 16:05:10 -07:00
parent fce58ab2d5
commit 7b802a7da4
6 changed files with 121 additions and 126 deletions

View File

@@ -73,7 +73,7 @@ func testCheckpoint(t *testing.T, userns bool) {
}
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
userns: userns,
})

View File

@@ -41,12 +41,12 @@ func testExecPS(t *testing.T, userns bool) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
userns: userns,
})
buffers, exitCode, err := runContainer(config, "", "ps", "-o", "pid,user,comm")
buffers, exitCode, err := runContainer(t, config, "", "ps", "-o", "pid,user,comm")
if err != nil {
t.Fatalf("%s: %s", buffers, err)
}
@@ -76,8 +76,8 @@ func TestIPCPrivate(t *testing.T) {
l, err := os.Readlink("/proc/1/ns/ipc")
ok(t, err)
config := newTemplateConfig(&tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/ipc")
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/ipc")
ok(t, err)
if exitCode != 0 {
@@ -101,9 +101,9 @@ func TestIPCHost(t *testing.T) {
l, err := os.Readlink("/proc/1/ns/ipc")
ok(t, err)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Namespaces.Remove(configs.NEWIPC)
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/ipc")
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/ipc")
ok(t, err)
if exitCode != 0 {
@@ -127,10 +127,10 @@ func TestIPCJoinPath(t *testing.T) {
l, err := os.Readlink("/proc/1/ns/ipc")
ok(t, err)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Namespaces.Add(configs.NEWIPC, "/proc/1/ns/ipc")
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/ipc")
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/ipc")
ok(t, err)
if exitCode != 0 {
@@ -151,10 +151,10 @@ func TestIPCBadPath(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Namespaces.Add(configs.NEWIPC, "/proc/1/ns/ipcc")
_, _, err = runContainer(config, "", "true")
_, _, err = runContainer(t, config, "", "true")
if err == nil {
t.Fatal("container succeeded with bad ipc path")
}
@@ -181,7 +181,7 @@ func testRlimit(t *testing.T, userns bool) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
userns: userns,
})
@@ -193,7 +193,7 @@ func testRlimit(t *testing.T, userns bool) {
Cur: 1024,
}))
out, _, err := runContainer(config, "", "/bin/sh", "-c", "ulimit -n")
out, _, err := runContainer(t, config, "", "/bin/sh", "-c", "ulimit -n")
ok(t, err)
if limit := strings.TrimSpace(out.Stdout.String()); limit != "1025" {
t.Fatalf("expected rlimit to be 1025, got %s", limit)
@@ -209,9 +209,9 @@ func TestEnter(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -296,9 +296,9 @@ func TestProcessEnv(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -344,10 +344,10 @@ func TestProcessEmptyCaps(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Capabilities = nil
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -393,9 +393,9 @@ func TestProcessCaps(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -458,9 +458,9 @@ func TestAdditionalGroups(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -512,11 +512,11 @@ func testFreeze(t *testing.T, systemd bool) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
systemd: systemd,
})
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -572,13 +572,13 @@ func testCpuShares(t *testing.T, systemd bool) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
systemd: systemd,
})
config.Cgroups.Resources.CpuShares = 1
_, _, err = runContainer(config, "", "ps")
_, _, err = runContainer(t, config, "", "ps")
if err == nil {
t.Fatalf("runContainer should failed with invalid CpuShares")
}
@@ -604,14 +604,14 @@ func testPids(t *testing.T, systemd bool) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
systemd: systemd,
})
config.Cgroups.Resources.PidsLimit = -1
// Running multiple processes.
_, ret, err := runContainer(config, "", "/bin/sh", "-c", "/bin/true | /bin/true | /bin/true | /bin/true")
_, ret, err := runContainer(t, config, "", "/bin/sh", "-c", "/bin/true | /bin/true | /bin/true | /bin/true")
if err != nil && strings.Contains(err.Error(), "no such directory for pids.max") {
t.Skip("PIDs cgroup is unsupported")
}
@@ -624,7 +624,7 @@ func testPids(t *testing.T, systemd bool) {
// Enforce a permissive limit. This needs to be fairly hand-wavey due to the
// issues with running Go binaries with pids restrictions (see below).
config.Cgroups.Resources.PidsLimit = 64
_, ret, err = runContainer(config, "", "/bin/sh", "-c", `
_, ret, err = runContainer(t, config, "", "/bin/sh", "-c", `
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
@@ -641,7 +641,7 @@ func testPids(t *testing.T, systemd bool) {
// Enforce a restrictive limit. 64 * /bin/true + 1 * shell should cause this
// to fail reliability.
config.Cgroups.Resources.PidsLimit = 64
out, _, err := runContainer(config, "", "/bin/sh", "-c", `
out, _, err := runContainer(t, config, "", "/bin/sh", "-c", `
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
@@ -689,14 +689,14 @@ func testCgroupResourcesUnifiedErrorOnV1(t *testing.T, systemd bool) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
systemd: systemd,
})
config.Cgroups.Resources.Unified = map[string]string{
"memory.min": "10240",
}
_, _, err = runContainer(config, "", "true")
_, _, err = runContainer(t, config, "", "true")
if !strings.Contains(err.Error(), cgroups.ErrV1NoUnified.Error()) {
t.Fatalf("expected error to contain %v, got %v", cgroups.ErrV1NoUnified, err)
}
@@ -724,7 +724,7 @@ func testCgroupResourcesUnified(t *testing.T, systemd bool) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
systemd: systemd,
})
@@ -786,7 +786,7 @@ func testCgroupResourcesUnified(t *testing.T, systemd bool) {
for _, tc := range testCases {
config.Cgroups.Resources.Unified = tc.cfg
buffers, ret, err := runContainer(config, "", tc.cmd...)
buffers, ret, err := runContainer(t, config, "", tc.cmd...)
if tc.expError != "" {
if err == nil {
t.Errorf("case %q failed: expected error, got nil", tc.name)
@@ -827,7 +827,7 @@ func TestContainerState(t *testing.T) {
t.Fatal(err)
}
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Namespaces = configs.Namespaces([]configs.Namespace{
{Type: configs.NEWNS},
{Type: configs.NEWUTS},
@@ -837,7 +837,7 @@ func TestContainerState(t *testing.T) {
{Type: configs.NEWNET},
})
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
if err != nil {
t.Fatal(err)
}
@@ -888,9 +888,9 @@ func TestPassExtraFiles(t *testing.T) {
}
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
if err != nil {
t.Fatal(err)
}
@@ -963,7 +963,7 @@ func TestMountCmds(t *testing.T) {
}
defer os.RemoveAll(tmpDir)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Mounts = append(config.Mounts, &configs.Mount{
Source: tmpDir,
Destination: "/tmp",
@@ -979,7 +979,7 @@ func TestMountCmds(t *testing.T) {
},
})
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
if err != nil {
t.Fatal(err)
}
@@ -1020,12 +1020,12 @@ func TestSysctl(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Sysctl = map[string]string{
"kernel.shmmni": "8192",
}
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -1057,8 +1057,8 @@ func TestMountCgroupRO(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(config, "", "mount")
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(t, config, "", "mount")
if err != nil {
t.Fatalf("%s: %s", buffers, err)
}
@@ -1099,7 +1099,7 @@ func TestMountCgroupRW(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
// clear the RO flag from cgroup mount
for _, m := range config.Mounts {
if m.Device == "cgroup" {
@@ -1108,7 +1108,7 @@ func TestMountCgroupRW(t *testing.T) {
}
}
buffers, exitCode, err := runContainer(config, "", "mount")
buffers, exitCode, err := runContainer(t, config, "", "mount")
if err != nil {
t.Fatalf("%s: %s", buffers, err)
}
@@ -1151,10 +1151,10 @@ func TestOomScoreAdj(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.OomScoreAdj = ptrInt(200)
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -1193,7 +1193,7 @@ func TestHook(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
expectedBundle := bundle
config.Labels = append(config.Labels, "bundle="+expectedBundle)
@@ -1295,7 +1295,7 @@ func TestHook(t *testing.T) {
ok(t, err)
ok(t, json.NewEncoder(f).Encode(config))
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
// e.g: 'ls /prestart ...'
@@ -1339,8 +1339,8 @@ func TestSTDIOPermissions(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(config, "", "sh", "-c", "echo hi > /dev/stderr")
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(t, config, "", "sh", "-c", "echo hi > /dev/stderr")
ok(t, err)
if exitCode != 0 {
t.Fatalf("exit code not 0. code %d stderr %q", exitCode, buffers.Stderr)
@@ -1372,7 +1372,7 @@ func TestRootfsPropagationSlaveMount(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.RootPropagation = unix.MS_SLAVE | unix.MS_REC
@@ -1395,7 +1395,7 @@ func TestRootfsPropagationSlaveMount(t *testing.T) {
Device: "bind",
Flags: unix.MS_BIND | unix.MS_REC})
container, err := newContainerWithName("testSlaveMount", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -1488,7 +1488,7 @@ func TestRootfsPropagationSharedMount(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.RootPropagation = unix.MS_PRIVATE
// Bind mount a volume
@@ -1510,7 +1510,7 @@ func TestRootfsPropagationSharedMount(t *testing.T) {
Device: "bind",
Flags: unix.MS_BIND | unix.MS_REC})
container, err := newContainerWithName("testSharedMount", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -1597,9 +1597,9 @@ func TestPIDHost(t *testing.T) {
l, err := os.Readlink("/proc/1/ns/pid")
ok(t, err)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Namespaces.Remove(configs.NEWPID)
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/pid")
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/pid")
ok(t, err)
if exitCode != 0 {
@@ -1623,9 +1623,9 @@ func TestPIDHostInitProcessWait(t *testing.T) {
pidns := "/proc/1/ns/pid"
// Run a container with two long-running processes.
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Namespaces.Add(configs.NEWPID, pidns)
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer func() {
_ = container.Destroy()
@@ -1673,7 +1673,7 @@ func TestInitJoinPID(t *testing.T) {
defer remove(rootfs)
// Execute a long-running container
container1, err := newContainer(newTemplateConfig(&tParam{rootfs: rootfs}))
container1, err := newContainer(t, newTemplateConfig(t, &tParam{rootfs: rootfs}))
ok(t, err)
defer container1.Destroy()
@@ -1697,10 +1697,10 @@ func TestInitJoinPID(t *testing.T) {
pidns1 := state1.NamespacePaths[configs.NEWPID]
// Run a container inside the existing pidns but with different cgroups
config2 := newTemplateConfig(&tParam{rootfs: rootfs})
config2 := newTemplateConfig(t, &tParam{rootfs: rootfs})
config2.Namespaces.Add(configs.NEWPID, pidns1)
config2.Cgroups.Path = "integration/test2"
container2, err := newContainerWithName("testCT2", config2)
container2, err := newContainer(t, config2)
ok(t, err)
defer container2.Destroy()
@@ -1776,11 +1776,11 @@ func TestInitJoinNetworkAndUser(t *testing.T) {
defer remove(rootfs)
// Execute a long-running container
config1 := newTemplateConfig(&tParam{
config1 := newTemplateConfig(t, &tParam{
rootfs: rootfs,
userns: true,
})
container1, err := newContainer(config1)
container1, err := newContainer(t, config1)
ok(t, err)
defer container1.Destroy()
@@ -1809,14 +1809,14 @@ func TestInitJoinNetworkAndUser(t *testing.T) {
ok(t, err)
defer remove(rootfs2)
config2 := newTemplateConfig(&tParam{
config2 := newTemplateConfig(t, &tParam{
rootfs: rootfs2,
userns: true,
})
config2.Namespaces.Add(configs.NEWNET, netns1)
config2.Namespaces.Add(configs.NEWUSER, userns1)
config2.Cgroups.Path = "integration/test2"
container2, err := newContainerWithName("testCT2", config2)
container2, err := newContainer(t, config2)
ok(t, err)
defer container2.Destroy()
@@ -1870,7 +1870,7 @@ func TestTmpfsCopyUp(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Mounts = append(config.Mounts, &configs.Mount{
Source: "tmpfs",
@@ -1879,7 +1879,7 @@ func TestTmpfsCopyUp(t *testing.T) {
Extensions: configs.EXT_COPYUP,
})
container, err := newContainerWithName("test", config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -1920,9 +1920,9 @@ func TestCGROUPPrivate(t *testing.T) {
l, err := os.Readlink("/proc/1/ns/cgroup")
ok(t, err)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Namespaces.Add(configs.NEWCGROUP, "")
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/cgroup")
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/cgroup")
ok(t, err)
if exitCode != 0 {
@@ -1949,8 +1949,8 @@ func TestCGROUPHost(t *testing.T) {
l, err := os.Readlink("/proc/1/ns/cgroup")
ok(t, err)
config := newTemplateConfig(&tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/cgroup")
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(t, config, "", "readlink", "/proc/self/ns/cgroup")
ok(t, err)
if exitCode != 0 {
@@ -1979,8 +1979,8 @@ func TestFdLeaks(t *testing.T) {
_, err = pfd.Seek(0, 0)
ok(t, err)
config := newTemplateConfig(&tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(config, "", "true")
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
buffers, exitCode, err := runContainer(t, config, "", "true")
ok(t, err)
if exitCode != 0 {

View File

@@ -25,8 +25,8 @@ func TestExecIn(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
container, err := newContainer(config)
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -91,12 +91,12 @@ func testExecInRlimit(t *testing.T, userns bool) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
userns: userns,
})
container, err := newContainer(config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -150,8 +150,8 @@ func TestExecInAdditionalGroups(t *testing.T) {
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
container, err := newContainer(config)
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -207,8 +207,8 @@ func TestExecInError(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
container, err := newContainer(config)
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -261,8 +261,8 @@ func TestExecInTTY(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
container, err := newContainer(config)
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -357,8 +357,8 @@ func TestExecInEnvironment(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
container, err := newContainer(config)
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -419,8 +419,8 @@ func TestExecinPassExtraFiles(t *testing.T) {
t.Fatal(err)
}
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
container, err := newContainer(config)
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
container, err := newContainer(t, config)
if err != nil {
t.Fatal(err)
}
@@ -503,9 +503,9 @@ func TestExecInOomScoreAdj(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.OomScoreAdj = ptrInt(200)
container, err := newContainer(config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()
@@ -555,11 +555,11 @@ func TestExecInUserns(t *testing.T) {
rootfs, err := newRootfs()
ok(t, err)
defer remove(rootfs)
config := newTemplateConfig(&tParam{
config := newTemplateConfig(t, &tParam{
rootfs: rootfs,
userns: true,
})
container, err := newContainer(config)
container, err := newContainer(t, config)
ok(t, err)
defer container.Destroy()

View File

@@ -25,7 +25,7 @@ func TestSeccompDenyGetcwdWithErrno(t *testing.T) {
errnoRet := uint(syscall.ESRCH)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Seccomp = &configs.Seccomp{
DefaultAction: configs.Allow,
Syscalls: []*configs.Syscall{
@@ -37,7 +37,7 @@ func TestSeccompDenyGetcwdWithErrno(t *testing.T) {
},
}
container, err := newContainer(config)
container, err := newContainer(t, config)
if err != nil {
t.Fatal(err)
}
@@ -95,7 +95,7 @@ func TestSeccompDenyGetcwd(t *testing.T) {
}
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Seccomp = &configs.Seccomp{
DefaultAction: configs.Allow,
Syscalls: []*configs.Syscall{
@@ -106,7 +106,7 @@ func TestSeccompDenyGetcwd(t *testing.T) {
},
}
container, err := newContainer(config)
container, err := newContainer(t, config)
if err != nil {
t.Fatal(err)
}
@@ -164,7 +164,7 @@ func TestSeccompPermitWriteConditional(t *testing.T) {
}
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Seccomp = &configs.Seccomp{
DefaultAction: configs.Allow,
Syscalls: []*configs.Syscall{
@@ -182,7 +182,7 @@ func TestSeccompPermitWriteConditional(t *testing.T) {
},
}
container, err := newContainer(config)
container, err := newContainer(t, config)
if err != nil {
t.Fatal(err)
}
@@ -226,7 +226,7 @@ func TestSeccompDenyWriteConditional(t *testing.T) {
}
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Seccomp = &configs.Seccomp{
DefaultAction: configs.Allow,
Syscalls: []*configs.Syscall{
@@ -244,7 +244,7 @@ func TestSeccompDenyWriteConditional(t *testing.T) {
},
}
container, err := newContainer(config)
container, err := newContainer(t, config)
if err != nil {
t.Fatal(err)
}
@@ -304,7 +304,7 @@ func TestSeccompPermitWriteMultipleConditions(t *testing.T) {
}
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Seccomp = &configs.Seccomp{
DefaultAction: configs.Allow,
Syscalls: []*configs.Syscall{
@@ -327,7 +327,7 @@ func TestSeccompPermitWriteMultipleConditions(t *testing.T) {
},
}
buffers, exitCode, err := runContainer(config, "", "ls", "/")
buffers, exitCode, err := runContainer(t, config, "", "ls", "/")
if err != nil {
t.Fatalf("%s: %s", buffers, err)
}
@@ -359,7 +359,7 @@ func TestSeccompDenyWriteMultipleConditions(t *testing.T) {
}
defer remove(rootfs)
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Seccomp = &configs.Seccomp{
DefaultAction: configs.Allow,
Syscalls: []*configs.Syscall{
@@ -382,7 +382,7 @@ func TestSeccompDenyWriteMultipleConditions(t *testing.T) {
},
}
buffers, exitCode, err := runContainer(config, "", "ls", "/does_not_exist")
buffers, exitCode, err := runContainer(t, config, "", "ls", "/does_not_exist")
if err == nil {
t.Fatalf("Expecting error return, instead got 0")
}
@@ -409,7 +409,7 @@ func TestSeccompMultipleConditionSameArgDeniesStdout(t *testing.T) {
defer remove(rootfs)
// Prevent writing to both stdout and stderr
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Seccomp = &configs.Seccomp{
DefaultAction: configs.Allow,
Syscalls: []*configs.Syscall{
@@ -432,7 +432,7 @@ func TestSeccompMultipleConditionSameArgDeniesStdout(t *testing.T) {
},
}
buffers, exitCode, err := runContainer(config, "", "ls", "/")
buffers, exitCode, err := runContainer(t, config, "", "ls", "/")
if err != nil {
t.Fatalf("%s: %s", buffers, err)
}
@@ -457,7 +457,7 @@ func TestSeccompMultipleConditionSameArgDeniesStderr(t *testing.T) {
defer remove(rootfs)
// Prevent writing to both stdout and stderr
config := newTemplateConfig(&tParam{rootfs: rootfs})
config := newTemplateConfig(t, &tParam{rootfs: rootfs})
config.Seccomp = &configs.Seccomp{
DefaultAction: configs.Allow,
Syscalls: []*configs.Syscall{
@@ -480,7 +480,7 @@ func TestSeccompMultipleConditionSameArgDeniesStderr(t *testing.T) {
},
}
buffers, exitCode, err := runContainer(config, "", "ls", "/does_not_exist")
buffers, exitCode, err := runContainer(t, config, "", "ls", "/does_not_exist")
if err == nil {
t.Fatalf("Expecting error return, instead got 0")
}

View File

@@ -1,8 +1,9 @@
package integration
import (
"math/rand"
"strconv"
"testing"
"time"
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runc/libcontainer/devices"
@@ -29,7 +30,7 @@ type tParam struct {
//
// it uses a network strategy of just setting a loopback interface
// and the default setup for devices
func newTemplateConfig(p *tParam) *configs.Config {
func newTemplateConfig(t *testing.T, p *tParam) *configs.Config {
var allowedDevices []*devices.Rule
for _, device := range specconv.AllowedDevices {
allowedDevices = append(allowedDevices, &device.Rule)
@@ -213,9 +214,9 @@ 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)
id := strconv.FormatInt(-int64(time.Now().Nanosecond()), 36)
config.Cgroups.Name = t.Name() + id
// do not change Parent (see newContainer)
config.Cgroups.Parent = "system.slice"
config.Cgroups.ScopePrefix = "runc-test"
} else {

View File

@@ -2,8 +2,6 @@ package integration
import (
"bytes"
"crypto/md5"
"encoding/hex"
"fmt"
"io/ioutil"
"os"
@@ -11,6 +9,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"syscall"
"testing"
@@ -152,13 +151,8 @@ func copyBusybox(dest string) error {
return nil
}
func newContainer(config *configs.Config) (libcontainer.Container, error) {
h := md5.New()
h.Write([]byte(time.Now().String()))
return newContainerWithName(hex.EncodeToString(h.Sum(nil)), config)
}
func newContainerWithName(name string, config *configs.Config) (libcontainer.Container, error) {
func newContainer(t *testing.T, config *configs.Config) (libcontainer.Container, error) {
name := t.Name() + strconv.FormatInt(int64(time.Now().Nanosecond()), 35)
root, err := newTestRoot()
if err != nil {
return nil, err
@@ -181,8 +175,8 @@ func newContainerWithName(name string, config *configs.Config) (libcontainer.Con
//
// buffers are returned containing the STDOUT and STDERR output for the run
// along with the exit code and any go error
func runContainer(config *configs.Config, console string, args ...string) (buffers *stdBuffers, exitCode int, err error) {
container, err := newContainer(config)
func runContainer(t *testing.T, config *configs.Config, console string, args ...string) (buffers *stdBuffers, exitCode int, err error) {
container, err := newContainer(t, config)
if err != nil {
return nil, -1, err
}