Skip to content

Commit

Permalink
network: enable dnsconfd service on installed system if required
Browse files Browse the repository at this point in the history
Resolves: RHEL-80023
  • Loading branch information
rvykydal committed Feb 27, 2025
1 parent f3314ea commit fb8a646
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pyanaconda/modules/network/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import shutil

from pyanaconda.core import util
from pyanaconda.core.kernel import kernel_arguments
from pyanaconda.modules.common.errors.installation import NetworkInstallationError
from pyanaconda.modules.common.task import Task
from pyanaconda.anaconda_loggers import get_module_logger
Expand Down Expand Up @@ -116,6 +117,7 @@ class NetworkInstallationTask(Task):
[Link]
Name={}
""".strip()
DNSCONFD_SERVICE = "dnsconfd"

def __init__(self, sysroot, disable_ipv6, overwrite,
network_ifaces, ifname_option_values,
Expand Down Expand Up @@ -160,6 +162,7 @@ def run(self):
if self._configure_persistent_device_names:
self._copy_prefixdevname_files(self._sysroot)
self._copy_global_dns_config(self._sysroot)
self._enable_dnsconfd(self._sysroot)

def _write_sysconfig_network(self, root, overwrite):
"""Write empty /etc/sysconfig/network target system configuration file.
Expand Down Expand Up @@ -305,6 +308,13 @@ def _copy_global_dns_config(self, root):
if os.path.isfile(src):
shutil.copy(src, dst)

def _enable_dnsconfd(self, root):
"""Enable dnsconfd service if dnsconfd backend is used."""
if kernel_arguments.get("rd.net.dns-backend") == "dnsconfd":
if not util.is_service_installed(self.DNSCONFD_SERVICE, root=root):
log.debug("The dnsconfd service is not installed.")
return
util.enable_service(self.DNSCONFD_SERVICE, root=root)

class ConfigureActivationOnBootTask(Task):
"""Task for configuration of automatic activation of devices on boot"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,29 @@ def _create_config_files_to_check_overwrite(self):
(("71-net-ifnames-prefix-XYZ", "installer environment content"),)
)

@patch("pyanaconda.modules.network.installation.util")
def test_network_installation_task_dnsconfd_enablement(self, mocked_util):
"""Test the task for network installation dnsconfd enablement."""

self._create_all_expected_dirs()
task = NetworkInstallationTask(
sysroot=self._target_root,
disable_ipv6=False,
overwrite=True,
network_ifaces=["ens3", "ens7", "ens10"],
ifname_option_values=["ens3:00:15:17:96:75:0a"],
configure_persistent_device_names=False,
)

kernel_args = KernelArguments.from_string("rd.net.dns-backend=dnsconfd")
with patch("pyanaconda.modules.network.installation.kernel_arguments", kernel_args):
mocked_util.is_service_installed.return_value = False
task._enable_dnsconfd(self._target_root)
mocked_util.enable_service.assert_not_called()
mocked_util.is_service_installed.return_value = True
task._enable_dnsconfd(self._target_root)
mocked_util.enable_service.assert_called_once()

def test_network_installation_task_overwrite(self):
"""Test the task for network installation with overwrite."""

Expand Down

0 comments on commit fb8a646

Please sign in to comment.