From c90a4e6e871a941ef65d9735852b3889d10ba51e Mon Sep 17 00:00:00 2001 From: liangxin1300 <XLiang@suse.com> Date: Tue, 2 Nov 2021 16:58:01 +0800 Subject: [PATCH] Dev: crm report: Get distribution info correctly and reuse it --- crmsh/report/collect.py | 2 +- crmsh/report/constants.py | 2 +- crmsh/report/utillib.py | 21 ++++++++++++--------- scripts/health/collect.py | 5 ++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/crmsh/report/collect.py b/crmsh/report/collect.py index e363785189..7593739d7c 100644 --- a/crmsh/report/collect.py +++ b/crmsh/report/collect.py @@ -257,7 +257,7 @@ def collect_sys_info(): out_string += "Kernel release: %s\n" % os.uname()[2] out_string += "Architecture: %s\n" % os.uname()[-1] if os.uname()[0] == "Linux": - out_string += "Distribution: %s\n" % utillib.distro() + out_string += "Distribution: %s\n" % utillib.get_distro_info() sys_info_f = os.path.join(constants.WORKDIR, constants.SYSINFO_F) crmutils.str2file(out_string, sys_info_f) diff --git a/crmsh/report/constants.py b/crmsh/report/constants.py index fe44c2db04..3767e703e7 100644 --- a/crmsh/report/constants.py +++ b/crmsh/report/constants.py @@ -144,5 +144,5 @@ TIME_F = "time.txt" OCFS2_F = "ocfs2.txt" SBD_F = "sbd.txt" - +OSRELEASE = "/etc/os-release" # vim:ts=4:sw=4:et: diff --git a/crmsh/report/utillib.py b/crmsh/report/utillib.py index d6197c876a..7382120e93 100644 --- a/crmsh/report/utillib.py +++ b/crmsh/report/utillib.py @@ -400,17 +400,20 @@ def diff_check(file1, file2): else: return (0, txt_diff(file1, file2)) -def distro(): + +def get_distro_info(): """ - get some system info + get distribution information """ - ret = "" - if which("lsb_release"): - logger.debug("using lsb_release for distribution info") - res = get_command_info("lsb_release -d")[1] - if re.search("Description:", res): - ret = ' '.join(res.split()[1:]) - return ret + res = None + if os.path.exists(constants.OSRELEASE): + logger.debug("Using {} to get distribution info".format(constants.OSRELEASE)) + res = re.search("PRETTY_NAME=\"(.*)\"", read_from_file(constants.OSRELEASE)) + elif which("lsb_release"): + logger.debug("Using lsb_release to get distribution info") + out = crmutils.get_stdout_or_raise_error("lsb_release -d") + res = re.search("Description:\s+(.*)", out) + return res.group(1) if res else "Unknown" def dump_log(logf, from_line, to_line): diff --git a/scripts/health/collect.py b/scripts/health/collect.py index fb3284f2e4..9b777be693 100755 --- a/scripts/health/collect.py +++ b/scripts/health/collect.py @@ -6,6 +6,7 @@ import hashlib import platform import crm_script +from crmsh.report import utillib data = crm_script.get_input() PACKAGES = ['booth', 'cluster-glue', 'corosync', 'crmsh', 'csync2', 'drbd', @@ -33,7 +34,7 @@ def sys_info(): # the number of currently running processes and the total number of # processes. The last column displays the last process ID used. system, node, release, version, machine, processor = platform.uname() - distname, distver, distid = platform.linux_distribution() + distname = utillib.get_distro_info() hostname = os.uname()[1] uptime = open('/proc/uptime').read().split() @@ -46,8 +47,6 @@ def sys_info(): 'machine': machine, 'processor': processor, 'distname': distname, - 'distver': distver, - 'distid': distid, 'user': get_user(), 'hostname': hostname, 'uptime': uptime[0],