Skip to content

Commit 67643cf

Browse files
author
Julio Montes
committed
agent: Fix CPU tests for both initrd and rootfs image
Now cgroups are mounted at /sys/fs/cgroup, in the past when initrd was used cgroups were mounted at /proc/cgroups fixes kata-containers#282 Signed-off-by: Julio Montes <julio.montes@intel.com>
1 parent bc973da commit 67643cf

3 files changed

Lines changed: 9 additions & 13 deletions

File tree

agent.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const (
4545

4646
var (
4747
// cgroup fs is mounted at /sys/fs when systemd is the init process
48-
cgroupPath = "/sys/fs/cgroup"
49-
sysfsCpusetPath = cgroupPath + "/cpuset"
48+
cgroupPath = "/sys/fs/cgroup"
49+
cgroupCpusetPath = cgroupPath + "/cpuset"
5050
)
5151

5252
var initRootfsMounts = []initMount{
@@ -773,10 +773,6 @@ func initAgentAsInit() error {
773773
syscall.Syscall(syscall.SYS_IOCTL, os.Stdin.Fd(), syscall.TIOCSCTTY, 1)
774774
os.Setenv("PATH", "/bin:/sbin/:/usr/bin/:/usr/sbin/")
775775

776-
// when agent runs as init process, cgroup fs is mounted at /proc
777-
cgroupPath = "/proc/cgroup"
778-
sysfsCpusetPath = cgroupPath + "/cpuset"
779-
780776
return announce()
781777
}
782778

grpc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func onlineMemResources() error {
161161
// don't update a cgroup twice.
162162
func updateContainerCpuset(cgroupPath string, newCpuset string, cookies cookie) error {
163163
// Each cpuset cgroup MUST BE updated with the actual number of vCPUs.
164-
cpusetPath := sysfsCpusetPath
164+
cpusetPath := cgroupCpusetPath
165165
cgroupsPaths := strings.Split(cgroupPath, "/")
166166
for _, path := range cgroupsPaths {
167167
// Skip if empty.

grpc_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,13 +261,13 @@ func TestOnlineCPUMem(t *testing.T) {
261261
_, err = a.OnlineCPUMem(context.TODO(), req)
262262
assert.Error(err, "docker cgroup path does not exist")
263263

264-
sysfsCpusetPath, err = ioutil.TempDir("", "cgroup")
264+
cgroupCpusetPath, err = ioutil.TempDir("", "cgroup")
265265
assert.NoError(err)
266266
cfg := container.container.Config()
267-
cgroupPath := filepath.Join(sysfsCpusetPath, cfg.Cgroups.Path)
267+
cgroupPath := filepath.Join(cgroupCpusetPath, cfg.Cgroups.Path)
268268
err = os.MkdirAll(cgroupPath, 0777)
269269
assert.NoError(err)
270-
defer os.RemoveAll(sysfsCpusetPath)
270+
defer os.RemoveAll(cgroupCpusetPath)
271271

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

501-
sysfsCpusetPath, err = ioutil.TempDir("", "cgroup")
501+
cgroupCpusetPath, err = ioutil.TempDir("", "cgroup")
502502
assert.NoError(err)
503-
defer os.Remove(sysfsCpusetPath)
503+
defer os.Remove(cgroupCpusetPath)
504504

505505
cgroupPath := "kata"
506-
err = os.MkdirAll(filepath.Join(sysfsCpusetPath, cgroupPath), 0777)
506+
err = os.MkdirAll(filepath.Join(cgroupCpusetPath, cgroupPath), 0777)
507507
assert.NoError(err)
508508

509509
cookies := make(cookie)

0 commit comments

Comments
 (0)