image-info: read content of /etc/resolv.conf

Read uncommented lined from /etc/resolv.conf and add them as a list to
the image-info report. The list of lines is present in the report even
if it is empty, so that the report is explicit about the file content
and presence.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
Tomas Hozza 2021-09-02 09:27:21 +02:00 committed by Achilleas Koutsou
parent 299bd201e6
commit ff2aa771fc

View file

@ -1919,6 +1919,34 @@ def read_authselect_conf(tree):
return result
def read_resolv_conf(tree):
"""
Read /etc/resolv.conf.
Returns: a list of uncommented lines from the /etc/resolv.conf.
An example return value:
[
"search redhat.com",
"nameserver 192.168.1.1",
"nameserver 192.168.1.2"
]
"""
result = []
with contextlib.suppress(FileNotFoundError):
with open(f"{tree}/resolv.conf") as f:
for line in f:
line = line.strip()
if not line:
continue
if line[0] == "#":
continue
result.append(line)
return result
def append_filesystem(report, tree, *, is_ostree=False):
if os.path.exists(f"{tree}/etc/os-release"):
report["packages"] = rpm_packages(tree, is_ostree)
@ -2029,6 +2057,10 @@ def append_filesystem(report, tree, *, is_ostree=False):
if tuned_profile:
report["tuned"] = tuned_profile
resolv_conf = read_resolv_conf(tree)
# add even empty resolv_conf to the report to express that it is empty or non-existent
report["/etc/resolv.conf"] = resolv_conf
udev_rules = read_udev_rules(tree)
if udev_rules:
report["/etc/udev/rules.d"] = udev_rules