From: Jozef Urbanovsky <jurbanov(a)redhat.com>
lnst/Common/Daemon.py
===================================
Issue#191 - daemonize doesn't work with py3
- Replaces file method with open method instead
lnst/Controller/SlavePool.py
===================================
Unable to match specific test cases
- Deleted iter from sorted list, as iterator object not needed
lnst/Controller/Task.py
===================================
Hash creation was unsuccessful due to type mismatch
- hashlib.sha1 is expecting str, instead of unicode object
- Changed encoding to utf-8 str
lnst/Slave/NetTestSlave.py
===================================
Top-level exception was thrown instead of specific one, could catch
exception, that wasn't meant for Slave process
- Created specific SystemCallException
- Throwing and expecting SystemCallException instead of general one
recipes/regression_tests/phase3/ipsec_esp_aead.py
===================================
Type mismatch
- py3 divison is float by default, added explicit conversion to int
test_modules/Netperf.py
===================================
Unable to interrupt netperf server instance
- Created new InterruptException
- Created new method wait_for_interrupt to catch sigint, instead
of waiting for exception, that's no longer thrown with PEP 475
- py3 divison is float by default, added explicit conversion to int
Signed-off-by: Jozef Urbanovsky <jurbanov(a)redhat.com>
---
lnst/Common/Daemon.py | 10 +++---
lnst/Controller/SlavePool.py | 4 +--
lnst/Controller/Task.py | 8 ++---
lnst/Slave/NetTestSlave.py | 9 +++--
.../regression_tests/phase3/ipsec_esp_aead.py | 2 +-
test_modules/Netperf.py | 33 ++++++++++++++-----
6 files changed, 43 insertions(+), 23 deletions(-)
diff --git a/lnst/Common/Daemon.py b/lnst/Common/Daemon.py
index 6fbf950..23bb77e 100644
--- a/lnst/Common/Daemon.py
+++ b/lnst/Common/Daemon.py
@@ -25,7 +25,7 @@ class Daemon:
def _read_pid(self):
try:
- handle = file(self._pidfile, "r")
+ handle = open(self._pidfile, "r")
pid = int(handle.read().strip())
handle.close()
except IOError:
@@ -33,7 +33,7 @@ class Daemon:
return pid
def _write_pid(self, pid):
- handle = file(self._pidfile, "w")
+ handle = open(self._pidfile, "w")
handle.write("%s\n" % str(pid))
handle.close()
self._pid_written = True
@@ -86,9 +86,9 @@ class Daemon:
sys.stdout.flush()
sys.stderr.flush()
- si = file("/dev/null", 'r')
- so = file("/dev/null", 'a+')
- se = file("/dev/null", 'a+', 0)
+ si = open("/dev/null", 'r')
+ so = open("/dev/null", 'a+')
+ se = open("/dev/null", 'a+', 0)
os.dup2(si.fileno(), sys.stdin.fileno())
os.dup2(so.fileno(), sys.stdout.fileno())
os.dup2(se.fileno(), sys.stderr.fileno())
diff --git a/lnst/Controller/SlavePool.py b/lnst/Controller/SlavePool.py
index 8166816..b271158 100644
--- a/lnst/Controller/SlavePool.py
+++ b/lnst/Controller/SlavePool.py
@@ -451,7 +451,7 @@ class SetupMapper(object):
self._pool = self._pools[self._pool_name]
self._unmatched_pool_machines = []
- for p_id, p_machine in sorted(iter(self._pool.items()), reverse=True):
+ for p_id, p_machine in sorted(self._pool.items(), reverse=True):
if self._virtual_matching:
if "libvirt_domain" in p_machine["params"]:
self._unmatched_pool_machines.append(p_id)
@@ -516,7 +516,7 @@ class SetupMapper(object):
self._pool_name)
self._unmatched_pool_machines = []
- for p_id, p_machine in sorted(iter(self._pool.items()), reverse=True):
+ for p_id, p_machine in sorted(self._pool.items(), reverse=True):
if self._virtual_matching:
if "libvirt_domain" in p_machine["params"]:
self._unmatched_pool_machines.append(p_id)
diff --git a/lnst/Controller/Task.py b/lnst/Controller/Task.py
index e2b98d0..42a50ab 100644
--- a/lnst/Controller/Task.py
+++ b/lnst/Controller/Task.py
@@ -1259,9 +1259,9 @@ class PerfRepoResult(object):
params = self._testExecution.get_parameters()
sha1 = hashlib.sha1()
- sha1.update(self._testExecution.get_testUid())
+ sha1.update((self._testExecution.get_testUid()).encode("utf-8"))
for i in sorted(tags):
- sha1.update(i)
+ sha1.update(i.encode("utf-8"))
for i in sorted(params, key=lambda x: x[0]):
skip = False
for j in ignore:
@@ -1270,8 +1270,8 @@ class PerfRepoResult(object):
break
if skip:
continue
- sha1.update(i[0])
- sha1.update(str(i[1]))
+ sha1.update(i[0].encode("utf-8"))
+ sha1.update(str(i[1]).encode("utf-8"))
return sha1.hexdigest()
class PerfRepoBaseline(object):
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 7c61d23..a861d2c 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -43,6 +43,11 @@ from lnst.Slave.InterfaceManager import InterfaceManager
from lnst.Slave.BridgeTool import BridgeTool
from lnst.Slave.SlaveSecSocket import SlaveSecSocket, SecSocketException
+class SystemCallException(Exception):
+ """Exception used to handle SIGINT waiting for system calls"""
+ pass
+
+
class SlaveMethods:
'''
Exported xmlrpc methods
@@ -1407,7 +1412,7 @@ class NetTestSlave:
for msg in msgs:
self._process_msg(msg[1])
- except:
+ except SystemCallException:
break
self._methods.machine_cleanup()
@@ -1509,7 +1514,7 @@ class NetTestSlave:
def _signal_die_handler(self, signum, frame):
logging.info("Caught signal %d -> dying" % signum)
- raise Exception("Recieved interrupt to system call")
+ raise SystemCallException()
def _parent_resend_signal_handler(self, signum, frame):
logging.info("Caught signal %d -> resending to parent" % signum)
diff --git a/recipes/regression_tests/phase3/ipsec_esp_aead.py b/recipes/regression_tests/phase3/ipsec_esp_aead.py
index 3c5028e..752448c 100644
--- a/recipes/regression_tests/phase3/ipsec_esp_aead.py
+++ b/recipes/regression_tests/phase3/ipsec_esp_aead.py
@@ -14,7 +14,7 @@ from lnst.RecipeCommon.PerfRepo import generate_perfrepo_comment
#lenth param is in bits
def generate_key(length):
key = "0x"
- key = key + (length/8) * "0b"
+ key = key + (int(length/8)) * "0b"
return key
algorithm = []
diff --git a/test_modules/Netperf.py b/test_modules/Netperf.py
index 7e9fbd0..8732bea 100644
--- a/test_modules/Netperf.py
+++ b/test_modules/Netperf.py
@@ -7,12 +7,17 @@ jprochaz(a)redhat.com (Jiri Prochazka)
"""
import logging
-import errno
import re
+import signal
from lnst.Common.TestsCommon import TestGeneric
from lnst.Common.ShellProcess import ShellProcess
from lnst.Common.Utils import std_deviation, is_installed, int_it
+class InterruptException(Exception):
+ """Exception used to handle SIGINT waiting"""
+ pass
+
+
class Netperf(TestGeneric):
supported_tests = ["TCP_STREAM", "TCP_RR", "UDP_STREAM", "UDP_RR",
@@ -384,10 +389,21 @@ class Netperf(TestGeneric):
logging.debug("running as server...")
server = ShellProcess(cmd)
try:
- server.wait()
- except OSError as e:
- if e.errno == errno.EINTR:
- server.kill()
+ self.wait_for_interrupt()
+ except InterruptException:
+ server.kill()
+
+ def wait_for_interrupt(self):
+ def handler(signum, frame):
+ raise InterruptException()
+
+ try:
+ old_handler = signal.signal(signal.SIGINT, handler)
+ signal.pause()
+ except InterruptException:
+ pass
+ finally:
+ signal.signal(signal.SIGINT, old_handler)
def _pretty_rate(self, rate, unit=None):
pretty_rate = {}
@@ -468,9 +484,8 @@ class Netperf(TestGeneric):
try:
ret_code = client.wait()
rv += ret_code
- except OSError as e:
- if e.errno == errno.EINTR:
- client.kill()
+ except InterruptException:
+ client.kill()
output = client.read_nonblocking()
logging.debug(output)
@@ -502,7 +517,7 @@ class Netperf(TestGeneric):
rate_deviation = 2*res_data["std_deviation"]
elif len(rates) == 1 and self._confidence is not None:
result = results[0]
- rate_deviation = rate * (result["confidence"][1] / 100)
+ rate_deviation = rate * (int(result["confidence"][1]) / 100)
else:
rate_deviation = 0.0
--
2.19.1