Skip to content

Commit

Permalink
Merge pull request #6214 from rvykydal/copy-dns-backend-conf-to-syste…
Browse files Browse the repository at this point in the history
…m-r9

network: pass 16-dns-backend.conf to target system
  • Loading branch information
rvykydal authored Mar 6, 2025
2 parents b7a99a2 + 5757d83 commit 08edfa4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
14 changes: 8 additions & 6 deletions pyanaconda/modules/network/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1803,27 +1806,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(
Expand All @@ -1838,10 +1837,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
"""
)

0 comments on commit 08edfa4

Please sign in to comment.