-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathdynamic-host-volume-detail-test.js
More file actions
266 lines (235 loc) · 8.61 KB
/
dynamic-host-volume-detail-test.js
File metadata and controls
266 lines (235 loc) · 8.61 KB
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
/**
* Copyright IBM Corp. 2015, 2025
* SPDX-License-Identifier: BUSL-1.1
*/
/* eslint-disable qunit/require-expect */
import { module, test } from 'qunit';
import { currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
import moment from 'moment';
import { formatBytes, formatHertz } from 'nomad-ui/utils/units';
import VolumeDetail from 'nomad-ui/tests/pages/storage/dynamic-host-volumes/detail';
import Layout from 'nomad-ui/tests/pages/layout';
import faker from 'nomad-ui/mirage/faker';
const assignAlloc = (volume, alloc) => {
volume.allocations.add(alloc);
volume.save();
};
module('Acceptance | dynamic host volume detail', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let volume;
hooks.beforeEach(function () {
faker.seed(1);
server.create('node-pool');
server.create('node');
server.create('job', {
name: 'dhv-job',
});
volume = server.create('dynamic-host-volume', {
nodeId: server.db.nodes[0].id,
});
});
test('it passes an accessibility audit', async function (assert) {
await VolumeDetail.visit({ id: `${volume.id}@default` });
await a11yAudit(assert);
});
test('/storage/volumes/:id should have a breadcrumb trail linking back to Volumes and Storage', async function (assert) {
await VolumeDetail.visit({ id: `${volume.id}@default` });
assert.equal(Layout.breadcrumbFor('storage.index').text, 'Storage');
assert.equal(
Layout.breadcrumbFor('storage.volumes.dynamic-host-volume').text,
volume.name
);
});
test('/storage/volumes/:id should show the volume name in the title', async function (assert) {
await VolumeDetail.visit({ id: `${volume.id}@default` });
assert.equal(document.title, `Dynamic Host Volume ${volume.name} - Nomad`);
assert.equal(VolumeDetail.title, volume.name);
});
test('/storage/volumes/:id should list additional details for the volume below the title', async function (assert) {
await VolumeDetail.visit({ id: `${volume.id}@default` });
assert.ok(VolumeDetail.node.includes(volume.node.name));
assert.ok(VolumeDetail.plugin.includes(volume.pluginID));
assert.notOk(
VolumeDetail.hasNamespace,
'Namespace is omitted when there is only one namespace'
);
assert.equal(VolumeDetail.capacity, 'Capacity 9.54 MiB');
});
test('/storage/volumes/:id should list all allocations the volume is attached to', async function (assert) {
// Use fixed timestamps so both absolute dates and relative times are
// deterministic across test runs.
const pinned = new Date('2025-06-15T12:00:00Z');
const pinnedNs = pinned.getTime() * 1e6; // nanoseconds
const allocations = [
server.create('allocation', {
createTime: pinnedNs - 9 * 3600e9,
modifyTime: pinnedNs - 9 * 3600e9,
}),
server.create('allocation', {
createTime: pinnedNs - 15 * 3600e9,
modifyTime: pinnedNs - 15 * 3600e9,
}),
server.create('allocation', {
createTime: pinnedNs - 1 * 3600e9,
modifyTime: pinnedNs - 1 * 3600e9,
}),
];
allocations.forEach((alloc) => assignAlloc(volume, alloc));
// Freeze moment's time reference so relative times ("9 hours ago") are
// deterministic across test runs.
const originalMomentNow = moment.now;
moment.now = () => pinned.getTime();
try {
await VolumeDetail.visit({ id: `${volume.id}@default` });
assert.equal(VolumeDetail.allocations.length, allocations.length);
allocations
.sortBy('modifyIndex')
.reverse()
.forEach((allocation, idx) => {
assert.equal(
allocation.id,
VolumeDetail.allocations.objectAt(idx).id
);
});
} finally {
moment.now = originalMomentNow;
}
});
test('each allocation should have high-level details for the allocation', async function (assert) {
const allocation = server.create('allocation', { clientStatus: 'running' });
assignAlloc(volume, allocation);
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));
const cpuUsed = tasks.reduce((sum, task) => sum + task.resources.CPU, 0);
const memoryUsed = tasks.reduce(
(sum, task) => sum + task.resources.MemoryMB,
0
);
await VolumeDetail.visit({ id: `${volume.id}@default` });
VolumeDetail.allocations.objectAt(0).as((allocationRow) => {
assert.equal(
allocationRow.shortId,
allocation.id.split('-')[0],
'Allocation short ID'
);
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'
);
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(
allocationRow.client,
server.db.nodes.find(allocation.nodeId).id.split('-')[0],
'Node ID'
);
assert.equal(
allocationRow.clientTooltip.substr(0, 15),
server.db.nodes.find(allocation.nodeId).name.substr(0, 15),
'Node Name'
);
assert.equal(
allocationRow.cpu,
Math.floor(allocStats.resourceUsage.CpuStats.TotalTicks) / cpuUsed,
'CPU %'
);
const roundedTicks = Math.floor(
allocStats.resourceUsage.CpuStats.TotalTicks
);
assert.equal(
allocationRow.cpuTooltip,
`${formatHertz(roundedTicks, 'MHz')} / ${formatHertz(cpuUsed, 'MHz')}`,
'Detailed CPU information is in a tooltip'
);
assert.equal(
allocationRow.mem,
allocStats.resourceUsage.MemoryStats.RSS / 1024 / 1024 / memoryUsed,
'Memory used'
);
assert.equal(
allocationRow.memTooltip,
`${formatBytes(
allocStats.resourceUsage.MemoryStats.RSS
)} / ${formatBytes(memoryUsed, 'MiB')}`,
'Detailed memory information is in a tooltip'
);
});
});
test('each allocation should link to the allocation detail page', async function (assert) {
const allocation = server.create('allocation');
assignAlloc(volume, allocation);
await VolumeDetail.visit({ id: `${volume.id}@default` });
await VolumeDetail.allocations.objectAt(0).visit();
assert.equal(currentURL(), `/allocations/${allocation.id}`);
});
test('when there are no allocations, the table presents an empty state', async function (assert) {
await VolumeDetail.visit({ id: `${volume.id}@default` });
assert.ok(VolumeDetail.allocationsTableIsEmpty);
assert.equal(VolumeDetail.allocationsEmptyState.headline, 'No Allocations');
});
test('Capabilities table shows access mode and attachment mode', async function (assert) {
await VolumeDetail.visit({ id: `${volume.id}@default` });
assert.equal(
VolumeDetail.capabilities.objectAt(0).accessMode,
'single-node-writer'
);
assert.equal(
VolumeDetail.capabilities.objectAt(0).attachmentMode,
'file-system'
);
assert.equal(
VolumeDetail.capabilities.objectAt(1).accessMode,
'single-node-reader-only'
);
assert.equal(
VolumeDetail.capabilities.objectAt(1).attachmentMode,
'block-device'
);
});
});
// Namespace test: details shows the namespace
module(
'Acceptance | dynamic volume detail (with namespaces)',
function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
let volume;
hooks.beforeEach(function () {
server.createList('namespace', 2);
server.create('node-pool');
server.create('node');
volume = server.create('dynamic-host-volume');
});
test('/storage/volumes/:id detail ribbon includes the namespace of the volume', async function (assert) {
await VolumeDetail.visit({ id: `${volume.id}@${volume.namespaceId}` });
assert.ok(VolumeDetail.hasNamespace);
assert.ok(
VolumeDetail.namespace.includes(volume.namespaceId || 'default')
);
});
}
);