2019-03-13 00:08:16 +00:00
|
|
|
import { currentURL } from '@ember/test-helpers';
|
2017-12-15 21:39:18 +00:00
|
|
|
import { get } from '@ember/object';
|
2019-03-13 00:04:16 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupApplicationTest } from 'ember-qunit';
|
2019-09-26 18:47:07 +00:00
|
|
|
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';
|
2017-09-19 14:47:10 +00:00
|
|
|
import moment from 'moment';
|
2018-07-11 16:13:44 +00:00
|
|
|
import Deployments from 'nomad-ui/tests/pages/jobs/job/deployments';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-05-23 17:39:43 +00:00
|
|
|
const sum = (list, key, getter = a => a) =>
|
|
|
|
list.reduce((sum, item) => sum + getter(get(item, key)), 0);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
let job;
|
|
|
|
let deployments;
|
|
|
|
let sortedDeployments;
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
module('Acceptance | job deployments', function(hooks) {
|
|
|
|
setupApplicationTest(hooks);
|
2019-03-13 01:09:19 +00:00
|
|
|
setupMirage(hooks);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
|
|
|
hooks.beforeEach(function() {
|
2017-09-19 14:47:10 +00:00
|
|
|
server.create('node');
|
|
|
|
job = server.create('job');
|
|
|
|
deployments = server.schema.deployments.where({ jobId: job.id });
|
|
|
|
sortedDeployments = deployments.sort((a, b) => {
|
|
|
|
const aVersion = server.db.jobVersions.findBy({ jobId: a.jobId, version: a.versionNumber });
|
|
|
|
const bVersion = server.db.jobVersions.findBy({ jobId: b.jobId, version: b.versionNumber });
|
|
|
|
if (aVersion.submitTime < bVersion.submitTime) {
|
|
|
|
return 1;
|
|
|
|
} else if (aVersion.submitTime > bVersion.submitTime) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
2019-03-13 00:04:16 +00:00
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-07-28 17:59:14 +00:00
|
|
|
test('it passes an accessibility audit', async function(assert) {
|
|
|
|
await Deployments.visit({ id: job.id });
|
2020-08-25 15:56:02 +00:00
|
|
|
await a11yAudit(assert);
|
2020-07-28 17:59:14 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('/jobs/:id/deployments should list all job deployments', async function(assert) {
|
|
|
|
await Deployments.visit({ id: job.id });
|
2018-07-11 16:13:44 +00:00
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
assert.ok(
|
2018-07-11 16:13:44 +00:00
|
|
|
Deployments.deployments.length,
|
2017-09-19 14:47:10 +00:00
|
|
|
deployments.length,
|
|
|
|
'Each deployment gets a row in the timeline'
|
|
|
|
);
|
2019-07-17 20:02:58 +00:00
|
|
|
assert.equal(document.title, `Job ${job.name} deployments - Nomad`);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('each deployment mentions the deployment shortId, status, version, and time since it was submitted', async function(assert) {
|
|
|
|
await Deployments.visit({ id: job.id });
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
const deployment = sortedDeployments.models[0];
|
|
|
|
const version = server.db.jobVersions.findBy({
|
|
|
|
jobId: deployment.jobId,
|
|
|
|
version: deployment.versionNumber,
|
|
|
|
});
|
2018-07-11 16:13:44 +00:00
|
|
|
const deploymentRow = Deployments.deployments.objectAt(0);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-07-11 16:13:44 +00:00
|
|
|
assert.ok(deploymentRow.text.includes(deployment.id.split('-')[0]), 'Short ID');
|
|
|
|
assert.equal(deploymentRow.status, deployment.status, 'Status');
|
2017-09-19 14:47:10 +00:00
|
|
|
assert.ok(
|
2018-07-11 16:13:44 +00:00
|
|
|
deploymentRow.statusClass.includes(classForStatus(deployment.status)),
|
2017-09-19 14:47:10 +00:00
|
|
|
'Status Class'
|
|
|
|
);
|
2018-07-11 16:13:44 +00:00
|
|
|
assert.ok(deploymentRow.version.includes(deployment.versionNumber), 'Version #');
|
2017-09-19 14:47:10 +00:00
|
|
|
assert.ok(
|
2018-07-11 16:13:44 +00:00
|
|
|
deploymentRow.submitTime.includes(moment(version.submitTime / 1000000).fromNow()),
|
2017-09-19 14:47:10 +00:00
|
|
|
'Submit time ago'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when the deployment is running and needs promotion, the deployment item says so', async function(assert) {
|
2019-03-13 00:04:16 +00:00
|
|
|
// Ensure the deployment needs deployment
|
|
|
|
const deployment = sortedDeployments.models[0];
|
|
|
|
const taskGroupSummary = deployment.deploymentTaskGroupSummaryIds.map(id =>
|
|
|
|
server.schema.deploymentTaskGroupSummaries.find(id)
|
|
|
|
)[0];
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
deployment.update('status', 'running');
|
|
|
|
deployment.save();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
taskGroupSummary.update({
|
|
|
|
desiredCanaries: 1,
|
|
|
|
placedCanaries: [],
|
|
|
|
promoted: false,
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
taskGroupSummary.save();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await Deployments.visit({ id: job.id });
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-07-11 16:13:44 +00:00
|
|
|
const deploymentRow = Deployments.deployments.objectAt(0);
|
|
|
|
assert.ok(deploymentRow.promotionIsRequired, 'Requires Promotion badge found');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('each deployment item can be opened to show details', async function(assert) {
|
|
|
|
await Deployments.visit({ id: job.id });
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-07-11 16:13:44 +00:00
|
|
|
const deploymentRow = Deployments.deployments.objectAt(0);
|
|
|
|
assert.notOk(deploymentRow.hasDetails, 'No deployment body');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await deploymentRow.toggle();
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.ok(deploymentRow.hasDetails, 'Deployment body found');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when open, a deployment shows the deployment metrics', async function(assert) {
|
|
|
|
await Deployments.visit({ id: job.id });
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
const deployment = sortedDeployments.models[0];
|
2018-07-11 16:13:44 +00:00
|
|
|
const deploymentRow = Deployments.deployments.objectAt(0);
|
2017-09-19 14:47:10 +00:00
|
|
|
const taskGroupSummaries = deployment.deploymentTaskGroupSummaryIds.map(id =>
|
|
|
|
server.db.deploymentTaskGroupSummaries.find(id)
|
|
|
|
);
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await deploymentRow.toggle();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.equal(
|
|
|
|
deploymentRow.metricFor('canaries').text,
|
|
|
|
`${sum(taskGroupSummaries, 'placedCanaries', a => a.length)} / ${sum(
|
|
|
|
taskGroupSummaries,
|
|
|
|
'desiredCanaries'
|
|
|
|
)}`,
|
|
|
|
'Canaries, both places and desired, are in the metrics'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
deploymentRow.metricFor('placed').text,
|
|
|
|
sum(taskGroupSummaries, 'placedAllocs'),
|
|
|
|
'Placed allocs aggregates across task groups'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
deploymentRow.metricFor('desired').text,
|
|
|
|
sum(taskGroupSummaries, 'desiredTotal'),
|
|
|
|
'Desired allocs aggregates across task groups'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
deploymentRow.metricFor('healthy').text,
|
|
|
|
sum(taskGroupSummaries, 'healthyAllocs'),
|
|
|
|
'Healthy allocs aggregates across task groups'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
deploymentRow.metricFor('unhealthy').text,
|
|
|
|
sum(taskGroupSummaries, 'unhealthyAllocs'),
|
|
|
|
'Unhealthy allocs aggregates across task groups'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
deploymentRow.notification,
|
|
|
|
deployment.statusDescription,
|
|
|
|
'Status description is in the metrics block'
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when open, a deployment shows a list of all task groups and their respective stats', async function(assert) {
|
|
|
|
await Deployments.visit({ id: job.id });
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
const deployment = sortedDeployments.models[0];
|
2018-07-11 16:13:44 +00:00
|
|
|
const deploymentRow = Deployments.deployments.objectAt(0);
|
2017-09-19 14:47:10 +00:00
|
|
|
const taskGroupSummaries = deployment.deploymentTaskGroupSummaryIds.map(id =>
|
|
|
|
server.db.deploymentTaskGroupSummaries.find(id)
|
|
|
|
);
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
await deploymentRow.toggle();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.ok(deploymentRow.hasTaskGroups, 'Task groups found');
|
|
|
|
|
|
|
|
assert.equal(
|
|
|
|
deploymentRow.taskGroups.length,
|
|
|
|
taskGroupSummaries.length,
|
|
|
|
'One row per task group'
|
|
|
|
);
|
|
|
|
|
|
|
|
const taskGroup = taskGroupSummaries[0];
|
2020-09-17 16:08:47 +00:00
|
|
|
const taskGroupRow = deploymentRow.taskGroups.findOneBy('name', taskGroup.name);
|
2019-03-13 00:04:16 +00:00
|
|
|
|
|
|
|
assert.equal(taskGroupRow.name, taskGroup.name, 'Name');
|
|
|
|
assert.equal(taskGroupRow.promotion, promotionTestForTaskGroup(taskGroup), 'Needs Promotion');
|
|
|
|
assert.equal(taskGroupRow.autoRevert, taskGroup.autoRevert ? 'Yes' : 'No', 'Auto Revert');
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow.canaries,
|
|
|
|
`${taskGroup.placedCanaries.length} / ${taskGroup.desiredCanaries}`,
|
|
|
|
'Canaries'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow.allocs,
|
|
|
|
`${taskGroup.placedAllocs} / ${taskGroup.desiredTotal}`,
|
|
|
|
'Allocs'
|
|
|
|
);
|
|
|
|
assert.equal(taskGroupRow.healthy, taskGroup.healthyAllocs, 'Healthy Allocs');
|
|
|
|
assert.equal(taskGroupRow.unhealthy, taskGroup.unhealthyAllocs, 'Unhealthy Allocs');
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow.progress,
|
|
|
|
moment(taskGroup.requireProgressBy).format("MMM DD, 'YY HH:mm:ss ZZ"),
|
|
|
|
'Progress By'
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when open, a deployment shows a list of all allocations for the deployment', async function(assert) {
|
|
|
|
await Deployments.visit({ id: job.id });
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
const deployment = sortedDeployments.models[0];
|
2018-07-11 16:13:44 +00:00
|
|
|
const deploymentRow = Deployments.deployments.objectAt(0);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
// TODO: Make this less brittle. This logic is copied from the mirage config,
|
|
|
|
// since there is no reference to allocations on the deployment model.
|
|
|
|
const allocations = server.db.allocations.where({ jobId: deployment.jobId }).slice(0, 3);
|
2019-03-14 06:44:53 +00:00
|
|
|
await deploymentRow.toggle();
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.ok(deploymentRow.hasAllocations, 'Allocations found');
|
|
|
|
assert.equal(deploymentRow.allocations.length, allocations.length, 'One row per allocation');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
const allocation = allocations[0];
|
|
|
|
const allocationRow = deploymentRow.allocations.objectAt(0);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
assert.equal(allocationRow.shortId, allocation.id.split('-')[0], 'Allocation is as expected');
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
|
2019-03-14 06:44:53 +00:00
|
|
|
test('when the job for the deployments is not found, an error message is shown, but the URL persists', async function(assert) {
|
|
|
|
await Deployments.visit({ id: 'not-a-real-job' });
|
2018-11-06 00:06:08 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2020-01-20 20:57:01 +00:00
|
|
|
server.pretender.handledRequests
|
|
|
|
.filter(request => !request.url.includes('policy'))
|
|
|
|
.findBy('status', 404).url,
|
2018-11-06 00:06:08 +00:00
|
|
|
'/v1/job/not-a-real-job',
|
|
|
|
'A request to the nonexistent job is made'
|
|
|
|
);
|
|
|
|
assert.equal(currentURL(), '/jobs/not-a-real-job/deployments', 'The URL persists');
|
|
|
|
assert.ok(Deployments.error.isPresent, 'Error message is shown');
|
|
|
|
assert.equal(Deployments.error.title, 'Not Found', 'Error message is for 404');
|
|
|
|
});
|
|
|
|
|
2019-03-13 00:04:16 +00:00
|
|
|
function classForStatus(status) {
|
|
|
|
const classMap = {
|
|
|
|
running: 'is-running',
|
|
|
|
successful: 'is-primary',
|
|
|
|
paused: 'is-light',
|
|
|
|
failed: 'is-error',
|
|
|
|
cancelled: 'is-cancelled',
|
|
|
|
};
|
|
|
|
|
|
|
|
return classMap[status] || 'is-dark';
|
2017-09-19 14:47:10 +00:00
|
|
|
}
|
2019-03-13 00:04:16 +00:00
|
|
|
|
|
|
|
function promotionTestForTaskGroup(taskGroup) {
|
|
|
|
if (taskGroup.desiredCanaries > 0 && taskGroup.promoted === false) {
|
|
|
|
return 'Yes';
|
|
|
|
} else if (taskGroup.desiredCanaries > 0) {
|
|
|
|
return 'No';
|
|
|
|
}
|
|
|
|
return 'N/A';
|
|
|
|
}
|
|
|
|
});
|