e2e: account for new job stop CLI exit behaviour.

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.
This commit is contained in:
James Rasell
2022-02-01 14:16:37 +01:00
parent 22bd08912a
commit c2b5a5ebd9
11 changed files with 47 additions and 22 deletions

View File

@@ -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{}

View File

@@ -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{}

View File

@@ -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

View File

@@ -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{}

View File

@@ -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
}

View File

@@ -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")
}

View File

@@ -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{}

View File

@@ -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{}

View File

@@ -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{}

View File

@@ -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{}

View File

@@ -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{}