2017-09-26 07:47:16 +00:00
|
|
|
import Ember from 'ember';
|
|
|
|
import { click, find, findAll, currentURL, visit } from 'ember-native-dom-helpers';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { test } from 'qunit';
|
|
|
|
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
|
2017-10-17 01:47:25 +00:00
|
|
|
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-09-26 07:47:16 +00:00
|
|
|
const { $ } = Ember;
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
let node;
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | client detail', {
|
|
|
|
beforeEach() {
|
|
|
|
server.create('node', 'forceIPv4');
|
|
|
|
node = server.db.nodes[0];
|
|
|
|
|
|
|
|
// Related models
|
|
|
|
server.create('agent');
|
|
|
|
server.create('job', { createAllocations: false });
|
|
|
|
server.createList('allocation', 3, { nodeId: node.id });
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
test('/clients/:id should have a breadrcumb trail linking back to clients', function(assert) {
|
|
|
|
visit(`/clients/${node.id}`);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-28 01:13:33 +00:00
|
|
|
assert.equal(findAll('.breadcrumb')[0].textContent, 'Clients', 'First breadcrumb says clients');
|
2017-10-06 03:11:17 +00:00
|
|
|
assert.equal(
|
|
|
|
findAll('.breadcrumb')[1].textContent,
|
|
|
|
node.id.split('-')[0],
|
|
|
|
'Second breadcrumb says the node short id'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
click(findAll('.breadcrumb')[0]);
|
|
|
|
});
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
andThen(() => {
|
2017-10-28 01:23:41 +00:00
|
|
|
assert.equal(currentURL(), '/clients', 'First breadcrumb links back to clients');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
test('/clients/:id should list immediate details for the node in the title', function(assert) {
|
|
|
|
visit(`/clients/${node.id}`);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.ok(find('.title').textContent.includes(node.name), 'Title includes name');
|
|
|
|
assert.ok(find('.title').textContent.includes(node.id), 'Title includes id');
|
|
|
|
assert.ok(
|
|
|
|
findAll(`.title .node-status-light.${node.status}`).length,
|
|
|
|
'Title includes status light'
|
|
|
|
);
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
test('/clients/:id should list additional detail for the node below the title', function(assert) {
|
|
|
|
visit(`/clients/${node.id}`);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
findAll('.inline-definitions .pair')[0].textContent,
|
|
|
|
`Status ${node.status}`,
|
|
|
|
'Status is in additional details'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
$('.inline-definitions .pair:eq(0) .status-text').hasClass(`node-${node.status}`),
|
|
|
|
'Status is decorated with a status class'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
findAll('.inline-definitions .pair')[1].textContent,
|
|
|
|
`Address ${node.httpAddr}`,
|
|
|
|
'Address is in additional detals'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
findAll('.inline-definitions .pair')[2].textContent,
|
|
|
|
`Datacenter ${node.datacenter}`,
|
|
|
|
'Datacenter is in additional details'
|
|
|
|
);
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
test('/clients/:id should list all allocations on the node', function(assert) {
|
2017-09-19 14:47:10 +00:00
|
|
|
const allocationsCount = server.db.allocations.where({ nodeId: node.id }).length;
|
2017-10-06 03:11:17 +00:00
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit(`/clients/${node.id}`);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
findAll('.allocations tbody tr').length,
|
|
|
|
allocationsCount,
|
|
|
|
`Allocations table lists all ${allocationsCount} associated allocations`
|
|
|
|
);
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('each allocation should have high-level details for the allocation', function(assert) {
|
|
|
|
const allocation = server.db.allocations
|
|
|
|
.where({ nodeId: node.id })
|
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse()[0];
|
|
|
|
|
|
|
|
const allocStats = server.db.clientAllocationStats.find(allocation.id);
|
|
|
|
const taskGroup = server.db.taskGroups.findBy({
|
|
|
|
name: allocation.taskGroup,
|
|
|
|
jobId: allocation.jobId,
|
|
|
|
});
|
|
|
|
|
|
|
|
const tasks = taskGroup.taskIds.map(id => server.db.tasks.find(id));
|
2017-10-17 01:47:25 +00:00
|
|
|
const cpuUsed = tasks.reduce((sum, task) => sum + task.Resources.CPU, 0);
|
|
|
|
const memoryUsed = tasks.reduce((sum, task) => sum + task.Resources.MemoryMB, 0);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit(`/clients/${node.id}`);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const allocationRow = $(findAll('.allocations tbody tr')[0]);
|
|
|
|
assert.equal(
|
|
|
|
allocationRow
|
|
|
|
.find('td:eq(0)')
|
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
allocation.id.split('-')[0],
|
|
|
|
'Allocation short ID'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
allocationRow
|
|
|
|
.find('td:eq(1)')
|
|
|
|
.text()
|
|
|
|
.trim(),
|
2017-10-18 02:19:02 +00:00
|
|
|
allocation.modifyIndex,
|
|
|
|
'Allocation modify index'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
allocationRow
|
|
|
|
.find('td:eq(2)')
|
|
|
|
.text()
|
|
|
|
.trim(),
|
2017-10-06 03:11:17 +00:00
|
|
|
allocation.name,
|
|
|
|
'Allocation name'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
allocationRow
|
2017-10-18 02:19:02 +00:00
|
|
|
.find('td:eq(3)')
|
2017-10-06 03:11:17 +00:00
|
|
|
.text()
|
|
|
|
.trim(),
|
|
|
|
allocation.clientStatus,
|
|
|
|
'Client status'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
allocationRow
|
2017-10-18 02:19:02 +00:00
|
|
|
.find('td:eq(4)')
|
2017-10-06 03:11:17 +00:00
|
|
|
.text()
|
|
|
|
.includes(server.db.jobs.find(allocation.jobId).name),
|
|
|
|
'Job name'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
allocationRow
|
2017-10-18 02:19:02 +00:00
|
|
|
.find('td:eq(4) .is-faded')
|
2017-10-06 03:11:17 +00:00
|
|
|
.text()
|
|
|
|
.includes(allocation.taskGroup),
|
|
|
|
'Task group name'
|
|
|
|
);
|
2017-10-18 19:29:33 +00:00
|
|
|
assert.ok(
|
2017-10-06 03:11:17 +00:00
|
|
|
allocationRow
|
2017-10-18 02:19:02 +00:00
|
|
|
.find('td:eq(5)')
|
2017-10-06 03:11:17 +00:00
|
|
|
.text()
|
2017-10-18 19:29:33 +00:00
|
|
|
.includes(allocation.jobVersion),
|
|
|
|
'Job Version'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
allocationRow
|
|
|
|
.find('td:eq(6)')
|
|
|
|
.text()
|
2017-10-06 03:11:17 +00:00
|
|
|
.trim(),
|
2017-10-19 17:43:33 +00:00
|
|
|
Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed,
|
2017-10-06 03:11:17 +00:00
|
|
|
'CPU %'
|
|
|
|
);
|
2017-10-17 01:47:25 +00:00
|
|
|
assert.equal(
|
2017-10-18 19:29:33 +00:00
|
|
|
allocationRow.find('td:eq(6) .tooltip').attr('aria-label'),
|
2017-10-17 01:47:25 +00:00
|
|
|
`${Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks)} / ${cpuUsed} MHz`,
|
|
|
|
'Detailed CPU information is in a tooltip'
|
|
|
|
);
|
2017-10-06 03:11:17 +00:00
|
|
|
assert.equal(
|
|
|
|
allocationRow
|
2017-10-18 19:29:33 +00:00
|
|
|
.find('td:eq(7)')
|
2017-10-06 03:11:17 +00:00
|
|
|
.text()
|
|
|
|
.trim(),
|
2017-10-17 01:47:25 +00:00
|
|
|
allocStats.resourceUsage.MemoryStats.RSS / 1024 / 1024 / memoryUsed,
|
2017-10-06 03:11:17 +00:00
|
|
|
'Memory used'
|
|
|
|
);
|
2017-10-17 01:47:25 +00:00
|
|
|
assert.equal(
|
2017-10-18 19:29:33 +00:00
|
|
|
allocationRow.find('td:eq(7) .tooltip').attr('aria-label'),
|
2017-10-17 01:47:25 +00:00
|
|
|
`${formatBytes([allocStats.resourceUsage.MemoryStats.RSS])} / ${memoryUsed} MiB`,
|
|
|
|
'Detailed memory information is in a tooltip'
|
|
|
|
);
|
2017-10-06 03:11:17 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each allocation should show job information even if the job is incomplete and already in the store', function(
|
|
|
|
assert
|
|
|
|
) {
|
2017-10-28 01:23:41 +00:00
|
|
|
// First, visit clients to load the allocations for each visible node.
|
2017-10-06 03:11:17 +00:00
|
|
|
// Don't load the job belongsTo of the allocation! Leave it unfulfilled.
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit('/clients');
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
// Then, visit jobs to load all jobs, which should implicitly fulfill
|
|
|
|
// the job belongsTo of each allocation pointed at each job.
|
|
|
|
|
|
|
|
visit('/jobs');
|
|
|
|
|
|
|
|
// Finally, visit a node to assert that the job name and task group name are
|
|
|
|
// present. This will require reloading the job, since task groups aren't a
|
|
|
|
// part of the jobs list response.
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit(`/clients/${node.id}`);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const allocationRow = $(findAll('.allocations tbody tr')[0]);
|
|
|
|
const allocation = server.db.allocations
|
|
|
|
.where({ nodeId: node.id })
|
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse()[0];
|
|
|
|
|
|
|
|
assert.ok(
|
|
|
|
allocationRow
|
2017-10-18 02:19:02 +00:00
|
|
|
.find('td:eq(4)')
|
2017-10-06 03:11:17 +00:00
|
|
|
.text()
|
|
|
|
.includes(server.db.jobs.find(allocation.jobId).name),
|
|
|
|
'Job name'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
allocationRow
|
2017-10-18 02:19:02 +00:00
|
|
|
.find('td:eq(4) .is-faded')
|
2017-10-06 03:11:17 +00:00
|
|
|
.text()
|
|
|
|
.includes(allocation.taskGroup),
|
|
|
|
'Task group name'
|
|
|
|
);
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('each allocation should link to the allocation detail page', function(assert) {
|
|
|
|
const allocation = server.db.allocations
|
|
|
|
.where({ nodeId: node.id })
|
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse()[0];
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
visit(`/clients/${node.id}`);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
click($('.allocations tbody tr:eq(0) td:eq(0) a').get(0));
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/allocations/${allocation.id}`,
|
|
|
|
'Allocation rows link to allocation detail pages'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each allocation should link to the job the allocation belongs to', function(assert) {
|
2017-10-28 01:23:41 +00:00
|
|
|
visit(`/clients/${node.id}`);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
const allocation = server.db.allocations.where({ nodeId: node.id })[0];
|
|
|
|
const job = server.db.jobs.find(allocation.jobId);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-18 02:19:02 +00:00
|
|
|
click($('.allocations tbody tr:eq(0) td:eq(4) a').get(0));
|
2017-10-06 03:11:17 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
currentURL(),
|
|
|
|
`/jobs/${job.id}`,
|
|
|
|
'Allocation rows link to the job detail page for the allocation'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-10-28 01:23:41 +00:00
|
|
|
test('/clients/:id should list all attributes for the node', function(assert) {
|
|
|
|
visit(`/clients/${node.id}`);
|
2017-10-06 03:11:17 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.ok(find('.attributes-table'), 'Attributes table is on the page');
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
2017-09-29 00:05:41 +00:00
|
|
|
|
|
|
|
test('when the node is not found, an error message is shown, but the URL persists', function(
|
|
|
|
assert
|
|
|
|
) {
|
2017-10-28 01:23:41 +00:00
|
|
|
visit('/clients/not-a-real-node');
|
2017-09-29 00:05:41 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
|
|
|
server.pretender.handledRequests.findBy('status', 404).url,
|
|
|
|
'/v1/node/not-a-real-node',
|
|
|
|
'A request to the non-existent node is made'
|
|
|
|
);
|
2017-10-28 01:23:41 +00:00
|
|
|
assert.equal(currentURL(), '/clients/not-a-real-node', 'The URL persists');
|
2017-09-29 00:05:41 +00:00
|
|
|
assert.ok(find('.error-message'), 'Error message is shown');
|
|
|
|
assert.equal(
|
|
|
|
find('.error-message .title').textContent,
|
|
|
|
'Not Found',
|
|
|
|
'Error message is for 404'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|