[PATCH-master-py3 v2] Python2 to Python3 conversion fixes
by jurbanov@redhat.com
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 | 29 +++++++++++++++----
6 files changed, 42 insertions(+), 20 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..8e66215 100644
--- a/test_modules/Netperf.py
+++ b/test_modules/Netperf.py
@@ -7,12 +7,18 @@ jprochaz(a)redhat.com (Jiri Prochazka)
"""
import logging
-import errno
import re
+import signal
+import errno
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 +390,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 = {}
@@ -502,7 +519,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.20.1
4 years, 3 months
[PATCH-next] lnst.Common: edit IpAddress
by csfakian@redhat.com
From: Christos Sfakianakis <csfakian(a)redhat.com>
Add "link_local" attribute in Ip6Address to be used for filtering
off ipv6 link-local addresses when this is desirable (e.g by using
the "ips_filter" method of the Device module). The value of this
attribute is determined by the "is_link_local" method.
Signed-off-by: Christos Sfakianakis <csfakian(a)redhat.com>
---
lnst/Common/IpAddress.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lnst/Common/IpAddress.py b/lnst/Common/IpAddress.py
index e54553d..53dc047 100644
--- a/lnst/Common/IpAddress.py
+++ b/lnst/Common/IpAddress.py
@@ -12,6 +12,8 @@ olichtne(a)redhat.com (Ondrej Lichtner)
import re
from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
+from binascii import hexlify
+import socket
from lnst.Common.LnstError import LnstError
#TODO create various generators for IPNetworks and IPaddresses in the same
@@ -77,6 +79,7 @@ class Ip6Address(BaseIpAddress):
super(Ip6Address, self).__init__(addr)
self.family = AF_INET6
+ self.link_local = self.is_link_local()
@staticmethod
def _parse_addr(addr):
@@ -97,6 +100,10 @@ class Ip6Address(BaseIpAddress):
return addr, prefixlen
+ def is_link_local(self):
+ left_half = hexlify(socket.inet_pton(socket.AF_INET6, str(self)))[:16]
+ return left_half == 'fe80000000000000'
+
def ipaddress(addr):
"""Factory method to create a BaseIpAddress object"""
if isinstance(addr, BaseIpAddress):
--
2.17.1
4 years, 4 months
[PATCH-next] lnst.RecipeCommon.Ping: redesign to handle parallel scenarios
by csfakian@redhat.com
From: Christos Sfakianakis <csfakian(a)redhat.com>
Add/edit methods in PingTestAndEvaluate to handle parallel scenarios:
a) added "ping_init" to initiate a Tests.Ping instance for all
scenarios
b) edited "ping_test" to split between default and parallel
scenarios
c) added "parallel_ping_evaluate_and_report" as the analogous of
"ping_evaluate_and_report" for the parallel case
d) added "single_ping_evaluate_and_report" to report which ip's
are used each time in the parallel case
In lnst.Recipes.BaseEnrtRecipe, allow the user to specify ping
interval, count, packet size. Include additional parameters for
specifying parallel scenarios, as well as bidirectional cases.
Modify "generate_ping_configurations" method to account for parallel
scenarios. Assume "ip_versions" and the 2 endpoints are compatible
in that the latter share equal numbers of corresponding ip's and
output error otherwise. Filter off link-local ipv6 addresses.
Generate a list of ping configurations for each ip version specified
in a parallel scenario, or the content of a single-element list in the
default, non-parallel case.
Signed-off-by: Christos Sfakianakis <csfakian(a)redhat.com>
---
lnst/RecipeCommon/Ping.py | 57 ++++++++++++++++++++++++--
lnst/Recipes/ENRT/BaseEnrtRecipe.py | 62 +++++++++++++++++++++++------
2 files changed, 103 insertions(+), 16 deletions(-)
diff --git a/lnst/RecipeCommon/Ping.py b/lnst/RecipeCommon/Ping.py
index f5cd652..194d984 100644
--- a/lnst/RecipeCommon/Ping.py
+++ b/lnst/RecipeCommon/Ping.py
@@ -1,5 +1,8 @@
+from copy import copy
+
from lnst.Controller.Recipe import BaseRecipe
from lnst.Tests import Ping
+from lnst.Controller.RecipeResults import ResultLevel
class PingConf(object):
def __init__(self,
@@ -44,22 +47,68 @@ class PingConf(object):
class PingTestAndEvaluate(BaseRecipe):
def ping_test(self, ping_config):
+ #parallel scenario
+ if isinstance(ping_config, list):
+ results = {}
+
+ running_ping_array = []
+ for pingconf in ping_config:
+ ping, client = self.ping_init(pingconf)
+ running_ping = client.prepare_job(ping)
+ running_ping.start(bg = True)
+ running_ping_array.append((pingconf, running_ping))
+
+ for _, pingjob in running_ping_array:
+ try:
+ pingjob.wait()
+ finally:
+ pingjob.kill()
+
+ for pingconf, pingjob in running_ping_array:
+ result = pingjob.result
+ results[pingconf] = result
+
+ return results
+
+ #non-parallel scenario
+ ping, client = self.ping_init(ping_config)
+ ping_job = client.run(ping)
+ return ping_job.result
+
+ def ping_init(self, ping_config):
client = ping_config.client
destination = ping_config.destination
-
kwargs = self._generate_ping_kwargs(ping_config)
ping = Ping(**kwargs)
-
- ping_job = client.run(ping)
- return ping_job.result
+ return (ping, client)
def ping_evaluate_and_report(self, ping_config, results):
+ if isinstance(ping_config, list):
+ self.parallel_ping_evaluate_and_report(results)
+ return
# do we want to use the "perf" measurements (store a baseline etc...) as well?
if results["rate"] > 50:
self.add_result(True, "Ping succesful", results)
else:
self.add_result(False, "Ping unsuccesful", results)
+ #parallel version of ping_evaluate_and_report
+ def parallel_ping_evaluate_and_report(self, results):
+ for pingconf, result in results.items():
+ self.single_ping_evaluate_and_report(pingconf, result)
+
+ #clarify source/destination in reporting for parallel scenarios
+ def single_ping_evaluate_and_report(self, ping_config, results):
+ fmt = "From: <{0.client.hostid} ({0.client_bind})> To: " \
+ "<{0.destination.hostid} ({0.destination_address})>"
+ description = fmt.format(ping_config)
+ if results["rate"] > 50:
+ message = "Ping successful --- " + description
+ self.add_result(True, message, results)
+ else:
+ message = "Ping unsuccessful --- " + description
+ self.add_result(False, message, results)
+
def _generate_ping_kwargs(self, ping_config):
kwargs = dict(dst=ping_config.destination_address,
interface=ping_config.client_bind)
diff --git a/lnst/Recipes/ENRT/BaseEnrtRecipe.py b/lnst/Recipes/ENRT/BaseEnrtRecipe.py
index d7d1aec..cbab341 100644
--- a/lnst/Recipes/ENRT/BaseEnrtRecipe.py
+++ b/lnst/Recipes/ENRT/BaseEnrtRecipe.py
@@ -65,6 +65,13 @@ class EnrtSubConfiguration(object):
class BaseEnrtRecipe(PingTestAndEvaluate, PerfRecipe):
ip_versions = Param(default=("ipv4", "ipv6"))
+
+ ping_parallel = BoolParam(default=False)
+ ping_bidirect = BoolParam(default=False)
+ ping_count = IntParam(default = 100)
+ ping_interval = StrParam(default = 0.2)
+ ping_psize = IntParam(default = None)
+
perf_tests = Param(default=("tcp_stream", "udp_stream", "sctp_stream"))
offload_combinations = Param(default=(
@@ -158,22 +165,53 @@ class BaseEnrtRecipe(PingTestAndEvaluate, PerfRecipe):
def generate_ping_configurations(self, main_config, sub_config):
client_nic = main_config.endpoint1
server_nic = main_config.endpoint2
- client_netns = client_nic.netns
- server_netns = server_nic.netns
+
+ count = self.params.ping_count
+ interval = self.params.ping_interval
+ size = self.params.ping_psize
+ common_args = {'count' : count, 'interval' : interval, 'size' : size}
for ipv in self.params.ip_versions:
+ kwargs = {}
if ipv == "ipv4":
- family = AF_INET
+ kwargs.update(family = AF_INET)
elif ipv == "ipv6":
- family = AF_INET6
-
- client_bind = client_nic.ips_filter(family=family)[0]
- server_bind = server_nic.ips_filter(family=family)[0]
-
- yield PingConf(client = client_netns,
- client_bind = client_bind,
- destination = server_netns,
- destination_address = server_bind)
+ kwargs.update(family = AF_INET6)
+ kwargs.update(link_local = False)
+
+ client_ips = client_nic.ips_filter(**kwargs)
+ server_ips = server_nic.ips_filter(**kwargs)
+
+ if len(client_ips) != len(server_ips) or len(client_ips) * len(server_ips) == 0:
+ raise LnstError("Source/destination ip lists are of different size or empty.")
+
+ number_of_ips = len(client_ips)
+ ping_conf_list = []
+ client_nic.valid_ips = client_ips
+ server_nic.valid_ips = server_ips
+ for n in range(number_of_ips):
+ for client_nic, server_nic in [(client_nic, server_nic), (server_nic, client_nic)]:
+ client_bind = client_nic.valid_ips[n]
+ server_bind = server_nic.valid_ips[n]
+
+ pconf = PingConf(client = client_nic.netns,
+ client_bind = client_bind,
+ destination = server_nic.netns,
+ destination_address = server_bind,
+ **common_args)
+
+ ping_conf_list.append(pconf)
+
+ if not self.params.ping_bidirect:
+ break
+
+ if not self.params.ping_parallel:
+ break
+
+ if not self.params.ping_bidirect and not self.params.ping_parallel:
+ yield ping_conf_list[0]
+ else:
+ yield ping_conf_list
def generate_perf_configurations(self, main_config, sub_config):
client_nic = main_config.endpoint1
--
2.17.1
4 years, 4 months
[PATCH-next] lnst.Recipes.ENRT.TeamVsBondRecipe: remove erroneous line
by csfakian@redhat.com
From: Christos Sfakianakis <csfakian(a)redhat.com>
Remove line 56 (there is no team for m2).
Signed-off-by: Christos Sfakianakis <csfakian(a)redhat.com>
---
lnst/Recipes/ENRT/TeamVsBondRecipe.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/lnst/Recipes/ENRT/TeamVsBondRecipe.py b/lnst/Recipes/ENRT/TeamVsBondRecipe.py
index 597579b..23bac2d 100644
--- a/lnst/Recipes/ENRT/TeamVsBondRecipe.py
+++ b/lnst/Recipes/ENRT/TeamVsBondRecipe.py
@@ -53,7 +53,6 @@ class TeamVsBondRecipe(BaseEnrtRecipe):
if "mtu" in self.params:
m1.team.mtu = self.params.mtu
- m2.team.mtu = self.params.mtu
net_addr_1 = "192.168.10"
net_addr6_1 = "fc00:0:0:1"
--
2.17.1
4 years, 4 months
开发票找我13602510796
by gfgs@cfhi.com
代开本地各行业正规发票,价钱便宜,可验证后付款
有需要联系:13602510796 李乐翠 (加微信同号)
4 years, 4 months
how to make the slave use NetworkManager
by yangj
i wrote the following in the /root/lnst/lnst-slave.conf file,it was in
slave machine
[cache]
cache_dir = ./cache
expiration_period = 7days
[environment]
log_dir = ./Logs
use_nm=yes
but in Control machine ,It will appear as follows:
2019-01-17 00:46:09 (localhost) - WARNING: NetworkManager
is running on a slave machine!
2019-01-17 00:46:09 (localhost) - WARNING: Usage of NM is
disabled!
2019-01-17 00:46:09 (localhost) - WARNING:
=============================================
it's true???
4 years, 4 months
开发票找我13602510796
by gfgs@cfhi.com
代开本地各行业正规发票,价钱便宜,可验证后付款
有需要联系:13602510796 李乐翠 (加微信同号)
4 years, 4 months
[PATCH-next] lnst.Recipes.ENRT.VirtualBridgeVlansOverBondRecipe: mistakes in names
by csfakian@redhat.com
From: Christos Sfakianakis <csfakian(a)redhat.com>
'eth2' or 'eth3' devices are not defined. Replace 'eth{2,3}' with 'tap{0,1}'
accordingly.
Signed-off-by: Christos Sfakianakis <csfakian(a)redhat.com>
---
.../Recipes/ENRT/VirtualBridgeVlansOverBondRecipe.py | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lnst/Recipes/ENRT/VirtualBridgeVlansOverBondRecipe.py b/lnst/Recipes/ENRT/VirtualBridgeVlansOverBondRecipe.py
index 5917b88..162e3c1 100644
--- a/lnst/Recipes/ENRT/VirtualBridgeVlansOverBondRecipe.py
+++ b/lnst/Recipes/ENRT/VirtualBridgeVlansOverBondRecipe.py
@@ -50,8 +50,8 @@ class VirtualBridgeVlansOverBondRecipe(BaseEnrtRecipe):
for m, n in [(host1, 10),(host2, 10)]:
m.eth0.down()
m.eth1.down()
- m.eth2.down()
- m.eth3.down()
+ m.tap0.down()
+ m.tap1.down()
m.bond = BondDevice(mode=self.params.bonding_mode, miimon=self.params.miimon_value)
m.bond.slave_add(m.eth0)
m.bond.slave_add(m.eth1)
@@ -59,10 +59,10 @@ class VirtualBridgeVlansOverBondRecipe(BaseEnrtRecipe):
m.vlan2 = VlanDevice(realdev=m.bond, vlan_id=2*n)
m.br0 = BridgeDevice()
m.br0.slave_add(m.vlan1)
- m.br0.slave_add(m.eth2)
+ m.br0.slave_add(m.tap0)
m.br1 = BridgeDevice()
m.br1.slave_add(m.vlan2)
- m.br1.slave_add(m.eth3)
+ m.br1.slave_add(m.tap1)
for m in (guest1, guest2, guest3, guest4):
m.eth0.down()
@@ -100,8 +100,8 @@ class VirtualBridgeVlansOverBondRecipe(BaseEnrtRecipe):
for m, g1, g2 in [(host1, guest1, guest2), (host2, guest3, guest4)]:
m.eth0.up()
m.eth1.up()
- m.eth2.up()
- m.eth3.up()
+ m.tap0.up()
+ m.tap1.up()
m.bond.up()
m.vlan1.up()
m.vlan2.up()
--
2.17.1
4 years, 4 months
[PATCH-next 0/1] Parallel Ping patch
by csfakian@redhat.com
From: Christos Sfakianakis <csfakian(a)redhat.com>
Added scenario for parallelism in ping tests.
- Added ping_* params to offer customization capapbility to the user
- Assume the two endpoints have equal-lenght ip lists assigned to them
(e.g 3 x IPv4, 2 x IPv6 ip's)
- Exluded link-local IPv6 addresses from the pings
- Preserved the traditional sequence of looping over the ip versions to
perform the pings.
- Bidirectional pings (ping_bidirect) are coded to run simultaneously
- Parallel pings (ping_parallel) are also coded to run simultaneously
An example showing the timing relations is given below.
ENDPOINT 1 <=> ENDPOINT 2
ipv4.1 ... ipv4.2
ipv4.3 ... ipv4.4
++++++ ++++++
ipv6.1 ... ipv6.2
ipv6.3 ... ipv6.4
Parameters chosen:
- ping_parallel = True
- ping_bidirect = True
Result will be:
--------------------------------------------------------
#TIMING# ENDPT1 #Direction# ENDPT2
--------------------------------------------------------
TIME t1: ipv4.1 --> ipv4.2
TIME t1: ipv4.1 <-- ipv4.2
TIME t1: ipv4.3 --> ipv4.4
TIME t1: ipv4.3 <-- ipv4.4
=======================================================
TIME t2: ipv6.1 --> ipv6.2
TIME t2: ipv6.1 <-- ipv6.2
TIME t2: ipv6.3 --> ipv6.4
TIME t2: ipv6.3 <-- ipv6.4
Christos Sfakianakis (1):
Edit IpAddress, RecipeCommon.Ping, BaseEnrtRecipe
lnst/Common/IpAddress.py | 8 +-
lnst/RecipeCommon/Ping.py | 60 +++++++++++++++
lnst/Recipes/ENRT/BaseEnrtRecipe.py | 110 +++++++++++++++++++++++++++-
3 files changed, 173 insertions(+), 5 deletions(-)
--
2.17.1
4 years, 4 months
[PATCH-master-py3] Python2 to Python3 conversion fixes
by jurbanov@redhat.com
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
4 years, 4 months