mirror of https://github.com/ansible/ansible.git
Remove deprecated `common.removed` module_util.
Tests have been updated to reflect its removal as well.pull/74506/head
parent
1a7923e318
commit
a30c55f68a
@ -0,0 +1,5 @@
|
||||
removed_features:
|
||||
- The built-in module_util ``ansible.module_utils.common.removed`` was previously deprecated and has been removed.
|
||||
minor_changes:
|
||||
- ansible-test - The ``validate-modules`` sanity test codes ``last-line-main-call``, ``missing-if-name-main`` and ``missing-main-call`` have been removed.
|
||||
- ansible-test - The ``validate-modules`` sanity test codes ``ansible-deprecated-module`` and ``collection-deprecated-module`` have been added.
|
@ -1,63 +0,0 @@
|
||||
# Copyright (c) 2018, Ansible Project
|
||||
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
def removed_module(removed_in, msg='This module has been removed. The module documentation for'
|
||||
' Ansible-%(version)s may contain hints for porting'):
|
||||
"""
|
||||
This function is deprecated and should not be used. Instead the module should just be
|
||||
actually removed. This function is scheduled for removal for the 2.12 release.
|
||||
|
||||
Returns module failure along with a message about the module being removed
|
||||
|
||||
:arg removed_in: The version that the module was removed in
|
||||
:kwarg msg: Message to use in the module's failure message. The default says that the module
|
||||
has been removed and what version of the Ansible documentation to search for porting help.
|
||||
|
||||
Remove the actual code and instead have boilerplate like this::
|
||||
|
||||
from ansible.module_utils.common.removed import removed_module
|
||||
|
||||
if __name__ == '__main__':
|
||||
removed_module("2.4")
|
||||
"""
|
||||
results = {
|
||||
'failed': True,
|
||||
'deprecations': [
|
||||
{
|
||||
'msg': 'The removed_module function is deprecated',
|
||||
'version': '2.12',
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
# Convert numbers into strings
|
||||
removed_in = to_native(removed_in)
|
||||
|
||||
version = removed_in.split('.')
|
||||
try:
|
||||
numeric_minor = int(version[-1])
|
||||
except Exception:
|
||||
last_version = None
|
||||
else:
|
||||
version = version[:-1]
|
||||
version.append(to_native(numeric_minor - 1))
|
||||
last_version = '.'.join(version)
|
||||
|
||||
if last_version is None:
|
||||
results['warnings'] = ['removed modules should specify the version they were removed in']
|
||||
results['msg'] = 'This module has been removed'
|
||||
else:
|
||||
results['msg'] = msg % {'version': last_version}
|
||||
|
||||
print('\n{0}\n'.format(json.dumps(results)))
|
||||
sys.exit(1)
|
@ -1,62 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2019, Andrew Klychkov @Andersson007 <aaklychkov@mail.ru>
|
||||
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible.module_utils.common.removed import removed_module
|
||||
|
||||
|
||||
@pytest.mark.parametrize('input_data', [u'2.8', 2.8, 2, '', ])
|
||||
def test_removed_module_sys_exit(input_data):
|
||||
"""Test for removed_module function, sys.exit()."""
|
||||
|
||||
with pytest.raises(SystemExit) as wrapped_e:
|
||||
removed_module(input_data)
|
||||
|
||||
assert wrapped_e.type == SystemExit
|
||||
assert wrapped_e.value.code == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'input_data, expected_msg, expected_warn',
|
||||
[
|
||||
(
|
||||
u'2.8',
|
||||
u'This module has been removed. '
|
||||
'The module documentation for Ansible-2.7 may contain hints for porting',
|
||||
u'',
|
||||
),
|
||||
(
|
||||
2.8,
|
||||
u'This module has been removed. '
|
||||
'The module documentation for Ansible-2.7 may contain hints for porting',
|
||||
u'',
|
||||
),
|
||||
(
|
||||
2,
|
||||
u'This module has been removed. '
|
||||
'The module documentation for Ansible-1 may contain hints for porting',
|
||||
u'',
|
||||
),
|
||||
(
|
||||
u'café',
|
||||
u'This module has been removed',
|
||||
u'"warnings": ["removed modules should specify the version they were removed in"]',
|
||||
),
|
||||
(
|
||||
0.1,
|
||||
u'This module has been removed. '
|
||||
'The module documentation for Ansible-0.0 may contain hints for porting',
|
||||
u'',
|
||||
),
|
||||
]
|
||||
)
|
||||
def test_removed_module_msgs(input_data, expected_msg, expected_warn, capsys):
|
||||
"""Test for removed_module function, content of output messages."""
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert expected_msg, expected_warn in captured.out
|
Loading…
Reference in New Issue