open-nomad/ui/tests/acceptance/client-detail-test.js

576 lines
18 KiB
JavaScript
Raw Normal View History

import { assign } from '@ember/polyfills';
2018-07-11 19:35:39 +00:00
import { currentURL } 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';
import formatDuration from 'nomad-ui/utils/format-duration';
2017-11-30 23:08:31 +00:00
import moment from 'moment';
2018-07-10 18:28:52 +00:00
import ClientDetail from 'nomad-ui/tests/pages/clients/detail';
import Clients from 'nomad-ui/tests/pages/clients/list';
2018-07-11 19:35:39 +00:00
import Jobs from 'nomad-ui/tests/pages/jobs/list';
2017-09-19 14:47:10 +00:00
let node;
moduleForAcceptance('Acceptance | client detail', {
beforeEach() {
server.create('node', 'forceIPv4', { schedulingEligibility: 'eligible' });
2017-09-19 14:47:10 +00:00
node = server.db.nodes[0];
// Related models
server.create('agent');
server.create('job', { createAllocations: false });
server.createList('allocation', 3, { nodeId: node.id });
},
});
2018-03-11 17:44:27 +00:00
test('/clients/:id should have a breadcrumb trail linking back to clients', function(assert) {
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
assert.equal(
2018-07-10 18:28:52 +00:00
ClientDetail.breadcrumbFor('clients.index').text,
'Clients',
'First breadcrumb says clients'
);
assert.equal(
2018-07-10 18:28:52 +00:00
ClientDetail.breadcrumbFor('clients.client').text,
node.id.split('-')[0],
'Second breadcrumb says the node short id'
);
});
andThen(() => {
2018-07-10 18:28:52 +00:00
ClientDetail.breadcrumbFor('clients.index').visit();
});
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) {
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
assert.ok(ClientDetail.title.includes(node.name), 'Title includes name');
assert.ok(ClientDetail.title.includes(node.id), 'Title includes id');
assert.equal(
ClientDetail.statusLight.objectAt(0).id,
node.status,
'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) {
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.statusDefinition.includes(node.status),
'Status is in additional details'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.statusDecorationClass.includes(`node-${node.status}`),
'Status is decorated with a status class'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.addressDefinition.includes(node.httpAddr),
2018-03-11 17:54:56 +00:00
'Address is in additional details'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.drainingDefinition.includes(node.drain + ''),
'Drain status is in additional details'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.eligibilityDefinition.includes(node.schedulingEligibility),
'Scheduling eligibility is in additional details'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.datacenterDefinition.includes(node.datacenter),
'Datacenter is in additional details'
);
});
2017-09-19 14:47:10 +00:00
});
test('/clients/:id should include resource utilization graphs', function(assert) {
ClientDetail.visit({ id: node.id });
andThen(() => {
assert.equal(ClientDetail.resourceCharts.length, 2, 'Two resource utilization graphs');
assert.equal(ClientDetail.resourceCharts.objectAt(0).name, 'CPU', 'First chart is CPU');
assert.equal(ClientDetail.resourceCharts.objectAt(1).name, 'Memory', 'Second chart is Memory');
});
});
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;
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
assert.equal(
2018-07-10 18:28:52 +00:00
ClientDetail.allocations.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
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
const allocationRow = ClientDetail.allocations.objectAt(0);
assert.equal(allocationRow.shortId, allocation.id.split('-')[0], 'Allocation short ID');
assert.equal(
allocationRow.createTime,
moment(allocation.createTime / 1000000).format('MM/DD HH:mm:ss'),
'Allocation create time'
);
assert.equal(
2018-07-10 18:28:52 +00:00
allocationRow.modifyTime,
moment(allocation.modifyTime / 1000000).fromNow(),
2017-11-30 23:08:31 +00:00
'Allocation modify time'
);
2018-07-10 18:28:52 +00:00
assert.equal(allocationRow.status, allocation.clientStatus, 'Client status');
assert.equal(allocationRow.job, server.db.jobs.find(allocation.jobId).name, 'Job name');
assert.ok(allocationRow.taskGroup, 'Task group name');
assert.ok(allocationRow.jobVersion, 'Job Version');
assert.equal(
2018-07-10 18:28:52 +00:00
allocationRow.cpu,
Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed,
'CPU %'
);
2017-10-17 01:47:25 +00:00
assert.equal(
2018-07-10 18:28:52 +00:00
allocationRow.cpuTooltip,
2017-10-17 01:47:25 +00:00
`${Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks)} / ${cpuUsed} MHz`,
'Detailed CPU information is in a tooltip'
);
assert.equal(
2018-07-10 18:28:52 +00:00
allocationRow.mem,
2017-10-17 01:47:25 +00:00
allocStats.resourceUsage.MemoryStats.RSS / 1024 / 1024 / memoryUsed,
'Memory used'
);
2017-10-17 01:47:25 +00:00
assert.equal(
2018-07-10 18:28:52 +00:00
allocationRow.memTooltip,
2017-10-17 01:47:25 +00:00
`${formatBytes([allocStats.resourceUsage.MemoryStats.RSS])} / ${memoryUsed} MiB`,
'Detailed memory information is in a tooltip'
);
});
});
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.
// Don't load the job belongsTo of the allocation! Leave it unfulfilled.
2018-07-10 18:28:52 +00:00
Clients.visit();
// Then, visit jobs to load all jobs, which should implicitly fulfill
// the job belongsTo of each allocation pointed at each job.
2018-07-11 19:35:39 +00:00
Jobs.visit();
// 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.
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
const allocationRow = ClientDetail.allocations.objectAt(0);
const allocation = server.db.allocations
.where({ nodeId: node.id })
.sortBy('modifyIndex')
.reverse()[0];
2018-07-10 18:28:52 +00:00
assert.equal(allocationRow.job, server.db.jobs.find(allocation.jobId).name, 'Job name');
assert.ok(allocationRow.taskGroup.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];
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
ClientDetail.allocations.objectAt(0).visit();
});
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) {
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
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);
andThen(() => {
2018-07-10 18:28:52 +00:00
ClientDetail.allocations.objectAt(0).visitJob();
});
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) {
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
assert.ok(ClientDetail.attributesTable, 'Attributes table is on the page');
});
2017-09-19 14:47:10 +00:00
});
2017-09-29 00:05:41 +00:00
test('/clients/:id lists all meta attributes', function(assert) {
node = server.create('node', 'forceIPv4', 'withMeta');
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
assert.ok(ClientDetail.metaTable, 'Meta attributes table is on the page');
assert.notOk(ClientDetail.emptyMetaMessage, 'Meta attributes is not empty');
2018-02-27 00:35:41 +00:00
const firstMetaKey = Object.keys(node.meta)[0];
2018-07-10 18:28:52 +00:00
const firstMetaAttribute = ClientDetail.metaAttributes.objectAt(0);
2018-02-27 00:35:41 +00:00
assert.equal(
2018-07-10 18:28:52 +00:00
firstMetaAttribute.key,
2018-02-27 00:35:41 +00:00
firstMetaKey,
'Meta attributes for the node are bound to the attributes table'
);
assert.equal(
2018-07-10 18:28:52 +00:00
firstMetaAttribute.value,
2018-02-27 00:35:41 +00:00
node.meta[firstMetaKey],
'Meta attributes for the node are bound to the attributes table'
);
});
});
test('/clients/:id shows an empty message when there is no meta data', function(assert) {
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
assert.notOk(ClientDetail.metaTable, 'Meta attributes table is not on the page');
assert.ok(ClientDetail.emptyMetaMessage, 'Meta attributes is empty');
});
});
test('when the node is not found, an error message is shown, but the URL persists', function(assert) {
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: '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 nonexistent node is made'
2017-09-29 00:05:41 +00:00
);
2017-10-28 01:23:41 +00:00
assert.equal(currentURL(), '/clients/not-a-real-node', 'The URL persists');
2018-07-10 18:28:52 +00:00
assert.ok(ClientDetail.error.isShown, 'Error message is shown');
assert.equal(ClientDetail.error.title, 'Not Found', 'Error message is for 404');
2017-09-29 00:05:41 +00:00
});
});
test('/clients/:id shows the recent events list', function(assert) {
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
assert.ok(ClientDetail.hasEvents, 'Client events section exists');
});
});
test('each node event shows basic node event information', function(assert) {
const event = server.db.nodeEvents
.where({ nodeId: node.id })
.sortBy('time')
.reverse()[0];
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
const eventRow = ClientDetail.events.objectAt(0);
assert.equal(eventRow.time, moment(event.time).format('MM/DD/YY HH:mm:ss'), 'Event timestamp');
assert.equal(eventRow.subsystem, event.subsystem, 'Event subsystem');
assert.equal(eventRow.message, event.message, 'Event message');
});
});
test('/clients/:id shows the driver status of every driver for the node', function(assert) {
// Set the drivers up so health and detection is well tested
const nodeDrivers = node.drivers;
const undetectedDriver = 'raw_exec';
Object.values(nodeDrivers).forEach(driver => {
driver.Detected = true;
});
nodeDrivers[undetectedDriver].Detected = false;
node.drivers = nodeDrivers;
const drivers = Object.keys(node.drivers)
.map(driverName => assign({ Name: driverName }, node.drivers[driverName]))
.sortBy('Name');
assert.ok(drivers.length > 0, 'Node has drivers');
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
drivers.forEach((driver, index) => {
2018-07-10 18:28:52 +00:00
const driverHead = ClientDetail.driverHeads.objectAt(index);
2018-07-10 18:28:52 +00:00
assert.equal(driverHead.name, driver.Name, `${driver.Name}: Name is correct`);
assert.equal(
2018-07-10 18:28:52 +00:00
driverHead.detected,
driver.Detected ? 'Yes' : 'No',
`${driver.Name}: Detection is correct`
);
assert.equal(
2018-07-10 18:28:52 +00:00
driverHead.lastUpdated,
moment(driver.UpdateTime).fromNow(),
`${driver.Name}: Last updated shows time since now`
);
if (driver.Name === undetectedDriver) {
assert.notOk(
2018-07-10 18:28:52 +00:00
driverHead.healthIsShown,
`${driver.Name}: No health for the undetected driver`
);
} else {
assert.equal(
2018-07-10 18:28:52 +00:00
driverHead.health,
driver.Healthy ? 'Healthy' : 'Unhealthy',
`${driver.Name}: Health is correct`
);
assert.ok(
2018-07-10 18:28:52 +00:00
driverHead.healthClass.includes(driver.Healthy ? 'running' : 'failed'),
`${driver.Name}: Swatch with correct class is shown`
);
}
});
});
});
test('each driver can be opened to see a message and attributes', function(assert) {
// Only detected drivers can be expanded
const nodeDrivers = node.drivers;
Object.values(nodeDrivers).forEach(driver => {
driver.Detected = true;
});
node.drivers = nodeDrivers;
const driver = Object.keys(node.drivers)
.map(driverName => assign({ Name: driverName }, node.drivers[driverName]))
.sortBy('Name')[0];
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
const driverHead = ClientDetail.driverHeads.objectAt(0);
const driverBody = ClientDetail.driverBodies.objectAt(0);
andThen(() => {
2018-07-10 18:28:52 +00:00
assert.notOk(driverBody.descriptionIsShown, 'Driver health description is not shown');
assert.notOk(driverBody.attributesAreShown, 'Driver attributes section is not shown');
driverHead.toggle();
});
andThen(() => {
assert.equal(
2018-07-10 18:28:52 +00:00
driverBody.description,
driver.HealthDescription,
'Driver health description is now shown'
);
2018-07-10 18:28:52 +00:00
assert.ok(driverBody.attributesAreShown, 'Driver attributes section is now shown');
});
});
test('the status light indicates when the node is ineligible for scheduling', function(assert) {
node = server.create('node', {
schedulingEligibility: 'ineligible',
});
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
assert.equal(
ClientDetail.statusLight.objectAt(0).id,
'ineligible',
'Title status light is in the ineligible state'
);
});
});
test('when the node has a drain strategy with a positive deadline, the drain stategy section prints the duration', function(assert) {
const deadline = 5400000000000; // 1.5 hours in nanoseconds
const forceDeadline = moment().add(1, 'd');
node = server.create('node', {
drain: true,
schedulingEligibility: 'ineligible',
drainStrategy: {
Deadline: deadline,
ForceDeadline: forceDeadline.toISOString(),
IgnoreSystemJobs: false,
},
});
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.drain.deadline.includes(formatDuration(deadline)),
'Deadline is shown in a human formatted way'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.drain.forcedDeadline.includes(forceDeadline.format('MM/DD/YY HH:mm:ss')),
'Force deadline is shown as an absolute date'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.drain.forcedDeadline.includes(forceDeadline.fromNow()),
'Force deadline is shown as a relative date'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.drain.ignoreSystemJobs.endsWith('No'),
'Ignore System Jobs state is shown'
);
});
});
test('when the node has a drain stategy with no deadline, the drain stategy section mentions that and omits the force deadline', function(assert) {
const deadline = 0;
node = server.create('node', {
drain: true,
schedulingEligibility: 'ineligible',
drainStrategy: {
Deadline: deadline,
ForceDeadline: '0001-01-01T00:00:00Z', // null as a date
IgnoreSystemJobs: true,
},
});
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.drain.deadline.includes('No deadline'),
'The value for Deadline is "no deadline"'
);
assert.notOk(
2018-07-10 18:28:52 +00:00
ClientDetail.drain.hasForcedDeadline,
'Forced deadline is not shown since there is no forced deadline'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.drain.ignoreSystemJobs.endsWith('Yes'),
'Ignore System Jobs state is shown'
);
});
});
test('when the node has a drain stategy with a negative deadline, the drain strategy section shows the force badge', function(assert) {
const deadline = -1;
node = server.create('node', {
drain: true,
schedulingEligibility: 'ineligible',
drainStrategy: {
Deadline: deadline,
ForceDeadline: '0001-01-01T00:00:00Z', // null as a date
IgnoreSystemJobs: false,
},
});
2018-07-10 18:28:52 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
2018-07-10 18:28:52 +00:00
assert.equal(ClientDetail.drain.badgeLabel, 'Forced Drain', 'Forced Drain badge is described');
assert.ok(ClientDetail.drain.badgeIsDangerous, 'Forced Drain is shown in a red badge');
assert.notOk(
2018-07-10 18:28:52 +00:00
ClientDetail.drain.hasForcedDeadline,
'Forced deadline is not shown since there is no forced deadline'
);
assert.ok(
2018-07-10 18:28:52 +00:00
ClientDetail.drain.ignoreSystemJobs.endsWith('No'),
'Ignore System Jobs state is shown'
);
});
});
moduleForAcceptance('Acceptance | client detail (multi-namespace)', {
beforeEach() {
server.create('node', 'forceIPv4', { schedulingEligibility: 'eligible' });
node = server.db.nodes[0];
// Related models
server.create('namespace');
server.create('namespace', { id: 'other-namespace' });
server.create('agent');
// Make a job for each namespace, but have both scheduled on the same node
server.create('job', { id: 'job-1', namespaceId: 'default', createAllocations: false });
server.createList('allocation', 3, { nodeId: node.id });
server.create('job', { id: 'job-2', namespaceId: 'other-namespace', createAllocations: false });
server.createList('allocation', 3, { nodeId: node.id, jobId: 'job-2' });
},
});
test('when the node has allocations on different namespaces, the associated jobs are fetched correctly', function(assert) {
window.localStorage.nomadActiveNamespace = 'other-namespace';
2018-07-11 19:35:39 +00:00
ClientDetail.visit({ id: node.id });
andThen(() => {
assert.equal(
2018-07-11 19:35:39 +00:00
ClientDetail.allocations.length,
server.db.allocations.length,
'All allocations are scheduled on this node'
);
assert.ok(
server.pretender.handledRequests.findBy('url', '/v1/job/job-1'),
'Job One fetched correctly'
);
assert.ok(
server.pretender.handledRequests.findBy('url', '/v1/job/job-2?namespace=other-namespace'),
'Job Two fetched correctly'
);
});
});