Skip to content

Commit

Permalink
network: pass NM global dns configuration to the installed system
Browse files Browse the repository at this point in the history
Resolves: INSTALLER-4097
  • Loading branch information
rvykydal committed Jan 22, 2025
1 parent 8c9b47c commit a8df73f
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pyanaconda/modules/network/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class NetworkInstallationTask(Task):
SYSTEMD_NETWORK_CONFIG_DIR = "/etc/systemd/network"
INTERFACE_RENAME_FILE_TEMPLATE = "10-anaconda-ifname-{}.link"
NM_SYSTEM_CONNECTIONS_DIR_PATH = KEYFILE_DIR
NM_GLOBAL_DNS_RUNTIME_CONFIG = "/run/NetworkManager/conf.d/16-global-dns.conf"
NM_GLOBAL_DNS_CONFIG = "/etc/NetworkManager/conf.d/16-global-dns.conf"
INTERFACE_RENAME_FILE_CONTENT_TEMPLATE = """
# Generated by Anaconda based on ifname= installer boot option.
[Match]
Expand Down Expand Up @@ -163,6 +165,7 @@ def run(self):
self._copy_dhclient_config_files(self._sysroot, self._network_ifaces)
if self._configure_persistent_device_names:
self._copy_prefixdevname_files(self._sysroot)
self._copy_global_dns_config(self._sysroot)

def _write_sysconfig_network(self, root, overwrite):
"""Write empty /etc/sysconfig/network target system configuration file.
Expand Down Expand Up @@ -289,6 +292,17 @@ def _copy_prefixdevname_files(self, root):
config_file)
self._copy_file_to_root(root, config_file_path)

def _copy_global_dns_config(self, root):
"""Copy NM global dns configuration to target system.
:param root: path to the root of the target system
:type root: str
"""
src = self.NM_GLOBAL_DNS_RUNTIME_CONFIG
dst = os.path.normpath(root + self.NM_GLOBAL_DNS_CONFIG)
if os.path.isfile(src):
shutil.copy(src, dst)


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 @@ -1297,6 +1297,8 @@ def _mock_task_paths(self, task):
type(task).NM_SYSTEM_CONNECTIONS_DIR_PATH
task.DHCLIENT_FILE_TEMPLATE = self._mocked_root + type(task).DHCLIENT_FILE_TEMPLATE
task.SYSTEMD_NETWORK_CONFIG_DIR = self._mocked_root + type(task).SYSTEMD_NETWORK_CONFIG_DIR
task.NM_GLOBAL_DNS_RUNTIME_CONFIG = self._mocked_root + type(task).NM_GLOBAL_DNS_RUNTIME_CONFIG
task.NM_GLOBAL_DNS_CONFIG = self._mocked_root + type(task).NM_GLOBAL_DNS_CONFIG

def _create_all_expected_dirs(self):
# Create directories that are expected to be existing in installer
Expand Down Expand Up @@ -1803,3 +1805,49 @@ def test_network_instalation_task_missing_target_dir(self):
bla
"""
)

def test_network_instalation_task_global_dns_config(self):
"""Test the task for network installation and global dns configuration."""

nm_runtime_config_dir, src_file = os.path.split(
NetworkInstallationTask.NM_GLOBAL_DNS_RUNTIME_CONFIG)
nm_config_dir, dst_file = os.path.split(
NetworkInstallationTask.NM_GLOBAL_DNS_CONFIG)

self._create_all_expected_dirs()

self._create_config_dirs(
installer_dirs=[
nm_runtime_config_dir,
nm_config_dir,
],
target_system_dirs=[
nm_config_dir,
]
)

self._dump_config_files(
nm_runtime_config_dir,
((src_file, "bla"),)
)

# Create the task
task = NetworkInstallationTask(
sysroot=self._target_root,
disable_ipv6=False,
overwrite=True,
network_ifaces=["ens3", "ens7"],
ifname_option_values=[],
configure_persistent_device_names=True,
)

self._mock_task_paths(task)
task.run()

self._check_config_file(
nm_config_dir,
dst_file,
"""
bla
"""
)

0 comments on commit a8df73f

Please sign in to comment.