Skip to content

Commit

Permalink
e2e: add test for verifying cgroups do not interfere with access to d…
Browse files Browse the repository at this point in the history
…evices

This validates the fix in #17535
  • Loading branch information
shoenig committed Jun 15, 2023
1 parent 57f31eb commit 2155cf4
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
54 changes: 54 additions & 0 deletions e2e/isolation/devices_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package isolation

import (
"testing"

"github.com/hashicorp/nomad/e2e/e2eutil"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/shoenig/test/must"
)

func TestCgroupDevices(t *testing.T) {
nomad := e2eutil.NomadClient(t)

e2eutil.WaitForLeader(t, nomad)
e2eutil.WaitForNodesReady(t, nomad, 1)

t.Run("testDevicesUsable", testDevicesUsable)
}

func testDevicesUsable(t *testing.T) {
nomad := e2eutil.NomadClient(t)

jobID := "cgroup-devices-" + uuid.Short()
jobIDs := []string{jobID}
t.Cleanup(e2eutil.CleanupJobsAndGC(t, &jobIDs))

// start job
allocs := e2eutil.RegisterAndWaitForAllocs(t, nomad, "./input/cgroup_devices.hcl", jobID, "")
must.Len(t, 2, allocs)

// pick one to stop and one to verify
allocA := allocs[0].ID
allocB := allocs[1].ID

// verify devices are working
checkDev(t, allocA)
checkDev(t, allocB)

// stop the chosen alloc
_, err := e2eutil.Command("nomad", "alloc", "stop", "-detach", allocA)
must.NoError(t, err)
e2eutil.WaitForAllocStopped(t, nomad, allocA)

// verify device of remaining alloc
checkDev(t, allocB)
}

func checkDev(t *testing.T, allocID string) {
_, err := e2eutil.Command("nomad", "alloc", "exec", allocID, "dd", "if=/dev/zero", "of=/dev/null", "count=1")
must.NoError(t, err)
}
41 changes: 41 additions & 0 deletions e2e/isolation/input/cgroup_devices.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

job "cgroup_devices" {
type = "service"

constraint {
attribute = "${attr.kernel.name}"
value = "linux"
}

group "group1" {

task "task1" {
driver = "raw_exec"
config {
command = "/bin/sleep"
args = ["infinity"]
}
resources {
cpu = 50
memory = 50
}
}
}

group "group2" {

task "task2" {
driver = "raw_exec"
config {
command = "/bin/sleep"
args = ["infinity"]
}
resources {
cpu = 50
memory = 50
}
}
}
}

0 comments on commit 2155cf4

Please sign in to comment.