Skip to content

Commit

Permalink
Merge pull request #569 from mlaventure/fix-cgroupspath-as-cgroupsparent
Browse files Browse the repository at this point in the history
Fix CgroupsPath interpretation
  • Loading branch information
LK4D4 committed Feb 17, 2016
2 parents 90472ae + 3ceff76 commit 382880b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,11 @@ func createCgroupConfig(name string, spec *specs.LinuxSpec) (*configs.Cgroup, er
if err != nil {
return nil, err
}
myCgroupPath = filepath.Join(myCgroupPath, name)
}

c := &configs.Cgroup{
Path: filepath.Join(myCgroupPath, name),
Path: myCgroupPath,
Resources: &configs.Resources{},
}
c.Resources.AllowedDevices = allowedDevices
Expand Down
39 changes: 39 additions & 0 deletions spec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// build +linux

package main

import (
"strings"
"testing"

"github.com/opencontainers/specs"
)

func TestLinuxCgroupsPathSpecified(t *testing.T) {
cgroupsPath := "/user/cgroups/path/id"

spec := &specs.LinuxSpec{}
spec.Linux.CgroupsPath = &cgroupsPath

cgroup, err := createCgroupConfig("ContainerID", spec)
if err != nil {
t.Errorf("Couldn't create Cgroup config: %v", err)
}

if cgroup.Path != cgroupsPath {
t.Errorf("Wrong cgroupsPath, expected '%s' got '%s'", cgroupsPath, cgroup.Path)
}
}

func TestLinuxCgroupsPathNotSpecified(t *testing.T) {
spec := &specs.LinuxSpec{}

cgroup, err := createCgroupConfig("ContainerID", spec)
if err != nil {
t.Errorf("Couldn't create Cgroup config: %v", err)
}

if !strings.HasSuffix(cgroup.Path, "/ContainerID") {
t.Errorf("Wrong cgroupsPath, expected it to have suffix '%s' got '%s'", "/ContainerID", cgroup.Path)
}
}

0 comments on commit 382880b

Please sign in to comment.