Skip to content

Commit

Permalink
Namespace added to example test in exec window (#20218)
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud authored Mar 25, 2024
1 parent facc3e8 commit fee242c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .changelog/20218.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Show the namespace in the web UI exec command hint
```
12 changes: 9 additions & 3 deletions ui/app/controllers/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,16 @@ export default class ExecController extends Controller {
'Customize your command, then hit ‘return’ to run.'
);
this.terminal.writeln('');

let namespaceCommandString = '';
if (this.namespace && this.namespace !== 'default') {
namespaceCommandString = `-namespace ${this.namespace} `;
}

this.terminal.write(
`$ nomad alloc exec -i -t -task ${escapeTaskName(taskName)} ${
this.taskState.allocation.shortId
} `
`$ nomad alloc exec -i -t ${namespaceCommandString}-task ${escapeTaskName(
taskName
)} ${this.taskState.allocation.shortId} `
);

this.terminal.write(ANSI_WHITE);
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/actions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ module('Acceptance | actions', function (hooks) {
);
await percySnapshot(assert, {
percyCSS: `
g.tick { visibility: hidden; };
g.tick { visibility: hidden; }
.recent-events-table td {
display: none;
}
Expand Down
44 changes: 41 additions & 3 deletions ui/tests/acceptance/exec-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ module('Acceptance | exec', function (hooks) {
});

test('navigating to a task adds its name to the route, chooses an allocation, and assigns a default command', async function (assert) {
await Exec.visitJob({ job: this.job.id });
await Exec.visitJob({ job: this.job.id, namespace: this.job.namespaceId });
await Exec.taskGroups[0].click();
await Exec.taskGroups[0].tasks[0].click();

Expand All @@ -282,7 +282,7 @@ module('Acceptance | exec', function (hooks) {

assert.equal(
currentURL(),
`/exec/${this.job.id}/${taskGroup.name}/${task.name}`
`/exec/${this.job.id}/${taskGroup.name}/${task.name}?namespace=${this.job.namespaceId}`
);
assert.ok(Exec.taskGroups[0].tasks[0].isActive);

Expand Down Expand Up @@ -332,6 +332,7 @@ module('Acceptance | exec', function (hooks) {
task_group: taskGroup.name,
task_name: task.name,
allocation: allocation.id.split('-')[0],
namespace: this.job.namespaceId,
});

await settled();
Expand All @@ -344,6 +345,42 @@ module('Acceptance | exec', function (hooks) {
);
});

test('a namespace can be specified', async function (assert) {
server.create('namespace'); // default
let namespace = server.create('namespace', {
id: 'should-show-in-example-string',
});
let job = server.create('job', {
namespaceId: namespace.id,
createAllocations: true,
});

let taskGroup = job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
let allocations = this.server.db.allocations.where({
jobId: job.id,
taskGroup: taskGroup.name,
});
let allocation = allocations[allocations.length - 1];

await Exec.visitTask({
job: job.id,
task_group: taskGroup.name,
task_name: task.name,
allocation: allocation.id.split('-')[0],
namespace: namespace.id,
});

await settled();

assert.equal(
window.execTerminal.buffer.active.getLine(4).translateToString().trim(),
`$ nomad alloc exec -i -t -namespace should-show-in-example-string -task ${
task.name
} ${allocation.id.split('-')[0]} /bin/bash`
);
});

test('running the command opens the socket for reading/writing and detects it closing', async function (assert) {
let mockSocket = new MockSocket();
let mockSockets = Service.extend({
Expand Down Expand Up @@ -495,7 +532,7 @@ module('Acceptance | exec', function (hooks) {

this.owner.register('service:sockets', mockSockets);

await Exec.visitJob({ job: this.job.id });
await Exec.visitJob({ job: this.job.id, namespace: this.job.namespaceId });
await Exec.taskGroups[0].click();
await Exec.taskGroups[0].tasks[0].click();

Expand Down Expand Up @@ -557,6 +594,7 @@ module('Acceptance | exec', function (hooks) {
task_group: taskGroup.name,
task_name: task.name,
allocation: allocation.id.split('-')[0],
namespace: this.job.namespaceId,
});

await settled();
Expand Down

0 comments on commit fee242c

Please sign in to comment.