image-info: read dracut configs from multiple paths
Extend image-info to read dracut configuration files from multiple paths: - /etc/dracut.conf.d/*.conf - /usr/lib/dracut/dracut.conf.d/*.conf Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
ee197346bb
commit
fb982b20b9
1 changed files with 55 additions and 34 deletions
|
|
@ -1209,50 +1209,71 @@ def read_cloud_init_conf(tree):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def read_dracut_conf_d(tree):
|
def read_dracut_config(config_path):
|
||||||
"""
|
"""
|
||||||
Read all *.conf files from /etc/dracut.conf.d/.
|
Read specific dracut configuration file.
|
||||||
|
|
||||||
Returns: dictionary with the keys representing names of configuration files
|
Returns: dictionary representing the uncommented configuration options read
|
||||||
from /etc/dracut.conf.d. Value of each key is a dictionary representing the
|
from the file.
|
||||||
uncommented configuration options read from the file.
|
|
||||||
|
|
||||||
An example return value:
|
An example return value:
|
||||||
{
|
{
|
||||||
"sgdisk.conf": {
|
"install_items": " sgdisk "
|
||||||
"install_items": " sgdisk "
|
"add_drivers": " xen-netfront xen-blkfront "
|
||||||
},
|
|
||||||
"xen.conf": {
|
|
||||||
"add_drivers": " xen-netfront xen-blkfront "
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
# iterate through all *.conf files in /etc/dracut.conf.d/
|
with open(config_path) as f:
|
||||||
files = glob.glob(f"{tree}/etc/dracut.conf.d/*.conf")
|
# dracut configuration key/values delimiter is '=' or '+='
|
||||||
for file in files:
|
for line in f:
|
||||||
confname = os.path.basename(file)
|
line = line.strip()
|
||||||
config = {}
|
# A '#' indicates the beginning of a comment; following
|
||||||
with open(file) as f:
|
# characters, up to the end of the line are not interpreted.
|
||||||
# dracut configuration key/values delimiter is '=' or '+='
|
line_comment = line.split("#", 1)
|
||||||
for line in f:
|
line = line_comment[0]
|
||||||
line = line.strip()
|
if line:
|
||||||
# A '#' indicates the beginning of a comment; following
|
key, value = line.split("=", 1)
|
||||||
# characters, up to the end of the line are not interpreted.
|
if key[-1] == "+":
|
||||||
line_comment = line.split("#", 1)
|
key = key[:-1]
|
||||||
line = line_comment[0]
|
result[key] = value.strip('"')
|
||||||
if line:
|
|
||||||
key, value = line.split("=", 1)
|
|
||||||
if key[-1] == "+":
|
|
||||||
key = key[:-1]
|
|
||||||
config[key] = value.strip('"')
|
|
||||||
|
|
||||||
result[confname] = config
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def read_dracut_configs(tree):
|
||||||
|
"""
|
||||||
|
Read all dracut *.conf files from a predefined list of paths and parse them.
|
||||||
|
|
||||||
|
The searched paths are:
|
||||||
|
- "/etc/dracut.conf.d/*.conf"
|
||||||
|
- "/usr/lib/dracut/dracut.conf.d/*.conf"
|
||||||
|
|
||||||
|
Returns: dictionary as returned by '_read_glob_paths_with_parser()' with
|
||||||
|
configuration representation as returned by 'read_dracut_config()'.
|
||||||
|
|
||||||
|
An example return value:
|
||||||
|
{
|
||||||
|
"/etc/dracut.conf.d": {
|
||||||
|
"sgdisk.conf": {
|
||||||
|
"install_items": " sgdisk "
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"/usr/lib/dracut/dracut.conf.d": {
|
||||||
|
"xen.conf": {
|
||||||
|
"add_drivers": " xen-netfront xen-blkfront "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
checked_globs = [
|
||||||
|
"/etc/dracut.conf.d/*.conf",
|
||||||
|
"/usr/lib/dracut/dracut.conf.d/*.conf"
|
||||||
|
]
|
||||||
|
|
||||||
|
return _read_glob_paths_with_parser(tree, checked_globs, read_dracut_config)
|
||||||
|
|
||||||
|
|
||||||
def read_keyboard_conf(tree):
|
def read_keyboard_conf(tree):
|
||||||
"""
|
"""
|
||||||
Read keyboard configuration for vconsole and X11.
|
Read keyboard configuration for vconsole and X11.
|
||||||
|
|
@ -1778,9 +1799,9 @@ def append_filesystem(report, tree, *, is_ostree=False):
|
||||||
if dnf_conf:
|
if dnf_conf:
|
||||||
report["dnf"] = dnf_conf
|
report["dnf"] = dnf_conf
|
||||||
|
|
||||||
dracut_config = read_dracut_conf_d(tree)
|
dracut_configs = read_dracut_configs(tree)
|
||||||
if dracut_config:
|
if dracut_configs:
|
||||||
report["/etc/dracut.conf.d"] = dracut_config
|
report["dracut"] = dracut_configs
|
||||||
|
|
||||||
with contextlib.suppress(FileNotFoundError):
|
with contextlib.suppress(FileNotFoundError):
|
||||||
report["firewall-enabled"] = read_firewall_zone(tree)
|
report["firewall-enabled"] = read_firewall_zone(tree)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue