mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
add namespacing, schedules, and sources to fixtures
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
|||||||
spread
|
spread
|
||||||
} from './api';
|
} from './api';
|
||||||
|
|
||||||
const sid = uuid().substr(0, 8);
|
const session = `e2e-${uuid().substr(0, 8)}`;
|
||||||
|
|
||||||
const store = {};
|
const store = {};
|
||||||
|
|
||||||
@@ -50,24 +50,43 @@ const getOrCreate = (endpoint, data) => {
|
|||||||
return store[endpoint][identity].then(created => created.data);
|
return store[endpoint][identity].then(created => created.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getOrganization = () => getOrCreate('/organizations/', {
|
const getOrganization = (namespace = session) => getOrCreate('/organizations/', {
|
||||||
name: `e2e-organization-${sid}`
|
name: `${namespace}-organization`,
|
||||||
|
description: namespace
|
||||||
});
|
});
|
||||||
|
|
||||||
const getInventory = () => getOrganization()
|
const getInventory = (namespace = session) => getOrganization(namespace)
|
||||||
.then(organization => getOrCreate('/inventories/', {
|
.then(organization => getOrCreate('/inventories/', {
|
||||||
name: `e2e-inventory-${sid}`,
|
name: `${namespace}-inventory`,
|
||||||
|
description: namespace,
|
||||||
organization: organization.id
|
organization: organization.id
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const getInventoryScript = () => getOrganization()
|
const getInventoryScript = (namespace = session) => getOrganization(namespace)
|
||||||
.then(organization => getOrCreate('/inventory_scripts/', {
|
.then(organization => getOrCreate('/inventory_scripts/', {
|
||||||
name: `e2e-inventory-script-${sid}`,
|
name: `${namespace}-inventory-script`,
|
||||||
|
description: namespace,
|
||||||
organization: organization.id,
|
organization: organization.id,
|
||||||
script: '#!/usr/bin/env python'
|
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 = [
|
const promises = [
|
||||||
get('/me/'),
|
get('/me/'),
|
||||||
getOrCreate('/credential_types/', {
|
getOrCreate('/credential_types/', {
|
||||||
@@ -80,7 +99,8 @@ const getAdminAWSCredential = () => {
|
|||||||
const [admin] = me.data.results;
|
const [admin] = me.data.results;
|
||||||
|
|
||||||
return getOrCreate('/credentials/', {
|
return getOrCreate('/credentials/', {
|
||||||
name: `e2e-aws-credential-${sid}`,
|
name: `${namespace}-credential-aws`,
|
||||||
|
description: namespace,
|
||||||
credential_type: credentialType.id,
|
credential_type: credentialType.id,
|
||||||
user: admin.id,
|
user: admin.id,
|
||||||
inputs: {
|
inputs: {
|
||||||
@@ -92,7 +112,7 @@ const getAdminAWSCredential = () => {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAdminMachineCredential = () => {
|
const getAdminMachineCredential = (namespace = session) => {
|
||||||
const promises = [
|
const promises = [
|
||||||
get('/me/'),
|
get('/me/'),
|
||||||
getOrCreate('/credential_types/', { name: 'Machine' })
|
getOrCreate('/credential_types/', { name: 'Machine' })
|
||||||
@@ -103,30 +123,34 @@ const getAdminMachineCredential = () => {
|
|||||||
const [admin] = me.data.results;
|
const [admin] = me.data.results;
|
||||||
|
|
||||||
return getOrCreate('/credentials/', {
|
return getOrCreate('/credentials/', {
|
||||||
name: `e2e-machine-credential-${sid}`,
|
name: `${namespace}-credential-machine-admin`,
|
||||||
|
description: namespace,
|
||||||
credential_type: credentialType.id,
|
credential_type: credentialType.id,
|
||||||
user: admin.id
|
user: admin.id
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTeam = () => getOrganization()
|
const getTeam = (namespace = session) => getOrganization(namespace)
|
||||||
.then(organization => getOrCreate('/teams/', {
|
.then(organization => getOrCreate('/teams/', {
|
||||||
name: `e2e-team-${sid}`,
|
name: `${namespace}-team`,
|
||||||
|
description: namespace,
|
||||||
organization: organization.id,
|
organization: organization.id,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const getSmartInventory = () => getOrganization()
|
const getSmartInventory = (namespace = session) => getOrganization(namespace)
|
||||||
.then(organization => getOrCreate('/inventories/', {
|
.then(organization => getOrCreate('/inventories/', {
|
||||||
name: `e2e-smart-inventory-${sid}`,
|
name: `${namespace}-smart-inventory`,
|
||||||
|
description: namespace,
|
||||||
organization: organization.id,
|
organization: organization.id,
|
||||||
host_filter: 'search=localhost',
|
host_filter: 'search=localhost',
|
||||||
kind: 'smart'
|
kind: 'smart'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const getNotificationTemplate = () => getOrganization()
|
const getNotificationTemplate = (namespace = session) => getOrganization(namespace)
|
||||||
.then(organization => getOrCreate('/notification_templates/', {
|
.then(organization => getOrCreate('/notification_templates/', {
|
||||||
name: `e2e-notification-template-${sid}`,
|
name: `${namespace}-notification-template`,
|
||||||
|
description: namespace,
|
||||||
organization: organization.id,
|
organization: organization.id,
|
||||||
notification_type: 'slack',
|
notification_type: 'slack',
|
||||||
notification_configuration: {
|
notification_configuration: {
|
||||||
@@ -135,9 +159,10 @@ const getNotificationTemplate = () => getOrganization()
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const getProject = () => getOrganization()
|
const getProject = (namespace = session) => getOrganization(namespace)
|
||||||
.then(organization => getOrCreate('/projects/', {
|
.then(organization => getOrCreate('/projects/', {
|
||||||
name: `e2e-project-${sid}`,
|
name: `${namespace}-project`,
|
||||||
|
description: namespace,
|
||||||
organization: organization.id,
|
organization: organization.id,
|
||||||
scm_url: 'https://github.com/ansible/ansible-tower-samples',
|
scm_url: 'https://github.com/ansible/ansible-tower-samples',
|
||||||
scm_type: 'git'
|
scm_type: 'git'
|
||||||
@@ -168,7 +193,7 @@ const waitForJob = endpoint => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUpdatedProject = () => getProject()
|
const getUpdatedProject = (namespace = session) => getProject(namespace)
|
||||||
.then(project => {
|
.then(project => {
|
||||||
const updateURL = project.related.current_update;
|
const updateURL = project.related.current_update;
|
||||||
|
|
||||||
@@ -179,27 +204,28 @@ const getUpdatedProject = () => getProject()
|
|||||||
return project;
|
return project;
|
||||||
});
|
});
|
||||||
|
|
||||||
const getJobTemplate = () => {
|
const getJobTemplate = (namespace = session) => {
|
||||||
const promises = [
|
const promises = [
|
||||||
getInventory(),
|
getInventory(namespace),
|
||||||
getAdminMachineCredential(),
|
getAdminMachineCredential(namespace),
|
||||||
getUpdatedProject()
|
getUpdatedProject(namespace)
|
||||||
];
|
];
|
||||||
|
|
||||||
return all(promises)
|
return all(promises)
|
||||||
.then(spread((inventory, credential, project) => getOrCreate('/job_templates', {
|
.then(spread((inventory, credential, project) => getOrCreate('/job_templates/', {
|
||||||
name: `e2e-job-template-${sid}`,
|
name: `${namespace}-job-template`,
|
||||||
|
description: namespace,
|
||||||
inventory: inventory.id,
|
inventory: inventory.id,
|
||||||
credential: credential.id,
|
credential: credential.id,
|
||||||
project: project.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/', {
|
.then(organization => getOrCreate('/users/', {
|
||||||
|
username: `auditor-${uuid().substr(0, 8)}`,
|
||||||
organization: organization.id,
|
organization: organization.id,
|
||||||
username: `e2e-auditor-${sid}`,
|
|
||||||
first_name: 'auditor',
|
first_name: 'auditor',
|
||||||
last_name: 'last',
|
last_name: 'last',
|
||||||
email: 'null@ansible.com',
|
email: 'null@ansible.com',
|
||||||
@@ -208,15 +234,54 @@ const getAuditor = () => getOrganization()
|
|||||||
password: 'password'
|
password: 'password'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const getUser = () => getOrCreate('/users/', {
|
const getUser = (namespace = session) => getOrganization(namespace)
|
||||||
username: `e2e-user-${sid}`,
|
.then(organization => getOrCreate('/users/', {
|
||||||
first_name: `user-${sid}-first`,
|
username: `user-${uuid().substr(0, 8)}`,
|
||||||
last_name: `user-${sid}-last`,
|
organization: organization.id,
|
||||||
email: `null-${sid}@ansible.com`,
|
first_name: 'firstname',
|
||||||
is_superuser: false,
|
last_name: 'lastname',
|
||||||
is_system_auditor: false,
|
email: 'null@ansible.com',
|
||||||
password: 'password'
|
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 = {
|
module.exports = {
|
||||||
getAdminAWSCredential,
|
getAdminAWSCredential,
|
||||||
@@ -224,7 +289,11 @@ module.exports = {
|
|||||||
getAuditor,
|
getAuditor,
|
||||||
getInventory,
|
getInventory,
|
||||||
getInventoryScript,
|
getInventoryScript,
|
||||||
|
getInventorySource,
|
||||||
|
getInventorySourceSchedule,
|
||||||
getJobTemplate,
|
getJobTemplate,
|
||||||
|
getJobTemplateAdmin,
|
||||||
|
getJobTemplateSchedule,
|
||||||
getNotificationTemplate,
|
getNotificationTemplate,
|
||||||
getOrCreate,
|
getOrCreate,
|
||||||
getOrganization,
|
getOrganization,
|
||||||
|
|||||||
Reference in New Issue
Block a user