From a60f7462fdc81ff6131462beb859825b8645db38 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Fri, 19 Apr 2024 11:21:51 +0200 Subject: [PATCH 1/5] dnf5: implement enable_plugin and disable_plugin options https://github.com/rpm-software-management/dnf5/commit/80cfea9c2514704058ce501c496433fbb6e349bf --- .../fragments/dnf5-enable-disable-plugins.yml | 2 ++ lib/ansible/modules/dnf5.py | 25 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/dnf5-enable-disable-plugins.yml diff --git a/changelogs/fragments/dnf5-enable-disable-plugins.yml b/changelogs/fragments/dnf5-enable-disable-plugins.yml new file mode 100644 index 00000000000000..5d4eacfbac03c1 --- /dev/null +++ b/changelogs/fragments/dnf5-enable-disable-plugins.yml @@ -0,0 +1,2 @@ +minor_changes: + - dnf5 - implement ``enable_plugin`` and ``disable_plugin`` options diff --git a/lib/ansible/modules/dnf5.py b/lib/ansible/modules/dnf5.py index 2ebc4a1004e325..558455fdbf1138 100644 --- a/lib/ansible/modules/dnf5.py +++ b/lib/ansible/modules/dnf5.py @@ -127,17 +127,19 @@ type: bool enable_plugin: description: - - This is currently a no-op as dnf5 itself does not implement this feature. - I(Plugin) name to enable for the install/update operation. The enabled plugin will not persist beyond the transaction. + - O(disable_plugin) takes precedence in case a plugin is listed in both O(enable_plugin) and O(disable_plugin) + - Requires python3-libdnf5 5.2.0.0+ type: list elements: str default: [] disable_plugin: description: - - This is currently a no-op as dnf5 itself does not implement this feature. - I(Plugin) name to disable for the install/update operation. The disabled plugins will not persist beyond the transaction. + - O(disable_plugin) takes precedence in case a plugin is listed in both O(enable_plugin) and O(disable_plugin). + - Requires python3-libdnf5 5.2.0.0+ type: list default: [] elements: str @@ -482,13 +484,6 @@ def run(self): rc=1, ) - if self.enable_plugin or self.disable_plugin: - self.module.fail_json( - msg="enable_plugin and disable_plugin options are not yet implemented in DNF5", - failures=[], - rc=1, - ) - base = libdnf5.base.Base() conf = base.get_config() @@ -531,6 +526,18 @@ def run(self): if self.download_dir: conf.destdir = self.download_dir + if self.enable_plugin: + try: + base.enable_disable_plugins(self.enable_plugin, True) + except AttributeError: + self.module.fail_json(msg="'enable_plugin' requires python3-libdnf5 5.2.0.0+") + + if self.disable_plugin: + try: + base.enable_disable_plugins(self.disable_plugin, False) + except AttributeError: + self.module.fail_json(msg="'disable_plugin' requires python3-libdnf5 5.2.0.0+") + base.setup() log_router = base.get_logger() From 085a10bbad035b28a2815448c21ff6827e8b1a95 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 29 Apr 2024 15:04:54 +0200 Subject: [PATCH 2/5] fail on non-existing plugins --- lib/ansible/modules/dnf5.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/dnf5.py b/lib/ansible/modules/dnf5.py index 558455fdbf1138..6a72271247585a 100644 --- a/lib/ansible/modules/dnf5.py +++ b/lib/ansible/modules/dnf5.py @@ -130,7 +130,7 @@ - I(Plugin) name to enable for the install/update operation. The enabled plugin will not persist beyond the transaction. - O(disable_plugin) takes precedence in case a plugin is listed in both O(enable_plugin) and O(disable_plugin) - - Requires python3-libdnf5 5.2.0.0+ + - Requires python3-libdnf5 5.2.0.0+. type: list elements: str default: [] @@ -139,7 +139,7 @@ - I(Plugin) name to disable for the install/update operation. The disabled plugins will not persist beyond the transaction. - O(disable_plugin) takes precedence in case a plugin is listed in both O(enable_plugin) and O(disable_plugin). - - Requires python3-libdnf5 5.2.0.0+ + - Requires python3-libdnf5 5.2.0.0+. type: list default: [] elements: str @@ -436,6 +436,21 @@ def __init__(self, module): self.pkg_mgr_name = "dnf5" + def fail_on_non_existing_plugins(self, base): + # https://github.com/rpm-software-management/dnf5/issues/1460 + plugin_names = [p.get_name() for p in base.get_plugins_info()] + msg = [] + if enable_unmatched := set(self.enable_plugin).difference(plugin_names): + msg.append( + f"No matches were found for the following plugin name patterns while enabling libdnf5 plugins: {", ".join(enable_unmatched)}." + ) + if disable_unmatched := set(self.disable_plugin).difference(plugin_names): + msg.append( + f"No matches were found for the following plugin name patterns while disabling libdnf5 plugins: {", ".join(disable_unmatched)}." + ) + if msg: + self.module.fail_json(msg=" ".join(msg)) + def _ensure_dnf(self): locale = get_best_parsable_locale(self.module) os.environ["LC_ALL"] = os.environ["LC_MESSAGES"] = locale @@ -540,6 +555,9 @@ def run(self): base.setup() + # https://github.com/rpm-software-management/dnf5/issues/1460 + self.fail_on_non_existing_plugins(base) + log_router = base.get_logger() global_logger = libdnf5.logger.GlobalLogger() global_logger.set(log_router.get(), libdnf5.logger.Logger.Level_DEBUG) From 869c3a1f0585b6175763be338e9d5a7cafdf3a06 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 29 Apr 2024 15:08:48 +0200 Subject: [PATCH 3/5] dot --- lib/ansible/modules/dnf5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/dnf5.py b/lib/ansible/modules/dnf5.py index 6a72271247585a..4a79c2d725d92c 100644 --- a/lib/ansible/modules/dnf5.py +++ b/lib/ansible/modules/dnf5.py @@ -129,7 +129,7 @@ description: - I(Plugin) name to enable for the install/update operation. The enabled plugin will not persist beyond the transaction. - - O(disable_plugin) takes precedence in case a plugin is listed in both O(enable_plugin) and O(disable_plugin) + - O(disable_plugin) takes precedence in case a plugin is listed in both O(enable_plugin) and O(disable_plugin). - Requires python3-libdnf5 5.2.0.0+. type: list elements: str From 47efa42f8c61bbec5c697e13779c7f414cf6facc Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 29 Apr 2024 15:15:21 +0200 Subject: [PATCH 4/5] fix sanity --- lib/ansible/modules/dnf5.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/dnf5.py b/lib/ansible/modules/dnf5.py index 4a79c2d725d92c..4007752adf21e0 100644 --- a/lib/ansible/modules/dnf5.py +++ b/lib/ansible/modules/dnf5.py @@ -442,11 +442,11 @@ def fail_on_non_existing_plugins(self, base): msg = [] if enable_unmatched := set(self.enable_plugin).difference(plugin_names): msg.append( - f"No matches were found for the following plugin name patterns while enabling libdnf5 plugins: {", ".join(enable_unmatched)}." + f"No matches were found for the following plugin name patterns while enabling libdnf5 plugins: {', '.join(enable_unmatched)}." ) if disable_unmatched := set(self.disable_plugin).difference(plugin_names): msg.append( - f"No matches were found for the following plugin name patterns while disabling libdnf5 plugins: {", ".join(disable_unmatched)}." + f"No matches were found for the following plugin name patterns while disabling libdnf5 plugins: {', '.join(disable_unmatched)}." ) if msg: self.module.fail_json(msg=" ".join(msg)) From a9c0b3535db433aa919b586e860509cac583c94d Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Mon, 6 May 2024 13:35:13 +0200 Subject: [PATCH 5/5] add test --- test/integration/targets/dnf/tasks/dnf.yml | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/integration/targets/dnf/tasks/dnf.yml b/test/integration/targets/dnf/tasks/dnf.yml index 4110d4b80c2841..bd40ec5869a3dd 100644 --- a/test/integration/targets/dnf/tasks/dnf.yml +++ b/test/integration/targets/dnf/tasks/dnf.yml @@ -885,3 +885,27 @@ - dnf: name: langpacks-ja state: absent + +- name: test passing non existing plugins, should fail + block: + - dnf: + name: sos + enable_plugin: nonexisting + ignore_errors: true + register: enable_plugin_result + + - dnf: + name: sos + disable_plugin: nonexisting + ignore_errors: true + register: disable_plugin_result + + - assert: + that: + - enable_plugin_result is failed + - disable_plugin_result is failed + - '"No matches were found for the following plugin name patterns while enabling libdnf5 plugins: " in enable_plugin_result.msg' + - '"No matches were found for the following plugin name patterns while disabling libdnf5 plugins: " in disable_plugin_result.msg' + - '"nonexisting" in enable_plugin_result.msg' + - '"nonexisting" in disable_plugin_result.msg' + when: dnf5|default(false)