From 1db167b12a37840b4468abb3db5e327c8edc5bbb Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 26 Nov 2020 14:26:36 +0100 Subject: [PATCH] Bump version to 2.0.0 (#1369) * Bump version to 2.0.0. * Remove deprecated 2.0.0 features. * Test for failure. * Fix cache plugin unit tests. * Accept direct import only for Ansible 2.9. --- changelogs/fragments/deprecation-removals.yml | 5 +++++ galaxy.yml | 2 +- plugins/action/system/iptables_state.py | 22 +++---------------- plugins/cache/memcached.py | 7 +++--- plugins/cache/redis.py | 7 +++--- plugins/modules/files/xml.py | 9 +------- .../xml/tasks/test-get-element-content.yml | 11 +++------- tests/unit/plugins/cache/test_memcached.py | 4 ---- tests/unit/plugins/cache/test_redis.py | 4 ---- 9 files changed, 21 insertions(+), 50 deletions(-) create mode 100644 changelogs/fragments/deprecation-removals.yml diff --git a/changelogs/fragments/deprecation-removals.yml b/changelogs/fragments/deprecation-removals.yml new file mode 100644 index 0000000000..4e8546dfcb --- /dev/null +++ b/changelogs/fragments/deprecation-removals.yml @@ -0,0 +1,5 @@ +removed_features: +- "iptables_state - the ``ANSIBLE_ASYNC_DIR`` environment is no longer supported, use the ``async_dir`` shell option instead (https://github.com/ansible-collections/community.general/pull/1371)." +- "memcached cache plugin - do not import ``CacheModule``s directly. Use ``ansible.plugins.loader.cache_loader`` instead (https://github.com/ansible-collections/community.general/pull/1371)." +- "redis cache plugin - do not import ``CacheModule``s directly. Use ``ansible.plugins.loader.cache_loader`` instead (https://github.com/ansible-collections/community.general/pull/1371)." +- "xml - when ``content=attribute``, the ``attribute`` option is ignored (https://github.com/ansible-collections/community.general/pull/1371)." diff --git a/galaxy.yml b/galaxy.yml index a25854d11d..b067db5530 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: community name: general -version: 1.3.0 +version: 2.0.0 readme: README.md authors: - Ansible (https://github.com/ansible) diff --git a/plugins/action/system/iptables_state.py b/plugins/action/system/iptables_state.py index 92fb079ae0..cc174b3bd7 100644 --- a/plugins/action/system/iptables_state.py +++ b/plugins/action/system/iptables_state.py @@ -98,25 +98,9 @@ class ActionModule(ActionBase): task_async, max_timeout)) - # BEGIN snippet from async_status action plugin - env_async_dir = [e for e in self._task.environment if - "ANSIBLE_ASYNC_DIR" in e] - if len(env_async_dir) > 0: - # for backwards compatibility we need to get the dir from - # ANSIBLE_ASYNC_DIR that is defined in the environment. This is - # deprecated and will be removed in favour of shell options - async_dir = env_async_dir[0]['ANSIBLE_ASYNC_DIR'] - - msg = "Setting the async dir from the environment keyword " \ - "ANSIBLE_ASYNC_DIR is deprecated. Set the async_dir " \ - "shell option instead" - display.deprecated(msg, version='2.0.0', - collection_name='community.general') # was Ansible 2.12 - else: - # inject the async directory based on the shell option into the - # module args - async_dir = self.get_shell_option('async_dir', default="~/.ansible_async") - # END snippet from async_status action plugin + # inject the async directory based on the shell option into the + # module args + async_dir = self.get_shell_option('async_dir', default="~/.ansible_async") # Bind the loop max duration to consistent values on both # remote and local sides (if not the same, make the loop diff --git a/plugins/cache/memcached.py b/plugins/cache/memcached.py index 3cf670d7a0..f4c65892bb 100644 --- a/plugins/cache/memcached.py +++ b/plugins/cache/memcached.py @@ -53,6 +53,7 @@ from ansible import constants as C from ansible.errors import AnsibleError from ansible.module_utils.common._collections_compat import MutableSet from ansible.plugins.cache import BaseCacheModule +from ansible.release import __version__ as ansible_base_version from ansible.utils.display import Display try: @@ -180,9 +181,9 @@ class CacheModule(BaseCacheModule): self._timeout = self.get_option('_timeout') self._prefix = self.get_option('_prefix') except KeyError: - display.deprecated('Rather than importing CacheModules directly, ' - 'use ansible.plugins.loader.cache_loader', - version='2.0.0', collection_name='community.general') # was Ansible 2.12 + # TODO: remove once we no longer support Ansible 2.9 + if not ansible_base_version.startswith('2.9.'): + raise AnsibleError("Do not import CacheModules directly. Use ansible.plugins.loader.cache_loader instead.") if C.CACHE_PLUGIN_CONNECTION: connection = C.CACHE_PLUGIN_CONNECTION.split(',') self._timeout = C.CACHE_PLUGIN_TIMEOUT diff --git a/plugins/cache/redis.py b/plugins/cache/redis.py index fe41c4c051..371eacfe78 100644 --- a/plugins/cache/redis.py +++ b/plugins/cache/redis.py @@ -69,6 +69,7 @@ from ansible.errors import AnsibleError from ansible.module_utils._text import to_native from ansible.parsing.ajson import AnsibleJSONEncoder, AnsibleJSONDecoder from ansible.plugins.cache import BaseCacheModule +from ansible.release import __version__ as ansible_base_version from ansible.utils.display import Display try: @@ -103,9 +104,9 @@ class CacheModule(BaseCacheModule): self._keys_set = self.get_option('_keyset_name') self._sentinel_service_name = self.get_option('_sentinel_service_name') except KeyError: - display.deprecated('Rather than importing CacheModules directly, ' - 'use ansible.plugins.loader.cache_loader', - version='2.0.0', collection_name='community.general') # was Ansible 2.12 + # TODO: remove once we no longer support Ansible 2.9 + if not ansible_base_version.startswith('2.9.'): + raise AnsibleError("Do not import CacheModules directly. Use ansible.plugins.loader.cache_loader instead.") if C.CACHE_PLUGIN_CONNECTION: uri = C.CACHE_PLUGIN_CONNECTION self._timeout = float(C.CACHE_PLUGIN_TIMEOUT) diff --git a/plugins/modules/files/xml.py b/plugins/modules/files/xml.py index 53b84b127b..cccae266f1 100644 --- a/plugins/modules/files/xml.py +++ b/plugins/modules/files/xml.py @@ -826,8 +826,7 @@ def main(): supports_check_mode=True, required_by=dict( add_children=['xpath'], - # TODO: Reinstate this in community.general 2.0.0 when we have deprecated the incorrect use below - # attribute=['value'], + attribute=['value'], content=['xpath'], set_children=['xpath'], value=['xpath'], @@ -876,12 +875,6 @@ def main(): elif LooseVersion('.'.join(to_native(f) for f in etree.LXML_VERSION)) < LooseVersion('3.0.0'): module.warn('Using lxml version lower than 3.0.0 does not guarantee predictable element attribute order.') - # Report wrongly used attribute parameter when using content=attribute - # TODO: Remove this in community.general 2.0.0 (and reinstate strict parameter test above) and remove the integration test example - if content == 'attribute' and attribute is not None: - module.deprecate("Parameter 'attribute=%s' is ignored when using 'content=attribute' only 'xpath' is used. Please remove entry." % attribute, - version='2.0.0', collection_name='community.general') # was Ansible 2.12 - # Check if the file exists if xml_string: infile = BytesIO(to_bytes(xml_string, errors='surrogate_or_strict')) diff --git a/tests/integration/targets/xml/tasks/test-get-element-content.yml b/tests/integration/targets/xml/tasks/test-get-element-content.yml index 29a423009b..4a40b42dcf 100644 --- a/tests/integration/targets/xml/tasks/test-get-element-content.yml +++ b/tests/integration/targets/xml/tasks/test-get-element-content.yml @@ -19,24 +19,19 @@ - get_element_attribute.matches[0]['rating'] is defined - get_element_attribute.matches[0]['rating']['subjective'] == 'true' - # TODO: Remove this in 2.0.0 when this incorrect use of attribute is deprecated - - name: Get element attributes + - name: Get element attributes (should fail) xml: path: /tmp/ansible-xml-beers.xml xpath: /business/rating content: attribute attribute: subjective register: get_element_attribute_wrong + ignore_errors: true - name: Test expected result assert: that: - - get_element_attribute_wrong.changed == false - - get_element_attribute_wrong.matches[0]['rating'] is defined - - get_element_attribute_wrong.matches[0]['rating']['subjective'] == 'true' - - get_element_attribute_wrong.deprecations is defined - - get_element_attribute_wrong.deprecations[0].msg == "Parameter 'attribute=subjective' is ignored when using 'content=attribute' only 'xpath' is used. Please remove entry." - - get_element_attribute_wrong.deprecations[0].version == '2.0.0' + - get_element_attribute_wrong is failed - name: Get element text xml: diff --git a/tests/unit/plugins/cache/test_memcached.py b/tests/unit/plugins/cache/test_memcached.py index f460b0a3a7..bfa9deec6c 100644 --- a/tests/unit/plugins/cache/test_memcached.py +++ b/tests/unit/plugins/cache/test_memcached.py @@ -28,8 +28,4 @@ from ansible_collections.community.general.plugins.cache.memcached import CacheM def test_memcached_cachemodule(): - assert isinstance(MemcachedCache(), MemcachedCache) - - -def test_memcached_cachemodule_with_loader(): assert isinstance(cache_loader.get('community.general.memcached'), MemcachedCache) diff --git a/tests/unit/plugins/cache/test_redis.py b/tests/unit/plugins/cache/test_redis.py index 2effec3488..e665826769 100644 --- a/tests/unit/plugins/cache/test_redis.py +++ b/tests/unit/plugins/cache/test_redis.py @@ -28,9 +28,5 @@ from ansible_collections.community.general.plugins.cache.redis import CacheModul def test_redis_cachemodule(): - assert isinstance(RedisCache(), RedisCache) - - -def test_redis_cachemodule_with_loader(): # The _uri option is required for the redis plugin assert isinstance(cache_loader.get('community.general.redis', **{'_uri': '127.0.0.1:6379:1'}), RedisCache)