ansible/test/units
Dag Wieers cd9471ef17 Introduce new 'required_by' argument_spec option (#28662)
* Introduce new "required_by' argument_spec option

This PR introduces a new **required_by** argument_spec option which allows you to say *"if parameter A is set, parameter B and C are required as well"*.

- The difference with **required_if** is that it can only add dependencies if a parameter is set to a specific value, not when it is just defined.
- The difference with **required_together** is that it has a commutative property, so: *"Parameter A and B are required together, if one of them has been defined"*.

As an example, we need this for the complex options that the xml module provides. One of the issues we often see is that users are not using the correct combination of options, and then are surprised that the module does not perform the requested action(s).

This would be solved by adding the correct dependencies, and mutual exclusives. For us this is important to get this shipped together with the new xml module in Ansible v2.4. (This is related to bugfix https://github.com/ansible/ansible/pull/28657)

```python
    module = AnsibleModule(
        argument_spec=dict(
            path=dict(type='path', aliases=['dest', 'file']),
            xmlstring=dict(type='str'),
            xpath=dict(type='str'),
            namespaces=dict(type='dict', default={}),
            state=dict(type='str', default='present', choices=['absent',
'present'], aliases=['ensure']),
            value=dict(type='raw'),
            attribute=dict(type='raw'),
            add_children=dict(type='list'),
            set_children=dict(type='list'),
            count=dict(type='bool', default=False),
            print_match=dict(type='bool', default=False),
            pretty_print=dict(type='bool', default=False),
            content=dict(type='str', choices=['attribute', 'text']),
            input_type=dict(type='str', default='yaml', choices=['xml',
'yaml']),
            backup=dict(type='bool', default=False),
        ),
        supports_check_mode=True,
        required_by=dict(
            add_children=['xpath'],
            attribute=['value', 'xpath'],
            content=['xpath'],
            set_children=['xpath'],
            value=['xpath'],
        ),
        required_if=[
            ['count', True, ['xpath']],
            ['print_match', True, ['xpath']],
        ],
        required_one_of=[
            ['path', 'xmlstring'],
            ['add_children', 'content', 'count', 'pretty_print', 'print_match', 'set_children', 'value'],
        ],
        mutually_exclusive=[
            ['add_children', 'content', 'count', 'print_match','set_children', 'value'],
            ['path', 'xmlstring'],
        ],
    )
```

* Rebase and fix conflict

* Add modules that use required_by functionality

* Update required_by schema

* Fix rebase issue
2019-02-15 10:57:45 +10:00
..
cli Move the arguments module into cli/ and context_objects into utils 2019-01-03 18:12:23 -08:00
compat Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
config Fix encoding issues with file paths. (#50830) 2019-01-14 13:06:47 -08:00
contrib Fix vmware_inventory unit tests so they run. 2018-10-09 22:52:04 -07:00
errors Add better error when k=v syntax is used with YAML in tasks (#41754) 2018-12-04 12:32:02 -05:00
executor Handle exception raised in recursive_finder API (#49590) 2019-01-04 10:33:37 +05:30
inventory_test_data/group_vars
mock Move unit test compat code out of lib/ansible/. (#46996) 2018-10-12 20:01:14 -07:00
module_utils Introduce new 'required_by' argument_spec option (#28662) 2019-02-15 10:57:45 +10:00
modules New Module: na_ontap_nvme (#51182) 2019-02-13 20:36:58 +00:00
parsing Fieldattribute inheritance with defaults (#50891) 2019-01-23 11:40:07 -06:00
playbook Become plugins (#50991) 2019-02-11 11:27:44 -06:00
plugins Disallow use of remote home directories containing .. in their path (CVE-2019-3828) (#52133) 2019-02-13 10:38:28 -06:00
template templar: ensure that exceptions are handled, fix 'AttributeError' (#48792) 2018-11-29 09:56:23 -05:00
utils Move the arguments module into cli/ and context_objects into utils 2019-01-03 18:12:23 -08:00
vars move extravars and option vars loading into VM (#51070) 2019-01-30 16:25:36 -05:00
__init__.py
ansible.cfg
conftest.py Run unit tests in parallel. (#45812) 2018-09-18 13:58:22 -07:00
test_constants.py
test_context.py Save the command line arguments into a global context 2019-01-03 18:12:23 -08:00