mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 12:20:45 -03:30
add namespacing, schedules, and sources to fixtures
This commit is contained in:
parent
0afe94c4d4
commit
aab66b8ce8
@ -7,7 +7,7 @@ import {
|
||||
spread
|
||||
} from './api';
|
||||
|
||||
const sid = uuid().substr(0, 8);
|
||||
const session = `e2e-${uuid().substr(0, 8)}`;
|
||||
|
||||
const store = {};
|
||||
|
||||
@ -50,24 +50,43 @@ const getOrCreate = (endpoint, data) => {
|
||||
return store[endpoint][identity].then(created => created.data);
|
||||
};
|
||||
|
||||
const getOrganization = () => getOrCreate('/organizations/', {
|
||||
name: `e2e-organization-${sid}`
|
||||
const getOrganization = (namespace = session) => getOrCreate('/organizations/', {
|
||||
name: `${namespace}-organization`,
|
||||
description: namespace
|
||||
});
|
||||
|
||||
const getInventory = () => getOrganization()
|
||||
const getInventory = (namespace = session) => getOrganization(namespace)
|
||||
.then(organization => getOrCreate('/inventories/', {
|
||||
name: `e2e-inventory-${sid}`,
|
||||
name: `${namespace}-inventory`,
|
||||
description: namespace,
|
||||
organization: organization.id
|
||||
}));
|
||||
|
||||
const getInventoryScript = () => getOrganization()
|
||||
const getInventoryScript = (namespace = session) => getOrganization(namespace)
|
||||
.then(organization => getOrCreate('/inventory_scripts/', {
|
||||
name: `e2e-inventory-script-${sid}`,
|
||||
name: `${namespace}-inventory-script`,
|
||||
description: namespace,
|
||||
organization: organization.id,
|
||||
script: '#!/usr/bin/env python'
|
||||
}));
|
||||
|
||||
const getAdminAWSCredential = () => {
|
||||
const getInventorySource = (namespace = session) => {
|
||||
const promises = [
|
||||
getInventory(namespace),
|
||||
getInventoryScript(namespace)
|
||||
];
|
||||
|
||||
return all(promises)
|
||||
.then(spread((inventory, inventoryScript) => getOrCreate('/inventory_sources/', {
|
||||
name: `${namespace}-inventory-source-custom`,
|
||||
description: namespace,
|
||||
source: 'custom',
|
||||
inventory: inventory.id,
|
||||
source_script: inventoryScript.id
|
||||
})));
|
||||
};
|
||||
|
||||
const getAdminAWSCredential = (namespace = session) => {
|
||||
const promises = [
|
||||
get('/me/'),
|
||||
getOrCreate('/credential_types/', {
|
||||
@ -80,7 +99,8 @@ const getAdminAWSCredential = () => {
|
||||
const [admin] = me.data.results;
|
||||
|
||||
return getOrCreate('/credentials/', {
|
||||
name: `e2e-aws-credential-${sid}`,
|
||||
name: `${namespace}-credential-aws`,
|
||||
description: namespace,
|
||||
credential_type: credentialType.id,
|
||||
user: admin.id,
|
||||
inputs: {
|
||||
@ -92,7 +112,7 @@ const getAdminAWSCredential = () => {
|
||||
}));
|
||||
};
|
||||
|
||||
const getAdminMachineCredential = () => {
|
||||
const getAdminMachineCredential = (namespace = session) => {
|
||||
const promises = [
|
||||
get('/me/'),
|
||||
getOrCreate('/credential_types/', { name: 'Machine' })
|
||||
@ -103,30 +123,34 @@ const getAdminMachineCredential = () => {
|
||||
const [admin] = me.data.results;
|
||||
|
||||
return getOrCreate('/credentials/', {
|
||||
name: `e2e-machine-credential-${sid}`,
|
||||
name: `${namespace}-credential-machine-admin`,
|
||||
description: namespace,
|
||||
credential_type: credentialType.id,
|
||||
user: admin.id
|
||||
});
|
||||
}));
|
||||
};
|
||||
|
||||
const getTeam = () => getOrganization()
|
||||
const getTeam = (namespace = session) => getOrganization(namespace)
|
||||
.then(organization => getOrCreate('/teams/', {
|
||||
name: `e2e-team-${sid}`,
|
||||
name: `${namespace}-team`,
|
||||
description: namespace,
|
||||
organization: organization.id,
|
||||
}));
|
||||
|
||||
const getSmartInventory = () => getOrganization()
|
||||
const getSmartInventory = (namespace = session) => getOrganization(namespace)
|
||||
.then(organization => getOrCreate('/inventories/', {
|
||||
name: `e2e-smart-inventory-${sid}`,
|
||||
name: `${namespace}-smart-inventory`,
|
||||
description: namespace,
|
||||
organization: organization.id,
|
||||
host_filter: 'search=localhost',
|
||||
kind: 'smart'
|
||||
}));
|
||||
|
||||
const getNotificationTemplate = () => getOrganization()
|
||||
const getNotificationTemplate = (namespace = session) => getOrganization(namespace)
|
||||
.then(organization => getOrCreate('/notification_templates/', {
|
||||
name: `e2e-notification-template-${sid}`,
|
||||
name: `${namespace}-notification-template`,
|
||||
description: namespace,
|
||||
organization: organization.id,
|
||||
notification_type: 'slack',
|
||||
notification_configuration: {
|
||||
@ -135,9 +159,10 @@ const getNotificationTemplate = () => getOrganization()
|
||||
}
|
||||
}));
|
||||
|
||||
const getProject = () => getOrganization()
|
||||
const getProject = (namespace = session) => getOrganization(namespace)
|
||||
.then(organization => getOrCreate('/projects/', {
|
||||
name: `e2e-project-${sid}`,
|
||||
name: `${namespace}-project`,
|
||||
description: namespace,
|
||||
organization: organization.id,
|
||||
scm_url: 'https://github.com/ansible/ansible-tower-samples',
|
||||
scm_type: 'git'
|
||||
@ -168,7 +193,7 @@ const waitForJob = endpoint => {
|
||||
});
|
||||
};
|
||||
|
||||
const getUpdatedProject = () => getProject()
|
||||
const getUpdatedProject = (namespace = session) => getProject(namespace)
|
||||
.then(project => {
|
||||
const updateURL = project.related.current_update;
|
||||
|
||||
@ -179,27 +204,28 @@ const getUpdatedProject = () => getProject()
|
||||
return project;
|
||||
});
|
||||
|
||||
const getJobTemplate = () => {
|
||||
const getJobTemplate = (namespace = session) => {
|
||||
const promises = [
|
||||
getInventory(),
|
||||
getAdminMachineCredential(),
|
||||
getUpdatedProject()
|
||||
getInventory(namespace),
|
||||
getAdminMachineCredential(namespace),
|
||||
getUpdatedProject(namespace)
|
||||
];
|
||||
|
||||
return all(promises)
|
||||
.then(spread((inventory, credential, project) => getOrCreate('/job_templates', {
|
||||
name: `e2e-job-template-${sid}`,
|
||||
.then(spread((inventory, credential, project) => getOrCreate('/job_templates/', {
|
||||
name: `${namespace}-job-template`,
|
||||
description: namespace,
|
||||
inventory: inventory.id,
|
||||
credential: credential.id,
|
||||
project: project.id,
|
||||
playbook: 'hello_world.yml'
|
||||
playbook: 'hello_world.yml',
|
||||
})));
|
||||
};
|
||||
|
||||
const getAuditor = () => getOrganization()
|
||||
const getAuditor = (namespace = session) => getOrganization(namespace)
|
||||
.then(organization => getOrCreate('/users/', {
|
||||
username: `auditor-${uuid().substr(0, 8)}`,
|
||||
organization: organization.id,
|
||||
username: `e2e-auditor-${sid}`,
|
||||
first_name: 'auditor',
|
||||
last_name: 'last',
|
||||
email: 'null@ansible.com',
|
||||
@ -208,15 +234,54 @@ const getAuditor = () => getOrganization()
|
||||
password: 'password'
|
||||
}));
|
||||
|
||||
const getUser = () => getOrCreate('/users/', {
|
||||
username: `e2e-user-${sid}`,
|
||||
first_name: `user-${sid}-first`,
|
||||
last_name: `user-${sid}-last`,
|
||||
email: `null-${sid}@ansible.com`,
|
||||
is_superuser: false,
|
||||
is_system_auditor: false,
|
||||
password: 'password'
|
||||
});
|
||||
const getUser = (namespace = session) => getOrganization(namespace)
|
||||
.then(organization => getOrCreate('/users/', {
|
||||
username: `user-${uuid().substr(0, 8)}`,
|
||||
organization: organization.id,
|
||||
first_name: 'firstname',
|
||||
last_name: 'lastname',
|
||||
email: 'null@ansible.com',
|
||||
is_superuser: false,
|
||||
is_system_auditor: false,
|
||||
password: 'password'
|
||||
}));
|
||||
|
||||
const getJobTemplateAdmin = (namespace = session) => {
|
||||
const rolePromise = getJobTemplate(namespace)
|
||||
.then(obj => obj.summary_fields.object_roles.admin_role);
|
||||
|
||||
const userPromise = getOrganization(namespace)
|
||||
.then(obj => getOrCreate('/users/', {
|
||||
username: `job-template-admin-${uuid().substr(0, 8)}`,
|
||||
organization: obj.id,
|
||||
first_name: 'firstname',
|
||||
last_name: 'lastname',
|
||||
email: 'null@ansible.com',
|
||||
is_superuser: false,
|
||||
is_system_auditor: false,
|
||||
password: 'password'
|
||||
}));
|
||||
|
||||
const assignRolePromise = Promise.all([userPromise, rolePromise])
|
||||
.then(spread((user, role) => post(`/api/v2/roles/${role.id}/users/`, { id: user.id })));
|
||||
|
||||
return Promise.all([userPromise, assignRolePromise])
|
||||
.then(spread(user => user));
|
||||
};
|
||||
|
||||
const getInventorySourceSchedule = (namespace = session) => getInventorySource(namespace)
|
||||
.then(source => getOrCreate(source.related.schedules, {
|
||||
name: `${source.name}-schedule`,
|
||||
description: namespace,
|
||||
rrule: 'DTSTART:20171104T040000Z RRULE:FREQ=DAILY;INTERVAL=1;COUNT=1'
|
||||
}));
|
||||
|
||||
const getJobTemplateSchedule = (namespace = session) => getJobTemplate(namespace)
|
||||
.then(template => getOrCreate(template.related.schedules, {
|
||||
name: `${template.name}-schedule`,
|
||||
description: namespace,
|
||||
rrule: 'DTSTART:20171104T040000Z RRULE:FREQ=DAILY;INTERVAL=1;COUNT=1'
|
||||
}));
|
||||
|
||||
module.exports = {
|
||||
getAdminAWSCredential,
|
||||
@ -224,7 +289,11 @@ module.exports = {
|
||||
getAuditor,
|
||||
getInventory,
|
||||
getInventoryScript,
|
||||
getInventorySource,
|
||||
getInventorySourceSchedule,
|
||||
getJobTemplate,
|
||||
getJobTemplateAdmin,
|
||||
getJobTemplateSchedule,
|
||||
getNotificationTemplate,
|
||||
getOrCreate,
|
||||
getOrganization,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user