Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: ensure exec tests pass valid task resources #4992

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
tests: ensure exec tests pass valid task resources
Prior to 97f33bb, executor cgroup validation errors were
silently ignored.  Enforcing them reveals test cases that missed them.

This doesn't change customer facing contract, as resource struct is
is either configured or we default to 100 (much higher than 2).
  • Loading branch information
Mahmood Ali committed Dec 12, 2018
commit 8d4bef796739577c8a321ba679a01355d65d28e4
58 changes: 39 additions & 19 deletions drivers/exec/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
"testing"
"time"

dtestutil "github.com/hashicorp/nomad/plugins/drivers/testutils"

"github.com/hashicorp/hcl2/hcl"
ctestutils "github.com/hashicorp/nomad/client/testutil"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/helper/testtask"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/plugins/drivers"
dtestutil "github.com/hashicorp/nomad/plugins/drivers/testutils"
"github.com/hashicorp/nomad/plugins/shared"
"github.com/hashicorp/nomad/plugins/shared/hclspec"
"github.com/hashicorp/nomad/testutil"
Expand All @@ -34,6 +34,17 @@ func TestMain(m *testing.M) {
}
}

var testResources = &drivers.Resources{
NomadResources: &structs.Resources{
MemoryMB: 128,
CPU: 100,
},
LinuxResources: &drivers.LinuxResources{
MemoryLimitBytes: 134217728,
CPUShares: 100,
},
}

func TestExecDriver_Fingerprint_NonLinux(t *testing.T) {
if !testutil.IsTravis() {
t.Parallel()
Expand Down Expand Up @@ -84,8 +95,9 @@ func TestExecDriver_StartWait(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -116,8 +128,9 @@ func TestExecDriver_StartWaitStop(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -175,8 +188,9 @@ func TestExecDriver_StartWaitStopKill(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -235,8 +249,9 @@ func TestExecDriver_StartWaitRecover(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -304,8 +319,9 @@ func TestExecDriver_Stats(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
}

taskConfig := map[string]interface{}{
Expand Down Expand Up @@ -337,8 +353,9 @@ func TestExecDriver_Start_Wait_AllocDir(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "sleep",
ID: uuid.Generate(),
Name: "sleep",
Resources: testResources,
}
cleanup := harness.MkAllocDir(task, false)
defer cleanup()
Expand Down Expand Up @@ -385,9 +402,10 @@ func TestExecDriver_User(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "sleep",
User: "alice",
ID: uuid.Generate(),
Name: "sleep",
User: "alice",
Resources: testResources,
}
cleanup := harness.MkAllocDir(task, false)
defer cleanup()
Expand Down Expand Up @@ -418,8 +436,9 @@ func TestExecDriver_HandlerExec(t *testing.T) {
d := NewExecDriver(testlog.HCLogger(t))
harness := dtestutil.NewDriverHarness(t, d)
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "sleep",
ID: uuid.Generate(),
Name: "sleep",
Resources: testResources,
}
cleanup := harness.MkAllocDir(task, false)
defer cleanup()
Expand Down Expand Up @@ -507,6 +526,7 @@ func TestExecDriver_DevicesAndMounts(t *testing.T) {
task := &drivers.TaskConfig{
ID: uuid.Generate(),
Name: "test",
Resources: testResources,
StdoutPath: filepath.Join(tmpDir, "task-stdout"),
StderrPath: filepath.Join(tmpDir, "task-stderr"),
Devices: []*drivers.DeviceConfig{
Expand Down