From bd3f52d0e7633f4852771e221e4e2a5890ef02ee Mon Sep 17 00:00:00 2001 From: hc-github-team-nomad-core <82989552+hc-github-team-nomad-core@users.noreply.github.com> Date: Thu, 17 Aug 2023 08:33:06 -0500 Subject: [PATCH] Backport of [ui] Preserve HCL2 on stop/start via the web UI into release/1.6.x (#18241) This pull request was automerged via backport-assistant --- .changelog/18120.txt | 3 +++ ui/app/components/job-page/parts/title.js | 6 ++---- ui/mirage/config.js | 2 +- ui/tests/integration/components/job-page/helpers.js | 7 +------ ui/tests/integration/components/job-page/periodic-test.js | 3 ++- ui/tests/integration/components/job-page/service-test.js | 4 ++-- 6 files changed, 11 insertions(+), 14 deletions(-) create mode 100644 .changelog/18120.txt diff --git a/.changelog/18120.txt b/.changelog/18120.txt new file mode 100644 index 000000000..e2b8582a9 --- /dev/null +++ b/.changelog/18120.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: maintain HCL2 jobspec when using Start Job in the web ui +``` diff --git a/ui/app/components/job-page/parts/title.js b/ui/app/components/job-page/parts/title.js index bdaf0dd21..b4bb411fc 100644 --- a/ui/app/components/job-page/parts/title.js +++ b/ui/app/components/job-page/parts/title.js @@ -71,10 +71,8 @@ export default class Title extends Component { */ @task(function* (withNotifications = false) { const job = this.job; - const definition = yield job.fetchRawDefinition(); - - delete definition.Stop; - job.set('_newDefinition', JSON.stringify(definition)); + const specification = yield job.fetchRawSpecification(); + job.set('_newDefinition', specification.Source); try { yield job.parse(); diff --git a/ui/mirage/config.js b/ui/mirage/config.js index 0555f118a..fac9d3761 100644 --- a/ui/mirage/config.js +++ b/ui/mirage/config.js @@ -117,7 +117,7 @@ export default function () { 200, {}, JSON.stringify({ - Source: 'the job source v0', + Source: `job "${req.params.id}" {`, Format: 'hcl2', VariableFlags: { X: 'x', Y: '42', Z: 'true' }, Variables: 'var file content', diff --git a/ui/tests/integration/components/job-page/helpers.js b/ui/tests/integration/components/job-page/helpers.js index 2f88b7df5..168f75496 100644 --- a/ui/tests/integration/components/job-page/helpers.js +++ b/ui/tests/integration/components/job-page/helpers.js @@ -32,17 +32,12 @@ export async function purgeJob() { export function expectStartRequest(assert, server, job) { const expectedURL = jobURL(job); + const request = server.pretender.handledRequests .filterBy('method', 'POST') .find((req) => req.url === expectedURL); - const requestPayload = JSON.parse(request.requestBody).Job; - assert.ok(request, 'POST URL was made correctly'); - assert.ok( - requestPayload.Stop == null, - 'The Stop signal is not sent in the POST request' - ); } export async function expectError(assert, title) { diff --git a/ui/tests/integration/components/job-page/periodic-test.js b/ui/tests/integration/components/job-page/periodic-test.js index 207d1ab7f..c0d102922 100644 --- a/ui/tests/integration/components/job-page/periodic-test.js +++ b/ui/tests/integration/components/job-page/periodic-test.js @@ -40,6 +40,7 @@ module('Integration | Component | job-page/periodic', function (hooks) { this.server = startMirage(); this.server.create('namespace'); this.server.create('node-pool'); + this.server.create('node'); }); hooks.afterEach(function () { @@ -194,7 +195,7 @@ module('Integration | Component | job-page/periodic', function (hooks) { }); test('Starting a job sends a post request for the job using the current definition', async function (assert) { - assert.expect(2); + assert.expect(1); const mirageJob = this.server.create('job', 'periodic', { childrenCount: 0, diff --git a/ui/tests/integration/components/job-page/service-test.js b/ui/tests/integration/components/job-page/service-test.js index aeae07779..56fcd66df 100644 --- a/ui/tests/integration/components/job-page/service-test.js +++ b/ui/tests/integration/components/job-page/service-test.js @@ -32,6 +32,7 @@ module('Integration | Component | job-page/service', function (hooks) { this.server = startMirage(); this.server.create('namespace'); this.server.create('node-pool'); + this.server.create('node'); }); hooks.afterEach(function () { @@ -109,7 +110,7 @@ module('Integration | Component | job-page/service', function (hooks) { }); test('Starting a job sends a post request for the job using the current definition', async function (assert) { - assert.expect(2); + assert.expect(1); const mirageJob = makeMirageJob(this.server, { status: 'dead' }); await this.store.findAll('job'); @@ -137,7 +138,6 @@ module('Integration | Component | job-page/service', function (hooks) { await render(commonTemplate); await startJob(); - await expectError(assert, 'Could Not Start Job'); });