Skip to content

Commit

Permalink
Tests for mounting cgroups
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
  • Loading branch information
LK4D4 committed Jul 15, 2015
1 parent 40b9b89 commit f6eb19c
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,3 +819,72 @@ func TestSeccompNoChown(t *testing.T) {
t.Fatalf("running chown should result in an EPERM but got %q", s)
}
}

func TestMountCgroupRO(t *testing.T) {
if testing.Short() {
return
}
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 | syscall.MS_RDONLY,
})

buffers, exitCode, err := runContainer(config, "", "mount")
if err != nil {
t.Fatalf("%s: %s", buffers, err)
}
if exitCode != 0 {
t.Fatalf("exit code not 0. code %d stderr %q", exitCode, buffers.Stderr)
}
mountInfo := buffers.Stdout.String()
lines := strings.Split(mountInfo, "\n")
for _, l := range lines {
if !strings.HasPrefix(l, "cgroup") {
continue
}
if !strings.Contains(l, "ro,nosuid,nodev,noexec") {
t.Fatalf("Mode expected to contain 'ro,nosuid,nodev,noexec': %s", l)
}
}
}

func TestMountCgroupRW(t *testing.T) {
t.Skip("This test is screwed because of dind")
if testing.Short() {
return
}
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,
})

buffers, exitCode, err := runContainer(config, "", "mount")
if err != nil {
t.Fatalf("%s: %s", buffers, err)
}
if exitCode != 0 {
t.Fatalf("exit code not 0. code %d stderr %q", exitCode, buffers.Stderr)
}
mountInfo := buffers.Stdout.String()
lines := strings.Split(mountInfo, "\n")
for _, l := range lines {
if !strings.HasPrefix(l, "cgroup") {
continue
}
if !strings.Contains(l, "rw,nosuid,nodev,noexec") {
t.Fatalf("Mode expected to contain 'rw,nosuid,nodev,noexec': %s", l)
}
}
}

0 comments on commit f6eb19c

Please sign in to comment.