2023-04-10 15:36:59 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2021-12-28 19:30:38 +00:00
|
|
|
/* eslint-disable qunit/require-expect */
|
2020-04-05 00:13:40 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { currentURL } from '@ember/test-helpers';
|
2020-03-25 12:51:26 +00:00
|
|
|
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-04-05 00:13:40 +00:00
|
|
|
import moment from 'moment';
|
2021-03-29 23:16:48 +00:00
|
|
|
import { formatBytes, formatHertz } from 'nomad-ui/utils/units';
|
2020-04-05 00:13:40 +00:00
|
|
|
import VolumeDetail from 'nomad-ui/tests/pages/storage/volumes/detail';
|
2020-12-10 17:51:22 +00:00
|
|
|
import Layout from 'nomad-ui/tests/pages/layout';
|
2020-04-05 00:13:40 +00:00
|
|
|
|
|
|
|
const assignWriteAlloc = (volume, alloc) => {
|
|
|
|
volume.writeAllocs.add(alloc);
|
2020-11-25 21:44:06 +00:00
|
|
|
volume.allocations.add(alloc);
|
2020-04-05 00:13:40 +00:00
|
|
|
volume.save();
|
|
|
|
};
|
|
|
|
|
|
|
|
const assignReadAlloc = (volume, alloc) => {
|
|
|
|
volume.readAllocs.add(alloc);
|
2020-11-25 21:44:06 +00:00
|
|
|
volume.allocations.add(alloc);
|
2020-04-05 00:13:40 +00:00
|
|
|
volume.save();
|
|
|
|
};
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | volume detail', function (hooks) {
|
2020-03-25 12:51:26 +00:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
|
|
|
|
2020-04-05 00:13:40 +00:00
|
|
|
let volume;
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2020-04-05 00:13:40 +00:00
|
|
|
server.create('node');
|
|
|
|
server.create('csi-plugin', { createVolumes: false });
|
|
|
|
volume = server.create('csi-volume');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('it passes an accessibility audit', async function (assert) {
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/csi/volumes/:id should have a breadcrumb trail linking back to Volumes and Storage', async function (assert) {
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-04-05 00:13:40 +00:00
|
|
|
|
2020-12-10 17:51:22 +00:00
|
|
|
assert.equal(Layout.breadcrumbFor('csi.index').text, 'Storage');
|
|
|
|
assert.equal(Layout.breadcrumbFor('csi.volumes').text, 'Volumes');
|
|
|
|
assert.equal(Layout.breadcrumbFor('csi.volumes.volume').text, volume.name);
|
2020-04-05 00:13:40 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/csi/volumes/:id should show the volume name in the title', async function (assert) {
|
2022-01-19 16:20:00 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-04-05 00:13:40 +00:00
|
|
|
|
|
|
|
assert.equal(document.title, `CSI Volume ${volume.name} - Nomad`);
|
|
|
|
assert.equal(VolumeDetail.title, volume.name);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/csi/volumes/:id should list additional details for the volume below the title', async function (assert) {
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-04-05 00:13:40 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.ok(
|
|
|
|
VolumeDetail.health.includes(
|
|
|
|
volume.schedulable ? 'Schedulable' : 'Unschedulable'
|
|
|
|
)
|
|
|
|
);
|
2020-04-05 00:13:40 +00:00
|
|
|
assert.ok(VolumeDetail.provider.includes(volume.provider));
|
|
|
|
assert.ok(VolumeDetail.externalId.includes(volume.externalId));
|
|
|
|
assert.notOk(
|
|
|
|
VolumeDetail.hasNamespace,
|
|
|
|
'Namespace is omitted when there is only one namespace'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/csi/volumes/:id should list all write allocations the volume is attached to', async function (assert) {
|
2020-04-05 00:13:40 +00:00
|
|
|
const writeAllocations = server.createList('allocation', 2);
|
|
|
|
const readAllocations = server.createList('allocation', 3);
|
2021-12-28 14:45:20 +00:00
|
|
|
writeAllocations.forEach((alloc) => assignWriteAlloc(volume, alloc));
|
|
|
|
readAllocations.forEach((alloc) => assignReadAlloc(volume, alloc));
|
2020-04-05 00:13:40 +00:00
|
|
|
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-04-05 00:13:40 +00:00
|
|
|
|
|
|
|
assert.equal(VolumeDetail.writeAllocations.length, writeAllocations.length);
|
|
|
|
writeAllocations
|
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse()
|
|
|
|
.forEach((allocation, idx) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
allocation.id,
|
|
|
|
VolumeDetail.writeAllocations.objectAt(idx).id
|
|
|
|
);
|
2020-04-05 00:13:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/csi/volumes/:id should list all read allocations the volume is attached to', async function (assert) {
|
2020-04-05 00:13:40 +00:00
|
|
|
const writeAllocations = server.createList('allocation', 2);
|
|
|
|
const readAllocations = server.createList('allocation', 3);
|
2021-12-28 14:45:20 +00:00
|
|
|
writeAllocations.forEach((alloc) => assignWriteAlloc(volume, alloc));
|
|
|
|
readAllocations.forEach((alloc) => assignReadAlloc(volume, alloc));
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-04-05 00:13:40 +00:00
|
|
|
assert.equal(VolumeDetail.readAllocations.length, readAllocations.length);
|
|
|
|
readAllocations
|
|
|
|
.sortBy('modifyIndex')
|
|
|
|
.reverse()
|
|
|
|
.forEach((allocation, idx) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
allocation.id,
|
|
|
|
VolumeDetail.readAllocations.objectAt(idx).id
|
|
|
|
);
|
2020-04-05 00:13:40 +00:00
|
|
|
});
|
|
|
|
});
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('each allocation should have high-level details for the allocation', async function (assert) {
|
2020-04-05 00:13:40 +00:00
|
|
|
const allocation = server.create('allocation', { clientStatus: 'running' });
|
|
|
|
assignWriteAlloc(volume, allocation);
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-04-05 00:13:40 +00:00
|
|
|
const allocStats = server.db.clientAllocationStats.find(allocation.id);
|
|
|
|
const taskGroup = server.db.taskGroups.findBy({
|
|
|
|
name: allocation.taskGroup,
|
|
|
|
jobId: allocation.jobId,
|
|
|
|
});
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
const tasks = taskGroup.taskIds.map((id) => server.db.tasks.find(id));
|
2020-10-12 22:26:54 +00:00
|
|
|
const cpuUsed = tasks.reduce((sum, task) => sum + task.resources.CPU, 0);
|
2021-12-28 16:08:12 +00:00
|
|
|
const memoryUsed = tasks.reduce(
|
|
|
|
(sum, task) => sum + task.resources.MemoryMB,
|
|
|
|
0
|
|
|
|
);
|
2020-04-05 00:13:40 +00:00
|
|
|
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-04-05 00:13:40 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
VolumeDetail.writeAllocations.objectAt(0).as((allocationRow) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
allocationRow.shortId,
|
|
|
|
allocation.id.split('-')[0],
|
|
|
|
'Allocation short ID'
|
|
|
|
);
|
2020-04-05 00:13:40 +00:00
|
|
|
assert.equal(
|
|
|
|
allocationRow.createTime,
|
|
|
|
moment(allocation.createTime / 1000000).format('MMM DD HH:mm:ss ZZ'),
|
|
|
|
'Allocation create time'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
allocationRow.modifyTime,
|
|
|
|
moment(allocation.modifyTime / 1000000).fromNow(),
|
|
|
|
'Allocation modify time'
|
|
|
|
);
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
allocationRow.status,
|
|
|
|
allocation.clientStatus,
|
|
|
|
'Client status'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
allocationRow.job,
|
|
|
|
server.db.jobs.find(allocation.jobId).name,
|
|
|
|
'Job name'
|
|
|
|
);
|
2020-04-05 00:13:40 +00:00
|
|
|
assert.ok(allocationRow.taskGroup, 'Task group name');
|
|
|
|
assert.ok(allocationRow.jobVersion, 'Job Version');
|
|
|
|
assert.equal(
|
|
|
|
allocationRow.client,
|
|
|
|
server.db.nodes.find(allocation.nodeId).id.split('-')[0],
|
|
|
|
'Node ID'
|
|
|
|
);
|
2021-10-21 17:12:33 +00:00
|
|
|
assert.equal(
|
|
|
|
allocationRow.clientTooltip.substr(0, 15),
|
|
|
|
server.db.nodes.find(allocation.nodeId).name.substr(0, 15),
|
|
|
|
'Node Name'
|
|
|
|
);
|
2020-04-05 00:13:40 +00:00
|
|
|
assert.equal(
|
|
|
|
allocationRow.cpu,
|
|
|
|
Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed,
|
|
|
|
'CPU %'
|
|
|
|
);
|
2021-12-28 16:08:12 +00:00
|
|
|
const roundedTicks = Math.floor(
|
|
|
|
allocStats.resourceUsage.CpuStats.TotalTicks
|
|
|
|
);
|
2020-04-05 00:13:40 +00:00
|
|
|
assert.equal(
|
|
|
|
allocationRow.cpuTooltip,
|
2021-03-29 23:16:48 +00:00
|
|
|
`${formatHertz(roundedTicks, 'MHz')} / ${formatHertz(cpuUsed, 'MHz')}`,
|
2020-04-05 00:13:40 +00:00
|
|
|
'Detailed CPU information is in a tooltip'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
allocationRow.mem,
|
|
|
|
allocStats.resourceUsage.MemoryStats.RSS / 1024 / 1024 / memoryUsed,
|
|
|
|
'Memory used'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
allocationRow.memTooltip,
|
2021-12-28 16:08:12 +00:00
|
|
|
`${formatBytes(
|
|
|
|
allocStats.resourceUsage.MemoryStats.RSS
|
|
|
|
)} / ${formatBytes(memoryUsed, 'MiB')}`,
|
2020-04-05 00:13:40 +00:00
|
|
|
'Detailed memory information is in a tooltip'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('each allocation should link to the allocation detail page', async function (assert) {
|
2020-04-05 00:13:40 +00:00
|
|
|
const allocation = server.create('allocation');
|
|
|
|
assignWriteAlloc(volume, allocation);
|
|
|
|
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-04-05 00:13:40 +00:00
|
|
|
await VolumeDetail.writeAllocations.objectAt(0).visit();
|
|
|
|
|
|
|
|
assert.equal(currentURL(), `/allocations/${allocation.id}`);
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when there are no write allocations, the table presents an empty state', async function (assert) {
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-04-05 00:13:40 +00:00
|
|
|
|
|
|
|
assert.ok(VolumeDetail.writeTableIsEmpty);
|
|
|
|
assert.equal(VolumeDetail.writeEmptyState.headline, 'No Write Allocations');
|
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('when there are no read allocations, the table presents an empty state', async function (assert) {
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-04-05 00:13:40 +00:00
|
|
|
|
|
|
|
assert.ok(VolumeDetail.readTableIsEmpty);
|
|
|
|
assert.equal(VolumeDetail.readEmptyState.headline, 'No Read Allocations');
|
|
|
|
});
|
2020-05-02 05:26:19 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('the constraints table shows access mode and attachment mode', async function (assert) {
|
2022-02-10 15:55:32 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@default` });
|
2020-05-02 05:26:19 +00:00
|
|
|
|
|
|
|
assert.equal(VolumeDetail.constraints.accessMode, volume.accessMode);
|
2021-12-28 16:08:12 +00:00
|
|
|
assert.equal(
|
|
|
|
VolumeDetail.constraints.attachmentMode,
|
|
|
|
volume.attachmentMode
|
|
|
|
);
|
2020-05-02 05:26:19 +00:00
|
|
|
});
|
2020-04-05 00:13:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Namespace test: details shows the namespace
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Acceptance | volume detail (with namespaces)', function (hooks) {
|
2020-04-05 00:13:40 +00:00
|
|
|
setupApplicationTest(hooks);
|
|
|
|
setupMirage(hooks);
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-04-05 00:13:40 +00:00
|
|
|
let volume;
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2020-04-05 00:13:40 +00:00
|
|
|
server.createList('namespace', 2);
|
|
|
|
server.create('node');
|
|
|
|
server.create('csi-plugin', { createVolumes: false });
|
|
|
|
volume = server.create('csi-volume');
|
|
|
|
});
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('/csi/volumes/:id detail ribbon includes the namespace of the volume', async function (assert) {
|
2022-02-17 14:20:11 +00:00
|
|
|
await VolumeDetail.visit({ id: `${volume.id}@${volume.namespaceId}` });
|
2020-03-25 12:51:26 +00:00
|
|
|
|
2020-04-05 00:13:40 +00:00
|
|
|
assert.ok(VolumeDetail.hasNamespace);
|
|
|
|
assert.ok(VolumeDetail.namespace.includes(volume.namespaceId || 'default'));
|
|
|
|
});
|
2020-03-25 12:51:26 +00:00
|
|
|
});
|