mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
UI: Add localStorage persistence of exec command (#7563)
This closes #7469. Trivial thanks to localStorageProperty! 🥳
This commit is contained in:
@@ -4,6 +4,7 @@ import { filterBy, mapBy, uniq } from '@ember/object/computed';
|
||||
import escapeTaskName from 'nomad-ui/utils/escape-task-name';
|
||||
import ExecCommandEditorXtermAdapter from 'nomad-ui/utils/classes/exec-command-editor-xterm-adapter';
|
||||
import ExecSocketXtermAdapter from 'nomad-ui/utils/classes/exec-socket-xterm-adapter';
|
||||
import localStorageProperty from 'nomad-ui/utils/properties/local-storage';
|
||||
|
||||
import { Terminal } from 'xterm-vendor';
|
||||
|
||||
@@ -16,7 +17,7 @@ export default Controller.extend({
|
||||
|
||||
queryParams: ['allocation'],
|
||||
|
||||
command: '/bin/bash', // Issue to improve: https://github.com/hashicorp/nomad/issues/7469
|
||||
command: localStorageProperty('nomadExecCommand', '/bin/bash'),
|
||||
socketOpen: false,
|
||||
taskState: null,
|
||||
|
||||
@@ -74,6 +75,7 @@ export default Controller.extend({
|
||||
|
||||
openAndConnectSocket(command) {
|
||||
this.set('socketOpen', true);
|
||||
this.set('command', command);
|
||||
this.socket = this.sockets.getTaskStateSocket(this.taskState, command);
|
||||
|
||||
new ExecSocketXtermAdapter(this.terminal, this.socket);
|
||||
|
||||
@@ -10,6 +10,8 @@ module('Acceptance | exec', function(hooks) {
|
||||
setupMirage(hooks);
|
||||
|
||||
hooks.beforeEach(async function() {
|
||||
window.localStorage.removeItem('nomadExecCommand');
|
||||
|
||||
server.create('agent');
|
||||
server.create('node');
|
||||
|
||||
@@ -305,6 +307,7 @@ module('Acceptance | exec', function(hooks) {
|
||||
let mockSockets = Service.extend({
|
||||
getTaskStateSocket(taskState, command) {
|
||||
assert.equal(command, '/sh');
|
||||
localStorage.getItem('nomadExecCommand', JSON.stringify('/sh'));
|
||||
|
||||
assert.step('Socket built');
|
||||
|
||||
@@ -362,6 +365,35 @@ module('Acceptance | exec', function(hooks) {
|
||||
|
||||
assert.verifySteps(['Socket built']);
|
||||
});
|
||||
|
||||
test('a persisted customised command is recalled', async function(assert) {
|
||||
localStorage.setItem('nomadExecCommand', JSON.stringify('/bin/sh'));
|
||||
|
||||
let taskGroup = this.job.task_groups.models[0];
|
||||
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(
|
||||
window.execTerminal.buffer
|
||||
.getLine(4)
|
||||
.translateToString()
|
||||
.trim(),
|
||||
`$ nomad alloc exec -i -t -task ${task.name} ${allocation.id.split('-')[0]} /bin/sh`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
class MockSocket {
|
||||
|
||||
Reference in New Issue
Block a user