-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |