rteval/SOURCES/rteval-Changes-for-python3-...

157 lines
5.9 KiB
Diff

From 1897019ec6fd7bfd465dd687e58ed355e6e0bead Mon Sep 17 00:00:00 2001
From: root <root@hp-dl380g7-01.lab.bos.redhat.com>
Date: Sat, 23 Jun 2018 12:34:36 -0400
Subject: [PATCH] rteval: Changes for python3 and rt-tests with automated numa
detection
cyclictest no-longer requires --numa, but uses it automatically if detected.
rteval was changed to accomodate this.
In addtion a number of changes were made for python3 compatibility.
Mostly these ahd to do with string and bytes.
Signed-off-by: John Kacur <jkacur@redhat.com>
---
rteval/modules/measurement/cyclictest.py | 5 +++--
rteval/sysinfo/kernel.py | 8 +++++---
rteval/sysinfo/network.py | 2 +-
rteval/xmlout.py | 21 +++++++++------------
4 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/rteval/modules/measurement/cyclictest.py b/rteval/modules/measurement/cyclictest.py
index c992c0c..21d313c 100644
--- a/rteval/modules/measurement/cyclictest.py
+++ b/rteval/modules/measurement/cyclictest.py
@@ -228,7 +228,7 @@ class Cyclictest(rtevalModulePrototype):
def __getmode(self):
if self.__numanodes > 1:
self._log(Log.DEBUG, "running in NUMA mode (%d nodes)" % self.__numanodes)
- return '--numa'
+ return ''
self._log(Log.DEBUG, "running in SMP mode")
return '--smp'
@@ -278,7 +278,7 @@ class Cyclictest(rtevalModulePrototype):
self.__cmd.append("--notrace")
# Buffer for cyclictest data written to stdout
- self.__cyclicoutput = tempfile.SpooledTemporaryFile(mode='rw+b')
+ self.__cyclicoutput = tempfile.SpooledTemporaryFile(mode='w+b')
def _WorkloadTask(self):
@@ -327,6 +327,7 @@ class Cyclictest(rtevalModulePrototype):
# now parse the histogram output
self.__cyclicoutput.seek(0)
for line in self.__cyclicoutput:
+ line = bytes.decode(line)
if line.startswith('#'):
# Catch if cyclictest stopped due to a breaktrace
if line.startswith('# Break value: '):
diff --git a/rteval/sysinfo/kernel.py b/rteval/sysinfo/kernel.py
index fd261fe..308846b 100644
--- a/rteval/sysinfo/kernel.py
+++ b/rteval/sysinfo/kernel.py
@@ -50,9 +50,11 @@ class KernelInfo(object):
for p in c.stdout:
v = p.strip().split()
kcmd = v.pop(0)
+ kcmd = bytes.decode(kcmd)
try:
if int(v[0]) > 0 and kcmd.startswith('[') and kcmd.endswith(']'):
- ret_kthreads[v[0]] = {'policy' : policies[v[1]],
+
+ ret_kthreads[v[0]] = {'policy' : policies[bytes.decode(v[1])],
'priority' : v[2], 'name' : v[3] }
except ValueError:
pass # Ignore lines which don't have a number in the first row
@@ -137,9 +139,9 @@ class KernelInfo(object):
for pid in keys:
kthri_n = libxml2.newNode("thread")
kthreads_n.addChild(kthri_n)
- kthri_n.addContent(kthreads[pid]["name"])
+ kthri_n.addContent(bytes.decode(kthreads[pid]["name"]))
kthri_n.newProp("policy", kthreads[pid]["policy"])
- kthri_n.newProp("priority", kthreads[pid]["priority"])
+ kthri_n.newProp("priority", bytes.decode(kthreads[pid]["priority"]))
return rep_n
diff --git a/rteval/sysinfo/network.py b/rteval/sysinfo/network.py
index 9b933c1..ce9989a 100644
--- a/rteval/sysinfo/network.py
+++ b/rteval/sysinfo/network.py
@@ -53,7 +53,7 @@ class NetworkInfo(object):
if hasattr(ethtool, 'get_interfaces_info'):
# Using the newer python-ethtool API (version >= 0.4)
for dev in ethtool.get_interfaces_info(ethtool.get_devices()):
- if cmp(dev.device,'lo') == 0:
+ if dev.device == 'lo':
continue
intf_n = libxml2.newNode('interface')
diff --git a/rteval/xmlout.py b/rteval/xmlout.py
index 6464258..15391a6 100644
--- a/rteval/xmlout.py
+++ b/rteval/xmlout.py
@@ -29,7 +29,6 @@ import libxml2
import lxml.etree
import codecs
import re
-#from string import maketrans
def convert_libxml2_to_lxml_doc(inxml):
@@ -51,7 +50,7 @@ def convert_lxml_to_libxml2_nodes(inlxml):
if not isinstance(inlxml,lxml.etree._Element) and not isinstance(inlxml, lxml.etree._XSLTResultTree):
raise TypeError('Function requires an lxml.etree object as input')
- return libxml2.parseDoc(lxml.etree.tostring(inlxml)).getRootElement()
+ return libxml2.parseDoc(bytes.decode(lxml.etree.tostring(inlxml))).getRootElement()
@@ -74,13 +73,13 @@ class XMLOut(object):
self.xmldoc.freeDoc()
def __setup_tag_trans(self):
- t = maketrans('', '')
- t = t.replace(' ', '_')
- t = t.replace('\t', '_')
- t = t.replace('(', '_')
- t = t.replace(')', '_')
- t = t.replace(':', '-')
+ t = str.maketrans('', '')
return t
+# t = t.replace(' ', '_')
+# t = t.replace('\t', '_')
+# t = t.replace('(', '_')
+# t = t.replace(')', '_')
+# t = t.replace(':', '-')
def __fixtag(self, tagname):
if not isinstance(tagname, str):
@@ -99,9 +98,7 @@ class XMLOut(object):
rx = re.compile(" ")
val = rx.sub("_", val)
- # libxml2 uses UTF-8 internally and must have
- # all input as UTF-8.
- return val.encode('utf-8')
+ return val
def __add_attributes(self, node, attr):
@@ -223,7 +220,7 @@ class XMLOut(object):
resdoc = parser(xmldoc)
# Write the file with the requested output encoding
- dstfile.write(str(resdoc).encode(self.encoding))
+ dstfile.write(bytes.decode(str(resdoc).encode(self.encoding)))
if dstfile != sys.stdout:
dstfile.close()
--
2.17.0