executor: fix tests

This commit is contained in:
Nick Ethier 2018-12-06 21:39:53 -05:00
parent 913efed9f5
commit 19a695308f
No known key found for this signature in database
GPG Key ID: 07C1A3ECED90D24A
5 changed files with 17 additions and 42 deletions

View File

@ -303,7 +303,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru
Env: cfg.EnvList(), Env: cfg.EnvList(),
User: cfg.User, User: cfg.User,
ResourceLimits: true, ResourceLimits: true,
Resources: toExecResources(cfg.Resources), Resources: cfg.Resources,
TaskDir: cfg.TaskDir().Dir, TaskDir: cfg.TaskDir().Dir,
StdoutPath: cfg.StdoutPath, StdoutPath: cfg.StdoutPath,
StderrPath: cfg.StderrPath, StderrPath: cfg.StderrPath,
@ -344,19 +344,6 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru
return handle, nil, nil 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) { func (d *Driver) WaitTask(ctx context.Context, taskID string) (<-chan *drivers.ExitResult, error) {
handle, ok := d.tasks.Get(taskID) handle, ok := d.tasks.Get(taskID)
if !ok { if !ok {

View File

@ -334,11 +334,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru
Env: cfg.EnvList(), Env: cfg.EnvList(),
User: cfg.User, User: cfg.User,
ResourceLimits: true, ResourceLimits: true,
Resources: &executor.Resources{ Resources: cfg.Resources,
CPU: cfg.Resources.NomadResources.CPU,
MemoryMB: cfg.Resources.NomadResources.MemoryMB,
DiskMB: cfg.Resources.NomadResources.DiskMB,
},
TaskDir: cfg.TaskDir().Dir, TaskDir: cfg.TaskDir().Dir,
StdoutPath: cfg.StdoutPath, StdoutPath: cfg.StdoutPath,
StderrPath: cfg.StderrPath, StderrPath: cfg.StderrPath,

View File

@ -645,11 +645,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *cstru
Cmd: absPath, Cmd: absPath,
Args: runArgs, Args: runArgs,
ResourceLimits: true, ResourceLimits: true,
Resources: &executor.Resources{ Resources: cfg.Resources,
CPU: int(cfg.Resources.LinuxResources.CPUShares),
MemoryMB: int(drivers.BytesToMB(cfg.Resources.LinuxResources.MemoryLimitBytes)),
DiskMB: cfg.Resources.NomadResources.DiskMB,
},
Env: cfg.EnvList(), Env: cfg.EnvList(),
TaskDir: cfg.TaskDir().Dir, TaskDir: cfg.TaskDir().Dir,
StdoutPath: cfg.StdoutPath, StdoutPath: cfg.StdoutPath,

View File

@ -18,6 +18,7 @@ import (
"github.com/hashicorp/nomad/client/testutil" "github.com/hashicorp/nomad/client/testutil"
"github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/mock" "github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/plugins/drivers"
tu "github.com/hashicorp/nomad/testutil" tu "github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -65,11 +66,8 @@ func testExecutorCommandWithChroot(t *testing.T) (*ExecCommand, *allocdir.AllocD
cmd := &ExecCommand{ cmd := &ExecCommand{
Env: taskEnv.List(), Env: taskEnv.List(),
TaskDir: td.Dir, TaskDir: td.Dir,
Resources: &Resources{ Resources: &drivers.Resources{
CPU: task.Resources.CPU, NomadResources: task.Resources,
MemoryMB: task.Resources.MemoryMB,
IOPS: task.Resources.IOPS,
DiskMB: task.Resources.DiskMB,
}, },
} }
configureTLogging(cmd) configureTLogging(cmd)
@ -109,7 +107,7 @@ func TestExecutor_IsolationAndConstraints(t *testing.T) {
data, err := ioutil.ReadFile(memLimits) data, err := ioutil.ReadFile(memLimits)
require.NoError(err) 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)) actualMemLim := strings.TrimSpace(string(data))
require.Equal(actualMemLim, expectedMemLim) require.Equal(actualMemLim, expectedMemLim)
require.NoError(executor.Shutdown("", 0)) require.NoError(executor.Shutdown("", 0))

View File

@ -12,6 +12,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/hashicorp/nomad/plugins/drivers"
tu "github.com/hashicorp/nomad/testutil" tu "github.com/hashicorp/nomad/testutil"
hclog "github.com/hashicorp/go-hclog" hclog "github.com/hashicorp/go-hclog"
@ -52,11 +53,8 @@ func testExecutorCommand(t *testing.T) (*ExecCommand, *allocdir.AllocDir) {
cmd := &ExecCommand{ cmd := &ExecCommand{
Env: taskEnv.List(), Env: taskEnv.List(),
TaskDir: td.Dir, TaskDir: td.Dir,
Resources: &Resources{ Resources: &drivers.Resources{
CPU: task.Resources.CPU, NomadResources: task.Resources,
MemoryMB: task.Resources.MemoryMB,
IOPS: task.Resources.IOPS,
DiskMB: task.Resources.DiskMB,
}, },
} }
configureTLogging(cmd) configureTLogging(cmd)