From ff2aa771fc599be877548de63e0202732f9633c8 Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Thu, 2 Sep 2021 09:27:21 +0200 Subject: [PATCH] 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 --- tools/image-info | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/image-info b/tools/image-info index b2e083d1a..c8d65c00f 100755 --- a/tools/image-info +++ b/tools/image-info @@ -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