mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
fix bug processing survey spec
This commit is contained in:
@@ -215,13 +215,15 @@ def main():
|
|||||||
new_fields['extra_vars'] = json.dumps(new_fields['extra_vars'])
|
new_fields['extra_vars'] = json.dumps(new_fields['extra_vars'])
|
||||||
|
|
||||||
on_change = None
|
on_change = None
|
||||||
existing_spec = None
|
|
||||||
if existing_item:
|
|
||||||
existing_spec = module.get_endpoint('spec_endpoint')
|
|
||||||
new_spec = module.params.get('survey')
|
new_spec = module.params.get('survey')
|
||||||
if new_spec and (new_spec != existing_spec):
|
if new_spec:
|
||||||
module.json_output['changed'] = True
|
existing_spec = None
|
||||||
on_change = update_survey
|
if existing_item:
|
||||||
|
spec_endpoint = existing_item.get('related', {}).get('survey_spec')
|
||||||
|
existing_spec = module.get_endpoint(spec_endpoint)
|
||||||
|
if new_spec != existing_spec:
|
||||||
|
module.json_output['changed'] = True
|
||||||
|
on_change = update_survey
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
# If the state was absent we can let the module delete it if needed, the module will handle exiting from this
|
||||||
|
|||||||
@@ -165,6 +165,15 @@ EXAMPLES = '''
|
|||||||
organization: Default # organization of workflow job template
|
organization: Default # organization of workflow job template
|
||||||
extra_data:
|
extra_data:
|
||||||
foo_key: bar_value
|
foo_key: bar_value
|
||||||
|
|
||||||
|
- name: Create parent node for prior node
|
||||||
|
tower_workflow_job_template_node:
|
||||||
|
identifier: my-root-node
|
||||||
|
workflow: example-workflow
|
||||||
|
unified_job_template: jt-for-node-use
|
||||||
|
organization: Default
|
||||||
|
success_nodes:
|
||||||
|
- my-first-node
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ..module_utils.tower_api import TowerModule
|
from ..module_utils.tower_api import TowerModule
|
||||||
|
|||||||
@@ -22,16 +22,35 @@ def test_create_workflow_job_template(run_module, admin_user, organization, surv
|
|||||||
assert wfjt.extra_vars == '{"foo": "bar", "another-foo": {"barz": "bar2"}}'
|
assert wfjt.extra_vars == '{"foo": "bar", "another-foo": {"barz": "bar2"}}'
|
||||||
|
|
||||||
result.pop('invocation', None)
|
result.pop('invocation', None)
|
||||||
assert result == {
|
assert result == {"name": "foo-workflow", "id": wfjt.id, "changed": True}
|
||||||
"name": "foo-workflow",
|
|
||||||
"id": wfjt.id,
|
|
||||||
"changed": True
|
|
||||||
}
|
|
||||||
|
|
||||||
assert wfjt.organization_id == organization.id
|
assert wfjt.organization_id == organization.id
|
||||||
assert wfjt.survey_spec == survey_spec
|
assert wfjt.survey_spec == survey_spec
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_create_modify_no_survey(run_module, admin_user, organization, survey_spec):
|
||||||
|
result = run_module('tower_workflow_job_template', {
|
||||||
|
'name': 'foo-workflow',
|
||||||
|
'organization': organization.name
|
||||||
|
}, admin_user)
|
||||||
|
assert not result.get('failed', False), result.get('msg', result)
|
||||||
|
assert result.get('changed', False), result
|
||||||
|
|
||||||
|
wfjt = WorkflowJobTemplate.objects.get(name='foo-workflow')
|
||||||
|
assert wfjt.organization_id == organization.id
|
||||||
|
assert wfjt.survey_spec == {}
|
||||||
|
result.pop('invocation', None)
|
||||||
|
assert result == {"name": "foo-workflow", "id": wfjt.id, "changed": True}
|
||||||
|
|
||||||
|
result = run_module('tower_workflow_job_template', {
|
||||||
|
'name': 'foo-workflow',
|
||||||
|
'organization': organization.name
|
||||||
|
}, admin_user)
|
||||||
|
assert not result.get('failed', False), result.get('msg', result)
|
||||||
|
assert not result.get('changed', True), result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_survey_spec_only_changed(run_module, admin_user, organization, survey_spec):
|
def test_survey_spec_only_changed(run_module, admin_user, organization, survey_spec):
|
||||||
wfjt = WorkflowJobTemplate.objects.create(
|
wfjt = WorkflowJobTemplate.objects.create(
|
||||||
@@ -60,3 +79,21 @@ def test_survey_spec_only_changed(run_module, admin_user, organization, survey_s
|
|||||||
assert result.get('changed', True), result
|
assert result.get('changed', True), result
|
||||||
wfjt.refresh_from_db()
|
wfjt.refresh_from_db()
|
||||||
assert wfjt.survey_spec == survey_spec
|
assert wfjt.survey_spec == survey_spec
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_delete_with_spec(run_module, admin_user, organization, survey_spec):
|
||||||
|
WorkflowJobTemplate.objects.create(
|
||||||
|
organization=organization, name='foo-workflow',
|
||||||
|
survey_enabled=True, survey_spec=survey_spec
|
||||||
|
)
|
||||||
|
result = run_module('tower_workflow_job_template', {
|
||||||
|
'name': 'foo-workflow',
|
||||||
|
'organization': organization.name,
|
||||||
|
'state': 'absent'
|
||||||
|
}, admin_user)
|
||||||
|
assert not result.get('failed', False), result.get('msg', result)
|
||||||
|
assert result.get('changed', True), result
|
||||||
|
|
||||||
|
assert WorkflowJobTemplate.objects.filter(
|
||||||
|
name='foo-workflow', organization=organization).count() == 0
|
||||||
|
|||||||
Reference in New Issue
Block a user