commit 60611c3e3264ad7efe47a54835ac1be081b328db Author: Ondrej Lichtner olichtne@redhat.com Date: Tue Mar 3 14:13:19 2015 +0100
NetTestCommand: fix signal handling for bg commands
This commit fixes signal handling (mainly SIGINT) for background commands. The default action is to ignore the signals SIGHUP, SIGINT and SIGTERM. This is needed for "run command" commands to work, and if the developer of a test module wants to change the behaviour he cna do so in the run method of his module.
This commit also changes the method wait_on_interrupt provided for test modules. Previously it was bound to usage coupled with the set_handle_intr signal handler. Now the method is standalone changes your SIGINT signal handler only for the duration of the method. This makes the method set_handle_intr obsolete so it was removed.
Finally the regression test #25 was modified to reflect these changes.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com Signed-off-by: Jiri Pirko jiri@resnulli.us
lnst/Common/NetTestCommand.py | 13 +--- lnst/Common/TestsCommon.py | 14 +--- regression-tests/tests/25/lnst-ctl.conf | 2 - regression-tests/tests/25/recipe2.xml | 20 +++-- regression-tests/tests/25/recipe3.xml | 53 -------------- regression-tests/tests/25/run.sh | 9 +-- regression-tests/tests/25/test_modules/IcmpPing.py | 75 -------------------- 7 files changed, 21 insertions(+), 165 deletions(-) --- diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py index 0f7c2a3..c1a796f 100644 --- a/lnst/Common/NetTestCommand.py +++ b/lnst/Common/NetTestCommand.py @@ -137,15 +137,11 @@ class NetTestCommand: "res_header": self._cmd_cls._format_cmd_res_header(), "msg": "Running in background."}
- def _sig_handler(self, signum, frame): - raise KeyboardInterrupt() - def _run(self): os.setpgrp() - signal.signal(signal.SIGHUP, self._sig_handler) - signal.signal(signal.SIGINT, self._sig_handler) - signal.signal(signal.SIGTERM, self._sig_handler) - self._cmd_cls.set_handle_intr() + signal.signal(signal.SIGHUP, signal.SIG_IGN) + signal.signal(signal.SIGINT, signal.SIG_IGN) + signal.signal(signal.SIGTERM, signal.SIG_IGN)
self._connection_pipe = self._write_pipe
@@ -362,9 +358,6 @@ class NetTestCommandGeneric(object):
return "%-9s" % (self._command["type"] + netns)
- def set_handle_intr(self): - pass - def set_resource_table(self, res_table): self._resource_table = res_table
diff --git a/lnst/Common/TestsCommon.py b/lnst/Common/TestsCommon.py index 2504ecf..b471d8d 100644 --- a/lnst/Common/TestsCommon.py +++ b/lnst/Common/TestsCommon.py @@ -59,25 +59,19 @@ class TestGeneric(NetTestCommandGeneric): self._testLogger = logging.getLogger("root.testLogger") NetTestCommandGeneric.__init__(self, command)
- 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): - raise KeyboardInterrupt() - def wait_on_interrupt(self): ''' Should be used by test implementation for waiting on SIGINT ''' try: + handler = signal.getsignal(signal.SIGINT) + signal.signal(signal.SIGINT, signal.default_int_handler) while True: time.sleep(1) except KeyboardInterrupt: pass + finally: + signal.signal(signal.SIGINT, handler)
def _get_val(self, value, opt_type, default): if opt_type == "addr": diff --git a/regression-tests/tests/25/recipe2.xml b/regression-tests/tests/25/recipe2.xml index fd8b3f6..30452aa 100644 --- a/regression-tests/tests/25/recipe2.xml +++ b/regression-tests/tests/25/recipe2.xml @@ -33,17 +33,21 @@ </host> </network> <task> - <run command="ping -c 4 {ip(tm2,phy1)}" host="tm1" netns="in"/> - <run host="tm1" module="IcmpPing" bg_id="on_bg" netns="in"> + <run module="PktCounter" host="tm1" netns="in" bg_id="ctr"> <options> - <option name="addr" value="{ip(tm2,phy1)}"/> - <option name="interval" value="1"/> + <option name="input_netdev_name" value="{devname(tm1,in)}"/> </options> </run> - <ctl_wait seconds="2"/> - <run command="pstree -p" host="tm1" netns="in"/> - <ctl_wait seconds="2"/> - <intr host="tm1" bg_id="on_bg"/> + <run module="PktgenTx" host="tm2"> + <options> + <option name="netdev_name" value="{devname(tm2,phy1)}"/> + <option name="pktgen_option" value="dst {ip(tm1, in)}"/> + <option name="pktgen_option" value="dst_mac {hwaddr(tm1,in)}"/> + <option name="pktgen_option" value="count 1000"/> + </options> + </run> + <ctl_wait seconds="5"/> + <intr host="tm1" bg_id="ctr"/> </task> </lnstrecipe>
diff --git a/regression-tests/tests/25/run.sh b/regression-tests/tests/25/run.sh index 34c1dc6..8e1daa2 100755 --- a/regression-tests/tests/25/run.sh +++ b/regression-tests/tests/25/run.sh @@ -4,22 +4,17 @@
init_test
-lnst-ctl -c lnst-ctl.conf -d run recipe1.xml | tee test.log +lnst-ctl -d run recipe1.xml | tee test.log rv1=${PIPESTATUS[0]} log1=`cat test.log`
-lnst-ctl -c lnst-ctl.conf -d run recipe2.xml | tee test.log +lnst-ctl -d run recipe2.xml | tee test.log rv2=${PIPESTATUS[0]} log2=`cat test.log`
-lnst-ctl -d run recipe3.xml | tee test.log -rv3=${PIPESTATUS[0]} -log3=`cat test.log` - print_separator assert_status "pass" "$rv1" assert_status "pass" "$rv2" -assert_status "pass" "$rv3"
rm -f test.log