From a8df73ff3291074f1d48f6f2e390a3f89c9410c4 Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Tue, 21 Jan 2025 15:14:14 +0100 Subject: [PATCH] network: pass NM global dns configuration to the installed system Resolves: INSTALLER-4097 --- pyanaconda/modules/network/installation.py | 14 ++++++ .../modules/network/test_module_network.py | 48 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/pyanaconda/modules/network/installation.py b/pyanaconda/modules/network/installation.py index 2c95c368c5f..cb30b48b2db 100644 --- a/pyanaconda/modules/network/installation.py +++ b/pyanaconda/modules/network/installation.py @@ -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] @@ -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. @@ -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""" diff --git a/tests/unit_tests/pyanaconda_tests/modules/network/test_module_network.py b/tests/unit_tests/pyanaconda_tests/modules/network/test_module_network.py index 452dce1aa55..a7ead17d3a6 100644 --- a/tests/unit_tests/pyanaconda_tests/modules/network/test_module_network.py +++ b/tests/unit_tests/pyanaconda_tests/modules/network/test_module_network.py @@ -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 @@ -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 + """ + )