Skip to content

Commit

Permalink
Support DNF5's config-manager
Browse files Browse the repository at this point in the history
Fedora rawhide is installing DNF5 on new systems. Payload that sets up
multilib support on the system runs on the installed system, thus using
DNF5. DNF5 changed config-manager plugin syntax. This commit makes sure
that it works with both DNF4 as well as with DNF5.
  • Loading branch information
marusak committed May 20, 2024
1 parent c416525 commit 9033e4e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 12 deletions.
21 changes: 21 additions & 0 deletions pyanaconda/modules/payloads/payload/dnf/dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from pyanaconda.anaconda_loggers import get_module_logger
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.core.signal import Signal
from pyanaconda.core.constants import MULTILIB_POLICY_BEST
from pyanaconda.modules.common.structures.packages import PackagesConfigurationData, \
PackagesSelectionData
from pyanaconda.modules.payloads.constants import PayloadType, SourceType
Expand Down Expand Up @@ -370,6 +371,25 @@ def calculate_required_space(self):
required_space = calculate_required_space(self.dnf_manager)
return required_space.get_bytes()

def collect_requirements(self):
"""Return installation requirements for this module.
:return: a list of requirements
"""
requirements = []

if self.dnf_manager.is_package_available("dnf5"):
plugins_name = "dnf5-modules"
else:
plugins_name = "dnf-plugins-core"

if self._packages_configuration.multilib_policy != MULTILIB_POLICY_BEST:
requirements.append(
Requirement.for_package(plugins_name, reason="Needed to enable multilib support.")
)

return requirements

def get_repo_configurations(self):
"""Get RepoConfiguration structures for all sources.
Expand Down Expand Up @@ -472,6 +492,7 @@ def post_install_with_tasks(self):
UpdateDNFConfigurationTask(
sysroot=conf.target.system_root,
configuration=self.packages_configuration,
dnf_manager=self.dnf_manager,
),
ResetDNFManagerTask(
dnf_manager=self.dnf_manager
Expand Down
20 changes: 14 additions & 6 deletions pyanaconda/modules/payloads/payload/dnf/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def run(self):
class UpdateDNFConfigurationTask(Task):
"""The installation task to update the dnf.conf file."""

def __init__(self, sysroot, configuration: PackagesConfigurationData):
def __init__(self, sysroot, configuration: PackagesConfigurationData, dnf_manager):
"""Create a new task.
:param sysroot: a path to the system root
Expand All @@ -386,6 +386,7 @@ def __init__(self, sysroot, configuration: PackagesConfigurationData):
super().__init__()
self._sysroot = sysroot
self._data = configuration
self._dnf_manager = dnf_manager

@property
def name(self):
Expand All @@ -405,11 +406,18 @@ def _set_option(self, option, value):
log.debug("Setting '%s' to '%s'.", option, value)

cmd = "dnf"
args = [
"config-manager",
"--save",
"--setopt={}={}".format(option, value),
]
if self._dnf_manager.is_package_available("dnf5"):
args = [
"config-manager",
"setopt",
"{}={}".format(option, value)
]
else:
args = [
"config-manager",
"--save",
"--setopt={}={}".format(option, value)
]

try:
rc = util.execWithRedirect(cmd, args, root=self._sysroot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,9 @@ def test_no_update(self, execute):
"""Don't update the DNF configuration."""
with tempfile.TemporaryDirectory() as sysroot:
data = PackagesConfigurationData()
dnf_manager = DNFManager()

task = UpdateDNFConfigurationTask(sysroot, data)
task = UpdateDNFConfigurationTask(sysroot, data, dnf_manager)
task.run()

execute.assert_not_called()
Expand All @@ -447,8 +448,9 @@ def test_failed_update(self, execute):
with tempfile.TemporaryDirectory() as sysroot:
data = PackagesConfigurationData()
data.multilib_policy = MULTILIB_POLICY_ALL
dnf_manager = DNFManager()

task = UpdateDNFConfigurationTask(sysroot, data)
task = UpdateDNFConfigurationTask(sysroot, data, dnf_manager)

with self.assertLogs(level="WARNING") as cm:
task.run()
Expand All @@ -464,8 +466,9 @@ def test_error_update(self, execute):
with tempfile.TemporaryDirectory() as sysroot:
data = PackagesConfigurationData()
data.multilib_policy = MULTILIB_POLICY_ALL
dnf_manager = DNFManager()

task = UpdateDNFConfigurationTask(sysroot, data)
task = UpdateDNFConfigurationTask(sysroot, data, dnf_manager)

with self.assertLogs(level="WARNING") as cm:
task.run()
Expand All @@ -474,15 +477,17 @@ def test_error_update(self, execute):
assert any(map(lambda x: msg in x, cm.output))

@patch("pyanaconda.core.util.execWithRedirect")
def test_multilib_policy(self, execute):
"""Update the multilib policy."""
def test_multilib_policy_dnf4(self, execute):
"""Update the multilib policy on pre-dnf5 systems."""
execute.return_value = 0

with tempfile.TemporaryDirectory() as sysroot:
data = PackagesConfigurationData()
data.multilib_policy = MULTILIB_POLICY_ALL
dnf_manager = Mock(spec=DNFManager)
dnf_manager.is_package_available.return_value = False

task = UpdateDNFConfigurationTask(sysroot, data)
task = UpdateDNFConfigurationTask(sysroot, data, dnf_manager)
task.run()

execute.assert_called_once_with(
Expand All @@ -495,6 +500,30 @@ def test_multilib_policy(self, execute):
root=sysroot
)

@patch("pyanaconda.core.util.execWithRedirect")
def test_multilib_policy_dnf5(self, execute):
"""Update the multilib policy on dnf5 systems."""
execute.return_value = 0

with tempfile.TemporaryDirectory() as sysroot:
data = PackagesConfigurationData()
data.multilib_policy = MULTILIB_POLICY_ALL
dnf_manager = Mock(spec=DNFManager)
dnf_manager.is_package_available.return_value = True

task = UpdateDNFConfigurationTask(sysroot, data, dnf_manager)
task.run()

execute.assert_called_once_with(
"dnf",
[
"config-manager",
"setopt",
"multilib_policy=all",
],
root=sysroot
)


class WriteRepositoriesTaskTestCase(unittest.TestCase):
"""Test the WriteRepositoriesTask task."""
Expand Down

0 comments on commit 9033e4e

Please sign in to comment.