2017-12-15 21:39:18 +00:00
|
|
|
import { get } from '@ember/object';
|
|
|
|
import $ from 'jquery';
|
2017-09-26 07:47:16 +00:00
|
|
|
import { click, findAll, find, visit } from 'ember-native-dom-helpers';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { test } from 'qunit';
|
|
|
|
import moment from 'moment';
|
|
|
|
import moduleForAcceptance from 'nomad-ui/tests/helpers/module-for-acceptance';
|
|
|
|
|
|
|
|
const sum = (list, key) => list.reduce((sum, item) => sum + get(item, key), 0);
|
|
|
|
|
|
|
|
let job;
|
|
|
|
let deployments;
|
|
|
|
let sortedDeployments;
|
|
|
|
|
|
|
|
moduleForAcceptance('Acceptance | job deployments', {
|
|
|
|
beforeEach() {
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test('/jobs/:id/deployments should list all job deployments', function(assert) {
|
|
|
|
visit(`/jobs/${job.id}/deployments`);
|
|
|
|
andThen(() => {
|
|
|
|
assert.ok(
|
2018-01-05 20:59:36 +00:00
|
|
|
findAll('[data-test-deployment]').length,
|
2017-09-19 14:47:10 +00:00
|
|
|
deployments.length,
|
|
|
|
'Each deployment gets a row in the timeline'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each deployment mentions the deployment shortId, status, version, and time since it was submitted', function(
|
|
|
|
assert
|
|
|
|
) {
|
|
|
|
visit(`/jobs/${job.id}/deployments`);
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const deployment = sortedDeployments.models[0];
|
|
|
|
const version = server.db.jobVersions.findBy({
|
|
|
|
jobId: deployment.jobId,
|
|
|
|
version: deployment.versionNumber,
|
|
|
|
});
|
2018-01-05 20:59:36 +00:00
|
|
|
const deploymentRow = $(find('[data-test-deployment]'));
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
assert.ok(deploymentRow.text().includes(deployment.id.split('-')[0]), 'Short ID');
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.equal(
|
|
|
|
deploymentRow.find('[data-test-deployment-status]').text(),
|
|
|
|
deployment.status,
|
|
|
|
'Status'
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
assert.ok(
|
2018-01-05 20:59:36 +00:00
|
|
|
deploymentRow
|
|
|
|
.find('[data-test-deployment-status]')
|
|
|
|
.hasClass(classForStatus(deployment.status)),
|
2017-09-19 14:47:10 +00:00
|
|
|
'Status Class'
|
|
|
|
);
|
|
|
|
assert.ok(
|
2018-01-05 20:59:36 +00:00
|
|
|
deploymentRow
|
|
|
|
.find('[data-test-deployment-version]')
|
|
|
|
.text()
|
|
|
|
.includes(deployment.versionNumber),
|
|
|
|
'Version #'
|
|
|
|
);
|
|
|
|
assert.ok(
|
|
|
|
deploymentRow
|
|
|
|
.find('[data-test-deployment-submit-time]')
|
|
|
|
.text()
|
|
|
|
.includes(moment(version.submitTime / 1000000).fromNow()),
|
2017-09-19 14:47:10 +00:00
|
|
|
'Submit time ago'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when the deployment is running and needs promotion, the deployment item says so', function(
|
|
|
|
assert
|
|
|
|
) {
|
|
|
|
// Ensure the deployment needs deployment
|
|
|
|
const deployment = sortedDeployments.models[0];
|
|
|
|
const taskGroupSummary = deployment.deploymentTaskGroupSummaryIds.map(id =>
|
|
|
|
server.schema.deploymentTaskGroupSummaries.find(id)
|
|
|
|
)[0];
|
|
|
|
|
|
|
|
deployment.update('status', 'running');
|
|
|
|
deployment.save();
|
|
|
|
|
|
|
|
taskGroupSummary.update({
|
|
|
|
desiredCanaries: 1,
|
|
|
|
placedCanaries: 0,
|
|
|
|
promoted: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
taskGroupSummary.save();
|
|
|
|
|
|
|
|
visit(`/jobs/${job.id}/deployments`);
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
const deploymentRow = find('[data-test-deployment]');
|
2017-09-19 14:47:10 +00:00
|
|
|
assert.ok(
|
2018-01-05 20:59:36 +00:00
|
|
|
deploymentRow.querySelector('[data-test-promotion-required]'),
|
2017-09-19 14:47:10 +00:00
|
|
|
'Requires Promotion badge found'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('each deployment item can be opened to show details', function(assert) {
|
|
|
|
let deploymentRow;
|
|
|
|
|
|
|
|
visit(`/jobs/${job.id}/deployments`);
|
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
deploymentRow = find('[data-test-deployment]');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.notOk(
|
|
|
|
deploymentRow.querySelector('[data-test-deployment-details]'),
|
|
|
|
'No deployment body'
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
click(deploymentRow.querySelector('[data-test-deployment-toggle-details]'));
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(
|
|
|
|
deploymentRow.querySelector('[data-test-deployment-details]'),
|
|
|
|
'Deployment body found'
|
|
|
|
);
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when open, a deployment shows the deployment metrics', function(assert) {
|
|
|
|
visit(`/jobs/${job.id}/deployments`);
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const deployment = sortedDeployments.models[0];
|
2018-01-05 20:59:36 +00:00
|
|
|
const deploymentRow = find('[data-test-deployment]');
|
2017-09-19 14:47:10 +00:00
|
|
|
const taskGroupSummaries = deployment.deploymentTaskGroupSummaryIds.map(id =>
|
|
|
|
server.db.deploymentTaskGroupSummaries.find(id)
|
|
|
|
);
|
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
click(deploymentRow.querySelector('[data-test-deployment-toggle-details]'));
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-deployment-metric="canaries"]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
`${sum(taskGroupSummaries, 'placedCanaries')} / ${sum(
|
|
|
|
taskGroupSummaries,
|
|
|
|
'desiredCanaries'
|
|
|
|
)}`,
|
|
|
|
'Canaries, both places and desired, are in the metrics'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-deployment-metric="placed"]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
sum(taskGroupSummaries, 'placedAllocs'),
|
|
|
|
'Placed allocs aggregates across task groups'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-deployment-metric="desired"]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
sum(taskGroupSummaries, 'desiredTotal'),
|
|
|
|
'Desired allocs aggregates across task groups'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-deployment-metric="healthy"]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
sum(taskGroupSummaries, 'healthyAllocs'),
|
|
|
|
'Healthy allocs aggregates across task groups'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-deployment-metric="unhealthy"]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
sum(taskGroupSummaries, 'unhealthyAllocs'),
|
|
|
|
'Unhealthy allocs aggregates across task groups'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
find('[data-test-deployment-notification]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
deployment.statusDescription,
|
|
|
|
'Status description is in the metrics block'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when open, a deployment shows a list of all task groups and their respective stats', function(
|
|
|
|
assert
|
|
|
|
) {
|
|
|
|
visit(`/jobs/${job.id}/deployments`);
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const deployment = sortedDeployments.models[0];
|
2018-01-05 20:59:36 +00:00
|
|
|
const deploymentRow = find('[data-test-deployment]');
|
2017-09-19 14:47:10 +00:00
|
|
|
const taskGroupSummaries = deployment.deploymentTaskGroupSummaryIds.map(id =>
|
|
|
|
server.db.deploymentTaskGroupSummaries.find(id)
|
|
|
|
);
|
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
click(deploymentRow.querySelector('[data-test-deployment-toggle-details]'));
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
2018-01-05 20:59:36 +00:00
|
|
|
const taskGroupTable = deploymentRow.querySelector('[data-test-deployment-task-groups]');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
assert.ok(taskGroupTable, 'Task groups found');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
taskGroupTable.querySelectorAll('[data-test-deployment-task-group]').length,
|
2017-09-19 14:47:10 +00:00
|
|
|
taskGroupSummaries.length,
|
|
|
|
'One row per task group'
|
|
|
|
);
|
|
|
|
|
|
|
|
const taskGroup = taskGroupSummaries[0];
|
2018-01-05 20:59:36 +00:00
|
|
|
const taskGroupRow = taskGroupTable.querySelector('[data-test-deployment-task-group]');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
taskGroupRow.querySelector('[data-test-deployment-task-group-name]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
taskGroup.name,
|
|
|
|
'Name'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow
|
2018-01-05 20:59:36 +00:00
|
|
|
.querySelector('[data-test-deployment-task-group-promotion]')
|
|
|
|
.textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
promotionTestForTaskGroup(taskGroup),
|
|
|
|
'Needs Promotion'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow
|
2018-01-05 20:59:36 +00:00
|
|
|
.querySelector('[data-test-deployment-task-group-auto-revert]')
|
|
|
|
.textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
taskGroup.autoRevert ? 'Yes' : 'No',
|
|
|
|
'Auto Revert'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
taskGroupRow.querySelector('[data-test-deployment-task-group-canaries]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
`${taskGroup.placedCanaries} / ${taskGroup.desiredCanaries}`,
|
|
|
|
'Canaries'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
taskGroupRow.querySelector('[data-test-deployment-task-group-allocs]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
`${taskGroup.placedAllocs} / ${taskGroup.desiredTotal}`,
|
|
|
|
'Allocs'
|
|
|
|
);
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
taskGroupRow.querySelector('[data-test-deployment-task-group-healthy]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
taskGroup.healthyAllocs,
|
|
|
|
'Healthy Allocs'
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
taskGroupRow
|
2018-01-05 20:59:36 +00:00
|
|
|
.querySelector('[data-test-deployment-task-group-unhealthy]')
|
|
|
|
.textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
taskGroup.unhealthyAllocs,
|
|
|
|
'Unhealthy Allocs'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('when open, a deployment shows a list of all allocations for the deployment', function(
|
|
|
|
assert
|
|
|
|
) {
|
|
|
|
visit(`/jobs/${job.id}/deployments`);
|
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
const deployment = sortedDeployments.models[0];
|
2018-01-05 20:59:36 +00:00
|
|
|
const deploymentRow = find('[data-test-deployment]');
|
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);
|
|
|
|
|
2018-01-05 20:59:36 +00:00
|
|
|
click(deploymentRow.querySelector('[data-test-deployment-toggle-details]'));
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
andThen(() => {
|
|
|
|
assert.ok(
|
2018-01-05 20:59:36 +00:00
|
|
|
deploymentRow.querySelector('[data-test-deployment-allocations]'),
|
2017-09-19 14:47:10 +00:00
|
|
|
'Allocations found'
|
|
|
|
);
|
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
deploymentRow.querySelectorAll('[data-test-deployment-allocation]').length,
|
2017-09-19 14:47:10 +00:00
|
|
|
allocations.length,
|
|
|
|
'One row per allocation'
|
|
|
|
);
|
|
|
|
|
|
|
|
const allocation = allocations[0];
|
2018-01-05 20:59:36 +00:00
|
|
|
const allocationRow = deploymentRow.querySelector('[data-test-deployment-allocation]');
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
assert.equal(
|
2018-01-05 20:59:36 +00:00
|
|
|
allocationRow.querySelector('[data-test-short-id]').textContent.trim(),
|
2017-09-19 14:47:10 +00:00
|
|
|
allocation.id.split('-')[0],
|
|
|
|
'Allocation is as expected'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
|
|
|
function promotionTestForTaskGroup(taskGroup) {
|
|
|
|
if (taskGroup.desiredCanaries > 0 && taskGroup.promoted === false) {
|
|
|
|
return 'Yes';
|
|
|
|
} else if (taskGroup.desiredCanaries > 0) {
|
|
|
|
return 'No';
|
|
|
|
}
|
|
|
|
return 'N/A';
|
|
|
|
}
|