Skip to content

Commit 0fe2ea9

Browse files
committed
add checksums to tests, formatting after rebase
1 parent e3376d1 commit 0fe2ea9

File tree

6 files changed

+42
-37
lines changed

6 files changed

+42
-37
lines changed

client/driver/exec_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,12 @@ func TestExecDriver_Start_Wait(t *testing.T) {
123123
func TestExecDriver_Start_Artifact_basic(t *testing.T) {
124124
ctestutils.ExecCompatible(t)
125125
file := "hi_linux_amd64"
126+
checksum := "sha256:6f99b4c5184726e601ecb062500aeb9537862434dfe1898dbe5c68d9f50c179c"
126127

127128
task := &structs.Task{
128129
Name: "sleep",
129130
Config: map[string]string{
130-
"artifact_source": fmt.Sprintf("https://dl.dropboxusercontent.com/u/47675/jar_thing/%s", file),
131+
"artifact_source": fmt.Sprintf("https://dl.dropboxusercontent.com/u/47675/jar_thing/%s?checksum=%s", file, checksum),
131132
"command": filepath.Join("$NOMAD_TASK_DIR", file),
132133
},
133134
Resources: basicResources,

client/driver/java_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ func TestJavaDriver_Start_Wait(t *testing.T) {
9797
task := &structs.Task{
9898
Name: "demo-app",
9999
Config: map[string]string{
100-
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar",
101-
"jvm_options": "-Xmx2048m -Xms256m",
100+
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar",
101+
"jvm_options": "-Xmx2048m -Xms256m",
102+
"checksum": "sha256:58d6e8130308d32e197c5108edd4f56ddf1417408f743097c2e662df0f0b17c8",
102103
},
103104
Resources: basicResources,
104105
}
@@ -143,7 +144,7 @@ func TestJavaDriver_Start_Kill_Wait(t *testing.T) {
143144
task := &structs.Task{
144145
Name: "demo-app",
145146
Config: map[string]string{
146-
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar",
147+
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/demoapp.jar",
147148
},
148149
Resources: basicResources,
149150
}

client/driver/qemu.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
"github.com/hashicorp/nomad/client/allocdir"
1818
"github.com/hashicorp/nomad/client/config"
19-
"github.com/hashicorp/nomad/client/getter"
19+
"github.com/hashicorp/nomad/client/getter"
2020
"github.com/hashicorp/nomad/nomad/structs"
2121
)
2222

@@ -79,7 +79,7 @@ func (d *QemuDriver) Fingerprint(cfg *config.Config, node *structs.Node) (bool,
7979
// image and save it to the Drivers Allocation Dir
8080
func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, error) {
8181
// Get the image source
82-
source, ok := task.Config["artifact_source"]
82+
source, ok := task.Config["artifact_source"]
8383
if !ok || source == "" {
8484
return nil, fmt.Errorf("Missing source image Qemu driver")
8585
}
@@ -96,18 +96,18 @@ func (d *QemuDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle,
9696
return nil, fmt.Errorf("Could not find task directory for task: %v", d.DriverContext.taskName)
9797
}
9898

99-
// Proceed to download an artifact to be executed.
100-
vmPath, err := getter.GetArtifact(
101-
filepath.Join(taskDir, allocdir.TaskLocal),
102-
task.Config["artifact_source"],
103-
task.Config["checksum"],
104-
d.logger,
105-
)
106-
if err != nil {
107-
return nil, err
108-
}
109-
110-
vmID := filepath.Base(vmPath)
99+
// Proceed to download an artifact to be executed.
100+
vmPath, err := getter.GetArtifact(
101+
filepath.Join(taskDir, allocdir.TaskLocal),
102+
task.Config["artifact_source"],
103+
task.Config["checksum"],
104+
d.logger,
105+
)
106+
if err != nil {
107+
return nil, err
108+
}
109+
110+
vmID := filepath.Base(vmPath)
111111

112112
// Parse configuration arguments
113113
// Create the base arguments

client/driver/qemu_test.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ func TestQemuDriver_Start(t *testing.T) {
5454
task := &structs.Task{
5555
Name: "linux",
5656
Config: map[string]string{
57-
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img",
58-
"checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544",
59-
"accelerator": "tcg",
60-
"guest_ports": "22,8080",
57+
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img",
58+
"checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544",
59+
"accelerator": "tcg",
60+
"guest_ports": "22,8080",
6161
},
6262
Resources: &structs.Resources{
6363
MemoryMB: 512,
@@ -103,11 +103,11 @@ func TestQemuDriver_RequiresMemory(t *testing.T) {
103103
task := &structs.Task{
104104
Name: "linux",
105105
Config: map[string]string{
106-
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img",
107-
"accelerator": "tcg",
108-
"host_port": "8080",
109-
"guest_port": "8081",
110-
"checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544",
106+
"artifact_source": "https://dl.dropboxusercontent.com/u/47675/jar_thing/linux-0.2.img",
107+
"accelerator": "tcg",
108+
"host_port": "8080",
109+
"guest_port": "8081",
110+
"checksum": "sha256:a5e836985934c3392cbbd9b26db55a7d35a8d7ae1deb7ca559dd9c0159572544",
111111
// ssh u/p would be here
112112
},
113113
}

client/driver/raw_exec.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/hashicorp/nomad/client/allocdir"
1414
"github.com/hashicorp/nomad/client/config"
1515
"github.com/hashicorp/nomad/client/driver/args"
16-
"github.com/hashicorp/nomad/client/getter"
16+
"github.com/hashicorp/nomad/client/getter"
1717
"github.com/hashicorp/nomad/nomad/structs"
1818
)
1919

@@ -80,14 +80,14 @@ func (d *RawExecDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandl
8080
source, ok := task.Config["artifact_source"]
8181
if ok && source != "" {
8282
// Proceed to download an artifact to be executed.
83-
_, err := getter.GetArtifact(
84-
filepath.Join(taskDir, allocdir.TaskLocal),
85-
task.Config["artifact_source"],
86-
task.Config["checksum"],
87-
d.logger,
88-
)
89-
if err != nil {
90-
return nil, err
83+
_, err := getter.GetArtifact(
84+
filepath.Join(taskDir, allocdir.TaskLocal),
85+
task.Config["artifact_source"],
86+
task.Config["checksum"],
87+
d.logger,
88+
)
89+
if err != nil {
90+
return nil, err
9191
}
9292
}
9393

client/driver/raw_exec_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,22 @@ func TestRawExecDriver_StartOpen_Wait(t *testing.T) {
9494
}
9595

9696
func TestRawExecDriver_Start_Artifact_basic(t *testing.T) {
97-
var file string
97+
var file, checksum string
9898
switch runtime.GOOS {
9999
case "darwin":
100100
file = "hi_darwin_amd64"
101+
checksum = "md5:d7f2fdb13b36dcb7407721d78926b335"
101102
default:
102103
file = "hi_linux_amd64"
104+
checksum = "md5:a9b14903a8942748e4f8474e11f795d3"
103105
}
104106

105107
task := &structs.Task{
106108
Name: "sleep",
107109
Config: map[string]string{
108110
"artifact_source": fmt.Sprintf("https://dl.dropboxusercontent.com/u/47675/jar_thing/%s", file),
109111
"command": filepath.Join("$NOMAD_TASK_DIR", file),
112+
"checksum": checksum,
110113
},
111114
}
112115
driverCtx := testDriverContext(task.Name)

0 commit comments

Comments
 (0)