Skip to content

Commit

Permalink
e2e: account for new job stop CLI exit behaviour.
Browse files Browse the repository at this point in the history
PR #11550 changed the job stop exit behaviour when monitoring the
deployment. When stopping a job, the deployment becomes cancelled
and therefore the CLI now exits with status code 1 as it see this
as an error.

This change adds a new utility e2e function that accounts for this
behaviour.
  • Loading branch information
jrasell committed Feb 1, 2022
1 parent 22bd089 commit 4f8f36a
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion e2e/consul/check_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (tc *CheckRestartE2ETest) AfterEach(f *framework.F) {
}

for _, id := range tc.jobIds {
_, err := e2e.Command("nomad", "job", "stop", "-purge", id)
err := e2e.StopJob(id, "-purge")
f.Assert().NoError(err)
}
tc.jobIds = []string{}
Expand Down
2 changes: 1 addition & 1 deletion e2e/consultemplate/consultemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (tc *ConsulTemplateTest) AfterEach(f *framework.F) {
}

for _, id := range tc.jobIDs {
_, err := e2eutil.Command("nomad", "job", "stop", "-purge", id)
err := e2eutil.StopJob(id, "-purge")
f.Assert().NoError(err, "could not clean up job", id)
}
tc.jobIDs = []string{}
Expand Down
10 changes: 5 additions & 5 deletions e2e/csi/ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (tc *CSIControllerPluginEBSTest) AfterAll(f *framework.F) {

// Stop all jobs in test
for _, id := range tc.testJobIDs {
out, err := e2e.Command("nomad", "job", "stop", "-purge", id)
f.Assert().NoError(err, out)
err := e2e.StopJob(id, "-purge")
f.Assert().NoError(err)
}
tc.testJobIDs = []string{}

Expand All @@ -94,8 +94,8 @@ func (tc *CSIControllerPluginEBSTest) AfterAll(f *framework.F) {

// Deregister all plugin jobs in test
for _, id := range tc.pluginJobIDs {
out, err := e2e.Command("nomad", "job", "stop", "-purge", id)
f.Assert().NoError(err, out)
err := e2e.StopJob(id, "-purge")
f.Assert().NoError(err)
}
tc.pluginJobIDs = []string{}

Expand Down Expand Up @@ -130,7 +130,7 @@ func (tc *CSIControllerPluginEBSTest) TestVolumeClaim(f *framework.F) {
// Shutdown (and purge) the writer so we can run a reader.
// we could mount the EBS volume with multi-attach, but we
// want this test to exercise the unpublish workflow.
_, err = e2e.Command("nomad", "job", "stop", "-purge", writeJobID)
err = e2e.StopJob(writeJobID, "-purge")
f.NoError(err)

// wait for the volume unpublish workflow to complete
Expand Down
10 changes: 5 additions & 5 deletions e2e/csi/efs.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (tc *CSINodeOnlyPluginEFSTest) TestEFSVolumeClaim(f *framework.F) {
// Shutdown the writer so we can run a reader.
// although EFS should support multiple readers, the plugin
// does not.
_, err = e2e.Command("nomad", "job", "stop", writeJobID)
err = e2e.StopJob(writeJobID)
require.NoError(err)

// wait for the volume unpublish workflow to complete
Expand Down Expand Up @@ -123,8 +123,8 @@ func (tc *CSINodeOnlyPluginEFSTest) AfterEach(f *framework.F) {

// Stop all jobs in test
for _, id := range tc.testJobIDs {
out, err := e2e.Command("nomad", "job", "stop", "-purge", id)
f.Assert().NoError(err, out)
err := e2e.StopJob(id, "-purge")
f.Assert().NoError(err)
}
tc.testJobIDs = []string{}

Expand All @@ -142,8 +142,8 @@ func (tc *CSINodeOnlyPluginEFSTest) AfterEach(f *framework.F) {

// Deregister all plugin jobs in test
for _, id := range tc.pluginJobIDs {
out, err := e2e.Command("nomad", "job", "stop", "-purge", id)
f.Assert().NoError(err, out)
err := e2e.StopJob(id, "-purge")
f.Assert().NoError(err)
}
tc.pluginJobIDs = []string{}

Expand Down
25 changes: 25 additions & 0 deletions e2e/e2eutil/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,28 @@ func DispatchedJobs(jobID string) ([]map[string]string, error) {

return summary, nil
}

func StopJob(jobID string, args ...string) error {

// Build our argument list in the correct order, ensuring the jobID is last
// and the Nomad subcommand are first.
baseArgs := []string{"job", "stop"}
for i := range args {
baseArgs = append(baseArgs, args[i])
}
baseArgs = append(baseArgs, jobID)

// Execute the command. We do not care about the stdout, only stderr.
_, err := Command("nomad", baseArgs...)

if err != nil {
// When stopping a job and monitoring the resulting deployment, we
// expect that the monitor fails and exits with status code one because
// technically the deployment has failed. Overwrite the error to be
// nil.
if strings.Contains(err.Error(), "Description = Cancelled because job is stopped") {
err = nil
}
}
return err
}
6 changes: 3 additions & 3 deletions e2e/namespaces/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func (tc *NamespacesE2ETest) AfterEach(f *framework.F) {
ns := pair[0]
jobID := pair[1]
if ns != "" {
_, err := e2e.Command("nomad", "job", "stop", "-purge", "-namespace", ns, jobID)
err := e2e.StopJob(jobID, "-purge", "-namespace", ns)
f.Assert().NoError(err)
} else {
_, err := e2e.Command("nomad", "job", "stop", "-purge", jobID)
err := e2e.StopJob(jobID, "-purge")
f.Assert().NoError(err)
}
}
Expand Down Expand Up @@ -179,6 +179,6 @@ func (tc *NamespacesE2ETest) TestNamespacesFiltering(f *framework.F) {
f.Equal(fmt.Sprintf("No job(s) with prefix or id %q found\n", jobA), out)
f.Error(err, "exit status 1")

_, err = e2e.Command("nomad", "job", "stop", "-namespace", "NamespaceA", jobA)
err = e2e.StopJob(jobA, "-namespace", "NamespaceA")
f.NoError(err, "could not stop job in namespace")
}
2 changes: 1 addition & 1 deletion e2e/networking/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (tc *NetworkingE2ETest) AfterEach(f *framework.F) {
}

for _, jobID := range tc.jobIDs {
_, err := e2eutil.Command("nomad", "job", "stop", "-purge", jobID)
err := e2eutil.StopJob(jobID, "-purge")
f.NoError(err)
}
tc.jobIDs = []string{}
Expand Down
2 changes: 1 addition & 1 deletion e2e/rescheduling/rescheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (tc *RescheduleE2ETest) AfterEach(f *framework.F) {
}

for _, id := range tc.jobIds {
_, err := e2e.Command("nomad", "job", "stop", "-purge", id)
err := e2e.StopJob(id, "-purge")
f.Assert().NoError(err)
}
tc.jobIds = []string{}
Expand Down
4 changes: 2 additions & 2 deletions e2e/scaling/scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (tc *ScalingE2ETest) AfterEach(f *framework.F) {
}

for _, namespacedJob := range tc.namespacedJobIDs {
_, err := e2eutil.Command("nomad", "job", "stop", "-purge", "-namespace",
namespacedJob[0], namespacedJob[1])
err := e2eutil.StopJob(namespacedJob[1], "-purge", "-namespace",
namespacedJob[0])
f.NoError(err)
}
tc.namespacedJobIDs = [][2]string{}
Expand Down
4 changes: 2 additions & 2 deletions e2e/scalingpolicies/scalingpolicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (tc *ScalingPolicyE2ETest) AfterEach(f *framework.F) {
}

for _, namespacedJob := range tc.namespacedJobIDs {
_, err := e2eutil.Command("nomad", "job", "stop", "-purge", "-namespace",
namespacedJob[0], namespacedJob[1])
err := e2eutil.StopJob(namespacedJob[1], "-purge", "-namespace",
namespacedJob[0])
f.Assert().NoError(err)
}
tc.namespacedJobIDs = [][2]string{}
Expand Down
2 changes: 1 addition & 1 deletion e2e/volumes/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (tc *VolumesTest) AfterEach(f *framework.F) {
}

for _, id := range tc.jobIDs {
_, err := e2e.Command("nomad", "job", "stop", "-purge", id)
err := e2e.StopJob(id, "-purge")
f.Assert().NoError(err)
}
tc.jobIDs = []string{}
Expand Down

0 comments on commit 4f8f36a

Please sign in to comment.