Skip to content

Commit

Permalink
Merge pull request kata-containers#297 from devimc/fix/updateCPU
Browse files Browse the repository at this point in the history
agent: Fix CPU tests for both initrd and rootfs image
  • Loading branch information
bergwolf committed Jul 8, 2018
2 parents 277c8f0 + 67643cf commit 17b44df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
8 changes: 2 additions & 6 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const (

var (
// cgroup fs is mounted at /sys/fs when systemd is the init process
cgroupPath = "/sys/fs/cgroup"
sysfsCpusetPath = cgroupPath + "/cpuset"
cgroupPath = "/sys/fs/cgroup"
cgroupCpusetPath = cgroupPath + "/cpuset"
)

var initRootfsMounts = []initMount{
Expand Down Expand Up @@ -776,10 +776,6 @@ func initAgentAsInit() error {
syscall.Syscall(syscall.SYS_IOCTL, os.Stdin.Fd(), syscall.TIOCSCTTY, 1)
os.Setenv("PATH", "/bin:/sbin/:/usr/bin/:/usr/sbin/")

// when agent runs as init process, cgroup fs is mounted at /proc
cgroupPath = "/proc/cgroup"
sysfsCpusetPath = cgroupPath + "/cpuset"

return announce()
}

Expand Down
2 changes: 1 addition & 1 deletion grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func onlineMemResources() error {
// don't update a cgroup twice.
func updateContainerCpuset(cgroupPath string, newCpuset string, cookies cookie) error {
// Each cpuset cgroup MUST BE updated with the actual number of vCPUs.
cpusetPath := sysfsCpusetPath
cpusetPath := cgroupCpusetPath
cgroupsPaths := strings.Split(cgroupPath, "/")
for _, path := range cgroupsPaths {
// Skip if empty.
Expand Down
12 changes: 6 additions & 6 deletions grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ func TestOnlineCPUMem(t *testing.T) {
_, err = a.OnlineCPUMem(context.TODO(), req)
assert.Error(err, "docker cgroup path does not exist")

sysfsCpusetPath, err = ioutil.TempDir("", "cgroup")
cgroupCpusetPath, err = ioutil.TempDir("", "cgroup")
assert.NoError(err)
cfg := container.container.Config()
cgroupPath := filepath.Join(sysfsCpusetPath, cfg.Cgroups.Path)
cgroupPath := filepath.Join(cgroupCpusetPath, cfg.Cgroups.Path)
err = os.MkdirAll(cgroupPath, 0777)
assert.NoError(err)
defer os.RemoveAll(sysfsCpusetPath)
defer os.RemoveAll(cgroupCpusetPath)

err = ioutil.WriteFile(memory0Online, []byte("0"), 0755)
assert.NoError(err)
Expand Down Expand Up @@ -498,12 +498,12 @@ func TestUpdateContainerCpuset(t *testing.T) {
var err error
assert := assert.New(t)

sysfsCpusetPath, err = ioutil.TempDir("", "cgroup")
cgroupCpusetPath, err = ioutil.TempDir("", "cgroup")
assert.NoError(err)
defer os.Remove(sysfsCpusetPath)
defer os.Remove(cgroupCpusetPath)

cgroupPath := "kata"
err = os.MkdirAll(filepath.Join(sysfsCpusetPath, cgroupPath), 0777)
err = os.MkdirAll(filepath.Join(cgroupCpusetPath, cgroupPath), 0777)
assert.NoError(err)

cookies := make(cookie)
Expand Down

0 comments on commit 17b44df

Please sign in to comment.