dnf5: implement enable_plugin and disable_plugin options (#83105)

80cfea9c25
pull/83220/head
Martin Krizek 7 months ago committed by GitHub
parent 036d14f1e6
commit 3c280e6c1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
minor_changes:
- dnf5 - implement ``enable_plugin`` and ``disable_plugin`` options

@ -127,17 +127,19 @@ options:
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
@ -434,6 +436,21 @@ class Dnf5Module(YumDnf):
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
@ -482,13 +499,6 @@ class Dnf5Module(YumDnf):
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,8 +541,23 @@ class Dnf5Module(YumDnf):
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()
# 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)

@ -873,3 +873,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)

Loading…
Cancel
Save