From fb8066d8f318b31a3ada4668a45a548d81ba308b Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Thu, 5 Nov 2015 09:23:45 -0600 Subject: [PATCH] add checksums to tests, formatting after rebase --- client/driver/exec_test.go | 3 ++- client/driver/java_test.go | 7 ++++--- client/driver/qemu.go | 26 +++++++++++++------------- client/driver/qemu_test.go | 18 +++++++++--------- client/driver/raw_exec.go | 18 +++++++++--------- client/driver/raw_exec_test.go | 5 ++++- 6 files changed, 41 insertions(+), 36 deletions(-) diff --git a/client/driver/exec_test.go b/client/driver/exec_test.go index 1bb4adf36..bc8323889 100644 --- a/client/driver/exec_test.go +++ b/client/driver/exec_test.go @@ -123,11 +123,12 @@ func TestExecDriver_Start_Wait(t *testing.T) { func TestExecDriver_Start_Artifact_basic(t *testing.T) { ctestutils.ExecCompatible(t) file := "hi_linux_amd64" + checksum := "sha256:6f99b4c5184726e601ecb062500aeb9537862434dfe1898dbe5c68d9f50c179c" task := &structs.Task{ Name: "sleep", Config: map[string]string{ - "artifact_source": fmt.Sprintf("https://dl.dropboxusercontent.com/u/47675/jar_thing/%s", file), + "artifact_source": fmt.Sprintf("https://dl.dropboxusercontent.com/u/47675/jar_thing/%s?checksum=%s", file, checksum), "command": filepath.Join("$NOMAD_TASK_DIR", file), }, Resources: basicResources, diff --git a/client/driver/java_test.go b/client/driver/java_test.go index e525d4dce..206cc1c78 100644 --- a/client/driver/java_test.go +++ b/client/driver/java_test.go @@ -97,8 +97,9 @@ func TestJavaDriver_Start_Wait(t *testing.T) { task := &structs.Task{ Name: "demo-app", Config: map[string]string{ - "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar", - "jvm_options": "-Xmx2048m -Xms256m", + "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar", + "jvm_options": "-Xmx2048m -Xms256m", + "checksum": "sha256:58d6e8130308d32e197c5108edd4f56ddf1417408f743097c2e662df0f0b17c8", }, Resources: basicResources, } @@ -143,7 +144,7 @@ func TestJavaDriver_Start_Kill_Wait(t *testing.T) { task := &structs.Task{ Name: "demo-app", Config: map[string]string{ - "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar", + "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar", }, Resources: basicResources, } diff --git a/client/driver/qemu.go b/client/driver/qemu.go index 52b2e78e0..0eab4e659 100644 --- a/client/driver/qemu.go +++ b/client/driver/qemu.go @@ -16,7 +16,7 @@ import ( "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/config" - "github.com/hashicorp/nomad/client/getter" + "github.com/hashicorp/nomad/client/getter" "github.com/hashicorp/nomad/nomad/structs" ) @@ -79,7 +79,7 @@ func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool, // image and save it to the Drivers Allocation Dir func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, error) { // Get the image source - source, ok := task.Config["artifact_source"] + source, ok := task.Config["artifact_source"] if !ok || source == "" { return nil, fmt.Errorf("Missing source image Qemu driver") } @@ -96,18 +96,18 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, return nil, fmt.Errorf("Could not find task directory for task: %v", d.DriverContext.taskName) } - // Proceed to download an artifact to be executed. - vmPath, err := getter.GetArtifact( - filepath.Join(taskDir, allocdir.TaskLocal), - task.Config["artifact_source"], - task.Config["checksum"], - d.logger, - ) - if err != nil { - return nil, err - } + // Proceed to download an artifact to be executed. + vmPath, err := getter.GetArtifact( + filepath.Join(taskDir, allocdir.TaskLocal), + task.Config["artifact_source"], + task.Config["checksum"], + d.logger, + ) + if err != nil { + return nil, err + } - vmID := filepath.Base(vmPath) + vmID := filepath.Base(vmPath) // Parse configuration arguments // Create the base arguments diff --git a/client/driver/qemu_test.go b/client/driver/qemu_test.go index 7b6ca1bb7..dffdc7bf0 100644 --- a/client/driver/qemu_test.go +++ b/client/driver/qemu_test.go @@ -54,10 +54,10 @@ func TestQemuDriver_Start(t *testing.T) { task := &structs.Task{ Name: "linux", Config: map[string]string{ - "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img", - "checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544", - "accelerator": "tcg", - "guest_ports": "22,8080", + "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img", + "checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544", + "accelerator": "tcg", + "guest_ports": "22,8080", }, Resources: &structs.Resources{ MemoryMB: 512, @@ -103,11 +103,11 @@ func TestQemuDriver_RequiresMemory(t *testing.T) { task := &structs.Task{ Name: "linux", Config: map[string]string{ - "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img", - "accelerator": "tcg", - "host_port": "8080", - "guest_port": "8081", - "checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544", + "artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img", + "accelerator": "tcg", + "host_port": "8080", + "guest_port": "8081", + "checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544", // ssh u/p would be here }, } diff --git a/client/driver/raw_exec.go b/client/driver/raw_exec.go index 9a2716297..856f2b7fc 100644 --- a/client/driver/raw_exec.go +++ b/client/driver/raw_exec.go @@ -13,7 +13,7 @@ import ( "github.com/hashicorp/nomad/client/allocdir" "github.com/hashicorp/nomad/client/config" "github.com/hashicorp/nomad/client/driver/args" - "github.com/hashicorp/nomad/client/getter" + "github.com/hashicorp/nomad/client/getter" "github.com/hashicorp/nomad/nomad/structs" ) @@ -80,14 +80,14 @@ func (d *RawExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandl source, ok := task.Config["artifact_source"] if ok && source != "" { // Proceed to download an artifact to be executed. - _, err := getter.GetArtifact( - filepath.Join(taskDir, allocdir.TaskLocal), - task.Config["artifact_source"], - task.Config["checksum"], - d.logger, - ) - if err != nil { - return nil, err + _, err := getter.GetArtifact( + filepath.Join(taskDir, allocdir.TaskLocal), + task.Config["artifact_source"], + task.Config["checksum"], + d.logger, + ) + if err != nil { + return nil, err } } diff --git a/client/driver/raw_exec_test.go b/client/driver/raw_exec_test.go index 0a6133df9..1dda991c8 100644 --- a/client/driver/raw_exec_test.go +++ b/client/driver/raw_exec_test.go @@ -94,12 +94,14 @@ func TestRawExecDriver_StartOpen_Wait(t *testing.T) { } func TestRawExecDriver_Start_Artifact_basic(t *testing.T) { - var file string + var file, checksum string switch runtime.GOOS { case "darwin": file = "hi_darwin_amd64" + checksum = "md5:d7f2fdb13b36dcb7407721d78926b335" default: file = "hi_linux_amd64" + checksum = "md5:a9b14903a8942748e4f8474e11f795d3" } task := &structs.Task{ @@ -107,6 +109,7 @@ func TestRawExecDriver_Start_Artifact_basic(t *testing.T) { Config: map[string]string{ "artifact_source": fmt.Sprintf("https://dl.dropboxusercontent.com/u/47675/jar_thing/%s", file), "command": filepath.Join("$NOMAD_TASK_DIR", file), + "checksum": checksum, }, } driverCtx := testDriverContext(task.Name)