Skip to content

Commit

Permalink
Merge branch 'master' into b-9227-scaling-policy-filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
cgbaker authored Nov 11, 2020
2 parents ece8cde + 057241d commit d25df37
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ __BACKWARDS INCOMPATIBILITIES:__

BUG FIXES:

* agent (Enterprise): Fixed a bug where audit logging caused websocket and streaming http endpoints to fail [[GH-9319](https://github.com/hashicorp/nomad/issues/9319)]
* core: Fixed a bug where ACL handling prevented cross-namespace allocation listing [[GH-9278](https://github.com/hashicorp/nomad/issues/9278)]
* core: Fixed a bug where scaling policy filtering would ignore type query if job query was present [[GH-9312](https://github.com/hashicorp/nomad/issues/9312)]
* core: Fixed a bug where a request to scale a job would fail if the job was not in the default namespace. [[GH-9296](https://github.com/hashicorp/nomad/pull/9296)]
Expand Down
7 changes: 7 additions & 0 deletions command/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,14 @@ func (j *JobGetter) ApiJobWithArgs(jpath string, vars []string, varfiles []strin
ArgVars: vars,
AllowFS: true,
})

if err != nil {
if _, merr := jobspec.Parse(&buf); merr == nil {
return nil, fmt.Errorf("Failed to parse using HCL 2. Use the HCL 1 parser with `nomad run -hcl1`, or address the following issues:\n%v", err)
}
}
}

if err != nil {
return nil, fmt.Errorf("Error parsing job file from %s:\n%v", jpath, err)
}
Expand Down
48 changes: 48 additions & 0 deletions command/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,54 @@ func TestJobGetter_LocalFile(t *testing.T) {
}
}

// TestJobGetter_LocalFile_InvalidHCL2 asserts that a custom message is emited
// if the file is a valid HCL1 but not HCL2
func TestJobGetter_LocalFile_InvalidHCL2(t *testing.T) {
t.Parallel()

cases := []struct {
name string
hcl string
expectHCL1Message bool
}{
{
"invalid HCL",
"nothing",
false,
},
{
"invalid HCL2",
`job "example" {
meta = { "a" = "b" }
}`,
true,
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
fh, err := ioutil.TempFile("", "nomad")
require.NoError(t, err)
defer os.Remove(fh.Name())
defer fh.Close()

_, err = fh.WriteString(c.hcl)
require.NoError(t, err)

j := &JobGetter{}
_, err = j.ApiJob(fh.Name())
require.Error(t, err)

exptMessage := "Failed to parse using HCL 2. Use the HCL 1"
if c.expectHCL1Message {
require.Contains(t, err.Error(), exptMessage)
} else {
require.NotContains(t, err.Error(), exptMessage)
}
})
}
}

// Test StructJob with jobfile from HTTP Server
func TestJobGetter_HTTPServer(t *testing.T) {
t.Parallel()
Expand Down
4 changes: 4 additions & 0 deletions e2e/terraform/config/full-cluster/nomad/base.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ consul {
address = "127.0.0.1:8500"
}

audit {
enabled = true
}

telemetry {
collection_interval = "1s"
disable_hostname = true
Expand Down

0 comments on commit d25df37

Please sign in to comment.