diff --git a/test/integration/targets/module_utils/library/test_alias_deprecation.py b/test/integration/targets/module_utils/library/test_alias_deprecation.py new file mode 100644 index 00000000000..96410fc4ef2 --- /dev/null +++ b/test/integration/targets/module_utils/library/test_alias_deprecation.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.facts import data + +results = {"data": data} + +arg_spec = dict( + foo=dict(type='str', aliases=['baz'], deprecated_aliases=[dict(name='baz', version='9.99')]) +) + +AnsibleModule(argument_spec=arg_spec).exit_json(**results) diff --git a/test/integration/targets/module_utils/module_utils_test.yml b/test/integration/targets/module_utils/module_utils_test.yml index cf0672bc30f..e29039f9018 100644 --- a/test/integration/targets/module_utils/module_utils_test.yml +++ b/test/integration/targets/module_utils/module_utils_test.yml @@ -49,3 +49,14 @@ that: - result is failed - result['msg'] == "Could not find imported module support code for test_failure. Looked for either foo.py or zebra.py" + + - name: Test that alias deprecation works + test_alias_deprecation: + baz: 'bar' + register: result + + - name: Assert that the deprecation message is given correctly + assert: + that: + - result.deprecations[0].msg == "Alias 'baz' is deprecated. See the module docs for more information" + - result.deprecations[0].version == '9.99' diff --git a/test/units/module_utils/basic/test_argument_spec.py b/test/units/module_utils/basic/test_argument_spec.py index d51d579a1fe..71e4b163dbe 100644 --- a/test/units/module_utils/basic/test_argument_spec.py +++ b/test/units/module_utils/basic/test_argument_spec.py @@ -102,6 +102,7 @@ def complex_argspec(): bar3=dict(type='list', elements='path'), zardoz=dict(choices=['one', 'two']), zardoz2=dict(type='list', choices=['one', 'two', 'three']), + zardoz3=dict(type='str', aliases=['zodraz'], deprecated_aliases=[dict(name='zodraz', version='9.99')]), ) mut_ex = (('bar', 'bam'), ('bing', 'bang', 'bong')) req_to = (('bam', 'baz'),) @@ -332,6 +333,14 @@ class TestComplexArgSpecs: assert am.params['bar3'][0].startswith('/') assert am.params['bar3'][1] == 'test/' + @pytest.mark.parametrize('stdin', [{'foo': 'hello', 'zodraz': 'one'}], indirect=['stdin']) + def test_deprecated_alias(self, capfd, mocker, stdin, complex_argspec): + """Test a deprecated alias""" + am = basic.AnsibleModule(**complex_argspec) + + assert "Alias 'zodraz' is deprecated." in am._deprecations[0]['msg'] + assert am._deprecations[0]['version'] == '9.99' + class TestComplexOptions: """Test arg spec options"""