2020-04-06 19:08:22 +00:00
|
|
|
|
import { module, skip, test } from 'qunit';
|
2020-03-24 23:22:16 +00:00
|
|
|
|
import { currentURL, settled } from '@ember/test-helpers';
|
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
|
|
|
|
import { setupMirage } from 'ember-cli-mirage/test-support';
|
2020-07-28 17:59:14 +00:00
|
|
|
|
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
|
2020-03-24 23:22:16 +00:00
|
|
|
|
import Service from '@ember/service';
|
|
|
|
|
import Exec from 'nomad-ui/tests/pages/exec';
|
UI: add handling for exec command-editing keys (#7601)
This is a minimal implementation that closes #7463. It doesn’t include
true support for moving around within the command to edit using arrow
keys because it gets too complex when managing wrapping at the edge of
the terminal. Instead, arrow keys are ignored. It also ignores ^A and
^E, which are cursor manipulations that pose similar problems to arrow
keys. It does support ^U, which deletes the entire command.
It also allows a command to be pasted, which was previously unsupported.
This is accomplished by migrating from Xterm.js’s onKey handler to
onData, which is recommended here:
https://github.com/xtermjs/xterm.js/issues/2673#issuecomment-574897733
onData is a higher-level handler that issues events with the final
interpreted data instead of the individual key events. That means the
processing in this PR has changed from inspecting DOM key events to
inspecting their ASCII equivalents, which I’ve extracted into a utility
dictionary for use in tests and implementation.
One consequence of ignoring most control characters is that if you paste
a string that includes a control character, that character will be
stripped. It’s somewhat strange for compound sequences like arrow keys;
if you run copy('/bin/b' + '\x1b[D' + 'ash') in a Javascript console and
paste what’s on the clipboard, you get "/bin/b[Dash". That’s because
the left arrow key, as in that centre portion of the string,
is represented by the escape character and a coded sequence. Stripping
the control character leaves the coded sequence as part of the paste.
That seems like an acceptable compromise vs either ignoring any pasted
string with control characters (confusing UX) or trying to interpret and
strip all such compound control sequences (difficult to be exhaustive).
2020-04-03 17:14:47 +00:00
|
|
|
|
import KEYS from 'nomad-ui/utils/keys';
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
|
|
module('Acceptance | exec', function(hooks) {
|
|
|
|
|
setupApplicationTest(hooks);
|
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
|
|
|
|
|
hooks.beforeEach(async function() {
|
2020-04-03 18:31:19 +00:00
|
|
|
|
window.localStorage.clear();
|
|
|
|
|
window.sessionStorage.clear();
|
2020-04-01 13:08:42 +00:00
|
|
|
|
|
2020-03-24 23:22:16 +00:00
|
|
|
|
server.create('agent');
|
|
|
|
|
server.create('node');
|
|
|
|
|
|
|
|
|
|
this.job = server.create('job', {
|
|
|
|
|
groupsCount: 2,
|
|
|
|
|
groupTaskCount: 5,
|
|
|
|
|
createAllocations: false,
|
2020-04-06 19:08:22 +00:00
|
|
|
|
status: 'running',
|
2020-03-24 23:22:16 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
this.job.taskGroups.models.forEach(taskGroup => {
|
2020-03-24 23:22:16 +00:00
|
|
|
|
server.create('allocation', {
|
|
|
|
|
jobId: this.job.id,
|
2020-08-28 00:58:24 +00:00
|
|
|
|
taskGroup: taskGroup.name,
|
2020-03-24 23:22:16 +00:00
|
|
|
|
forceRunningClientStatus: true,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-07-28 17:59:14 +00:00
|
|
|
|
test('it passes an accessibility audit', async function(assert) {
|
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
2020-08-25 15:56:02 +00:00
|
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
|
});
|
|
|
|
|
|
2020-03-24 23:22:16 +00:00
|
|
|
|
test('/exec/:job should show the region, namespace, and job name', async function(assert) {
|
|
|
|
|
server.create('namespace');
|
|
|
|
|
let namespace = server.create('namespace');
|
|
|
|
|
|
|
|
|
|
server.create('region', { id: 'global' });
|
|
|
|
|
server.create('region', { id: 'region-2' });
|
|
|
|
|
|
2020-04-06 19:08:22 +00:00
|
|
|
|
this.job = server.create('job', {
|
|
|
|
|
createAllocations: false,
|
|
|
|
|
namespaceId: namespace.id,
|
|
|
|
|
status: 'running',
|
|
|
|
|
});
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
|
|
await Exec.visitJob({ job: this.job.id, namespace: namespace.id, region: 'region-2' });
|
|
|
|
|
|
|
|
|
|
assert.equal(document.title, 'Exec - region-2 - Nomad');
|
|
|
|
|
|
|
|
|
|
assert.equal(Exec.header.region.text, this.job.region);
|
|
|
|
|
assert.equal(Exec.header.namespace.text, this.job.namespace);
|
|
|
|
|
assert.equal(Exec.header.job, this.job.name);
|
2020-04-06 19:08:22 +00:00
|
|
|
|
|
|
|
|
|
assert.notOk(Exec.jobDead.isPresent);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('/exec/:job should not show region and namespace when there are none', async function(assert) {
|
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
|
|
|
|
|
|
|
|
|
assert.ok(Exec.header.region.isHidden);
|
|
|
|
|
assert.ok(Exec.header.namespace.isHidden);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('/exec/:job should show the task groups collapsed by default and allow the tasks to be shown', async function(assert) {
|
2020-08-28 00:58:24 +00:00
|
|
|
|
const firstTaskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
assert.equal(Exec.taskGroups.length, this.job.taskGroups.length);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
2020-04-06 18:52:42 +00:00
|
|
|
|
assert.equal(Exec.taskGroups[0].name, firstTaskGroup.name);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
assert.equal(Exec.taskGroups[0].tasks.length, 0);
|
|
|
|
|
assert.ok(Exec.taskGroups[0].chevron.isRight);
|
2020-04-06 18:52:42 +00:00
|
|
|
|
assert.notOk(Exec.taskGroups[0].isLoading);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
|
|
await Exec.taskGroups[0].click();
|
2020-04-06 18:52:42 +00:00
|
|
|
|
assert.equal(Exec.taskGroups[0].tasks.length, firstTaskGroup.tasks.length);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
assert.notOk(Exec.taskGroups[0].tasks[0].isActive);
|
|
|
|
|
assert.ok(Exec.taskGroups[0].chevron.isDown);
|
|
|
|
|
|
|
|
|
|
await Exec.taskGroups[0].click();
|
|
|
|
|
assert.equal(Exec.taskGroups[0].tasks.length, 0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('/exec/:job should require selecting a task', async function(assert) {
|
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-03-24 23:22:16 +00:00
|
|
|
|
.getLine(0)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
'Select a task to start your session.'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-06 18:52:42 +00:00
|
|
|
|
test('a task group with a pending allocation shows a loading spinner', async function(assert) {
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
this.server.db.allocations.update({ taskGroup: taskGroup.name }, { clientStatus: 'pending' });
|
|
|
|
|
|
2020-04-06 18:52:42 +00:00
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
|
|
|
|
assert.ok(Exec.taskGroups[0].isLoading);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('a task group with no running task states or pending allocations should not be shown', async function(assert) {
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-04-06 18:52:42 +00:00
|
|
|
|
this.server.db.allocations.update({ taskGroup: taskGroup.name }, { clientStatus: 'failed' });
|
|
|
|
|
|
2020-03-24 23:22:16 +00:00
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
|
|
|
|
assert.notEqual(Exec.taskGroups[0].name, taskGroup.name);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('an inactive task should not be shown', async function(assert) {
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let notRunningTaskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
this.server.db.allocations.update(
|
|
|
|
|
{ taskGroup: notRunningTaskGroup.name },
|
2020-04-06 18:52:42 +00:00
|
|
|
|
{ clientStatus: 'failed' }
|
2020-03-24 23:22:16 +00:00
|
|
|
|
);
|
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let runningTaskGroup = this.job.taskGroups.models.sortBy('name')[1];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
runningTaskGroup.tasks.models.forEach((task, index) => {
|
|
|
|
|
if (index > 0) {
|
|
|
|
|
this.server.db.taskStates.update({ name: task.name }, { finishedAt: new Date() });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
|
|
|
|
await Exec.taskGroups[0].click();
|
|
|
|
|
|
|
|
|
|
assert.equal(Exec.taskGroups[0].tasks.length, 1);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-06 18:52:42 +00:00
|
|
|
|
test('a task that becomes active should appear', async function(assert) {
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let notRunningTaskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-04-06 18:52:42 +00:00
|
|
|
|
this.server.db.allocations.update(
|
|
|
|
|
{ taskGroup: notRunningTaskGroup.name },
|
|
|
|
|
{ clientStatus: 'failed' }
|
|
|
|
|
);
|
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let runningTaskGroup = this.job.taskGroups.models.sortBy('name')[1];
|
2020-04-06 18:52:42 +00:00
|
|
|
|
let changingTaskStateName;
|
|
|
|
|
runningTaskGroup.tasks.models.sortBy('name').forEach((task, index) => {
|
|
|
|
|
if (index > 0) {
|
|
|
|
|
this.server.db.taskStates.update({ name: task.name }, { finishedAt: new Date() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (index === 1) {
|
|
|
|
|
changingTaskStateName = task.name;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
|
|
|
|
await Exec.taskGroups[0].click();
|
|
|
|
|
|
|
|
|
|
assert.equal(Exec.taskGroups[0].tasks.length, 1);
|
|
|
|
|
|
|
|
|
|
// Approximate new task arrival via polling by changing a finished task state to be not finished
|
|
|
|
|
this.owner
|
|
|
|
|
.lookup('service:store')
|
|
|
|
|
.peekAll('allocation')
|
|
|
|
|
.forEach(allocation => {
|
|
|
|
|
const changingTaskState = allocation.states.findBy('name', changingTaskStateName);
|
|
|
|
|
|
|
|
|
|
if (changingTaskState) {
|
|
|
|
|
changingTaskState.set('finishedAt', undefined);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.equal(Exec.taskGroups[0].tasks.length, 2);
|
|
|
|
|
assert.equal(Exec.taskGroups[0].tasks[1].name, changingTaskStateName);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-06 19:08:22 +00:00
|
|
|
|
test('a dead job has an inert window', async function(assert) {
|
|
|
|
|
this.job.status = 'dead';
|
|
|
|
|
this.job.save();
|
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-04-06 19:08:22 +00:00
|
|
|
|
let task = taskGroup.tasks.models.sortBy('name')[0];
|
|
|
|
|
|
|
|
|
|
this.server.db.taskStates.update({ finishedAt: new Date() });
|
|
|
|
|
|
|
|
|
|
await Exec.visitTask({
|
|
|
|
|
job: this.job.id,
|
|
|
|
|
task_group: taskGroup.name,
|
|
|
|
|
task_name: task.name,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assert.ok(Exec.jobDead.isPresent);
|
|
|
|
|
assert.equal(
|
|
|
|
|
Exec.jobDead.message,
|
|
|
|
|
`Job ${this.job.name} is dead and cannot host an exec session.`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('when a job dies the exec window becomes inert', async function(assert) {
|
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
|
|
|
|
|
|
|
|
|
// Approximate live-polling job death
|
|
|
|
|
this.owner
|
|
|
|
|
.lookup('service:store')
|
|
|
|
|
.peekAll('job')
|
|
|
|
|
.forEach(job => job.set('status', 'dead'));
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.ok(Exec.jobDead.isPresent);
|
|
|
|
|
});
|
|
|
|
|
|
2020-03-24 23:22:16 +00:00
|
|
|
|
test('visiting a path with a task group should open the group by default', async function(assert) {
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
await Exec.visitTaskGroup({ job: this.job.id, task_group: taskGroup.name });
|
|
|
|
|
|
2020-04-06 18:52:42 +00:00
|
|
|
|
assert.equal(Exec.taskGroups[0].tasks.length, taskGroup.tasks.length);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
assert.ok(Exec.taskGroups[0].chevron.isDown);
|
|
|
|
|
|
2020-04-06 18:52:42 +00:00
|
|
|
|
let task = taskGroup.tasks.models.sortBy('name')[0];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
await Exec.visitTask({ job: this.job.id, task_group: taskGroup.name, task_name: task.name });
|
|
|
|
|
|
2020-04-06 18:52:42 +00:00
|
|
|
|
assert.equal(Exec.taskGroups[0].tasks.length, taskGroup.tasks.length);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
assert.ok(Exec.taskGroups[0].chevron.isDown);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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.taskGroups[0].click();
|
|
|
|
|
await Exec.taskGroups[0].tasks[0].click();
|
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-04-06 18:52:42 +00:00
|
|
|
|
let task = taskGroup.tasks.models.sortBy('name')[0];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
|
|
let taskStates = this.server.db.taskStates.where({
|
|
|
|
|
name: task.name,
|
|
|
|
|
});
|
|
|
|
|
let allocationId = taskStates.find(ts => ts.allocationId).allocationId;
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.equal(currentURL(), `/exec/${this.job.id}/${taskGroup.name}/${task.name}`);
|
|
|
|
|
assert.ok(Exec.taskGroups[0].tasks[0].isActive);
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-03-24 23:22:16 +00:00
|
|
|
|
.getLine(2)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
'Multiple instances of this task are running. The allocation below was selected by random draw.'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-03-24 23:22:16 +00:00
|
|
|
|
.getLine(4)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
'Customize your command, then hit ‘return’ to run.'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-03-24 23:22:16 +00:00
|
|
|
|
.getLine(6)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
`$ nomad alloc exec -i -t -task ${task.name} ${allocationId.split('-')[0]} /bin/bash`
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('an allocation can be specified', async function(assert) {
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-04-06 18:52:42 +00:00
|
|
|
|
let task = taskGroup.tasks.models.sortBy('name')[0];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
let allocations = this.server.db.allocations.where({
|
|
|
|
|
jobId: this.job.id,
|
|
|
|
|
taskGroup: taskGroup.name,
|
|
|
|
|
});
|
|
|
|
|
let allocation = allocations[allocations.length - 1];
|
|
|
|
|
|
|
|
|
|
this.server.db.taskStates.update({ name: task.name }, { name: 'spaced name!' });
|
|
|
|
|
|
|
|
|
|
task.name = 'spaced name!';
|
|
|
|
|
task.save();
|
|
|
|
|
|
|
|
|
|
await Exec.visitTask({
|
|
|
|
|
job: this.job.id,
|
|
|
|
|
task_group: taskGroup.name,
|
|
|
|
|
task_name: task.name,
|
|
|
|
|
allocation: allocation.id.split('-')[0],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-03-24 23:22:16 +00:00
|
|
|
|
.getLine(4)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
`$ nomad alloc exec -i -t -task spaced\\ 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({
|
|
|
|
|
getTaskStateSocket(taskState, command) {
|
|
|
|
|
assert.equal(taskState.name, task.name);
|
|
|
|
|
assert.equal(taskState.allocation.id, allocation.id);
|
|
|
|
|
|
|
|
|
|
assert.equal(command, '/bin/bash');
|
|
|
|
|
|
|
|
|
|
assert.step('Socket built');
|
|
|
|
|
|
|
|
|
|
return mockSocket;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.owner.register('service:sockets', mockSockets);
|
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-04-06 18:52:42 +00:00
|
|
|
|
let task = taskGroup.tasks.models.sortBy('name')[0];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
let allocations = this.server.db.allocations.where({
|
|
|
|
|
jobId: this.job.id,
|
|
|
|
|
taskGroup: taskGroup.name,
|
|
|
|
|
});
|
|
|
|
|
let allocation = allocations[allocations.length - 1];
|
|
|
|
|
|
|
|
|
|
await Exec.visitTask({
|
|
|
|
|
job: this.job.id,
|
|
|
|
|
task_group: taskGroup.name,
|
|
|
|
|
task_name: task.name,
|
|
|
|
|
allocation: allocation.id.split('-')[0],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
await Exec.terminal.pressEnter();
|
|
|
|
|
await settled();
|
|
|
|
|
mockSocket.onopen();
|
|
|
|
|
|
|
|
|
|
assert.verifySteps(['Socket built']);
|
|
|
|
|
|
|
|
|
|
mockSocket.onmessage({
|
|
|
|
|
data: '{"stdout":{"data":"c2gtMy4yIPCfpbMk"}}',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-03-24 23:22:16 +00:00
|
|
|
|
.getLine(5)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
'sh-3.2 🥳$'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await Exec.terminal.pressEnter();
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(mockSocket.sent, [
|
2020-04-03 15:22:22 +00:00
|
|
|
|
'{"version":1,"auth_token":""}',
|
2020-03-24 23:22:16 +00:00
|
|
|
|
`{"tty_size":{"width":${window.execTerminal.cols},"height":${window.execTerminal.rows}}}`,
|
|
|
|
|
'{"stdin":{"data":"DQ=="}}',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
await mockSocket.onclose();
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-03-24 23:22:16 +00:00
|
|
|
|
.getLine(6)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
'The connection has closed.'
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2020-04-03 17:35:51 +00:00
|
|
|
|
test('the opening message includes the token if it exists', async function(assert) {
|
2020-04-03 17:27:03 +00:00
|
|
|
|
const { secretId } = server.create('token');
|
2020-04-03 17:26:25 +00:00
|
|
|
|
window.localStorage.nomadTokenSecret = secretId;
|
2020-04-03 15:22:22 +00:00
|
|
|
|
|
|
|
|
|
let mockSocket = new MockSocket();
|
|
|
|
|
let mockSockets = Service.extend({
|
2020-04-03 17:52:39 +00:00
|
|
|
|
getTaskStateSocket() {
|
2020-04-03 15:22:22 +00:00
|
|
|
|
return mockSocket;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.owner.register('service:sockets', mockSockets);
|
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models[0];
|
2020-04-03 15:22:22 +00:00
|
|
|
|
let task = taskGroup.tasks.models[0];
|
|
|
|
|
let allocations = this.server.db.allocations.where({
|
|
|
|
|
jobId: this.job.id,
|
|
|
|
|
taskGroup: taskGroup.name,
|
|
|
|
|
});
|
|
|
|
|
let allocation = allocations[allocations.length - 1];
|
|
|
|
|
|
|
|
|
|
await Exec.visitTask({
|
|
|
|
|
job: this.job.id,
|
|
|
|
|
task_group: taskGroup.name,
|
|
|
|
|
task_name: task.name,
|
|
|
|
|
allocation: allocation.id.split('-')[0],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await Exec.terminal.pressEnter();
|
|
|
|
|
await settled();
|
|
|
|
|
mockSocket.onopen();
|
|
|
|
|
|
|
|
|
|
await Exec.terminal.pressEnter();
|
|
|
|
|
await settled();
|
|
|
|
|
|
2020-04-03 17:35:51 +00:00
|
|
|
|
assert.equal(mockSocket.sent[0], `{"version":1,"auth_token":"${secretId}"}`);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('only one socket is opened after switching between tasks', async function(assert) {
|
|
|
|
|
let mockSockets = Service.extend({
|
|
|
|
|
getTaskStateSocket() {
|
|
|
|
|
assert.step('Socket built');
|
|
|
|
|
return new MockSocket();
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.owner.register('service:sockets', mockSockets);
|
|
|
|
|
|
|
|
|
|
await Exec.visitJob({
|
|
|
|
|
job: this.job.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
await Exec.taskGroups[0].click();
|
|
|
|
|
await Exec.taskGroups[0].tasks[0].click();
|
|
|
|
|
|
|
|
|
|
await Exec.taskGroups[1].click();
|
|
|
|
|
await Exec.taskGroups[1].tasks[0].click();
|
|
|
|
|
|
|
|
|
|
await Exec.terminal.pressEnter();
|
|
|
|
|
|
|
|
|
|
assert.verifySteps(['Socket built']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('the command can be customised', async function(assert) {
|
|
|
|
|
let mockSockets = Service.extend({
|
|
|
|
|
getTaskStateSocket(taskState, command) {
|
|
|
|
|
assert.equal(command, '/sh');
|
2020-04-03 18:31:19 +00:00
|
|
|
|
window.localStorage.getItem('nomadExecCommand', JSON.stringify('/sh'));
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
|
|
assert.step('Socket built');
|
|
|
|
|
|
|
|
|
|
return new MockSocket();
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.owner.register('service:sockets', mockSockets);
|
|
|
|
|
|
|
|
|
|
await Exec.visitJob({ job: this.job.id });
|
|
|
|
|
await Exec.taskGroups[0].click();
|
|
|
|
|
await Exec.taskGroups[0].tasks[0].click();
|
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-04-06 18:52:42 +00:00
|
|
|
|
let task = taskGroup.tasks.models.sortBy('name')[0];
|
2020-03-24 23:22:16 +00:00
|
|
|
|
let allocation = this.server.db.allocations.findBy({
|
|
|
|
|
jobId: this.job.id,
|
|
|
|
|
taskGroup: taskGroup.name,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
// Delete /bash
|
UI: add handling for exec command-editing keys (#7601)
This is a minimal implementation that closes #7463. It doesn’t include
true support for moving around within the command to edit using arrow
keys because it gets too complex when managing wrapping at the edge of
the terminal. Instead, arrow keys are ignored. It also ignores ^A and
^E, which are cursor manipulations that pose similar problems to arrow
keys. It does support ^U, which deletes the entire command.
It also allows a command to be pasted, which was previously unsupported.
This is accomplished by migrating from Xterm.js’s onKey handler to
onData, which is recommended here:
https://github.com/xtermjs/xterm.js/issues/2673#issuecomment-574897733
onData is a higher-level handler that issues events with the final
interpreted data instead of the individual key events. That means the
processing in this PR has changed from inspecting DOM key events to
inspecting their ASCII equivalents, which I’ve extracted into a utility
dictionary for use in tests and implementation.
One consequence of ignoring most control characters is that if you paste
a string that includes a control character, that character will be
stripped. It’s somewhat strange for compound sequences like arrow keys;
if you run copy('/bin/b' + '\x1b[D' + 'ash') in a Javascript console and
paste what’s on the clipboard, you get "/bin/b[Dash". That’s because
the left arrow key, as in that centre portion of the string,
is represented by the escape character and a coded sequence. Stripping
the control character leaves the coded sequence as part of the paste.
That seems like an acceptable compromise vs either ignoring any pasted
string with control characters (confusing UX) or trying to interpret and
strip all such compound control sequences (difficult to be exhaustive).
2020-04-03 17:14:47 +00:00
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
|
|
// Delete /bin and try to go beyond
|
UI: add handling for exec command-editing keys (#7601)
This is a minimal implementation that closes #7463. It doesn’t include
true support for moving around within the command to edit using arrow
keys because it gets too complex when managing wrapping at the edge of
the terminal. Instead, arrow keys are ignored. It also ignores ^A and
^E, which are cursor manipulations that pose similar problems to arrow
keys. It does support ^U, which deletes the entire command.
It also allows a command to be pasted, which was previously unsupported.
This is accomplished by migrating from Xterm.js’s onKey handler to
onData, which is recommended here:
https://github.com/xtermjs/xterm.js/issues/2673#issuecomment-574897733
onData is a higher-level handler that issues events with the final
interpreted data instead of the individual key events. That means the
processing in this PR has changed from inspecting DOM key events to
inspecting their ASCII equivalents, which I’ve extracted into a utility
dictionary for use in tests and implementation.
One consequence of ignoring most control characters is that if you paste
a string that includes a control character, that character will be
stripped. It’s somewhat strange for compound sequences like arrow keys;
if you run copy('/bin/b' + '\x1b[D' + 'ash') in a Javascript console and
paste what’s on the clipboard, you get "/bin/b[Dash". That’s because
the left arrow key, as in that centre portion of the string,
is represented by the escape character and a coded sequence. Stripping
the control character leaves the coded sequence as part of the paste.
That seems like an acceptable compromise vs either ignoring any pasted
string with control characters (confusing UX) or trying to interpret and
strip all such compound control sequences (difficult to be exhaustive).
2020-04-03 17:14:47 +00:00
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
|
|
|
|
await window.execTerminal.simulateCommandDataEvent(KEYS.DELETE);
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-03-24 23:22:16 +00:00
|
|
|
|
.getLine(6)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
`$ nomad alloc exec -i -t -task ${task.name} ${allocation.id.split('-')[0]}`
|
|
|
|
|
);
|
|
|
|
|
|
UI: add handling for exec command-editing keys (#7601)
This is a minimal implementation that closes #7463. It doesn’t include
true support for moving around within the command to edit using arrow
keys because it gets too complex when managing wrapping at the edge of
the terminal. Instead, arrow keys are ignored. It also ignores ^A and
^E, which are cursor manipulations that pose similar problems to arrow
keys. It does support ^U, which deletes the entire command.
It also allows a command to be pasted, which was previously unsupported.
This is accomplished by migrating from Xterm.js’s onKey handler to
onData, which is recommended here:
https://github.com/xtermjs/xterm.js/issues/2673#issuecomment-574897733
onData is a higher-level handler that issues events with the final
interpreted data instead of the individual key events. That means the
processing in this PR has changed from inspecting DOM key events to
inspecting their ASCII equivalents, which I’ve extracted into a utility
dictionary for use in tests and implementation.
One consequence of ignoring most control characters is that if you paste
a string that includes a control character, that character will be
stripped. It’s somewhat strange for compound sequences like arrow keys;
if you run copy('/bin/b' + '\x1b[D' + 'ash') in a Javascript console and
paste what’s on the clipboard, you get "/bin/b[Dash". That’s because
the left arrow key, as in that centre portion of the string,
is represented by the escape character and a coded sequence. Stripping
the control character leaves the coded sequence as part of the paste.
That seems like an acceptable compromise vs either ignoring any pasted
string with control characters (confusing UX) or trying to interpret and
strip all such compound control sequences (difficult to be exhaustive).
2020-04-03 17:14:47 +00:00
|
|
|
|
await window.execTerminal.simulateCommandDataEvent('/sh');
|
2020-03-24 23:22:16 +00:00
|
|
|
|
|
|
|
|
|
await Exec.terminal.pressEnter();
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.verifySteps(['Socket built']);
|
|
|
|
|
});
|
2020-04-01 13:08:42 +00:00
|
|
|
|
|
|
|
|
|
test('a persisted customised command is recalled', async function(assert) {
|
2020-04-03 18:31:19 +00:00
|
|
|
|
window.localStorage.setItem('nomadExecCommand', JSON.stringify('/bin/sh'));
|
2020-04-01 13:08:42 +00:00
|
|
|
|
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models[0];
|
2020-04-01 13:08:42 +00:00
|
|
|
|
let task = taskGroup.tasks.models[0];
|
|
|
|
|
let allocations = this.server.db.allocations.where({
|
|
|
|
|
jobId: this.job.id,
|
|
|
|
|
taskGroup: taskGroup.name,
|
|
|
|
|
});
|
|
|
|
|
let allocation = allocations[allocations.length - 1];
|
|
|
|
|
|
|
|
|
|
await Exec.visitTask({
|
|
|
|
|
job: this.job.id,
|
|
|
|
|
task_group: taskGroup.name,
|
|
|
|
|
task_name: task.name,
|
|
|
|
|
allocation: allocation.id.split('-')[0],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-04-01 13:08:42 +00:00
|
|
|
|
.getLine(4)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
`$ nomad alloc exec -i -t -task ${task.name} ${allocation.id.split('-')[0]} /bin/sh`
|
|
|
|
|
);
|
|
|
|
|
});
|
2020-04-06 19:08:22 +00:00
|
|
|
|
|
|
|
|
|
skip('when a task state finishes submitting a command displays an error', async function(assert) {
|
2020-08-28 00:58:24 +00:00
|
|
|
|
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
|
2020-04-06 19:08:22 +00:00
|
|
|
|
let task = taskGroup.tasks.models.sortBy('name')[0];
|
|
|
|
|
|
|
|
|
|
await Exec.visitTask({
|
|
|
|
|
job: this.job.id,
|
|
|
|
|
task_group: taskGroup.name,
|
|
|
|
|
task_name: task.name,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Approximate allocation failure via polling
|
|
|
|
|
this.owner
|
|
|
|
|
.lookup('service:store')
|
|
|
|
|
.peekAll('allocation')
|
|
|
|
|
.forEach(allocation => allocation.set('clientStatus', 'failed'));
|
|
|
|
|
|
|
|
|
|
await Exec.terminal.pressEnter();
|
|
|
|
|
await settled();
|
|
|
|
|
|
|
|
|
|
assert.equal(
|
2020-05-26 14:56:25 +00:00
|
|
|
|
window.execTerminal.buffer.active
|
2020-04-06 19:08:22 +00:00
|
|
|
|
.getLine(7)
|
|
|
|
|
.translateToString()
|
|
|
|
|
.trim(),
|
|
|
|
|
`Failed to open a socket because task ${task.name} is not active.`
|
|
|
|
|
);
|
|
|
|
|
});
|
2020-03-24 23:22:16 +00:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
class MockSocket {
|
|
|
|
|
constructor() {
|
|
|
|
|
this.sent = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
send(message) {
|
|
|
|
|
this.sent.push(message);
|
|
|
|
|
}
|
|
|
|
|
}
|