From 04cf64afc2e529be5cfc91118b8cf36bc373a277 Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Mon, 24 Feb 2025 10:53:15 +0100 Subject: [PATCH] network: pass 16-dns-backend.conf to target system Resolves: RHEL-80233 --- pyanaconda/modules/network/installation.py | 14 +++--- .../modules/network/test_module_network.py | 44 +++++++++---------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/pyanaconda/modules/network/installation.py b/pyanaconda/modules/network/installation.py index 0f62a47b5bb..2f1a0c44794 100644 --- a/pyanaconda/modules/network/installation.py +++ b/pyanaconda/modules/network/installation.py @@ -107,8 +107,9 @@ 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" + NM_GLOBAL_DNS_RUNTIME_CONFIG_DIR = "/run/NetworkManager/conf.d" + NM_GLOBAL_DNS_CONFIG_DIR = "/etc/NetworkManager/conf.d" + NM_GLOBAL_DNS_CONFIG_FILES = ("16-global-dns.conf", "16-dns-backend.conf") INTERFACE_RENAME_FILE_CONTENT_TEMPLATE = """ # Generated by Anaconda based on ifname= installer boot option. [Match] @@ -303,10 +304,11 @@ def _copy_global_dns_config(self, root): :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) + for file in self.NM_GLOBAL_DNS_CONFIG_FILES: + src = os.path.join(self.NM_GLOBAL_DNS_RUNTIME_CONFIG_DIR, file) + dst = os.path.normpath(root + os.path.join(self.NM_GLOBAL_DNS_CONFIG_DIR, file)) + if os.path.isfile(src): + shutil.copy(src, dst) def _enable_dnsconfd(self, root): """Enable dnsconfd service if dnsconfd backend is used.""" 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 cf4e0ebc23b..f9a2dda37ea 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 @@ -1184,6 +1184,9 @@ def setUp(self): self._nm_syscons_dir = NetworkInstallationTask.NM_SYSTEM_CONNECTIONS_DIR_PATH self._systemd_network_dir = NetworkInstallationTask.SYSTEMD_NETWORK_CONFIG_DIR self._dhclient_dir = os.path.dirname(NetworkInstallationTask.DHCLIENT_FILE_TEMPLATE) + self._nm_dns_runtime_dir = NetworkInstallationTask.NM_GLOBAL_DNS_RUNTIME_CONFIG_DIR + self._nm_dns_dir = NetworkInstallationTask.NM_GLOBAL_DNS_CONFIG_DIR + self._nm_dns_files = NetworkInstallationTask.NM_GLOBAL_DNS_CONFIG_FILES def _create_config_dirs(self, installer_dirs, target_system_dirs): for config_dir in installer_dirs: @@ -1232,9 +1235,9 @@ 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 + task.NM_GLOBAL_DNS_RUNTIME_CONFIG_DIR = self._mocked_root + \ + type(task).NM_GLOBAL_DNS_RUNTIME_CONFIG_DIR + task.NM_GLOBAL_DNS_CONFIG_DIR = self._mocked_root + type(task).NM_GLOBAL_DNS_CONFIG_DIR def _create_all_expected_dirs(self): # Create directories that are expected to be existing in installer @@ -1780,27 +1783,23 @@ def test_network_instalation_task_missing_target_dir(self): 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, + self._nm_dns_runtime_dir, + self._nm_dns_dir, ], target_system_dirs=[ - nm_config_dir, + self._nm_dns_dir, ] ) - self._dump_config_files( - nm_runtime_config_dir, - ((src_file, "bla"),) - ) + for file in self._nm_dns_files: + self._dump_config_files( + self._nm_dns_runtime_dir, + ((file, "bla"),) + ) # Create the task task = NetworkInstallationTask( @@ -1815,10 +1814,11 @@ def test_network_instalation_task_global_dns_config(self): self._mock_task_paths(task) task.run() - self._check_config_file( - nm_config_dir, - dst_file, - """ - bla - """ - ) + for file in self._nm_dns_files: + self._check_config_file( + self._nm_dns_dir, + file, + """ + bla + """ + )