From 494909aba535d3f35d2f3aeca0129cd5cb97efcf Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Fri, 9 Jun 2023 22:56:10 +1200 Subject: [PATCH] MH mh/mixins/deps.py: prevent deprecation warning when no deps are specified (#6644) * MH mh/mixins/deps.py: prevent deprecation warning when no deps are specified * rollback empty "patch" on license markers to prevent test error * disable test in ansible 2.12 * add changelog frag --- .../fragments/6644-dependencymixin-fix.yml | 2 ++ plugins/module_utils/mh/mixins/deps.py | 2 ++ .../targets/kernel_blacklist/tasks/main.yml | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/6644-dependencymixin-fix.yml diff --git a/changelogs/fragments/6644-dependencymixin-fix.yml b/changelogs/fragments/6644-dependencymixin-fix.yml new file mode 100644 index 0000000000..3b75758303 --- /dev/null +++ b/changelogs/fragments/6644-dependencymixin-fix.yml @@ -0,0 +1,2 @@ +bugfixes: + - MH DependencyMixin module utils - deprecation notice was popping up for modules not using dependencies (https://github.com/ansible-collections/community.general/pull/6644, https://github.com/ansible-collections/community.general/issues/6639). diff --git a/plugins/module_utils/mh/mixins/deps.py b/plugins/module_utils/mh/mixins/deps.py index 2a5b2a716c..772df8c0e9 100644 --- a/plugins/module_utils/mh/mixins/deps.py +++ b/plugins/module_utils/mh/mixins/deps.py @@ -52,6 +52,8 @@ class DependencyMixin(ModuleHelperBase): return cls._dependencies[-1] def fail_on_missing_deps(self): + if not self._dependencies: + return self.module.deprecate( 'The DependencyMixin is being deprecated. ' 'Modules should use community.general.plugins.module_utils.deps instead.', diff --git a/tests/integration/targets/kernel_blacklist/tasks/main.yml b/tests/integration/targets/kernel_blacklist/tasks/main.yml index e169d5479e..45136e119c 100644 --- a/tests/integration/targets/kernel_blacklist/tasks/main.yml +++ b/tests/integration/targets/kernel_blacklist/tasks/main.yml @@ -36,6 +36,13 @@ path: '{{ bl_file }}' register: stat_test_1 +- name: show bl_test_1 + ansible.builtin.debug: + var: bl_test_1_depr_msgs + vars: + bl_test_1_depr_msgs: "{{ (bl_test_1.deprecations | default([])) | map(attribute='msg') }}" + # q('ansible.builtin.subelements', bl_test_1, 'deprecations', {'skip_missing': True}) }}" + - name: assert file is unchanged assert: that: @@ -49,12 +56,17 @@ expected_content: | # Copyright (c) Ansible Project # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) - # SPDX-{{ '' }}License-Identifier: GPL-3.0-or-later + # SPDX{{ '' }}-License-Identifier: GPL-3.0-or-later blacklist aaaa blacklist bbbb blacklist cccc +- name: test deprecation + assert: + that: + - "'deprecations' not in bl_test_1 or (ansible_version.major == 2 and ansible_version.minor == 12)" + - name: add new item to list community.general.kernel_blacklist: blacklist_file: '{{ bl_file }}' @@ -76,7 +88,7 @@ content: | # Copyright (c) Ansible Project # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) - # SPDX-{{ '' }}License-Identifier: GPL-3.0-or-later + # SPDX{{ '' }}-License-Identifier: GPL-3.0-or-later blacklist aaaa blacklist bbbb @@ -104,7 +116,7 @@ content: | # Copyright (c) Ansible Project # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) - # SPDX-{{ '' }}License-Identifier: GPL-3.0-or-later + # SPDX{{ '' }}-License-Identifier: GPL-3.0-or-later blacklist aaaa blacklist cccc