From c746806784c06fccac28a3e92578fa9abf9e9a1a Mon Sep 17 00:00:00 2001 From: Matej Matuska Date: Thu, 21 Aug 2025 18:59:01 +0200 Subject: [PATCH 105/111] checkyumpluginsenabled: Drop yum-related code The name of the actor is kept for backwards compatibility. --- .../actors/checkyumpluginsenabled/actor.py | 7 +-- .../libraries/checkyumpluginsenabled.py | 51 ++++++++----------- .../tests/test_checkyumpluginsenabled.py | 14 +++-- 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/repos/system_upgrade/common/actors/checkyumpluginsenabled/actor.py b/repos/system_upgrade/common/actors/checkyumpluginsenabled/actor.py index fbc2f8bc..c5a4853a 100644 --- a/repos/system_upgrade/common/actors/checkyumpluginsenabled/actor.py +++ b/repos/system_upgrade/common/actors/checkyumpluginsenabled/actor.py @@ -1,13 +1,14 @@ from leapp.actors import Actor -from leapp.libraries.actor.checkyumpluginsenabled import check_required_yum_plugins_enabled +from leapp.libraries.actor.checkyumpluginsenabled import check_required_dnf_plugins_enabled from leapp.models import PkgManagerInfo from leapp.reporting import Report from leapp.tags import ChecksPhaseTag, IPUWorkflowTag +# NOTE: the name is kept for backwards compatibility, even though this scans only DNF now class CheckYumPluginsEnabled(Actor): """ - Checks that the required yum plugins are enabled. + Checks that the required DNF plugins are enabled. """ name = 'check_yum_plugins_enabled' @@ -17,4 +18,4 @@ class CheckYumPluginsEnabled(Actor): def process(self): pkg_manager_info = next(self.consume(PkgManagerInfo)) - check_required_yum_plugins_enabled(pkg_manager_info) + check_required_dnf_plugins_enabled(pkg_manager_info) diff --git a/repos/system_upgrade/common/actors/checkyumpluginsenabled/libraries/checkyumpluginsenabled.py b/repos/system_upgrade/common/actors/checkyumpluginsenabled/libraries/checkyumpluginsenabled.py index 5522af9c..87ff6511 100644 --- a/repos/system_upgrade/common/actors/checkyumpluginsenabled/libraries/checkyumpluginsenabled.py +++ b/repos/system_upgrade/common/actors/checkyumpluginsenabled/libraries/checkyumpluginsenabled.py @@ -1,25 +1,24 @@ import os from leapp import reporting -from leapp.libraries.common.config.version import get_source_major_version from leapp.libraries.common.rhsm import skip_rhsm # If LEAPP_NO_RHSM is set, subscription-manager and product-id will not be # considered as required when checking whether the required plugins are enabled. -REQUIRED_YUM_PLUGINS = {'subscription-manager', 'product-id'} +REQUIRED_DNF_PLUGINS = {'subscription-manager', 'product-id'} FMT_LIST_SEPARATOR = '\n - ' -def check_required_yum_plugins_enabled(pkg_manager_info): +def check_required_dnf_plugins_enabled(pkg_manager_info): """ - Checks whether the yum plugins required by the IPU are enabled. + Checks whether the DNF plugins required by the IPU are enabled. If they are not enabled, a report is produced informing the user about it. :param pkg_manager_info: PkgManagerInfo """ - missing_required_plugins = REQUIRED_YUM_PLUGINS - set(pkg_manager_info.enabled_plugins) + missing_required_plugins = REQUIRED_DNF_PLUGINS - set(pkg_manager_info.enabled_plugins) if skip_rhsm(): missing_required_plugins -= {'subscription-manager', 'product-id'} @@ -29,37 +28,30 @@ def check_required_yum_plugins_enabled(pkg_manager_info): for missing_plugin in missing_required_plugins: missing_required_plugins_text += '{0}{1}'.format(FMT_LIST_SEPARATOR, missing_plugin) - if get_source_major_version() == '7': - pkg_manager = 'YUM' - pkg_manager_config_path = '/etc/yum.conf' - plugin_configs_dir = '/etc/yum/pluginconf.d' - else: - # On RHEL8+ the yum package might not be installed - pkg_manager = 'DNF' - pkg_manager_config_path = '/etc/dnf/dnf.conf' - plugin_configs_dir = '/etc/dnf/plugins' - - # pkg_manager_config_path - enable/disable plugins globally - # subscription_manager_plugin_conf, product_id_plugin_conf - plugins can be disabled individually - subscription_manager_plugin_conf = os.path.join(plugin_configs_dir, 'subscription-manager.conf') + # dnf_conf_path - enable/disable plugins globally + # rhsm_plugin_conf, product_id_plugin_conf - plugins can be disabled individually + dnf_conf_path = '/etc/dnf/dnf.conf' + plugin_configs_dir = '/etc/dnf/plugins' + rhsm_plugin_conf = os.path.join(plugin_configs_dir, 'subscription-manager.conf') product_id_plugin_conf = os.path.join(plugin_configs_dir, 'product-id.conf') remediation_commands = [ - 'sed -i \'s/^plugins=0/plugins=1/\' \'{0}\''.format(pkg_manager_config_path), - 'sed -i \'s/^enabled=0/enabled=1/\' \'{0}\''.format(subscription_manager_plugin_conf), - 'sed -i \'s/^enabled=0/enabled=1/\' \'{0}\''.format(product_id_plugin_conf) + f"sed -i 's/^plugins=0/plugins=1/' '{dnf_conf_path}'" + f"sed -i 's/^enabled=0/enabled=1/' '{rhsm_plugin_conf}'" + f"sed -i 's/^enabled=0/enabled=1/' '{product_id_plugin_conf}'" ] reporting.create_report([ - reporting.Title('Required {0} plugins are not being loaded.'.format(pkg_manager)), + reporting.Title('Required DNF plugins are not being loaded.'), reporting.Summary( - 'The following {0} plugins are not being loaded: {1}'.format(pkg_manager, - missing_required_plugins_text) + 'The following DNF plugins are not being loaded: {}'.format(missing_required_plugins_text) ), reporting.Remediation( - hint='If you have yum plugins globally disabled, please enable them by editing the {0}. ' - 'Individually, the {1} plugins can be enabled in their corresponding configurations found at: {2}' - .format(pkg_manager_config_path, pkg_manager, plugin_configs_dir), + hint=( + 'If you have DNF plugins globally disabled, please enable them by editing the {0}. ' + 'Individually, the DNF plugins can be enabled in their corresponding configurations found at: {1}' + .format(dnf_conf_path, plugin_configs_dir) + ), # Provide all commands as one due to problems with satellites commands=[['bash', '-c', '"{0}"'.format('; '.join(remediation_commands))]] ), @@ -67,10 +59,11 @@ def check_required_yum_plugins_enabled(pkg_manager_info): url='https://access.redhat.com/solutions/7028063', title='Why is Leapp preupgrade generating "Inhibitor: Required YUM plugins are not being loaded."' ), - reporting.RelatedResource('file', pkg_manager_config_path), - reporting.RelatedResource('file', subscription_manager_plugin_conf), + reporting.RelatedResource('file', dnf_conf_path), + reporting.RelatedResource('file', rhsm_plugin_conf), reporting.RelatedResource('file', product_id_plugin_conf), reporting.Severity(reporting.Severity.HIGH), reporting.Groups([reporting.Groups.INHIBITOR]), reporting.Groups([reporting.Groups.REPOSITORY]), + reporting.Key("2a0ff91bea885cfe9d763cf3a379789848a501b9"), ]) diff --git a/repos/system_upgrade/common/actors/checkyumpluginsenabled/tests/test_checkyumpluginsenabled.py b/repos/system_upgrade/common/actors/checkyumpluginsenabled/tests/test_checkyumpluginsenabled.py index 9bf9a3ba..1f7e916c 100644 --- a/repos/system_upgrade/common/actors/checkyumpluginsenabled/tests/test_checkyumpluginsenabled.py +++ b/repos/system_upgrade/common/actors/checkyumpluginsenabled/tests/test_checkyumpluginsenabled.py @@ -1,7 +1,5 @@ -import pytest - from leapp import reporting -from leapp.libraries.actor.checkyumpluginsenabled import check_required_yum_plugins_enabled +from leapp.libraries.actor.checkyumpluginsenabled import check_required_dnf_plugins_enabled from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked from leapp.libraries.stdlib import api from leapp.models import PkgManagerInfo @@ -37,15 +35,15 @@ def test__create_report_mocked(monkeypatch): def test_report_when_missing_required_plugins(monkeypatch): - """Test whether a report entry is created when any of the required YUM plugins are missing.""" - yum_config = PkgManagerInfo(enabled_plugins=['product-id', 'some-user-plugin']) + """Test whether a report entry is created when any of the required DNF plugins are missing.""" + dnf_config = PkgManagerInfo(enabled_plugins=['product-id', 'some-user-plugin']) actor_reports = create_report_mocked() monkeypatch.setattr(api, 'current_actor', CurrentActorMocked()) monkeypatch.setattr(reporting, 'create_report', actor_reports) - check_required_yum_plugins_enabled(yum_config) + check_required_dnf_plugins_enabled(dnf_config) assert actor_reports.called, "Report wasn't created when required a plugin is missing." @@ -62,7 +60,7 @@ def test_nothing_is_reported_when_rhsm_disabled(monkeypatch): monkeypatch.setattr(api, 'current_actor', actor_mocked) monkeypatch.setattr(reporting, 'create_report', create_report_mocked()) - yum_config = PkgManagerInfo(enabled_plugins=[]) - check_required_yum_plugins_enabled(yum_config) + dnf_config = PkgManagerInfo(enabled_plugins=[]) + check_required_dnf_plugins_enabled(dnf_config) assert not reporting.create_report.called, 'Report was created even if LEAPP_NO_RHSM was set' -- 2.52.0