Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DBG IMAGE BUILD IGNORE] Edns global image r9 #6211

Draft
wants to merge 4 commits into
base: rhel-9
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dracut/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ dist_dracut_SCRIPTS = module-setup.sh \
anaconda-copy-dhclient.sh \
anaconda-copy-prefixdevname.sh \
anaconda-copy-s390ccwconf.sh \
anaconda-dnsconfd.sh \
anaconda-start-dnsconfd.sh \
anaconda-ifcfg.sh \
anaconda-set-kernel-hung-timeout.sh \
anaconda-error-reporting.sh \
Expand Down
9 changes: 9 additions & 0 deletions dracut/anaconda-dnsconfd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# Enable dnsconfd.service in installer environment
# if dnsconfd backend is used.

dns_backend=$(getarg rd.net.dns-backend=)

if [ ${dns_backend} == "dnsconfd" ]; then
systemctl --root=/sysroot enable dnsconfd.service
fi
44 changes: 44 additions & 0 deletions dracut/anaconda-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ parse_kickstart() {
unset CMDLINE # re-read the commandline
. /tmp/ks.info # save the parsed kickstart
[ -e "$parsed_kickstart" ] && cp $parsed_kickstart /run/install/ks.cfg
start_dnsconfd "The certificates may have been imported."
}

# print a list of net devices that dracut says are set up.
Expand Down Expand Up @@ -379,6 +380,10 @@ run_kickstart() {
udevadm trigger --action=change --subsystem-match=block
fi

if [ "$do_net" ]; then
start_dnsconfd "The network may have become required"
fi

# net: re-run online hooks
if [ "$do_net" ]; then
# If NetworkManager is used in initramfs
Expand Down Expand Up @@ -447,3 +452,42 @@ wait_for_disks() {
DISKS_WAIT_RETRIES=$((DISKS_WAIT_DELAY * 2))
echo "[ \"\$main_loop\" -ge \"$DISKS_WAIT_RETRIES\" ]" > "$finished_hook"
}

# This script should start dnsconfd if all required conditions to run it are met
start_dnsconfd() {

local reason="$1"
local start="yes"

echo "Attempting to start dnsconfd. Reason: ${reason}"

# dnsconfd is explicitly required by kernel boot option
dns_backend=$(getarg rd.net.dns-backend=)
if [ "${dns_backend}" != "dnsconfd" ]; then
echo "Attempting to start dnsconfd. Not starting because not required by kernel boot option."
start="no"
fi

# Network is required in initramfs
getargbool 0 rd.neednet && neednet=1
if [ ! -e "/tmp/net.ifaces" ] && [ "${neednet}" != "1" ]; then
echo "Attempting to start dnsconfd. Not starting because network is not required (yet)."
start="no"
fi

# It is not possible certificates for dnsconfd will be imported after start by kickstart
kickstart="$(getarg inst.ks=)"
# If kickstart has not been parsed yet && is reqiured by boot options
if [ ! -e /run/install/ks.cfg ] && ([ -n "$kickstart" ] || getargbool 0 inst.ks); then
echo "Attempting to start dnsconfd. Not starting because certificates can be imported via kickstart later."
start="no"
fi

if [ "${start}" == "yes" ]; then
echo "Attempting to start dnsconfd. Starting."
systemctl start --no-block unbound.service
return 0
else
return 1
fi
}
10 changes: 10 additions & 0 deletions dracut/anaconda-start-dnsconfd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh
# Attempt to start dnsconfd after boot options are parsed.
# The script needs to be run only after boot options are parsed,
# (parse-anaconda-* cmdline hooks are finished).
# There are also other attempts to start dnsconfd with start_dnsconfd
# called after parsing kickstart, see anaconda-lib.

. /lib/anaconda-lib.sh
start_dnsconfd "Anaconda boot options have been parsed"

2 changes: 2 additions & 0 deletions dracut/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ install() {
inst_hook cmdline 26 "$moddir/parse-anaconda-kickstart.sh"
inst_hook cmdline 27 "$moddir/parse-anaconda-repo.sh"
inst_hook cmdline 28 "$moddir/parse-anaconda-net.sh"
inst_hook cmdline 99 "$moddir/anaconda-start-dnsconfd.sh"
inst_hook pre-udev 30 "$moddir/anaconda-modprobe.sh"
inst_hook pre-trigger 50 "$moddir/repo-genrules.sh"
inst_hook pre-trigger 50 "$moddir/kickstart-genrules.sh"
Expand All @@ -50,6 +51,7 @@ install() {
inst_hook pre-pivot 50 "$moddir/anaconda-copy-s390ccwconf.sh"
inst_hook pre-pivot 90 "$moddir/anaconda-copy-dhclient.sh"
inst_hook pre-pivot 91 "$moddir/anaconda-copy-prefixdevname.sh"
inst_hook pre-pivot 92 "$moddir/anaconda-dnsconfd.sh"
inst_hook pre-pivot 95 "$moddir/anaconda-set-kernel-hung-timeout.sh"
inst_hook pre-pivot 99 "$moddir/save-initramfs.sh"
inst_hook cleanup 98 "$moddir/anaconda-nfsrepo-cleanup.sh"
Expand Down
26 changes: 19 additions & 7 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 @@ -106,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 All @@ -116,6 +118,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 +163,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 @@ -300,11 +304,19 @@ 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."""
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 @@ -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 @@ -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(
Expand All @@ -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
"""
)
Loading