Merge pull request #8771 from hashicorp/f-ui/mirage-consistency

UI: Clean up erroneous and redundant mirage things
This commit is contained in:
Michael Lange 2020-08-28 08:12:07 -07:00 committed by GitHub
commit 3787978ab1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 45 additions and 53 deletions

View file

@ -11,7 +11,7 @@ export default Factory.extend({
name: () => `nomad@${faker.internet.ip()}`,
status: () => faker.helpers.randomize(AGENT_STATUSES),
serf_port: () => faker.random.number({ min: 4000, max: 4999 }),
serfPort: () => faker.random.number({ min: 4000, max: 4999 }),
address() {
return this.name.split('@')[1];
@ -20,7 +20,7 @@ export default Factory.extend({
tags() {
const rpcPortCandidate = faker.random.number({ min: 4000, max: 4999 });
return {
port: rpcPortCandidate === this.serf_port ? rpcPortCandidate + 1 : rpcPortCandidate,
port: rpcPortCandidate === this.serfPort ? rpcPortCandidate + 1 : rpcPortCandidate,
dc: faker.helpers.randomize(DATACENTERS),
};
},

View file

@ -104,7 +104,6 @@ function assignJob(evaluation, server) {
const job = evaluation.jobId ? server.db.jobs.find(evaluation.jobId) : pickOne(server.db.jobs);
evaluation.update({
jobId: job.id,
job_id: job.id,
});
}

View file

@ -6,7 +6,6 @@ export default Factory.extend({
// Hidden property used to compute the Summary hash
groupNames: [],
JobID: '',
namespace: null,
withSummary: trait({

View file

@ -25,7 +25,7 @@ export default Factory.extend({
region: () => 'global',
type: () => faker.helpers.randomize(JOB_TYPES),
priority: () => faker.random.number(100),
all_at_once: faker.random.boolean,
allAtOnce: faker.random.boolean,
status: () => faker.helpers.randomize(JOB_STATUSES),
datacenters: () =>
faker.helpers.shuffle(DATACENTERS).slice(0, faker.random.number({ min: 1, max: 4 })),
@ -141,21 +141,17 @@ export default Factory.extend({
job.update({
taskGroupIds: groups.mapBy('id'),
task_group_ids: groups.mapBy('id'),
});
const hasChildren = job.periodic || (job.parameterized && !job.parentId);
const jobSummary = server.create('job-summary', hasChildren ? 'withChildren' : 'withSummary', {
jobId: job.id,
groupNames: groups.mapBy('name'),
job,
job_id: job.id,
JobID: job.id,
namespace: job.namespace,
});
job.update({
jobSummaryId: jobSummary.id,
job_summary_id: jobSummary.id,
});
const jobScale = server.create('job-scale', {

View file

@ -17,7 +17,7 @@ export default Factory.extend({
nodeClass: () => faker.helpers.randomize(NODE_CLASSES),
drain: faker.random.boolean,
status: () => faker.helpers.randomize(NODE_STATUSES),
tls_enabled: faker.random.boolean,
tlsEnabled: faker.random.boolean,
schedulingEligibility: () => (faker.random.boolean() ? 'eligible' : 'ineligible'),
createIndex: i => i,

View file

@ -85,7 +85,6 @@ export default Factory.extend({
group.update({
taskIds: taskIds,
task_ids: taskIds,
});
if (group.createAllocations) {
@ -116,7 +115,7 @@ export default Factory.extend({
.fill(null)
.forEach(() => {
server.create('service', {
task_group: group,
taskGroup: group,
});
});
}

View file

@ -1,6 +1,6 @@
import { Model, hasMany } from 'ember-cli-mirage';
export default Model.extend({
task_states: hasMany('task-state'),
task_resources: hasMany('task-resource'),
taskStates: hasMany('task-state'),
taskResources: hasMany('task-resource'),
});

View file

@ -1,5 +0,0 @@
import { Model, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
job: belongsTo(),
});

View file

@ -1,7 +1,7 @@
import { Model, hasMany, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
task_groups: hasMany('task-group'),
job_summary: belongsTo('job-summary'),
taskGroups: hasMany('task-group'),
jobSummary: belongsTo('job-summary'),
jobScale: belongsTo('job-scale'),
});

View file

@ -1,5 +1,5 @@
import { Model, belongsTo } from 'ember-cli-mirage';
export default Model.extend({
task_group: belongsTo('task-group'),
taskGroup: belongsTo('task-group'),
});

View file

@ -3,7 +3,7 @@ import { arrToObj } from '../utils';
export default ApplicationSerializer.extend({
embed: true,
include: ['task_states', 'task_resources'],
include: ['taskStates', 'taskResources'],
serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);

View file

@ -19,6 +19,8 @@ export default RestSerializer.extend({
}
},
keyForModel: keyCase,
keyForForeignKey: str => `${keyCase(str)}ID`,
keyForCollection: keyCase,
keyForAttribute: keyCase,
keyForRelationship: keyCase,

View file

@ -2,7 +2,7 @@ import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
embed: true,
include: ['task_groups', 'job_summary'],
include: ['taskGroups', 'jobSummary'],
serialize() {
var json = ApplicationSerializer.prototype.serialize.apply(this, arguments);

View file

@ -265,7 +265,7 @@ module('Acceptance | allocation detail', function(hooks) {
jobId: job.id,
});
const taskState = allocation.task_states.models.sortBy('name')[0];
const taskState = allocation.taskStates.models.sortBy('name')[0];
const task = server.schema.tasks.findBy({ name: taskState.name });
task.update('kind', 'connect-proxy:task');
task.save();
@ -295,7 +295,9 @@ module('Acceptance | allocation detail', function(hooks) {
assert.equal(renderedPort.name, serverPort.Label);
assert.equal(renderedPort.to, serverPort.To);
const expectedAddr = isIp.v6(serverPort.HostIP) ? `[${serverPort.HostIP}]:${serverPort.Value}` : `${serverPort.HostIP}:${serverPort.Value}`;
const expectedAddr = isIp.v6(serverPort.HostIP)
? `[${serverPort.HostIP}]:${serverPort.Value}`
: `${serverPort.HostIP}:${serverPort.Value}`;
assert.equal(renderedPort.address, expectedAddr);
});
});

View file

@ -25,10 +25,10 @@ module('Acceptance | exec', function(hooks) {
status: 'running',
});
this.job.task_group_ids.forEach(taskGroupId => {
this.job.taskGroups.models.forEach(taskGroup => {
server.create('allocation', {
jobId: this.job.id,
taskGroup: server.db.taskGroups.find(taskGroupId).name,
taskGroup: taskGroup.name,
forceRunningClientStatus: true,
});
});
@ -71,10 +71,10 @@ module('Acceptance | exec', function(hooks) {
});
test('/exec/:job should show the task groups collapsed by default and allow the tasks to be shown', async function(assert) {
const firstTaskGroup = this.job.task_groups.models.sortBy('name')[0];
const firstTaskGroup = this.job.taskGroups.models.sortBy('name')[0];
await Exec.visitJob({ job: this.job.id });
assert.equal(Exec.taskGroups.length, this.job.task_groups.length);
assert.equal(Exec.taskGroups.length, this.job.taskGroups.length);
assert.equal(Exec.taskGroups[0].name, firstTaskGroup.name);
assert.equal(Exec.taskGroups[0].tasks.length, 0);
@ -103,7 +103,7 @@ module('Acceptance | exec', function(hooks) {
});
test('a task group with a pending allocation shows a loading spinner', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
this.server.db.allocations.update({ taskGroup: taskGroup.name }, { clientStatus: 'pending' });
await Exec.visitJob({ job: this.job.id });
@ -111,7 +111,7 @@ module('Acceptance | exec', function(hooks) {
});
test('a task group with no running task states or pending allocations should not be shown', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
this.server.db.allocations.update({ taskGroup: taskGroup.name }, { clientStatus: 'failed' });
await Exec.visitJob({ job: this.job.id });
@ -119,13 +119,13 @@ module('Acceptance | exec', function(hooks) {
});
test('an inactive task should not be shown', async function(assert) {
let notRunningTaskGroup = this.job.task_groups.models.sortBy('name')[0];
let notRunningTaskGroup = this.job.taskGroups.models.sortBy('name')[0];
this.server.db.allocations.update(
{ taskGroup: notRunningTaskGroup.name },
{ clientStatus: 'failed' }
);
let runningTaskGroup = this.job.task_groups.models.sortBy('name')[1];
let runningTaskGroup = this.job.taskGroups.models.sortBy('name')[1];
runningTaskGroup.tasks.models.forEach((task, index) => {
if (index > 0) {
this.server.db.taskStates.update({ name: task.name }, { finishedAt: new Date() });
@ -139,13 +139,13 @@ module('Acceptance | exec', function(hooks) {
});
test('a task that becomes active should appear', async function(assert) {
let notRunningTaskGroup = this.job.task_groups.models.sortBy('name')[0];
let notRunningTaskGroup = this.job.taskGroups.models.sortBy('name')[0];
this.server.db.allocations.update(
{ taskGroup: notRunningTaskGroup.name },
{ clientStatus: 'failed' }
);
let runningTaskGroup = this.job.task_groups.models.sortBy('name')[1];
let runningTaskGroup = this.job.taskGroups.models.sortBy('name')[1];
let changingTaskStateName;
runningTaskGroup.tasks.models.sortBy('name').forEach((task, index) => {
if (index > 0) {
@ -184,7 +184,7 @@ module('Acceptance | exec', function(hooks) {
this.job.status = 'dead';
this.job.save();
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
this.server.db.taskStates.update({ finishedAt: new Date() });
@ -217,7 +217,7 @@ module('Acceptance | exec', function(hooks) {
});
test('visiting a path with a task group should open the group by default', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
await Exec.visitTaskGroup({ job: this.job.id, task_group: taskGroup.name });
assert.equal(Exec.taskGroups[0].tasks.length, taskGroup.tasks.length);
@ -235,7 +235,7 @@ module('Acceptance | exec', function(hooks) {
await Exec.taskGroups[0].click();
await Exec.taskGroups[0].tasks[0].click();
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
let taskStates = this.server.db.taskStates.where({
@ -274,7 +274,7 @@ module('Acceptance | exec', function(hooks) {
});
test('an allocation can be specified', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
let allocations = this.server.db.allocations.where({
jobId: this.job.id,
@ -322,7 +322,7 @@ module('Acceptance | exec', function(hooks) {
this.owner.register('service:sockets', mockSockets);
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
let allocations = this.server.db.allocations.where({
jobId: this.job.id,
@ -393,7 +393,7 @@ module('Acceptance | exec', function(hooks) {
this.owner.register('service:sockets', mockSockets);
let taskGroup = this.job.task_groups.models[0];
let taskGroup = this.job.taskGroups.models[0];
let task = taskGroup.tasks.models[0];
let allocations = this.server.db.allocations.where({
jobId: this.job.id,
@ -463,7 +463,7 @@ module('Acceptance | exec', function(hooks) {
await Exec.taskGroups[0].click();
await Exec.taskGroups[0].tasks[0].click();
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
let allocation = this.server.db.allocations.findBy({
jobId: this.job.id,
@ -509,7 +509,7 @@ module('Acceptance | exec', function(hooks) {
test('a persisted customised command is recalled', async function(assert) {
window.localStorage.setItem('nomadExecCommand', JSON.stringify('/bin/sh'));
let taskGroup = this.job.task_groups.models[0];
let taskGroup = this.job.taskGroups.models[0];
let task = taskGroup.tasks.models[0];
let allocations = this.server.db.allocations.where({
jobId: this.job.id,
@ -536,7 +536,7 @@ module('Acceptance | exec', function(hooks) {
});
skip('when a task state finishes submitting a command displays an error', async function(assert) {
let taskGroup = this.job.task_groups.models.sortBy('name')[0];
let taskGroup = this.job.taskGroups.models.sortBy('name')[0];
let task = taskGroup.tasks.models.sortBy('name')[0];
await Exec.visitTask({

View file

@ -60,7 +60,7 @@ module('Acceptance | servers list', function(hooks) {
assert.equal(agentRow.status, agent.status, 'Status');
assert.equal(agentRow.leader, 'True', 'Leader?');
assert.equal(agentRow.address, agent.address, 'Address');
assert.equal(agentRow.serfPort, agent.serf_port, 'Serf Port');
assert.equal(agentRow.serfPort, agent.serfPort, 'Serf Port');
assert.equal(agentRow.datacenter, agent.tags.dc, 'Datacenter');
});

View file

@ -109,15 +109,15 @@ module('Acceptance | task detail', function(hooks) {
status: 'running',
});
job.task_group_ids.forEach(taskGroupId => {
job.taskGroups.models.forEach(taskGroup => {
server.create('allocation', {
jobId: job.id,
taskGroup: server.db.taskGroups.find(taskGroupId).name,
taskGroup: taskGroup.name,
forceRunningClientStatus: true,
});
});
const taskGroup = job.task_groups.models[0];
const taskGroup = job.taskGroups.models[0];
const [mainTask, sidecarTask, prestartTask] = taskGroup.tasks.models;
mainTask.attrs.Lifecycle = null;
@ -131,7 +131,7 @@ module('Acceptance | task detail', function(hooks) {
taskGroup.save();
const noPrestartTasksTaskGroup = job.task_groups.models[1];
const noPrestartTasksTaskGroup = job.taskGroups.models[1];
noPrestartTasksTaskGroup.tasks.models.forEach(task => {
task.attrs.Lifecycle = null;
task.save();
@ -421,7 +421,7 @@ module('Acceptance | proxy task detail', function(hooks) {
server.create('job', { createAllocations: false });
allocation = server.create('allocation', 'withTaskWithPorts', { clientStatus: 'running' });
const taskState = allocation.task_states.models[0];
const taskState = allocation.taskStates.models[0];
const task = server.schema.tasks.findBy({ name: taskState.name });
task.update('kind', 'connect-proxy:task');
task.save();

View file

@ -18,7 +18,7 @@ module('Integration | Component | scale-events-accordion', function(hooks) {
this.server.create('node');
this.taskGroupWithEvents = async function(events) {
const job = this.server.create('job', { createAllocations: false });
const group = job.task_groups.models[0];
const group = job.taskGroups.models[0];
job.jobScale.taskGroupScales.models.findBy('name', group.name).update({ events });
const jobModel = await this.store.find('job', JSON.stringify([job.id, 'default']));