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
This commit is contained in:
hc-github-team-nomad-core 2023-08-17 08:33:06 -05:00 committed by GitHub
parent d5e3b7c262
commit bd3f52d0e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 14 deletions

3
.changelog/18120.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
ui: maintain HCL2 jobspec when using Start Job in the web ui
```

View File

@ -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();

View File

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

View File

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

View File

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

View File

@ -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');
});