From a70820d7ca8111bf7e9e4e5271b13f19d97a0de4 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 15 Mar 2016 20:21:52 -0700 Subject: [PATCH] Respond to comments and fix test --- api/tasks.go | 1 + client/driver/java.go | 6 +++--- client/driver/qemu.go | 3 +-- client/driver/rkt.go | 6 +++--- jobspec/parse_test.go | 5 +++++ jobspec/test-fixtures/bad-artifact.hcl | 13 +++++++++++++ nomad/structs/structs.go | 2 +- nomad/structs/structs_test.go | 5 +++++ scripts/test.sh | 2 +- 9 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 jobspec/test-fixtures/bad-artifact.hcl diff --git a/api/tasks.go b/api/tasks.go index 5f9b24cb6..d09339f34 100644 --- a/api/tasks.go +++ b/api/tasks.go @@ -95,6 +95,7 @@ type Task struct { Artifacts []*TaskArtifact } +// TaskArtifact is used to download artifacts before running a task. type TaskArtifact struct { GetterSource string GetterOptions map[string]string diff --git a/client/driver/java.go b/client/driver/java.go index 954810e73..c8849f951 100644 --- a/client/driver/java.go +++ b/client/driver/java.go @@ -149,7 +149,7 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, Cmd: exec.Command(bin, "executor", pluginLogFile), } - execImpl, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput, d.config) + execIntf, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput, d.config) if err != nil { return nil, err } @@ -169,7 +169,7 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, return nil, err } - ps, err := execImpl.LaunchCmd(&executor.ExecCommand{Cmd: absPath, Args: args}, executorCtx) + ps, err := execIntf.LaunchCmd(&executor.ExecCommand{Cmd: absPath, Args: args}, executorCtx) if err != nil { pluginClient.Kill() return nil, fmt.Errorf("error starting process via the plugin: %v", err) @@ -180,7 +180,7 @@ func (d *JavaDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, maxKill := d.DriverContext.config.MaxKillTimeout h := &javaHandle{ pluginClient: pluginClient, - executor: execImpl, + executor: execIntf, userPid: ps.Pid, isolationConfig: ps.IsolationConfig, taskDir: taskDir, diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 255f85375..1c8d89cf5 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -103,8 +103,7 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, vmID := filepath.Base(vmPath) // Get the tasks local directory. - taskName := d.DriverContext.taskName - taskDir, ok := ctx.AllocDir.TaskDirs[taskName] + taskDir, ok := ctx.AllocDir.TaskDirs[d.DriverContext.taskName] if !ok { return nil, fmt.Errorf("Could not find task directory for task: %v", d.DriverContext.taskName) } diff --git a/client/driver/rkt.go b/client/driver/rkt.go index 325328976..3dea50b04 100644 --- a/client/driver/rkt.go +++ b/client/driver/rkt.go @@ -228,7 +228,7 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, e Cmd: exec.Command(bin, "executor", pluginLogFile), } - execImpl, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput, d.config) + execIntf, pluginClient, err := createExecutor(pluginConfig, d.config.LogOutput, d.config) if err != nil { return nil, err } @@ -246,7 +246,7 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, e return nil, err } - ps, err := execImpl.LaunchCmd(&executor.ExecCommand{Cmd: absPath, Args: cmdArgs}, executorCtx) + ps, err := execIntf.LaunchCmd(&executor.ExecCommand{Cmd: absPath, Args: cmdArgs}, executorCtx) if err != nil { pluginClient.Kill() return nil, fmt.Errorf("error starting process via the plugin: %v", err) @@ -256,7 +256,7 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, e maxKill := d.DriverContext.config.MaxKillTimeout h := &rktHandle{ pluginClient: pluginClient, - executor: execImpl, + executor: execIntf, executorPid: ps.Pid, allocDir: ctx.AllocDir, logger: d.logger, diff --git a/jobspec/parse_test.go b/jobspec/parse_test.go index 82ae7d71d..28cc6afe8 100644 --- a/jobspec/parse_test.go +++ b/jobspec/parse_test.go @@ -315,6 +315,11 @@ func TestParse(t *testing.T) { }, false, }, + { + "bad-artifact.hcl", + nil, + true, + }, } for _, tc := range cases { diff --git a/jobspec/test-fixtures/bad-artifact.hcl b/jobspec/test-fixtures/bad-artifact.hcl new file mode 100644 index 000000000..3027d5e3d --- /dev/null +++ b/jobspec/test-fixtures/bad-artifact.hcl @@ -0,0 +1,13 @@ +job "binstore-storagelocker" { + group "binsl" { + count = 5 + task "binstore" { + driver = "docker" + + artifact { + bad = "bad" + } + resources {} + } + } +} diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 761f73d81..97ff2c32f 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1677,7 +1677,7 @@ func (t *Task) FindHostAndPortFor(portLabel string) (string, int) { return "", 0 } -// Validate is used to sanity check a task group +// Validate is used to sanity check a task func (t *Task) Validate() error { var mErr multierror.Error if t.Name == "" { diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 51daa0deb..7b1e0d2b3 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -131,6 +131,11 @@ func testJob() *Job { Env: map[string]string{ "FOO": "bar", }, + Artifacts: []*TaskArtifact{ + { + GetterSource: "http://foo.com", + }, + }, Services: []*Service{ { Name: "${TASK}-frontend", diff --git a/scripts/test.sh b/scripts/test.sh index ea23141d5..293216d54 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -10,4 +10,4 @@ go build -o $TEMPDIR/nomad || exit 1 # Run the tests echo "--> Running tests" -go list ./... | grep -v '/vendor/' | sudo -E PATH=$TEMPDIR:$PATH xargs -n1 go test -cover -timeout=180s +go list ./... | grep -v '/vendor/' | sudo -E PATH=$TEMPDIR:$PATH xargs -n1 go test -cover -timeout=300s