-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathallocation-detail-test.js
619 lines (522 loc) · 19 KB
/
allocation-detail-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
/* eslint-disable qunit/require-expect */
/* Mirage fixtures are random so we can't expect a set number of assertions */
import { run } from '@ember/runloop';
import { currentURL } from '@ember/test-helpers';
import { assign } from '@ember/polyfills';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import Allocation from 'nomad-ui/tests/pages/allocations/detail';
import moment from 'moment';
import formatHost from 'nomad-ui/utils/format-host';
let job;
let node;
let allocation;
module('Acceptance | allocation detail', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
hooks.beforeEach(async function () {
server.create('agent');
node = server.create('node');
job = server.create('job', {
groupsCount: 1,
withGroupServices: true,
createAllocations: false,
});
allocation = server.create('allocation', 'withTaskWithPorts', {
clientStatus: 'running',
});
// Make sure the node has an unhealthy driver
node.update({
driver: assign(node.drivers, {
docker: {
detected: true,
healthy: false,
},
}),
});
// Make sure a task for the allocation depends on the unhealthy driver
server.schema.tasks.first().update({
driver: 'docker',
});
await Allocation.visit({ id: allocation.id });
});
test('it passes an accessibility audit', async function (assert) {
await a11yAudit(assert);
});
test('/allocation/:id should name the allocation and link to the corresponding job and node', async function (assert) {
assert.ok(
Allocation.title.includes(allocation.name),
'Allocation name is in the heading'
);
assert.equal(
Allocation.details.job,
job.name,
'Job name is in the subheading'
);
assert.equal(
Allocation.details.client,
node.id.split('-')[0],
'Node short id is in the subheading'
);
assert.ok(Allocation.execButton.isPresent);
assert.equal(document.title, `Allocation ${allocation.name} - Nomad`);
await Allocation.details.visitJob();
assert.equal(
currentURL(),
`/jobs/${job.id}@default`,
'Job link navigates to the job'
);
await Allocation.visit({ id: allocation.id });
await Allocation.details.visitClient();
assert.equal(
currentURL(),
`/clients/${node.id}`,
'Client link navigates to the client'
);
});
test('/allocation/:id should include resource utilization graphs', async function (assert) {
assert.equal(
Allocation.resourceCharts.length,
2,
'Two resource utilization graphs'
);
assert.equal(
Allocation.resourceCharts.objectAt(0).name,
'CPU',
'First chart is CPU'
);
assert.equal(
Allocation.resourceCharts.objectAt(1).name,
'Memory',
'Second chart is Memory'
);
});
test('/allocation/:id should present task lifecycles', async function (assert) {
const job = server.create('job', {
groupsCount: 1,
groupTaskCount: 6,
withGroupServices: true,
createAllocations: false,
});
const allocation = server.create('allocation', 'withTaskWithPorts', {
clientStatus: 'running',
jobId: job.id,
});
await Allocation.visit({ id: allocation.id });
assert.ok(Allocation.lifecycleChart.isPresent);
assert.equal(Allocation.lifecycleChart.title, 'Task Lifecycle Status');
assert.equal(Allocation.lifecycleChart.phases.length, 4);
assert.equal(Allocation.lifecycleChart.tasks.length, 6);
await Allocation.lifecycleChart.tasks[0].visit();
const prestartEphemeralTask = server.db.taskStates
.where({ allocationId: allocation.id })
.sortBy('name')
.find((taskState) => {
const task = server.db.tasks.findBy({ name: taskState.name });
return (
task.Lifecycle &&
task.Lifecycle.Hook === 'prestart' &&
!task.Lifecycle.Sidecar
);
});
assert.equal(
currentURL(),
`/allocations/${allocation.id}/${prestartEphemeralTask.name}`
);
});
test('/allocation/:id should list all tasks for the allocation', async function (assert) {
assert.equal(
Allocation.tasks.length,
server.db.taskStates.where({ allocationId: allocation.id }).length,
'Table lists all tasks'
);
assert.notOk(Allocation.isEmpty, 'Task table empty state is not shown');
});
test('each task row should list high-level information for the task', async function (assert) {
const job = server.create('job', {
groupsCount: 1,
groupTaskCount: 3,
withGroupServices: true,
createAllocations: false,
});
const allocation = server.create('allocation', 'withTaskWithPorts', {
clientStatus: 'running',
jobId: job.id,
});
const taskGroup = server.schema.taskGroups.where({
jobId: allocation.jobId,
name: allocation.taskGroup,
}).models[0];
// Set the expected task states.
const states = ['running', 'pending', 'dead'];
server.db.taskStates
.where({ allocationId: allocation.id })
.sortBy('name')
.forEach((task, i) => {
server.db.taskStates.update(task.id, { state: states[i] });
});
await Allocation.visit({ id: allocation.id });
Allocation.tasks.forEach((taskRow, i) => {
const task = server.db.taskStates
.where({ allocationId: allocation.id })
.sortBy('name')[i];
const events = server.db.taskEvents.where({ taskStateId: task.id });
const event = events[events.length - 1];
const jobTask = taskGroup.tasks.models.find((m) => m.name === task.name);
const volumes = jobTask.volumeMounts.map((volume) => ({
name: volume.Volume,
source: taskGroup.volumes[volume.Volume].Source,
}));
assert.equal(taskRow.name, task.name, 'Name');
assert.equal(taskRow.state, task.state, 'State');
assert.equal(taskRow.message, event.displayMessage, 'Event Message');
assert.equal(
taskRow.time,
moment(event.time / 1000000).format("MMM DD, 'YY HH:mm:ss ZZ"),
'Event Time'
);
const expectStats = task.state === 'running';
assert.equal(taskRow.hasCpuMetrics, expectStats, 'CPU metrics');
assert.equal(taskRow.hasMemoryMetrics, expectStats, 'Memory metrics');
const volumesText = taskRow.volumes;
volumes.forEach((volume) => {
assert.ok(
volumesText.includes(volume.name),
`Found label ${volume.name}`
);
assert.ok(
volumesText.includes(volume.source),
`Found value ${volume.source}`
);
});
});
});
test('each task row should link to the task detail page', async function (assert) {
const task = server.db.taskStates
.where({ allocationId: allocation.id })
.sortBy('name')[0];
await Allocation.tasks.objectAt(0).clickLink();
// Make sure the allocation is pending in order to ensure there are no tasks
assert.equal(
currentURL(),
`/allocations/${allocation.id}/${task.name}`,
'Task name in task row links to task detail'
);
await Allocation.visit({ id: allocation.id });
await Allocation.tasks.objectAt(0).clickRow();
assert.equal(
currentURL(),
`/allocations/${allocation.id}/${task.name}`,
'Task row links to task detail'
);
});
test('tasks with an unhealthy driver have a warning icon', async function (assert) {
assert.ok(
Allocation.firstUnhealthyTask().hasUnhealthyDriver,
'Warning is shown'
);
});
test('proxy task has a proxy tag', async function (assert) {
// Must create a new job as existing one has loaded and it contains the tasks
job = server.create('job', {
groupsCount: 1,
withGroupServices: true,
createAllocations: false,
});
allocation = server.create('allocation', 'withTaskWithPorts', {
clientStatus: 'running',
jobId: job.id,
});
const taskState = allocation.taskStates.models.sortBy('name')[0];
const task = server.schema.tasks.findBy({ name: taskState.name });
task.update('kind', 'connect-proxy:task');
task.save();
await Allocation.visit({ id: allocation.id });
assert.ok(Allocation.tasks[0].hasProxyTag);
});
test('when there are no tasks, an empty state is shown', async function (assert) {
// Make sure the allocation is pending in order to ensure there are no tasks
allocation = server.create('allocation', 'withTaskWithPorts', {
clientStatus: 'pending',
});
await Allocation.visit({ id: allocation.id });
assert.ok(Allocation.isEmpty, 'Task table empty state is shown');
});
test('when the allocation has not been rescheduled, the reschedule events section is not rendered', async function (assert) {
assert.notOk(
Allocation.hasRescheduleEvents,
'Reschedule Events section exists'
);
});
test('ports are listed', async function (assert) {
const allServerPorts = allocation.taskResources.models[0].resources.Ports;
allServerPorts.sortBy('Label').forEach((serverPort, index) => {
const renderedPort = Allocation.ports[index];
assert.equal(renderedPort.name, serverPort.Label);
assert.equal(renderedPort.to, serverPort.To);
assert.equal(
renderedPort.address,
formatHost(serverPort.HostIP, serverPort.Value)
);
});
});
test('services are listed', async function (assert) {
const taskGroup = server.schema.taskGroups.findBy({
name: allocation.taskGroup,
});
assert.equal(Allocation.services.length, taskGroup.services.length);
taskGroup.services.models.sortBy('name').forEach((serverService, index) => {
const renderedService = Allocation.services[index];
assert.equal(renderedService.name, serverService.name);
assert.equal(renderedService.port, serverService.portLabel);
assert.equal(renderedService.onUpdate, serverService.onUpdate);
assert.equal(renderedService.tags, (serverService.tags || []).join(', '));
assert.equal(
renderedService.connect,
serverService.Connect ? 'Yes' : 'No'
);
const upstreams = serverService.Connect.SidecarService.Proxy.Upstreams;
const serverUpstreamsString = upstreams
.map(
(upstream) => `${upstream.DestinationName}:${upstream.LocalBindPort}`
)
.join(' ');
assert.equal(renderedService.upstreams, serverUpstreamsString);
});
});
test('when the allocation is not found, an error message is shown, but the URL persists', async function (assert) {
await Allocation.visit({ id: 'not-a-real-allocation' });
assert.equal(
server.pretender.handledRequests
.filter((request) => !request.url.includes('policy'))
.findBy('status', 404).url,
'/v1/allocation/not-a-real-allocation',
'A request to the nonexistent allocation is made'
);
assert.equal(
currentURL(),
'/allocations/not-a-real-allocation',
'The URL persists'
);
assert.ok(Allocation.error.isShown, 'Error message is shown');
assert.equal(
Allocation.error.title,
'Not Found',
'Error message is for 404'
);
});
test('allocation can be stopped', async function (assert) {
await Allocation.stop.idle();
await Allocation.stop.confirm();
assert.equal(
server.pretender.handledRequests
.reject((request) => request.url.includes('fuzzy'))
.findBy('method', 'POST').url,
`/v1/allocation/${allocation.id}/stop`,
'Stop request is made for the allocation'
);
});
test('allocation can be restarted', async function (assert) {
await Allocation.restart.idle();
await Allocation.restart.confirm();
assert.equal(
server.pretender.handledRequests.findBy('method', 'PUT').url,
`/v1/client/allocation/${allocation.id}/restart`,
'Restart request is made for the allocation'
);
});
test('while an allocation is being restarted, the stop button is disabled', async function (assert) {
server.pretender.post('/v1/allocation/:id/stop', () => [204, {}, ''], true);
await Allocation.stop.idle();
run.later(() => {
assert.ok(Allocation.stop.isRunning, 'Stop is loading');
assert.ok(Allocation.restart.isDisabled, 'Restart is disabled');
server.pretender.resolve(server.pretender.requestReferences[0].request);
}, 500);
await Allocation.stop.confirm();
});
test('if stopping or restarting fails, an error message is shown', async function (assert) {
server.pretender.post('/v1/allocation/:id/stop', () => [403, {}, '']);
await Allocation.stop.idle();
await Allocation.stop.confirm();
assert.ok(Allocation.inlineError.isShown, 'Inline error is shown');
assert.ok(
Allocation.inlineError.title.includes('Could Not Stop Allocation'),
'Title is descriptive'
);
assert.ok(
/ACL token.+?allocation lifecycle/.test(Allocation.inlineError.message),
'Message mentions ACLs and the appropriate permission'
);
await Allocation.inlineError.dismiss();
assert.notOk(
Allocation.inlineError.isShown,
'Inline error is no longer shown'
);
});
});
module('Acceptance | allocation detail (rescheduled)', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
hooks.beforeEach(async function () {
server.create('agent');
node = server.create('node');
job = server.create('job', { createAllocations: false });
allocation = server.create('allocation', 'rescheduled');
await Allocation.visit({ id: allocation.id });
});
test('when the allocation has been rescheduled, the reschedule events section is rendered', async function (assert) {
assert.ok(
Allocation.hasRescheduleEvents,
'Reschedule Events section exists'
);
});
});
module('Acceptance | allocation detail (not running)', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
hooks.beforeEach(async function () {
server.create('agent');
node = server.create('node');
job = server.create('job', { createAllocations: false });
allocation = server.create('allocation', { clientStatus: 'pending' });
await Allocation.visit({ id: allocation.id });
});
test('when the allocation is not running, the utilization graphs are replaced by an empty message', async function (assert) {
assert.equal(Allocation.resourceCharts.length, 0, 'No resource charts');
assert.equal(
Allocation.resourceEmptyMessage,
"Allocation isn't running",
'Empty message is appropriate'
);
});
test('the exec and stop/restart buttons are absent', async function (assert) {
assert.notOk(Allocation.execButton.isPresent);
assert.notOk(Allocation.stop.isPresent);
assert.notOk(Allocation.restart.isPresent);
});
});
module('Acceptance | allocation detail (preemptions)', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
hooks.beforeEach(async function () {
server.create('agent');
node = server.create('node');
job = server.create('job', { createAllocations: false });
});
test('shows a dedicated section to the allocation that preempted this allocation', async function (assert) {
allocation = server.create('allocation', 'preempted');
const preempter = server.schema.find(
'allocation',
allocation.preemptedByAllocation
);
const preempterJob = server.schema.find('job', preempter.jobId);
const preempterClient = server.schema.find('node', preempter.nodeId);
await Allocation.visit({ id: allocation.id });
assert.ok(Allocation.wasPreempted, 'Preempted allocation section is shown');
assert.equal(
Allocation.preempter.status,
preempter.clientStatus,
'Preempter status matches'
);
assert.equal(
Allocation.preempter.name,
preempter.name,
'Preempter name matches'
);
assert.equal(
Allocation.preempter.priority,
preempterJob.priority,
'Preempter priority matches'
);
await Allocation.preempter.visit();
assert.equal(
currentURL(),
`/allocations/${preempter.id}`,
'Clicking the preempter id navigates to the preempter allocation detail page'
);
await Allocation.visit({ id: allocation.id });
await Allocation.preempter.visitJob();
assert.equal(
currentURL(),
`/jobs/${preempterJob.id}@default`,
'Clicking the preempter job link navigates to the preempter job page'
);
await Allocation.visit({ id: allocation.id });
await Allocation.preempter.visitClient();
assert.equal(
currentURL(),
`/clients/${preempterClient.id}`,
'Clicking the preempter client link navigates to the preempter client page'
);
});
test('shows a dedicated section to the allocations this allocation preempted', async function (assert) {
allocation = server.create('allocation', 'preempter');
await Allocation.visit({ id: allocation.id });
assert.ok(
Allocation.preempted,
'The allocations this allocation preempted are shown'
);
});
test('each preempted allocation in the table lists basic allocation information', async function (assert) {
allocation = server.create('allocation', 'preempter');
await Allocation.visit({ id: allocation.id });
const preemption = allocation.preemptedAllocations
.map((id) => server.schema.find('allocation', id))
.sortBy('modifyIndex')
.reverse()[0];
const preemptionRow = Allocation.preemptions.objectAt(0);
assert.equal(
Allocation.preemptions.length,
allocation.preemptedAllocations.length,
'The preemptions table has a row for each preempted allocation'
);
assert.equal(
preemptionRow.shortId,
preemption.id.split('-')[0],
'Preemption short id'
);
assert.equal(
preemptionRow.createTime,
moment(preemption.createTime / 1000000).format('MMM DD HH:mm:ss ZZ'),
'Preemption create time'
);
assert.equal(
preemptionRow.modifyTime,
moment(preemption.modifyTime / 1000000).fromNow(),
'Preemption modify time'
);
assert.equal(
preemptionRow.status,
preemption.clientStatus,
'Client status'
);
assert.equal(
preemptionRow.jobVersion,
preemption.jobVersion,
'Job Version'
);
assert.equal(
preemptionRow.client,
server.db.nodes.find(preemption.nodeId).id.split('-')[0],
'Node ID'
);
await preemptionRow.visitClient();
assert.equal(
currentURL(),
`/clients/${preemption.nodeId}`,
'Node links to node page'
);
});
test('when an allocation both preempted allocations and was preempted itself, both preemptions sections are shown', async function (assert) {
allocation = server.create('allocation', 'preempter', 'preempted');
await Allocation.visit({ id: allocation.id });
assert.ok(
Allocation.preempted,
'The allocations this allocation preempted are shown'
);
assert.ok(Allocation.wasPreempted, 'Preempted allocation section is shown');
});
});