Fix diassociate EE from JT and WFJT

Allow EE to be removed from JT and WFJT.

Also, add unit-test related to those changes.

See: https://github.com/ansible/awx/issues/9487
This commit is contained in:
nixocio
2021-03-04 17:11:28 -05:00
parent 18ba40506f
commit fbd46f7799
4 changed files with 54 additions and 8 deletions

View File

@@ -49,6 +49,7 @@ function JobTemplateEdit({ template }) {
webhook_credential, webhook_credential,
webhook_key, webhook_key,
webhook_url, webhook_url,
execution_environment,
...remainingValues ...remainingValues
} = values; } = values;
@@ -56,11 +57,9 @@ function JobTemplateEdit({ template }) {
setIsLoading(true); setIsLoading(true);
remainingValues.project = values.project.id; remainingValues.project = values.project.id;
remainingValues.webhook_credential = webhook_credential?.id || null; remainingValues.webhook_credential = webhook_credential?.id || null;
remainingValues.execution_environment = execution_environment?.id || null;
try { try {
await JobTemplatesAPI.update(template.id, { await JobTemplatesAPI.update(template.id, remainingValues);
...remainingValues,
execution_environment: values.execution_environment?.id,
});
await Promise.all([ await Promise.all([
submitLabels(labels, template?.organization), submitLabels(labels, template?.organization),
submitInstanceGroups(instanceGroups, initialInstanceGroups), submitInstanceGroups(instanceGroups, initialInstanceGroups),

View File

@@ -13,6 +13,7 @@ import {
LabelsAPI, LabelsAPI,
ProjectsAPI, ProjectsAPI,
InventoriesAPI, InventoriesAPI,
ExecutionEnvironmentsAPI,
} from '../../../api'; } from '../../../api';
import JobTemplateEdit from './JobTemplateEdit'; import JobTemplateEdit from './JobTemplateEdit';
@@ -49,6 +50,12 @@ const mockJobTemplate = {
scm_branch: '', scm_branch: '',
skip_tags: '', skip_tags: '',
summary_fields: { summary_fields: {
execution_environment: {
id: 1,
name: 'Default EE',
description: '',
image: 'quay.io/ansible/awx-ee',
},
user_capabilities: { user_capabilities: {
edit: true, edit: true,
}, },
@@ -81,6 +88,7 @@ const mockJobTemplate = {
related: { related: {
webhook_receiver: '/api/v2/workflow_job_templates/57/gitlab/', webhook_receiver: '/api/v2/workflow_job_templates/57/gitlab/',
}, },
execution_environment: 1,
}; };
const mockRelatedCredentials = { const mockRelatedCredentials = {
@@ -176,6 +184,15 @@ const mockInstanceGroups = [
}, },
]; ];
const mockExecutionEnvironment = [
{
id: 1,
name: 'Default EE',
description: '',
image: 'quay.io/ansible/awx-ee',
},
];
JobTemplatesAPI.readCredentials.mockResolvedValue({ JobTemplatesAPI.readCredentials.mockResolvedValue({
data: mockRelatedCredentials, data: mockRelatedCredentials,
}); });
@@ -197,6 +214,10 @@ CredentialsAPI.read.mockResolvedValue({
}); });
CredentialTypesAPI.loadAllTypes.mockResolvedValue([]); CredentialTypesAPI.loadAllTypes.mockResolvedValue([]);
ExecutionEnvironmentsAPI.read.mockResolvedValue({
data: mockExecutionEnvironment,
});
describe('<JobTemplateEdit />', () => { describe('<JobTemplateEdit />', () => {
beforeEach(() => { beforeEach(() => {
LabelsAPI.read.mockResolvedValue({ data: { results: [] } }); LabelsAPI.read.mockResolvedValue({ data: { results: [] } });
@@ -266,6 +287,8 @@ describe('<JobTemplateEdit />', () => {
id: 1, id: 1,
organization: 1, organization: 1,
}); });
wrapper.find('ExecutionEnvironmentLookup').invoke('onChange')(null);
}); });
wrapper.update(); wrapper.update();
await act(async () => { await act(async () => {
@@ -277,6 +300,7 @@ describe('<JobTemplateEdit />', () => {
...mockJobTemplate, ...mockJobTemplate,
project: mockJobTemplate.project, project: mockJobTemplate.project,
...updatedTemplateData, ...updatedTemplateData,
execution_environment: null,
}; };
delete expected.summary_fields; delete expected.summary_fields;
delete expected.id; delete expected.id;

View File

@@ -17,11 +17,13 @@ function WorkflowJobTemplateEdit({ template }) {
organization, organization,
webhook_credential, webhook_credential,
webhook_key, webhook_key,
execution_environment,
...templatePayload ...templatePayload
} = values; } = values;
templatePayload.inventory = inventory?.id || null; templatePayload.inventory = inventory?.id || null;
templatePayload.organization = organization?.id || null; templatePayload.organization = organization?.id || null;
templatePayload.webhook_credential = webhook_credential?.id || null; templatePayload.webhook_credential = webhook_credential?.id || null;
templatePayload.execution_environment = execution_environment?.id || null;
const formOrgId = const formOrgId =
organization?.id || inventory?.summary_fields?.organization.id || null; organization?.id || inventory?.summary_fields?.organization.id || null;
@@ -29,10 +31,7 @@ function WorkflowJobTemplateEdit({ template }) {
await Promise.all( await Promise.all(
await submitLabels(labels, formOrgId, template.organization) await submitLabels(labels, formOrgId, template.organization)
); );
await WorkflowJobTemplatesAPI.update(template.id, { await WorkflowJobTemplatesAPI.update(template.id, templatePayload);
...templatePayload,
execution_environment: values.execution_environment?.id,
});
history.push(`/templates/workflow_job_template/${template.id}/details`); history.push(`/templates/workflow_job_template/${template.id}/details`);
} catch (err) { } catch (err) {
setFormSubmitError(err); setFormSubmitError(err);

View File

@@ -6,6 +6,7 @@ import {
WorkflowJobTemplatesAPI, WorkflowJobTemplatesAPI,
OrganizationsAPI, OrganizationsAPI,
LabelsAPI, LabelsAPI,
ExecutionEnvironmentsAPI,
} from '../../../api'; } from '../../../api';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers'; import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import WorkflowJobTemplateEdit from './WorkflowJobTemplateEdit'; import WorkflowJobTemplateEdit from './WorkflowJobTemplateEdit';
@@ -14,12 +15,19 @@ jest.mock('../../../api/models/WorkflowJobTemplates');
jest.mock('../../../api/models/Labels'); jest.mock('../../../api/models/Labels');
jest.mock('../../../api/models/Organizations'); jest.mock('../../../api/models/Organizations');
jest.mock('../../../api/models/Inventories'); jest.mock('../../../api/models/Inventories');
jest.mock('../../../api/models/ExecutionEnvironments');
const mockTemplate = { const mockTemplate = {
id: 6, id: 6,
name: 'Foo', name: 'Foo',
description: 'Foo description', description: 'Foo description',
summary_fields: { summary_fields: {
execution_environment: {
id: 1,
name: 'Default EE',
description: '',
image: 'quay.io/ansible/awx-ee',
},
inventory: { id: 1, name: 'Inventory 1' }, inventory: { id: 1, name: 'Inventory 1' },
organization: { id: 1, name: 'Organization 1' }, organization: { id: 1, name: 'Organization 1' },
labels: { labels: {
@@ -32,7 +40,18 @@ const mockTemplate = {
scm_branch: 'devel', scm_branch: 'devel',
limit: '5000', limit: '5000',
variables: '---', variables: '---',
execution_environment: 1,
}; };
const mockExecutionEnvironment = [
{
id: 1,
name: 'Default EE',
description: '',
image: 'quay.io/ansible/awx-ee',
},
];
describe('<WorkflowJobTemplateEdit/>', () => { describe('<WorkflowJobTemplateEdit/>', () => {
let wrapper; let wrapper;
let history; let history;
@@ -48,6 +67,9 @@ describe('<WorkflowJobTemplateEdit/>', () => {
}, },
}); });
OrganizationsAPI.read.mockResolvedValue({ results: [{ id: 1 }] }); OrganizationsAPI.read.mockResolvedValue({ results: [{ id: 1 }] });
ExecutionEnvironmentsAPI.read.mockResolvedValue({
data: mockExecutionEnvironment,
});
await act(async () => { await act(async () => {
history = createMemoryHistory({ history = createMemoryHistory({
@@ -100,6 +122,7 @@ describe('<WorkflowJobTemplateEdit/>', () => {
.find('LabelSelect') .find('LabelSelect')
.find('SelectToggle') .find('SelectToggle')
.simulate('click'); .simulate('click');
wrapper.find('ExecutionEnvironmentLookup').invoke('onChange')(null);
}); });
wrapper.update(); wrapper.update();
@@ -142,6 +165,7 @@ describe('<WorkflowJobTemplateEdit/>', () => {
ask_limit_on_launch: false, ask_limit_on_launch: false,
ask_scm_branch_on_launch: false, ask_scm_branch_on_launch: false,
ask_variables_on_launch: false, ask_variables_on_launch: false,
execution_environment: null,
}); });
wrapper.update(); wrapper.update();
await expect(WorkflowJobTemplatesAPI.disassociateLabel).toBeCalledWith(6, { await expect(WorkflowJobTemplatesAPI.disassociateLabel).toBeCalledWith(6, {