Fix dmi traceback on some arm boxes

- Fix "DMI WARNING" when not running as root
- Don't attempt to get DMI info if dmidecode returns warnings
Resolves: rhbz#2136924

Signed-off-by: John Kacur <jkacur@redhat.com>
This commit is contained in:
John Kacur 2022-10-27 12:21:52 -04:00
parent 6a1006345e
commit e79b4e59fc
3 changed files with 344 additions and 1 deletions

View File

@ -0,0 +1,165 @@
From 149c119df7c7a8ddfd1abc7a127d536cc0674230 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Tue, 23 Aug 2022 14:57:37 -0400
Subject: [PATCH 1/3] rteval: Fix "DMI WARNING" when not running as root
In some cases it is not necessary to run as root, for example when
running -Z (--summarize) to summarize an existing report.
In such cases we do not want to see the message:
** DMI WARNING ** Failed to open memory buffer (/dev/mem): Permission denied
The fix here is to surpresses that message.
In addition:
- the unused "config" option to DMIinfo.__init__ is removed
- A few strings are converted to f-strings
- "with" is used to open the xsltfile
Signed-off-by: John Kacur <jkacur@redhat.com>
---
rteval/sysinfo/__init__.py | 6 ++---
rteval/sysinfo/dmi.py | 45 +++++++++++++++++++-------------------
2 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/rteval/sysinfo/__init__.py b/rteval/sysinfo/__init__.py
index 0436ebb350d9..a4359382f006 100644
--- a/rteval/sysinfo/__init__.py
+++ b/rteval/sysinfo/__init__.py
@@ -42,7 +42,7 @@ class SystemInfo(KernelInfo, SystemServices, dmi.DMIinfo, CPUtopology,
self.__logger = logger
KernelInfo.__init__(self, logger=logger)
SystemServices.__init__(self, logger=logger)
- dmi.DMIinfo.__init__(self, config, logger=logger)
+ dmi.DMIinfo.__init__(self, logger=logger)
CPUtopology.__init__(self)
OSInfo.__init__(self, logger=logger)
cmdlineInfo.__init__(self, logger=logger)
@@ -80,8 +80,8 @@ if __name__ == "__main__":
cfg.installdir = "."
si = SystemInfo(cfg, logger=l)
- print("\tRunning on %s" % si.get_base_os())
- print("\tNUMA nodes: %d" % si.mem_get_numa_nodes())
+ print(f"\tRunning on {si.get_base_os()}")
+ print(f"\tNUMA nodes: {si.mem_get_numa_nodes()}")
print("\tMemory available: %03.2f %s\n" % si.mem_get_size())
print("\tServices: ")
diff --git a/rteval/sysinfo/dmi.py b/rteval/sysinfo/dmi.py
index 80cf3c723b36..5965c128c093 100644
--- a/rteval/sysinfo/dmi.py
+++ b/rteval/sysinfo/dmi.py
@@ -1,6 +1,4 @@
#
-# dmi.py - class to wrap DMI Table information
-#
# Copyright 2009 - 2013 Clark Williams <williams@redhat.com>
# Copyright 2009 - 2013 David Sommerseth <davids@redhat.com>
#
@@ -24,6 +22,7 @@
# including keys needed to generate an equivalently functional executable
# are deemed to be part of the source code.
#
+""" dmi.py class to wrap DMI Table Information """
import sys
import os
@@ -52,16 +51,18 @@ def ProcessWarnings():
if warnings is None:
return
+ ignore1 = '/dev/mem: Permission denied'
+ ignore2 = 'No SMBIOS nor DMI entry point found, sorry.'
+ ignore3 = 'Failed to open memory buffer (/dev/mem): Permission denied'
+ ignore = (ignore1, ignore2, ignore3)
for warnline in warnings.split('\n'):
# Ignore these warnings, as they are "valid" if not running as root
- if warnline == '/dev/mem: Permission denied':
- continue
- if warnline == 'No SMBIOS nor DMI entry point found, sorry.':
+ if warnline in ignore:
continue
# All other warnings will be printed
if len(warnline) > 0:
- print("** DMI WARNING ** %s" % warnline)
+ print(f"** DMI WARNING ** {warnline}")
dmidecode.clear_warnings()
@@ -69,8 +70,7 @@ def ProcessWarnings():
class DMIinfo:
'''class used to obtain DMI info via python-dmidecode'''
- # TODO: Remove unnecessary config
- def __init__(self, config, logger):
+ def __init__(self, logger):
self.__version = '0.5'
if not dmidecode_loaded:
@@ -83,22 +83,24 @@ class DMIinfo:
self.__xsltparser = self.__load_xslt('rteval_dmi.xsl')
- def __load_xslt(self, fname):
- xsltfile = None
+ @staticmethod
+ def __load_xslt(fname):
+ xsltf = None
if os.path.exists(fname):
- xsltfile = open(fname, "r")
- elif rtevalConfig.default_config_search([fname], os.path.isfile):
- xsltfile = open(rtevalConfig.default_config_search([fname], os.path.isfile), "r")
-
- if xsltfile:
- xsltdoc = lxml.etree.parse(xsltfile)
- ret = lxml.etree.XSLT(xsltdoc)
- xsltfile.close()
+ xsltf = fname
+ else:
+ xsltf = rtevalConfig.default_config_search([fname], os.path.isfile)
+
+ if xsltf:
+ with open(xsltf, "r") as xsltfile:
+ xsltdoc = lxml.etree.parse(xsltfile)
+ ret = lxml.etree.XSLT(xsltdoc)
return ret
raise RuntimeError(f'Could not locate XSLT template for DMI data ({fname})')
def MakeReport(self):
+ """ Add DMI information to final report """
rep_n = libxml2.newNode("DMIinfo")
rep_n.newProp("version", self.__version)
if self.__fake:
@@ -113,7 +115,7 @@ class DMIinfo:
return rep_n
def unit_test(rootdir):
- """ unit_test for dmi.py, looks a little crufty! """
+ """ unit_test for dmi.py """
class UnittestConfigDummy:
def __init__(self, rootdir):
@@ -132,15 +134,14 @@ def unit_test(rootdir):
log = Log()
log.SetLogVerbosity(Log.DEBUG|Log.INFO)
- cfg = UnittestConfigDummy(rootdir)
- d = DMIinfo(cfg, log)
+ d = DMIinfo(log)
dx = d.MakeReport()
x = libxml2.newDoc("1.0")
x.setRootElement(dx)
x.saveFormatFileEnc("-", "UTF-8", 1)
return 0
except Exception as e:
- print("** EXCEPTION: %s" % str(e))
+ print(f"** EXCEPTION: {str(e)}")
return 1
if __name__ == '__main__':
--
2.37.3

View File

@ -0,0 +1,169 @@
From bce23ecc5d8bb6cab86843f7a42164ee44ef091f Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@redhat.com>
Date: Thu, 27 Oct 2022 11:14:27 -0400
Subject: [PATCH 3/3] rteval: Don't attempt to get DMIinfo if there are dmi
warnings
If the python module dmidecode is available, but produces warnings,
you can get a traceback. This happens on some arm boxes,
as shown in the traceback below.
Fix this by treating any warnings that are not listed in the
ignorable warnings as if dmi info is not available.
Also add logging to dmi.ProcessWarnings()
./rteval-cmd -d10s
** DMI WARNING ** /sys/firmware/efi/systab: SMBIOS entry point missing
got system topology: 1 node system (4 cores per node)
rteval run on 5.19.16-200.fc36.aarch64 started at Fri Oct 21 16:11:51 2022
started 3 loads on 4 cores
started measurement threads on 4 cores
Run duration: 10.0 seconds
stopping run at Fri Oct 21 16:13:26 2022
Traceback (most recent call last):
File "/root/src/rteval/./rteval-cmd", line 402, in <module>
ec = rteval.Measure()
File "/root/src/rteval/rteval/__init__.py", line 286, in Measure
self._report(measure_start, self.__rtevcfg.xslt_report)
File "/root/src/rteval/rteval/rtevalReport.py", line 76, in _report
self.__xmlreport.AppendXMLnodes(self._sysinfo.MakeReport())
File "/root/src/rteval/rteval/sysinfo/__init__.py", line 69, in MakeReport
report_n.addChild(dmi.DMIinfo.MakeReport(self))
File "/root/src/rteval/rteval/sysinfo/dmi.py", line 111, in MakeReport
dmiqry = xmlout.convert_libxml2_to_lxml_doc(self.__dmixml.QuerySection('all'))
File "/usr/lib64/python3.10/site-packages/dmidecode.py", line 64, in QuerySection
ret = libxml2.xmlDoc( _obj = xmlapi(query_type='s',
RuntimeError: [src/dmidecodemodule.c:331] Error decoding DMI data
** COLLECTED WARNINGS **
/sys/firmware/efi/systab: SMBIOS entry point missing
** END OF WARNINGS **
Signed-off-by: John Kacur <jkacur@redhat.com>
---
rteval-cmd | 4 ++--
rteval/sysinfo/__init__.py | 2 +-
rteval/sysinfo/dmi.py | 34 +++++++++++++++++++++-------------
3 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/rteval-cmd b/rteval-cmd
index 6a928362828f..1e6a7fc86baa 100755
--- a/rteval-cmd
+++ b/rteval-cmd
@@ -210,8 +210,6 @@ def remove_offline(cpulist):
if __name__ == '__main__':
from rteval.sysinfo import dmi
- dmi.ProcessWarnings()
-
# set LD_BIND_NOW to resolve shared library symbols
# note: any string will do, nothing significant about 'rteval'
@@ -261,6 +259,8 @@ if __name__ == '__main__':
| (rtevcfg.debugging and Log.DEBUG)
logger.SetLogVerbosity(loglev)
+ dmi.ProcessWarnings(logger=logger)
+
# Load modules
loadmods = LoadModules(config, logger=logger)
measuremods = MeasurementModules(config, logger=logger)
diff --git a/rteval/sysinfo/__init__.py b/rteval/sysinfo/__init__.py
index bb1d00810856..5767e5b7f6fe 100644
--- a/rteval/sysinfo/__init__.py
+++ b/rteval/sysinfo/__init__.py
@@ -49,7 +49,7 @@ class SystemInfo(KernelInfo, SystemServices, dmi.DMIinfo, CPUtopology,
NetworkInfo.__init__(self, logger=logger)
# Parse initial DMI decoding errors
- dmi.ProcessWarnings()
+ dmi.ProcessWarnings(logger=logger)
# Parse CPU info
CPUtopology._parse(self)
diff --git a/rteval/sysinfo/dmi.py b/rteval/sysinfo/dmi.py
index 5965c128c093..83f347623b58 100644
--- a/rteval/sysinfo/dmi.py
+++ b/rteval/sysinfo/dmi.py
@@ -1,6 +1,7 @@
#
# Copyright 2009 - 2013 Clark Williams <williams@redhat.com>
# Copyright 2009 - 2013 David Sommerseth <davids@redhat.com>
+# Copyright 2022 John Kacur <jkacur@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -34,14 +35,19 @@ from rteval import rtevalConfig
try:
import dmidecode
- dmidecode_loaded = True
+ dmidecode_avail = True
except ModuleNotFoundError:
- dmidecode_loaded = False
+ dmidecode_avail = False
-def ProcessWarnings():
+def set_dmidecode_avail(val):
+ """ Used to set global variable dmidecode_avail from a function """
+ global dmidecode_avail
+ dmidecode_avail = val
+
+def ProcessWarnings(logger=None):
""" Process Warnings from dmidecode """
- if not dmidecode_loaded:
+ if not dmidecode_avail:
return
if not hasattr(dmidecode, 'get_warnings'):
@@ -62,7 +68,8 @@ def ProcessWarnings():
# All other warnings will be printed
if len(warnline) > 0:
- print(f"** DMI WARNING ** {warnline}")
+ logger.log(Log.DEBUG, f"** DMI WARNING ** {warnline}")
+ set_dmidecode_avail(False)
dmidecode.clear_warnings()
@@ -70,11 +77,11 @@ def ProcessWarnings():
class DMIinfo:
'''class used to obtain DMI info via python-dmidecode'''
- def __init__(self, logger):
- self.__version = '0.5'
+ def __init__(self, logger=None):
+ self.__version = '0.6'
- if not dmidecode_loaded:
- logger.log(Log.DEBUG|Log.WARN, "No dmidecode module found, ignoring DMI tables")
+ if not dmidecode_avail:
+ logger.log(Log.DEBUG, "DMI info unavailable, ignoring DMI tables")
self.__fake = True
return
@@ -127,14 +134,15 @@ def unit_test(rootdir):
self.__dict__[k] = self.config[k]
try:
- ProcessWarnings()
+ log = Log()
+ log.SetLogVerbosity(Log.DEBUG|Log.INFO)
+
+ ProcessWarnings(logger=log)
if os.getuid() != 0:
print("** ERROR ** Must be root to run this unit_test()")
return 1
- log = Log()
- log.SetLogVerbosity(Log.DEBUG|Log.INFO)
- d = DMIinfo(log)
+ d = DMIinfo(logger=log)
dx = d.MakeReport()
x = libxml2.newDoc("1.0")
x.setRootElement(dx)
--
2.37.3

View File

@ -1,6 +1,6 @@
Name: rteval
Version: 3.5
Release: 2%{?dist}
Release: 3%{?dist}
Summary: Utility to evaluate system suitability for RT Linux
Group: Development/Tools
@ -31,6 +31,8 @@ BuildArch: noarch
#Patches
Patch1: rteval-Replace-python-ethtool-with-inline-code.patch
Patch2: Fix-DMI-WARNING-when-not-running-as-root.patch
Patch3: rteval-Don-t-attempt-to-get-DMIinfo-if-there-are-dmi.patch
%description
The rteval script is a utility for measuring various aspects of
@ -44,6 +46,8 @@ to the screen.
%prep
%setup -q
%patch1 -p1
%patch2 -p1
%patch3 -p1
%build
%{__python3} setup.py build
@ -65,6 +69,11 @@ to the screen.
%{_bindir}/rteval
%changelog
* Thu Oct 27 2022 John Kacur <jkacur@redhat.com> - 3.5-3
- Fix "DMI WARNING" when not running as root
- Don't attempt to get DMI info if dmidecode returns warnings
Resolves: rhbz#2136924
* Mon Oct 17 2022 John Kacur <jkacur@redhat.com> - 3.5-2
- Remove dependency on python-ethtool by using inline code
- Add Requires of python-libxml2