rteval: rteval/__init__.py: Convert regular strings to f-strings
PATCH 1/8 rteval: rteval/__init__.py: Convert regular strings to f-strings
Convert regular strings to f-strings in __init__.py
--- rteval/__init__.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
rteval/__init__.py +15 -17
@@ -59,7 +59,7 @@ def sig_handler(signum, frame): stopsig_received = True print("*** stop signal received - stopping rteval run ***") else: - raise RuntimeError("SIGNAL received! (%d)" % signum) + raise RuntimeError(f"SIGNAL received! ({signum})") class RtEval(rtevalReport): def __init__(self, config, loadmods, measuremods, logger):
@@ -96,10 +96,10 @@ class RtEval(rtevalReport): self.__mailer = None if not os.path.exists(self.__rtevcfg.xslt_report): - raise RuntimeError("can't find XSL template (%s)!" % self.__rtevcfg.xslt_report) + raise RuntimeError(f"can't find XSL template ({self.__rtevcfg.xslt_report})!") # Add rteval directory into module search path - sys.path.insert(0, '%s/rteval' % sysconfig.get_python_lib()) + sys.path.insert(0, f'{sysconfig.get_python_lib()}/rteval') # Initialise the report module rtevalReport.__init__(self, self.__version,
@@ -110,8 +110,7 @@ class RtEval(rtevalReport): self.__xmlrpc = rtevalXMLRPC(self.__rtevcfg.xmlrpc, self.__logger, self.__mailer) if not self.__xmlrpc.Ping(): if not self.__rtevcfg.xmlrpc_noabort: - print("ERROR: Could not reach XML-RPC server '%s'. Aborting." % \ - self.__rtevcfg.xmlrpc) + print(f"ERROR: Could not reach XML-RPC server '{self.__rtevcfg.xmlrpc}'. Aborting.") sys.exit(2) else: print("WARNING: Could not ping the XML-RPC server. Will continue anyway.")
@@ -174,8 +173,7 @@ class RtEval(rtevalReport): measure_start = None (with_loads, run_parallel) = measure_profile.GetProfile() - self.__logger.log(Log.INFO, "Using measurement profile [loads: %s parallel: %s]" % ( - with_loads, run_parallel)) + self.__logger.log(Log.INFO, f"Using measurement profile [loads: {with_loads} parallel: {run_parallel}]") try: nthreads = 0
@@ -183,23 +181,23 @@ class RtEval(rtevalReport): if with_loads: self._loadmods.Start() - print("rteval run on %s started at %s" % (os.uname()[2], time.asctime())) + print(f"rteval run on {os.uname()[2]} started at {time.asctime()}") onlinecpus = self._sysinfo.cpu_getCores(True) cpulist = self._loadmods._cfg.GetSection("loads").cpulist if cpulist: - print("started %d loads on cores %s" % (self._loadmods.ModulesLoaded(), cpulist), end=' ') + print(f"started {self._loadmods.ModulesLoaded()} loads on cores {cpulist}", end=' ') else: - print("started %d loads on %d cores" % (self._loadmods.ModulesLoaded(), onlinecpus), end=' ') + print(f"started {self._loadmods.ModulesLoaded()} loads on {onlinecpus} cores", end=' ') if self._sysinfo.mem_get_numa_nodes() > 1: - print(" with %d numa nodes" % self._sysinfo.mem_get_numa_nodes()) + print(f" with {self._sysinfo.mem_get_numa_nodes()} numa nodes") else: print("") cpulist = self._measuremods._MeasurementModules__cfg.GetSection("measurement").cpulist if cpulist: - print("started measurement threads on cores %s" % cpulist) + print(f"started measurement threads on cores {cpulist}") else: - print("started measurement threads on %d cores" % onlinecpus) - print("Run duration: %s seconds" % str(self.__rtevcfg.duration)) + print(f"started measurement threads on {onlinecpus} cores") + print(f"Run duration: {str(self.__rtevcfg.duration)} seconds") # start the cyclictest thread measure_profile.Start()
@@ -219,7 +217,7 @@ class RtEval(rtevalReport): # wait for time to expire or thread to die signal.signal(signal.SIGINT, sig_handler) signal.signal(signal.SIGTERM, sig_handler) - self.__logger.log(Log.INFO, "waiting for duration (%s)" % str(self.__rtevcfg.duration)) + self.__logger.log(Log.INFO, f"waiting for duration ({str(self.__rtevcfg.duration)})") stoptime = (time.time() + float(self.__rtevcfg.duration)) currtime = time.time() rpttime = currtime + report_interval
@@ -246,7 +244,7 @@ class RtEval(rtevalReport): left_to_run = stoptime - currtime self.__show_remaining_time(left_to_run) rpttime = currtime + report_interval - print("load average: %.2f" % self._loadmods.GetLoadAvg()) + print(f"load average: {self._loadmods.GetLoadAvg():.2f}") currtime = time.time() self.__logger.log(Log.DEBUG, "out of measurement loop")
@@ -265,7 +263,7 @@ class RtEval(rtevalReport): if with_loads: self._loadmods.Stop() - print("stopping run at %s" % time.asctime()) + print(f"stopping run at {time.asctime()}") # wait for measurement modules to finish calculating stats measure_profile.WaitForCompletion()
Signature · 1 line
2.39.0
PATCH 2/8 rteval: rtevalReport.py: Convert regular strings to f-strings
Convert regular strings to f-strings in rtevalReport.py
--- rteval/rtevalReport.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
rteval/rtevalReport.py +3 -3
@@ -100,11 +100,11 @@ class rtevalReport: def _show_report(self, xmlfile, xsltfile): '''summarize a previously generated xml file''' - print("Loading %s for summarizing" % xmlfile) + print(f"Loading {xmlfile} for summarizing") xsltfullpath = os.path.join(self.__installdir, xsltfile) if not os.path.exists(xsltfullpath): - raise RuntimeError("can't find XSL template (%s)!" % xsltfullpath) + raise RuntimeError(f"can't find XSL template ({xsltfullpath})!") xmlreport = xmlout.XMLOut('rteval', self.__version) xmlreport.LoadReport(xmlfile)
@@ -131,7 +131,7 @@ class rtevalReport: def _tar_results(self): if not os.path.isdir(self.__reportdir): - raise RuntimeError("no such directory: %s" % self.__reportdir) + raise RuntimeError(f"no such directory: {self.__reportdir}") dirname = os.path.dirname(self.__reportdir) rptdir = os.path.basename(self.__reportdir)
Signature · 1 line
2.39.0
PATCH 3/8 rteval: rtevalXMLRPC.py: Convert regular strings to f-strings
In reply to John KacurConvert regular strings to f-strings in rtevalXMLRPC.py
--- rteval/rtevalXMLRPC.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-)
rteval/rtevalXMLRPC.py +14 -20
@@ -33,7 +33,7 @@ from .Log import Log class rtevalXMLRPC: def __init__(self, host, logger, mailer=None): self.__host = host - self.__url = "http://%s/rteval/API1/" % self.__host + self.__url = f"http://{self.__host}/rteval/API1/" self.__logger = logger self.__mailer = mailer self.__client = rtevalclient.rtevalclient(self.__url)
@@ -41,7 +41,7 @@ class rtevalXMLRPC: def Ping(self): res = None - self.__logger.log(Log.DEBUG, "Checking if XML-RPC server '%s' is reachable" % self.__host) + self.__logger.log(Log.DEBUG, f"Checking if XML-RPC server '{self.__host}' is reachable") attempt = 0 ping_success = False warning_sent = False
@@ -52,10 +52,10 @@ class rtevalXMLRPC: ping_success = True except xmlrpc.client.ProtocolError: # Server do not support Hello(), but is reachable - self.__logger.log(Log.INFO, "Got XML-RPC connection with %s but it did not support Hello()" % self.__host) + self.__logger.log(Log.INFO, f"Got XML-RPC connection with {self.__host} but it did not support Hello()") res = None except socket.error as err: - self.__logger.log(Log.INFO, "Could not establish XML-RPC contact with %s\n%s" % (self.__host, str(err))) + self.__logger.log(Log.INFO, f"Could not establish XML-RPC contact with {self.__host}\n{str(err)}") # Do attempts handling attempt += 1
@@ -63,17 +63,16 @@ class rtevalXMLRPC: break # To avoid sleeping before we abort if (self.__mailer is not None) and (not warning_sent): - self.__mailer.SendMessage("[RTEVAL:WARNING] Failed to ping XML-RPC server", "Server %s did not respond." % self.__host) + self.__mailer.SendMessage("[RTEVAL:WARNING] Failed to ping XML-RPC server", f"Server {self.__host} did not respond.") warning_sent = True - print("Failed pinging XML-RPC server. Doing another attempt(%i) " % attempt) + print(f"Failed pinging XML-RPC server. Doing another attempt({attempt}) ") time.sleep(attempt) #*15) # Incremental sleep - sleep attempts*15 seconds ping_success = False if res: - self.__logger.log(Log.INFO, "Verified XML-RPC connection with %s (XML-RPC API version: %i)" % (res["server"], res["APIversion"])) - self.__logger.log(Log.DEBUG, "Recieved greeting: %s" % res["greeting"]) - + self.__logger.log(Log.INFO, f'Verified XML-RPC connection with {res["server"]} (XML-RPC API version: {res["APIversion"]})') + self.__logger.log(Log.DEBUG, f"Recieved greeting: {res['greeting']}") return ping_success
@@ -85,9 +84,9 @@ class rtevalXMLRPC: warning_sent = False while attempt < 6: try: - print("Submitting report to %s" % self.__url) + print(f"Submitting report to {self.__url}") rterid = self.__client.SendReport(xmlreport) - print("Report registered with submission id %i" % rterid) + print(f"Report registered with submission id {rterid}") attempt = 10 exitcode = 0 # Success except socket.error:
@@ -96,12 +95,10 @@ class rtevalXMLRPC: break # To avoid sleeping before we abort if (self.__mailer is not None) and (not warning_sent): - self.__mailer.SendMessage("[RTEVAL:WARNING] Failed to submit report to XML-RPC server", - "Server %s did not respond. Not giving up yet." - % self.__host) + self.__mailer.SendMessage("[RTEVAL:WARNING] Failed to submit report to XML-RPC server", f"Server {self.__host} did not respond. Not giving up yet.") warning_sent = True - print("Failed sending report. Doing another attempt(%i) " % attempt) + print(f"Failed sending report. Making another attempt({attempt}) ") time.sleep(attempt) #*5*60) # Incremental sleep - sleep attempts*5 minutes except Exception as err:
@@ -111,12 +108,9 @@ class rtevalXMLRPC: if self.__mailer is not None: # Send final result messages if exitcode == 2: - self.__mailer.SendMessage("[RTEVAL:FAILURE] Failed to submit report to XML-RPC server", - "Server %s did not respond at all after %i attempts." - % (self.__host, attempt - 1)) + self.__mailer.SendMessage("[RTEVAL:FAILURE] Failed to submit report to XML-RPC server", f"Server {self.__host} did not respond at all after {attempt - 1} attempts.") elif (exitcode == 0) and warning_sent: self.__mailer.SendMessage("[RTEVAL:SUCCESS] XML-RPC server available again", - "Succeeded to submit the report to %s" - % self.__host) + f"Succeeded to submit the report to {self.__host}") return exitcode
Signature · 1 line
2.39.0
PATCH 4/8 rteval: rtevalConfig.py: Convert regular strings to f-strings
In reply to John KacurConvert regular strings to f-strings in rtevalConfig.py
--- rteval/rtevalConfig.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
rteval/rtevalConfig.py +5 -5
@@ -196,7 +196,7 @@ class rtevalConfig: # get our system topology info self.__systopology = SysTopology() - print(("got system topology: %s" % self.__systopology)) + print(f"got system topology: {self.__systopology}") # Import the default config first for sect, vals in list(default_config.items()):
@@ -225,7 +225,7 @@ class rtevalConfig: "Simple method for dumping config when object is used as a string" ret = "" for sect in list(self.__config_data.keys()): - ret += "[%s]\n%s\n" % (sect, str(self.__config_data[sect])) + ret += f"[{sect}]\n{str(self.__config_data[sect])}\n" return ret
@@ -240,7 +240,7 @@ class rtevalConfig: for f in ('rteval.conf', '/etc/rteval.conf'): p = os.path.abspath(f) if os.path.exists(p): - self.__info("found config file %s" % p) + self.__info(f"found config file {p}") return p raise RuntimeError("Unable to find configfile")
@@ -258,7 +258,7 @@ class rtevalConfig: # Don't try to reread this file if it's already been parsed return - self.__info("reading config file %s" % cfgfile) + self.__info(f"reading config file {cfgfile}") ini = configparser.ConfigParser() ini.optionxform = str ini.read(cfgfile)
@@ -321,7 +321,7 @@ class rtevalConfig: # Return a new object with config settings of a given section return self.__config_data[section] except KeyError: - raise KeyError("The section '%s' does not exist in the config file" % section) + raise KeyError(f"The section '{section}' does not exist in the config file") def unit_test(rootdir):
Signature · 1 line
2.39.0
PATCH 5/8 rteval: xmlout.py: Convert to f-strings where possible
In reply to John KacurConvert xmlout.py to f-strings where possible
--- rteval/xmlout.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
rteval/xmlout.py +5 -5
@@ -67,7 +67,7 @@ class XMLOut: def __del__(self): if self.level > 0: - raise RuntimeError("XMLOut: open blocks at __del__ (last opened '%s')" % self.currtag.name) + raise RuntimeError(f"XMLOut: open blocks at __del__ (last opened '{self.currtag.name}')") if self.xmldoc is not None: self.xmldoc.freeDoc()
@@ -131,7 +131,7 @@ class XMLOut: self.__parseToXML(n, v) node.addChild(n) else: - raise TypeError("unhandled type (%s) for value '%s'" % (type(data), str(data))) + raise TypeError(f"unhandled type ({str(type(data))}) for value '{str(data)}'") def close(self): if self.status == 0:
@@ -139,7 +139,7 @@ class XMLOut: if self.status == 3: raise RuntimeError("XMLOut: XML document already closed") if self.level > 0: - raise RuntimeError("XMLOut: open blocks at close() (last opened '%s')" % self.currtag.name) + raise RuntimeError(f"XMLOut: open blocks at close() (last opened '{self.currtag.name}')") if self.status == 1: # Only set the root node in the doc on created reports (NewReport called) self.xmldoc.setRootElement(self.xmlroot)
@@ -172,7 +172,7 @@ class XMLOut: root = self.xmldoc.children if root.name != self.roottag: self.status = 3 - raise RuntimeError("XMLOut: Loaded report is not a valid %s XML file" % self.roottag) + raise RuntimeError(f"XMLOut: Loaded report is not a valid {self.roottag} XML file") if validate_version is True: ver = root.hasProp('version')
@@ -183,7 +183,7 @@ class XMLOut: if ver.getContent() != self.version: self.status = 3 - raise RuntimeError("XMLOut: Loaded report is not of version %s" % self.version) + raise RuntimeError(f"XMLOut: Loaded report is not of version {self.version}") self.status = 2 # Confirm that we have loaded a report from file
Signature · 1 line
2.39.0
PATCH 6/8 rteval: Log.py: Convert to f-strings
In reply to John KacurConvert Log.py to f-strings
--- rteval/Log.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
rteval/Log.py +3 -6
@@ -60,10 +60,7 @@ class Log: def log(self, logtype, msg): if (logtype & self.__logverb) or logtype == self.ALWAYS: - self.__logfile.write("%s%s\n" % - (self.__logtype_str(logtype), - msg) - ) + self.__logfile.write(f"{self.__logtype_str(logtype)}{msg}\n")
@@ -80,8 +77,8 @@ def unit_test(rootdir): def run_log_test(l): for lt in range(min(logtypes), max(logtypes)*2): test = ", ".join([logtypes_s[logtypes.index(i)] for i in [p for p in takewhile(lambda x: x <= lt, (2**i for i in count())) if p & lt]]) - print("Testing verbosity flags set to: (%i) %s" % (lt, test)) - msg = "Log entry when verbosity is set to %i [%s]" % (lt, test) + print(f"Testing verbosity flags set to: ({lt}) {test}") + msg = f"Log entry when verbosity is set to {lt} [{test}]" l.SetLogVerbosity(lt) test_log(l, msg) print("-"*20)
Signature · 1 line
2.39.0
PATCH 7/8 rteval: Catch failures in python-dmidecode
In reply to John Kacurpython-dmidecode can generate incorrect xml,
namely Attribute unit redefined
Although useful, the dmidecode is not critical to rteval reporting.
Therefore catch this, and first see if we can at least query the bios. If that works report the bios instead of all, and if that doesn't work, just continue without the dmidecode report.
--- rteval/sysinfo/dmi.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
rteval/sysinfo/dmi.py +13 -1
@@ -79,6 +79,7 @@ class DMIinfo: def __init__(self, logger=None): self.__version = '0.6' + self._log = logger if not dmidecode_avail: logger.log(Log.DEBUG, "DMI info unavailable, ignoring DMI tables")
@@ -115,7 +116,18 @@ class DMIinfo: rep_n.newProp("not_available", "1") else: self.__dmixml.SetResultType(dmidecode.DMIXML_DOC) - dmiqry = xmlout.convert_libxml2_to_lxml_doc(self.__dmixml.QuerySection('all')) + try: + dmiqry = xmlout.convert_libxml2_to_lxml_doc(self.__dmixml.QuerySection('all')) + except Exception as ex1: + self._log.log(Log.DEBUG, f'** EXCEPTION {str(ex1)}, will query BIOS only') + try: + # If we can't query 'all', at least query 'bios' + dmiqry = xmlout.convert_libxml2_to_lxml_doc(self.__dmixml.QuerySection('bios')) + except Exception as ex2: + rep_n.addContent("No DMI tables available") + rep_n.newProp("not_available", "1") + self._log.log(Log.DEBUG, f'** EXCEPTION {str(ex2)}, dmi info will not be reported') + return rep_n resdoc = self.__xsltparser(dmiqry) dmi_n = xmlout.convert_lxml_to_libxml2_nodes(resdoc.getroot()) rep_n.addChild(dmi_n)
Signature · 1 line
2.39.0
PATCH 8/8 rteval: Change the default kernel to compile to linux-6.1.8
In reply to John Kacurrteval compiles the linux kernel as a load
Change the default kernel that rteval compiles to linux-6.1.8
--- Makefile | 2 +- rteval/modules/loads/kcompile.py | 4 ++-- rteval/rteval.conf | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
Makefile +1 -1
@@ -17,7 +17,7 @@ PREFIX := /usr DATADIR := $(DESTDIR)/$(PREFIX)/share LOADDIR := loadsource -KLOAD := $(LOADDIR)/linux-5.18.1.tar.xz +KLOAD := $(LOADDIR)/linux-6.1.8.tar.xz BLOAD := $(LOADDIR)/dbench-4.0.tar.gz LOADS := $(KLOAD) $(BLOAD)
rteval/modules/loads/kcompile.py +2 -2
@@ -38,7 +38,7 @@ from rteval.systopology import CpuList, SysTopology expand_cpulist = CpuList.expand_cpulist compress_cpulist = CpuList.compress_cpulist -DEFAULT_KERNEL_PREFIX = "linux-5.18" +DEFAULT_KERNEL_PREFIX = "linux-6.1" class KBuildJob: '''Class to manage a build job bound to a particular node'''
@@ -349,7 +349,7 @@ class Kcompile(CommandLineLoad): def ModuleParameters(): return {"source": {"descr": "Source tar ball", - "default": "linux-5.18.1.tar.xz", + "default": "linux-6.1.8.tar.xz", "metavar": "TARBALL"}, "jobspercore": {"descr": "Number of working threads per core", "default": 2,
rteval/rteval.conf +1 -1
@@ -18,7 +18,7 @@ dbench: external stressng: module [kcompile] -source: linux-5.18.1.xz +source: linux-6.1.8.xz jobspercore: 2 [hackbench]
Signature · 1 line
2.39.0