Skip to content

Commit

Permalink
Dev: crm report: Get distribution info correctly and reuse it
Browse files Browse the repository at this point in the history
  • Loading branch information
liangxin1300 committed Nov 2, 2021
1 parent c091f9d commit c90a4e6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crmsh/report/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion crmsh/report/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
21 changes: 12 additions & 9 deletions crmsh/report/utillib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions scripts/health/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
Expand All @@ -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],
Expand Down

0 comments on commit c90a4e6

Please sign in to comment.