1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-30 05:25:29 +03:00

Merge pull request #6186 from AlanCoding/wfjt_vars

Modernize types of WFJT module

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-03-12 19:43:04 +00:00 committed by GitHub
commit 1876849d89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 13 deletions

View File

@ -35,15 +35,20 @@ have it function as a collection.
The following notes are changes that may require changes to playbooks:
- Specifying `inputs` or `injectors` as strings in the
`tower_credential_type` module is no longer supported. Provide them as dictionaries instead.
- When a project is created, it will wait for the update/sync to finish by default; this can be turned off with the `wait` parameter, if desired.
- Creating a "scan" type job template is no longer supported.
- `extra_vars` in the `tower_job_launch` module worked with a list previously, but is now configured to work solely in a `dict` format.
- When the `extra_vars` parameter is used with the `tower_job_launch` module, the Job Template launch will fail unless `add_extra_vars` or `survey_enabled` is explicitly set to `True` on the Job Template.
- Type changes of variable fields
- `extra_vars` in the `tower_job_launch` module worked with a list previously, but is now configured to work solely in a `dict` format.
- `extra_vars` in the `tower_workflow_job_template` module worked with a string previously but now expects a dict.
- When the `extra_vars` parameter is used with the `tower_job_launch` module, the Job Template launch will fail unless `add_extra_vars` or `survey_enabled` is explicitly set to `True` on the Job Template.
- The `variables` parameter in the `tower_group`, `tower_host` and `tower_inventory` modules are now in `dict` format and no longer supports the use of the `C(@)` syntax (for an external `vars` file).
- Type changes of other types of fields
- Specifying `inputs` or `injectors` as strings in the
`tower_credential_type` module is no longer supported. Provide them as dictionaries instead.
- Specifying `schema` as in the `tower_workflow_job_template` module is no longer supported. Use a list of dicts instead.
- `tower_group` used to also service inventory sources, but this functionality has been removed from this module; use `tower_inventory_source` instead.
- Specified `tower_config` file used to handle `k=v` pairs on a single line; this is no longer supported. Please use a file formatted as `yaml`, `json` or `ini` only.
- The `variables` parameter in the `tower_group`, `tower_host` and `tower_inventory` modules are now in `dict` format and no longer supports the use of the `C(@)` syntax (for an external `vars` file).
- Some return values (e.g., `credential_type`) have been removed. Use of `id` is recommended.
## Running Unit Tests

View File

@ -44,7 +44,7 @@ options:
extra_vars:
description:
- Extra variables used by Ansible in YAML or key=value format.
type: str
type: dict
inventory:
description:
- Name of the inventory to use for the job template.
@ -65,7 +65,8 @@ options:
The schema is a JSON- or YAML-formatted string defining the
hierarchy structure that connects the nodes. Refer to Tower
documentation for more information.
type: str
type: list
elements: dict
survey_enabled:
description:
- Setting that variable will prompt the user for job type on the
@ -111,6 +112,8 @@ from ..module_utils.ansible_tower import (
tower_check_mode
)
import json
try:
import tower_cli
import tower_cli.exceptions as exc
@ -123,10 +126,10 @@ def main():
argument_spec = dict(
name=dict(required=True),
description=dict(required=False),
extra_vars=dict(required=False),
extra_vars=dict(type='dict', required=False),
organization=dict(required=False),
allow_simultaneous=dict(type='bool', required=False),
schema=dict(required=False),
schema=dict(type='list', elements='dict', required=False),
survey=dict(required=False),
survey_enabled=dict(type='bool', required=False),
inventory=dict(required=False),
@ -187,18 +190,23 @@ def main():
if module.params.get('ask_inventory'):
params['ask_inventory_on_launch'] = module.params.get('ask_inventory')
for key in ('allow_simultaneous', 'extra_vars', 'inventory',
for key in ('allow_simultaneous', 'inventory',
'survey_enabled', 'description'):
if module.params.get(key):
params[key] = module.params.get(key)
# Special treatment for tower-cli extra_vars
extra_vars = module.params.get('extra_vars')
if extra_vars:
params['extra_vars'] = [json.dumps(extra_vars)]
try:
if state == 'present':
params['create_on_missing'] = True
result = wfjt_res.modify(**params)
json_output['id'] = result['id']
if schema:
wfjt_res.schema(result['id'], schema)
wfjt_res.schema(result['id'], json.dumps(schema))
elif state == 'absent':
params['fail_on_missing'] = False
result = wfjt_res.delete(**params)

View File

@ -0,0 +1,35 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import pytest
from awx.main.models import WorkflowJobTemplate
@pytest.mark.django_db
def test_create_workflow_job_template(run_module, admin_user, organization):
module_args = {
'name': 'foo-workflow',
'organization': organization.name,
'extra_vars': {'foo': 'bar', 'another-foo': {'barz': 'bar2'}},
'state': 'present'
}
result = run_module('tower_workflow_template', module_args, admin_user)
wfjt = WorkflowJobTemplate.objects.get(name='foo-workflow')
assert wfjt.extra_vars == '{"foo": "bar", "another-foo": {"barz": "bar2"}}'
result.pop('module_args', None)
assert result == {
"workflow_template": "foo-workflow", # TODO: remove after refactor
"state": "present",
"id": wfjt.id,
"changed": True,
"invocation": {
"module_args": module_args
}
}
assert wfjt.organization_id == organization.id

View File

@ -51,7 +51,7 @@
- name: Create a workflow job template
tower_workflow_template:
name: my-workflow
schema: '[{"success": [{"job_template": "my-job-1"}], "job_template": "my-job-2"}]'
schema: [{"success": [{"job_template": "my-job-1"}], "job_template": "my-job-2"}]
register: result
- assert:
@ -72,7 +72,7 @@
tower_workflow_template:
name: my-workflow
organization: Non Existing Organization
schema: '[{"success": [{"job_template": "my-job-1"}], "job_template": "my-job-2"}]'
schema: [{"success": [{"job_template": "my-job-1"}], "job_template": "my-job-2"}]
register: result
ignore_errors: true