diff --git a/e2e/consul/check_restart.go b/e2e/consul/check_restart.go index c7756fc1308..030b27a2134 100644 --- a/e2e/consul/check_restart.go +++ b/e2e/consul/check_restart.go @@ -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{} diff --git a/e2e/consultemplate/consultemplate.go b/e2e/consultemplate/consultemplate.go index 034e2b2c28b..a700268fccf 100644 --- a/e2e/consultemplate/consultemplate.go +++ b/e2e/consultemplate/consultemplate.go @@ -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{} diff --git a/e2e/csi/ebs.go b/e2e/csi/ebs.go index f2ae4a152d6..6935fd8b54e 100644 --- a/e2e/csi/ebs.go +++ b/e2e/csi/ebs.go @@ -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{} @@ -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{} @@ -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 diff --git a/e2e/csi/efs.go b/e2e/csi/efs.go index 8a82cee70c1..bbc41d9528a 100644 --- a/e2e/csi/efs.go +++ b/e2e/csi/efs.go @@ -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 @@ -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{} @@ -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{} diff --git a/e2e/e2eutil/job.go b/e2e/e2eutil/job.go index 518e725799c..cb67ca6d55a 100644 --- a/e2e/e2eutil/job.go +++ b/e2e/e2eutil/job.go @@ -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 +} diff --git a/e2e/namespaces/namespaces.go b/e2e/namespaces/namespaces.go index 67a81d91314..c7700140289 100644 --- a/e2e/namespaces/namespaces.go +++ b/e2e/namespaces/namespaces.go @@ -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) } } @@ -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") } diff --git a/e2e/networking/networking.go b/e2e/networking/networking.go index 90c86e66a7b..a1d410dd1e6 100644 --- a/e2e/networking/networking.go +++ b/e2e/networking/networking.go @@ -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{} diff --git a/e2e/rescheduling/rescheduling.go b/e2e/rescheduling/rescheduling.go index dd4895b85b0..ce9a5f3420e 100644 --- a/e2e/rescheduling/rescheduling.go +++ b/e2e/rescheduling/rescheduling.go @@ -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{} diff --git a/e2e/scaling/scaling.go b/e2e/scaling/scaling.go index 0fd90eca663..cb046ae9c8f 100644 --- a/e2e/scaling/scaling.go +++ b/e2e/scaling/scaling.go @@ -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{} diff --git a/e2e/scalingpolicies/scalingpolicies.go b/e2e/scalingpolicies/scalingpolicies.go index 3579219d206..b011bf4fb0a 100644 --- a/e2e/scalingpolicies/scalingpolicies.go +++ b/e2e/scalingpolicies/scalingpolicies.go @@ -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{} diff --git a/e2e/volumes/volumes.go b/e2e/volumes/volumes.go index 936c2099b27..9e7b48cddc3 100644 --- a/e2e/volumes/volumes.go +++ b/e2e/volumes/volumes.go @@ -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{}