[lnst] TestsCommon: set SIGINT handler only for bgprocess
by Jiří Pírko
commit b0aa8fb070f6d28a7295cc528342ce32e4c5cf63
Author: Jiri Pirko <jpirko(a)redhat.com>
Date: Fri Jul 1 17:38:51 2011 +0200
TestsCommon: set SIGINT handler only for bgprocess
Signed-off-by: Jiri Pirko <jpirko(a)redhat.com>
Common/TestsCommon.py | 8 +++++++-
NetTest/NetTestCommand.py | 1 +
2 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/Common/TestsCommon.py b/Common/TestsCommon.py
index 1e275ca..6d92667 100644
--- a/Common/TestsCommon.py
+++ b/Common/TestsCommon.py
@@ -57,13 +57,19 @@ class TestGeneric(NetTestCommandGeneric):
def __init__(self, command):
self._testLogger = logging.getLogger("root.testLogger")
self._read_pipe, self._write_pipe = os.pipe()
- signal.signal(signal.SIGINT, self._signal_intr_handler)
NetTestCommandGeneric.__init__(self, command)
def __del__(self):
os.close(self._read_pipe)
os.close(self._write_pipe)
+ def set_handle_intr(self):
+ """
+ Call this if you need this class to handle SIGINT. For backgroud
+ process purposes.
+ """
+ signal.signal(signal.SIGINT, self._signal_intr_handler)
+
def _signal_intr_handler(self, signum, frame):
os.write(self._write_pipe, "a")
diff --git a/NetTest/NetTestCommand.py b/NetTest/NetTestCommand.py
index 1605401..031865a 100644
--- a/NetTest/NetTestCommand.py
+++ b/NetTest/NetTestCommand.py
@@ -184,6 +184,7 @@ class NetTestCommand:
return {"passed": True}
os.close(read_pipe)
os.setpgrp()
+ cmd_cls.set_handle_intr()
try:
cmd_cls.run()
result = cmd_cls.get_result()
12 years, 2 months
[lnst] NetTestCommand: add intr command
by Jiří Pírko
commit 4338f18609c3fc2a80b9a3a67fdd521e80569386
Author: Jiri Pirko <jpirko(a)redhat.com>
Date: Fri Jul 1 17:12:58 2011 +0200
NetTestCommand: add intr command
This patch also reverts kill command and improves it by sending SIGKILL
Signed-off-by: Jiri Pirko <jpirko(a)redhat.com>
NetTest/NetTestCommand.py | 15 +++++++++++++--
NetTest/NetTestParse.py | 2 +-
example_recipes/jpirko_test/recipe_brpktgen.xml | 2 +-
3 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/NetTest/NetTestCommand.py b/NetTest/NetTestCommand.py
index 24f432c..1605401 100644
--- a/NetTest/NetTestCommand.py
+++ b/NetTest/NetTestCommand.py
@@ -129,17 +129,26 @@ class NetTestCommandWait(NetTestCommandGeneric):
bg_processes.remove(bg_id)
self.set_result(result)
-class NetTestCommandKill(NetTestCommandGeneric):
+class NetTestCommandIntr(NetTestCommandGeneric):
def run(self):
bg_id = int(self._command["value"])
pid = bg_processes.get_pid(bg_id)
- logging.debug("Killing background id \"%d\", pid \"%d\"" % (bg_id, pid))
+ logging.debug("Interrupting background id \"%d\", pid \"%d\"" % (bg_id, pid))
os.killpg(os.getpgid(pid), signal.SIGINT)
os.waitpid(pid, 0)
result = get_bg_process_result(bg_id)
bg_processes.remove(bg_id)
self.set_result(result)
+class NetTestCommandKill(NetTestCommandGeneric):
+ def run(self):
+ bg_id = int(self._command["value"])
+ pid = bg_processes.get_pid(bg_id)
+ logging.debug("Killing background id \"%d\", pid \"%d\"" % (bg_id, pid))
+ os.killpg(os.getpgid(pid), signal.SIGKILL)
+ bg_processes.remove(bg_id)
+ self.set_result({"passed": True})
+
def get_command_class(command):
cmd_type = command["type"]
if cmd_type == "exec":
@@ -148,6 +157,8 @@ def get_command_class(command):
return NetTestCommandTest(command)
elif cmd_type == "wait":
return NetTestCommandWait(command)
+ elif cmd_type == "intr":
+ return NetTestCommandIntr(command)
elif cmd_type == "kill":
return NetTestCommandKill(command)
else:
diff --git a/NetTest/NetTestParse.py b/NetTest/NetTestParse.py
index f0be155..c042292 100644
--- a/NetTest/NetTestParse.py
+++ b/NetTest/NetTestParse.py
@@ -159,7 +159,7 @@ class NetTestParse:
bg_ids[machine_id] = set()
cmd_type = command["type"]
- if cmd_type in ["kill", "wait"]:
+ if cmd_type in ["wait", "intr", "kill"]:
bg_id = int(command["value"])
if bg_id in bg_ids[machine_id]:
bg_ids[machine_id].remove(bg_id)
diff --git a/example_recipes/jpirko_test/recipe_brpktgen.xml b/example_recipes/jpirko_test/recipe_brpktgen.xml
index 1fcd8c8..0e186de 100644
--- a/example_recipes/jpirko_test/recipe_brpktgen.xml
+++ b/example_recipes/jpirko_test/recipe_brpktgen.xml
@@ -48,6 +48,6 @@
<option name="netdev_name" type="recipe_eval" value="['machines'][2]['netconfig'][2]['name']"/>
</options>
</command>
- <command machine_id="1" type="kill" value="1"/>
+ <command machine_id="1" type="intr" value="1"/>
</command_sequence>
</nettestrecipe>
12 years, 2 months
[lnst] example_recipes: add brpktgen recipe
by Jiří Pírko
commit d3293bf2d0da59a2f7956d3356f4bb0f0ea9cd33
Author: Jiri Pirko <jpirko(a)redhat.com>
Date: Fri Jul 1 14:42:39 2011 +0200
example_recipes: add brpktgen recipe
shows how to use Pktgen and PktCounter test. Recipe is useful to
measure regressions on bridge rx_path.
Signed-off-by: Jiri Pirko <jpirko(a)redhat.com>
example_recipes/jpirko_test/recipe_brpktgen.xml | 53 +++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/example_recipes/jpirko_test/recipe_brpktgen.xml b/example_recipes/jpirko_test/recipe_brpktgen.xml
new file mode 100644
index 0000000..1fcd8c8
--- /dev/null
+++ b/example_recipes/jpirko_test/recipe_brpktgen.xml
@@ -0,0 +1,53 @@
+<nettestrecipe>
+ <machines>
+ <machine id="1">
+ <netmachineconfig source="machine_configs/config-f14peanut.xml"/>
+ <netconfig>
+ <netdevice id="1" type="eth" phys_id="1"/>
+ <netdevice id="2" type="eth" phys_id="2"/>
+ <netdevice id="3" type="bridge">
+ <slaves>
+ <slave id="1"/>
+ </slaves>
+ <addresses>
+ <address value="192.168.101.1/24"/>
+ </addresses>
+ </netdevice>
+ </netconfig>
+ </machine>
+ <machine id="2">
+ <netmachineconfig source="machine_configs/config-junkbox.xml"/>
+ <netconfig>
+ <netdevice id="1" type="eth" phys_id="1">
+ <addresses>
+ <address value="192.168.101.2/24"/>
+ </addresses>
+ </netdevice>
+ <netdevice id="2" type="eth" phys_id="2">
+ <addresses>
+ <address value="192.168.101.2/24"/>
+ </addresses>
+ </netdevice>
+ </netconfig>
+ </machine>
+ </machines>
+ <command_sequence>
+ <command type="exec" value="sleep 4"/>
+ <command machine_id="1" type="test" value="PktCounter" bg_id="1">
+ <options>
+ <option name="input_netdev_name" type="recipe_eval" value="['machines'][1]['netconfig'][3]['name']"/>
+ <option name="proto" value="udp"/>
+ <option name="dport" value="9"/>
+ </options>
+ </command>
+ <command machine_id="2" type="test" value="PktgenTx" timeout="40">
+ <options>
+ <option name="addr" type="recipe_eval" value="['machines'][1]['netconfig'][3]['addresses'][0]"/>
+ <option name="hwaddr" type="recipe_eval" value="['machines'][1]['netconfig'][1]['hwaddr']"/>
+ <option name="netdev_name" type="recipe_eval" value="['machines'][2]['netconfig'][1]['name']"/>
+ <option name="netdev_name" type="recipe_eval" value="['machines'][2]['netconfig'][2]['name']"/>
+ </options>
+ </command>
+ <command machine_id="1" type="kill" value="1"/>
+ </command_sequence>
+</nettestrecipe>
12 years, 2 months
[lnst] Tests: add TestPktCounter
by Jiří Pírko
commit 9d6a74ae16600349e5a414e9b545560581525571
Author: Jiri Pirko <jpirko(a)redhat.com>
Date: Fri Jul 1 14:11:37 2011 +0200
Tests: add TestPktCounter
Signed-off-by: Jiri Pirko <jpirko(a)redhat.com>
Tests/TestPktCounter.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/Tests/TestPktCounter.py b/Tests/TestPktCounter.py
new file mode 100644
index 0000000..92a155c
--- /dev/null
+++ b/Tests/TestPktCounter.py
@@ -0,0 +1,69 @@
+"""
+This module defines packet counter implemented by iptables
+
+Copyright 2011 Red Hat, Inc.
+Licensed under the GNU General Public License, version 2 as
+published by the Free Software Foundation; see COPYING for details.
+"""
+
+__author__ = """
+jpirko(a)redhat.com (Jiri Pirko)
+"""
+
+import logging
+import re
+import os
+from Common.TestsCommon import TestGeneric
+from Common.ExecCmd import exec_cmd, ExecCmdFail
+
+def get_pkt_count(indev_name, dport, proto):
+ if indev_name:
+ p_indev_name = indev_name
+ else:
+ p_indev_name = "\*"
+ if proto:
+ p_proto = proto
+ p_protodport = "%s dpt:%s" % (proto, dport)
+ else:
+ p_proto = "all"
+ p_protodport = ""
+ pttr = (r'\s*(\d+)\s+\d+\s+%s\s+\-\-\s+%s\s+\*\s+0\.0\.0\.0\/0\s+0\.0\.0\.0\/0\s*%s'
+ % (p_proto, p_indev_name, p_protodport))
+ data_stdout = exec_cmd("iptables -L -v -x -n")[0]
+ match = re.search(pttr, data_stdout)
+ if not match:
+ return None
+ return match.groups()[0]
+
+class TestPktCounter(TestGeneric):
+ def run(self):
+ indev_name = self.get_opt("input_netdev_name")
+ dport = self.get_opt("dport")
+ proto = self.get_opt("proto")
+ params = ""
+ if indev_name:
+ params += " -i %s" % indev_name
+
+ if proto:
+ params += " -p %s" % proto
+
+ if dport:
+ params += " --dport %s" % dport
+
+ '''
+ Remove all same already existing rules
+ '''
+ while True:
+ if get_pkt_count(indev_name, dport, proto) == None:
+ break
+ exec_cmd("iptables -D INPUT%s" % params)
+
+ exec_cmd("iptables -I INPUT%s" % params)
+
+ self.wait_on_interrupt()
+
+ count = get_pkt_count(indev_name, dport, proto)
+
+ exec_cmd("iptables -D INPUT%s" % params)
+
+ return self.set_pass(res_data={"pkt_count": count})
12 years, 2 months
[lnst] Tests: allow to interrupt running test and get its result
by Jiří Pírko
commit d9d07ef1ee8863b7598e147ccb8d4952e2f78461
Author: Jiri Pirko <jpirko(a)redhat.com>
Date: Fri Jul 1 14:09:49 2011 +0200
Tests: allow to interrupt running test and get its result
Signed-off-by: Jiri Pirko <jpirko(a)redhat.com>
Common/TestsCommon.py | 28 ++++++++++++++++++++++++++--
NetTest/NetTestCommand.py | 40 +++++++++++++++++++++++++---------------
2 files changed, 51 insertions(+), 17 deletions(-)
---
diff --git a/Common/TestsCommon.py b/Common/TestsCommon.py
index 197bb62..1e275ca 100644
--- a/Common/TestsCommon.py
+++ b/Common/TestsCommon.py
@@ -10,7 +10,11 @@ __author__ = """
jpirko(a)redhat.com (Jiri Pirko)
"""
-import re, logging, sys, os
+import re
+import logging
+import sys
+import os
+import signal
from NetTest.NetTestCommand import NetTestCommandGeneric
class testLogger(logging.Logger):
@@ -51,8 +55,28 @@ class TestOptionMissing(Exception):
class TestGeneric(NetTestCommandGeneric):
def __init__(self, command):
- self._command = command
self._testLogger = logging.getLogger("root.testLogger")
+ self._read_pipe, self._write_pipe = os.pipe()
+ signal.signal(signal.SIGINT, self._signal_intr_handler)
+ NetTestCommandGeneric.__init__(self, command)
+
+ def __del__(self):
+ os.close(self._read_pipe)
+ os.close(self._write_pipe)
+
+ def _signal_intr_handler(self, signum, frame):
+ os.write(self._write_pipe, "a")
+
+ def wait_on_interrupt(self):
+ '''
+ Should be used by test implementation for waiting on SIGINT
+ '''
+ while True:
+ try:
+ os.read(self._read_pipe, 1)
+ except OSError:
+ continue
+ break
def set_fail(self, err_msg, res_data = None):
self._testLogger.error("FAILED - %s" % err_msg)
diff --git a/NetTest/NetTestCommand.py b/NetTest/NetTestCommand.py
index 0c9bc54..24f432c 100644
--- a/NetTest/NetTestCommand.py
+++ b/NetTest/NetTestCommand.py
@@ -67,6 +67,7 @@ def NetTestCommandTest(command):
class NetTestCommandGeneric:
def __init__(self, command):
self._command = command
+ self._result = None
def run(self):
pass
@@ -75,6 +76,12 @@ class NetTestCommandGeneric:
self._result = result
def get_result(self):
+ if not self._result:
+ '''
+ In case result is not set yet, it most likely means that
+ command was killed. So set pass in this case
+ '''
+ self.set_pass()
return self._result
def set_fail(self, err_msg):
@@ -95,27 +102,30 @@ class NetTestCommandExec(NetTestCommandGeneric):
except ExecCmdFail:
self.set_fail("Command failed to execute")
-
class BgProcessException(Exception):
"""Base class for client errors."""
def __init__(self, str):
- self.str = str
+ self._str = str
def __str__(self):
- return "BgProcessError: " + self.str
+ return "BgProcessError: " + self._str
+
+def get_bg_process_result(bg_id):
+ pipe = bg_processes.get_pipe(bg_id)
+ tmp = os.read(pipe, 4096*10)
+ result = pickle.loads(tmp)
+ if "Exception" in result:
+ raise BgProcessException(result["Exception"])
+ os.close(pipe)
+ return result
class NetTestCommandWait(NetTestCommandGeneric):
def run(self):
bg_id = int(self._command["value"])
pid = bg_processes.get_pid(bg_id)
- pipe = bg_processes.get_pipe(bg_id)
logging.debug("Waiting for background id \"%d\", pid \"%d\"" % (bg_id, pid))
os.waitpid(pid, 0)
- tmp = os.read(pipe, 4096*10)
- result = pickle.loads(tmp)
- if "Exception" in result:
- raise BgProcessException(result["Exception"])
- os.close(pipe)
+ result = get_bg_process_result(bg_id)
bg_processes.remove(bg_id)
self.set_result(result)
@@ -125,8 +135,10 @@ class NetTestCommandKill(NetTestCommandGeneric):
pid = bg_processes.get_pid(bg_id)
logging.debug("Killing background id \"%d\", pid \"%d\"" % (bg_id, pid))
os.killpg(os.getpgid(pid), signal.SIGINT)
+ os.waitpid(pid, 0)
+ result = get_bg_process_result(bg_id)
bg_processes.remove(bg_id)
- self.set_result({"passed": True})
+ self.set_result(result)
def get_command_class(command):
cmd_type = command["type"]
@@ -164,15 +176,13 @@ class NetTestCommand:
try:
cmd_cls.run()
result = cmd_cls.get_result()
- tmp = pickle.dumps(result)
- os.write(write_pipe, tmp)
except KeyboardInterrupt:
- pass
+ result = cmd_cls.get_result()
except:
type, value, tb = sys.exc_info()
result = {"Exception": ''.join(traceback.format_exception(type, value, tb))}
- tmp = pickle.dumps(result)
- os.write(write_pipe, tmp)
+ tmp = pickle.dumps(result)
+ os.write(write_pipe, tmp)
os.close(write_pipe)
os._exit(0)
else:
12 years, 2 months