From 19a695308f0e6e35f9078bc7e967dfa6aafe3a91 Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Thu, 6 Dec 2018 21:39:53 -0500 Subject: [PATCH] executor: fix tests --- drivers/exec/driver.go | 15 +-------------- drivers/java/driver.go | 12 ++++-------- drivers/rkt/driver.go | 14 +++++--------- drivers/shared/executor/executor_linux_test.go | 10 ++++------ drivers/shared/executor/executor_test.go | 8 +++----- 5 files changed, 17 insertions(+), 42 deletions(-) diff --git a/drivers/exec/driver.go b/drivers/exec/driver.go index da9174829..072d7f69f 100644 --- a/drivers/exec/driver.go +++ b/drivers/exec/driver.go @@ -303,7 +303,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru Env: cfg.EnvList(), User: cfg.User, ResourceLimits: true, - Resources: toExecResources(cfg.Resources), + Resources: cfg.Resources, TaskDir: cfg.TaskDir().Dir, StdoutPath: cfg.StdoutPath, StderrPath: cfg.StderrPath, @@ -344,19 +344,6 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru return handle, nil, nil } -func toExecResources(resources *drivers.Resources) *executor.Resources { - if resources == nil || resources.NomadResources == nil { - return nil - } - - return &executor.Resources{ - CPU: resources.NomadResources.CPU, - MemoryMB: resources.NomadResources.MemoryMB, - DiskMB: resources.NomadResources.DiskMB, - } - -} - func (d *Driver) WaitTask(ctx context.Context, taskID string) (<-chan *drivers.ExitResult, error) { handle, ok := d.tasks.Get(taskID) if !ok { diff --git a/drivers/java/driver.go b/drivers/java/driver.go index 18250bad5..793010c36 100644 --- a/drivers/java/driver.go +++ b/drivers/java/driver.go @@ -334,14 +334,10 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru Env: cfg.EnvList(), User: cfg.User, ResourceLimits: true, - Resources: &executor.Resources{ - CPU: cfg.Resources.NomadResources.CPU, - MemoryMB: cfg.Resources.NomadResources.MemoryMB, - DiskMB: cfg.Resources.NomadResources.DiskMB, - }, - TaskDir: cfg.TaskDir().Dir, - StdoutPath: cfg.StdoutPath, - StderrPath: cfg.StderrPath, + Resources: cfg.Resources, + TaskDir: cfg.TaskDir().Dir, + StdoutPath: cfg.StdoutPath, + StderrPath: cfg.StderrPath, } ps, err := exec.Launch(execCmd) diff --git a/drivers/rkt/driver.go b/drivers/rkt/driver.go index a022db9fb..9cb7cec03 100644 --- a/drivers/rkt/driver.go +++ b/drivers/rkt/driver.go @@ -645,15 +645,11 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru Cmd: absPath, Args: runArgs, ResourceLimits: true, - Resources: &executor.Resources{ - CPU: int(cfg.Resources.LinuxResources.CPUShares), - MemoryMB: int(drivers.BytesToMB(cfg.Resources.LinuxResources.MemoryLimitBytes)), - DiskMB: cfg.Resources.NomadResources.DiskMB, - }, - Env: cfg.EnvList(), - TaskDir: cfg.TaskDir().Dir, - StdoutPath: cfg.StdoutPath, - StderrPath: cfg.StderrPath, + Resources: cfg.Resources, + Env: cfg.EnvList(), + TaskDir: cfg.TaskDir().Dir, + StdoutPath: cfg.StdoutPath, + StderrPath: cfg.StderrPath, } ps, err := execImpl.Launch(execCmd) if err != nil { diff --git a/drivers/shared/executor/executor_linux_test.go b/drivers/shared/executor/executor_linux_test.go index e11e9d5df..6f29d72f8 100644 --- a/drivers/shared/executor/executor_linux_test.go +++ b/drivers/shared/executor/executor_linux_test.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/nomad/mock" + "github.com/hashicorp/nomad/plugins/drivers" tu "github.com/hashicorp/nomad/testutil" "github.com/stretchr/testify/require" ) @@ -65,11 +66,8 @@ func testExecutorCommandWithChroot(t *testing.T) (*ExecCommand, *allocdir.AllocD cmd := &ExecCommand{ Env: taskEnv.List(), TaskDir: td.Dir, - Resources: &Resources{ - CPU: task.Resources.CPU, - MemoryMB: task.Resources.MemoryMB, - IOPS: task.Resources.IOPS, - DiskMB: task.Resources.DiskMB, + Resources: &drivers.Resources{ + NomadResources: task.Resources, }, } configureTLogging(cmd) @@ -109,7 +107,7 @@ func TestExecutor_IsolationAndConstraints(t *testing.T) { data, err := ioutil.ReadFile(memLimits) require.NoError(err) - expectedMemLim := strconv.Itoa(execCmd.Resources.MemoryMB * 1024 * 1024) + expectedMemLim := strconv.Itoa(execCmd.Resources.NomadResources.MemoryMB * 1024 * 1024) actualMemLim := strings.TrimSpace(string(data)) require.Equal(actualMemLim, expectedMemLim) require.NoError(executor.Shutdown("", 0)) diff --git a/drivers/shared/executor/executor_test.go b/drivers/shared/executor/executor_test.go index 26067ebc8..a3b5d49d6 100644 --- a/drivers/shared/executor/executor_test.go +++ b/drivers/shared/executor/executor_test.go @@ -12,6 +12,7 @@ import ( "testing" "time" + "github.com/hashicorp/nomad/plugins/drivers" tu "github.com/hashicorp/nomad/testutil" hclog "github.com/hashicorp/go-hclog" @@ -52,11 +53,8 @@ func testExecutorCommand(t *testing.T) (*ExecCommand, *allocdir.AllocDir) { cmd := &ExecCommand{ Env: taskEnv.List(), TaskDir: td.Dir, - Resources: &Resources{ - CPU: task.Resources.CPU, - MemoryMB: task.Resources.MemoryMB, - IOPS: task.Resources.IOPS, - DiskMB: task.Resources.DiskMB, + Resources: &drivers.Resources{ + NomadResources: task.Resources, }, } configureTLogging(cmd)