[PATCH] regression_tests: add set of tests for timeout handling
by Jan Tluka
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
regression-tests/tests/27/desc | 10 ++++++++
regression-tests/tests/27/recipe1.xml | 32 +++++++++++++++++++++++
regression-tests/tests/27/recipe2.xml | 32 +++++++++++++++++++++++
regression-tests/tests/27/recipe3.xml | 31 ++++++++++++++++++++++
regression-tests/tests/27/recipe4.xml | 31 ++++++++++++++++++++++
regression-tests/tests/27/recipe5.xml | 32 +++++++++++++++++++++++
regression-tests/tests/27/recipe6.xml | 30 ++++++++++++++++++++++
regression-tests/tests/27/recipe7.xml | 30 ++++++++++++++++++++++
regression-tests/tests/27/recipe8.xml | 32 +++++++++++++++++++++++
regression-tests/tests/27/run.sh | 48 +++++++++++++++++++++++++++++++++++
10 files changed, 308 insertions(+)
create mode 100644 regression-tests/tests/27/desc
create mode 100644 regression-tests/tests/27/recipe1.xml
create mode 100644 regression-tests/tests/27/recipe2.xml
create mode 100644 regression-tests/tests/27/recipe3.xml
create mode 100644 regression-tests/tests/27/recipe4.xml
create mode 100644 regression-tests/tests/27/recipe5.xml
create mode 100644 regression-tests/tests/27/recipe6.xml
create mode 100644 regression-tests/tests/27/recipe7.xml
create mode 100644 regression-tests/tests/27/recipe8.xml
create mode 100755 regression-tests/tests/27/run.sh
diff --git a/regression-tests/tests/27/desc b/regression-tests/tests/27/desc
new file mode 100644
index 0000000..fb66011
--- /dev/null
+++ b/regression-tests/tests/27/desc
@@ -0,0 +1,10 @@
+Check timeout handling for commands run in background and foreground.
+
+1. put a command on bg and intr() it before desired timeout
+2. put a command on bg and intr() it after desired timeout
+3. put a command on bg and immediately wait for it's completion before timeout
+4. put a command on bg and immediately wait for it's completion after timeout
+5. put a command on bg and wait for it not earlier after it's completed
+6. put a command on fg and set timeout longer than expected completion
+7. put a command on fg and set timeout shorter than expected completion
+
diff --git a/regression-tests/tests/27/recipe1.xml b/regression-tests/tests/27/recipe1.xml
new file mode 100644
index 0000000..56b1ff6
--- /dev/null
+++ b/regression-tests/tests/27/recipe1.xml
@@ -0,0 +1,32 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 10" host="testmachine1" bg_id="1" timeout="15"/>
+ <ctl_wait seconds="2"/>
+ <intr host="testmachine1" bg_id="1"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/27/recipe2.xml b/regression-tests/tests/27/recipe2.xml
new file mode 100644
index 0000000..c7a60dc
--- /dev/null
+++ b/regression-tests/tests/27/recipe2.xml
@@ -0,0 +1,32 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 5" host="testmachine1" bg_id="2" timeout="5"/>
+ <ctl_wait seconds="7"/>
+ <intr host="testmachine1" bg_id="2"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/27/recipe3.xml b/regression-tests/tests/27/recipe3.xml
new file mode 100644
index 0000000..83510a1
--- /dev/null
+++ b/regression-tests/tests/27/recipe3.xml
@@ -0,0 +1,31 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 5" host="testmachine1" bg_id="3" timeout="3"/>
+ <wait host="testmachine1" bg_id="3"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/27/recipe4.xml b/regression-tests/tests/27/recipe4.xml
new file mode 100644
index 0000000..b9f1fe2
--- /dev/null
+++ b/regression-tests/tests/27/recipe4.xml
@@ -0,0 +1,31 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 5" host="testmachine1" bg_id="4" timeout="7"/>
+ <wait host="testmachine1" bg_id="4"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/27/recipe5.xml b/regression-tests/tests/27/recipe5.xml
new file mode 100644
index 0000000..f7ac10c
--- /dev/null
+++ b/regression-tests/tests/27/recipe5.xml
@@ -0,0 +1,32 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 10" host="testmachine1" bg_id="1"/>
+ <ctl_wait seconds="15"/>
+ <wait host="testmachine1" bg_id="1"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/27/recipe6.xml b/regression-tests/tests/27/recipe6.xml
new file mode 100644
index 0000000..0dac603
--- /dev/null
+++ b/regression-tests/tests/27/recipe6.xml
@@ -0,0 +1,30 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 5" host="testmachine1" timeout="10"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/27/recipe7.xml b/regression-tests/tests/27/recipe7.xml
new file mode 100644
index 0000000..bcc8c2c
--- /dev/null
+++ b/regression-tests/tests/27/recipe7.xml
@@ -0,0 +1,30 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 5" host="testmachine1" timeout="3"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/27/recipe8.xml b/regression-tests/tests/27/recipe8.xml
new file mode 100644
index 0000000..9809b17
--- /dev/null
+++ b/regression-tests/tests/27/recipe8.xml
@@ -0,0 +1,32 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet">
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 10" host="testmachine1" bg_id="1"/>
+ <ctl_wait seconds="2"/>
+ <intr host="testmachine1" bg_id="1"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/27/run.sh b/regression-tests/tests/27/run.sh
new file mode 100755
index 0000000..e61da3f
--- /dev/null
+++ b/regression-tests/tests/27/run.sh
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+. ../lib.sh
+
+init_test
+
+lnst-ctl -d run recipe1.xml | tee test.log
+rv1=${PIPESTATUS[0]}
+log1=`cat 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`
+
+lnst-ctl -d run recipe4.xml | tee test.log
+rv4=${PIPESTATUS[0]}
+log4=`cat test.log`
+
+lnst-ctl -d run recipe5.xml | tee test.log
+rv5=${PIPESTATUS[0]}
+log5=`cat test.log`
+
+lnst-ctl -d run recipe6.xml | tee test.log
+rv6=${PIPESTATUS[0]}
+log6=`cat test.log`
+
+lnst-ctl -d run recipe7.xml | tee test.log
+rv7=${PIPESTATUS[0]}
+log7=`cat test.log`
+
+print_separator
+assert_status "pass" "$rv1"
+assert_status "pass" "$rv2"
+assert_status "fail" "$rv3"
+assert_log "INFO" "RPC connection to machine testmachine1 timed out" "$log3"
+assert_status "pass" "$rv4"
+assert_status "pass" "$rv5"
+assert_status "pass" "$rv6"
+assert_status "fail" "$rv7"
+assert_log "INFO" "RPC connection to machine testmachine1 timed out" "$log7"
+
+rm -f test.log
+
+end_test
--
1.9.3
9 years
[lnst] NetTestCommand: use custom signal handler function instead of SIG_IGN
by Jiří Pírko
commit f62d5db85cfa0e71f51926dc1521f4248df4551a
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Mon Mar 9 17:23:26 2015 +0100
NetTestCommand: use custom signal handler function instead of SIG_IGN
The exec syscall resets all signal handlers except for SIG_IGN. This
means that exec_cmd() doesn't work with <intr> commands. The original
regression test didn't catch this because ping sets it's own SIGINT
handler. To fix this we will use our own handler function that will just
ignore the signal, it has the same behaviour as SIG_IGN, but will get
reset on exec syscall, which is what we want.
The patch also adds a new recipe to the regression test.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Common/NetTestCommand.py | 9 ++++++---
regression-tests/tests/25/recipe3.xml | 28 ++++++++++++++++++++++++++++
regression-tests/tests/25/run.sh | 6 ++++++
3 files changed, 40 insertions(+), 3 deletions(-)
---
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index c1a796f..cfa2b3b 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -137,11 +137,14 @@ class NetTestCommand:
"res_header": self._cmd_cls._format_cmd_res_header(),
"msg": "Running in background."}
+ def _sig_ign(self, signum, frame):
+ pass
+
def _run(self):
os.setpgrp()
- signal.signal(signal.SIGHUP, signal.SIG_IGN)
- signal.signal(signal.SIGINT, signal.SIG_IGN)
- signal.signal(signal.SIGTERM, signal.SIG_IGN)
+ signal.signal(signal.SIGHUP, self._sig_ign)
+ signal.signal(signal.SIGINT, self._sig_ign)
+ signal.signal(signal.SIGTERM, self._sig_ign)
self._connection_pipe = self._write_pipe
diff --git a/regression-tests/tests/25/recipe3.xml b/regression-tests/tests/25/recipe3.xml
new file mode 100644
index 0000000..4cdb6f4
--- /dev/null
+++ b/regression-tests/tests/25/recipe3.xml
@@ -0,0 +1,28 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <interfaces>
+ <eth id="test_if" label="tnet">
+ <addresses>
+ <address value="192.168.0.1/24" />
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <interfaces>
+ <eth id="test_if" label="tnet">
+ <addresses>
+ <address value="192.168.0.2/24" />
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 120" host="testmachine1" bg_id="1" timeout="125"/>
+ <ctl_wait seconds="5"/>
+ <intr host="testmachine1" bg_id="1"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/25/run.sh b/regression-tests/tests/25/run.sh
index 8e1daa2..745a06b 100755
--- a/regression-tests/tests/25/run.sh
+++ b/regression-tests/tests/25/run.sh
@@ -12,9 +12,15 @@ 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"
+assert_log "ERROR" "Command execution failed (exited with -2)" "$log3"
rm -f test.log
9 years
[PATCH] NetTestCommand: use custom signal handler function instead of SIG_IGN
by Ondrej Lichtner
From: Ondrej Lichtner <olichtne(a)redhat.com>
The exec syscall resets all signal handlers except for SIG_IGN. This
means that exec_cmd() doesn't work with <intr> commands. The original
regression test didn't catch this because ping sets it's own SIGINT
handler. To fix this we will use our own handler function that will just
ignore the signal, it has the same behaviour as SIG_IGN, but will get
reset on exec syscall, which is what we want.
The patch also adds a new recipe to the regression test.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Common/NetTestCommand.py | 9 ++++++---
regression-tests/tests/25/recipe3.xml | 28 ++++++++++++++++++++++++++++
regression-tests/tests/25/run.sh | 6 ++++++
3 files changed, 40 insertions(+), 3 deletions(-)
create mode 100644 regression-tests/tests/25/recipe3.xml
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index c1a796f..cfa2b3b 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -137,11 +137,14 @@ class NetTestCommand:
"res_header": self._cmd_cls._format_cmd_res_header(),
"msg": "Running in background."}
+ def _sig_ign(self, signum, frame):
+ pass
+
def _run(self):
os.setpgrp()
- signal.signal(signal.SIGHUP, signal.SIG_IGN)
- signal.signal(signal.SIGINT, signal.SIG_IGN)
- signal.signal(signal.SIGTERM, signal.SIG_IGN)
+ signal.signal(signal.SIGHUP, self._sig_ign)
+ signal.signal(signal.SIGINT, self._sig_ign)
+ signal.signal(signal.SIGTERM, self._sig_ign)
self._connection_pipe = self._write_pipe
diff --git a/regression-tests/tests/25/recipe3.xml b/regression-tests/tests/25/recipe3.xml
new file mode 100644
index 0000000..4cdb6f4
--- /dev/null
+++ b/regression-tests/tests/25/recipe3.xml
@@ -0,0 +1,28 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <interfaces>
+ <eth id="test_if" label="tnet">
+ <addresses>
+ <address value="192.168.0.1/24" />
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <interfaces>
+ <eth id="test_if" label="tnet">
+ <addresses>
+ <address value="192.168.0.2/24" />
+ </addresses>
+ </eth>
+ </interfaces>
+ </host>
+ </network>
+
+ <task>
+ <run command="sleep 120" host="testmachine1" bg_id="1" timeout="125"/>
+ <ctl_wait seconds="5"/>
+ <intr host="testmachine1" bg_id="1"/>
+ </task>
+</lnstrecipe>
diff --git a/regression-tests/tests/25/run.sh b/regression-tests/tests/25/run.sh
index 8e1daa2..745a06b 100755
--- a/regression-tests/tests/25/run.sh
+++ b/regression-tests/tests/25/run.sh
@@ -12,9 +12,15 @@ 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"
+assert_log "ERROR" "Command execution failed (exited with -2)" "$log3"
rm -f test.log
--
2.1.0
9 years
[lnst] regression-tests: update README.md
by Jiří Pírko
commit 84d5ece38a4baa6d5f2b440c54a1587d68301b1e
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Mon Mar 9 10:50:32 2015 +0100
regression-tests: update README.md
This commit moves the wiki page describing regression tests into the
README.md file for regression tests. This makes it useful both when
viewing from github, since it's autmatically shown when you open the
regression-tests directory, and viewing locally after a git clone.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
regression-tests/README.md | 97 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 97 insertions(+), 0 deletions(-)
---
diff --git a/regression-tests/README.md b/regression-tests/README.md
index e2d7f70..7798333 100644
--- a/regression-tests/README.md
+++ b/regression-tests/README.md
@@ -4,6 +4,18 @@
Project. It contains a number of test cases and scenario to verify LNST
before releases and also to catch bugs and regressions.
+In case you're interested in contributing to our project you should be
+interested in this page as well since we won't be accepting contributions that
+break any of our tests.
+
+Currently there are two sets of tests that reside in our repository:
+* smoke tests, located in ```recipes/smoke/```
+* regression tests, located in ```regression-tests/```
+
+It is important to note that all of these tests were created to test LNST
+functionality for bugs. For this reason we assume that when running these
+tests, they're being run on stable systems.
+
## Required Non-default Packages on slave machines
* rsync
@@ -13,3 +25,88 @@ before releases and also to catch bugs and regressions.
* bzip2
* make
* gcc
+
+## Smoke tests
+
+Smoke tests were created to cover a wide area of basic LNST functionality, but
+avoid testing for more complex/in-depth bugs.
+
+As was mentioned before, smoke tests are located in the ```recipes/smoke/```
+directory. Here you can find a subdirectory ```lib/``` and a python script
+```generate-recipes.py```. The ```lib/``` directory contains 4 types of files:
+* ```recipe-temp.xml``` recipe template file,
+* ```conf-*.xml``` network configuration files,
+* ```task-*.xml``` task definition files,
+* ```variables.conf``` file.
+
+The generate-recipes script loads the remplate file and fills it with two
+configuration files and all the task files to create recipes for all possible
+configuration combinations. The generated recipes are placed in the
+```recipes/smoke/tests/``` directory.
+
+Finally the variables file defines values for some variables (e.g. result of a
+command), that are dependent on the combination of the configuration files.
+When a recipe file is generated these variables are replaced with their
+respective values.
+
+To run these recipes you need to have 2 machines available in the pool you've
+configured and you can use the following command:
+```
+lnst-ctl -d run recipes/smoke/tests/*
+```
+
+## Regression tests
+
+Regression tests were created as a means to test for specific bugs that we have
+already fixed. Our policy is to add a new regression test every time we fix a
+more serious bug, however this isn't always possible due to different reasons.
+If you find a bug in LNST and you want to contribute a patch that fixes it, it
+is **highly recommended** to also create a regression test.
+
+The directory structure for regression tests is as follows:
+* ```regression-tests/``` is the main directory where everything related to
+ regression tests is located.
+* ```regression-tests/env/``` contains a LNST environment that is used by the
+ regression tests. It contains a lnst-ctl configuration file and you're
+ expected to create a machine pool directory here.
+* ```regression-tests/tests/``` contains all the regression tests we currently
+ have, isolated in their own directories that are numbered. You can also find
+ the ```lib.sh``` file which contains definitions of some useful functions.
+* ```regression-tests/tests/<test_number>/``` represents a regression test. It
+ contains everything the tests needs. You can always find at least 2 files
+ here: the ```run.sh``` script that executes the test, and ```desc``` which is
+ a text file that contains the description of the test.
+* ```regression-tests/run-test.sh``` is the script that controls the execution
+ of regression tests.
+
+Before running the regression tests, you need to prepare the environment. As
+was mentioned the ```env/``` directory already contains the ```lnst-ctl.conf```
+file. In addition to that you are also expected to create a machine pool
+directory ```regression-tests/env/pool/``` and fill it with at least two slave
+machine description files that should be used. Alternatively you can also use
+your local configuration in ```~/.lnst/```, to do this you just need to use the
+**-c** argument of the run-test.sh script.
+
+In addition to this you need to ensure that the slave machines are running and
+you have configured automatic ssh access to them. This is all the preparation
+you need to do to run the regression tests, the ```run-test.sh``` script will
+take care of synchronizing LNST to all the necessary machines, running
+lnst-slave and lnst-ctl processes and cleaning them up in the end as well.
+
+When it comes to running the tests you first need to change to the
+```regression-tests``` directory and from here you have several options
+depending on how you run the ```run-test.sh``` script.
+```sh
+Usage: ./run-test.sh [-c] [-r revision] [-l logdir] [-t list_of_tests] [-u url] [-n]
+ -r revision Test a specific git branch/rev/tag
+ Note: ignored when -s is used
+ -l logdir Save test results to a directory
+ -t list_of_tests Run only these tests
+ Example: -t 0,1,2 will run tests 0, 1, and 2
+ -n Disable use of NetworkManager on slavemachines
+ Note: enabled by default
+ -u url URL pointing to LNST repository that should be used
+ Note: git clone and checkout by default
+ -s use rsync instead of git
+ -c use user configuration
+```
9 years
[lnst] VirtUtils: fix log message
by Jiří Pírko
commit f213aa93e32f2626e5aaf6c69119692e8f4994ec
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Mar 6 12:28:45 2015 +0100
VirtUtils: fix log message
A log message was missing a space after the hardware address.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Controller/VirtUtils.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
---
diff --git a/lnst/Controller/VirtUtils.py b/lnst/Controller/VirtUtils.py
index 544de3b..25a6f39 100644
--- a/lnst/Controller/VirtUtils.py
+++ b/lnst/Controller/VirtUtils.py
@@ -94,7 +94,7 @@ class VirtDomainCtl:
net_name,
driver)
self._domain.attachDevice(device_xml)
- logging.debug("libvirt device with hwaddr '%s'"
+ logging.debug("libvirt device with hwaddr '%s' "
"driver '%s' attached" % (hw_addr, driver))
self._created_interfaces[hw_addr] = device_xml
return True
9 years
[lnst] Machine: ensure interface deconfiguration if configure was called
by Jiří Pírko
commit 3b7dd9fd66ee43b4ec51db5199d5e010a74927cd
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Fri Mar 6 12:28:44 2015 +0100
Machine: ensure interface deconfiguration if configure was called
This commit moves the "self._configured = True" assignment to the top of
the Interface configure() methods, right after the check is it's already
set. This ensures that if the configuration raised an exception the
deconfigure method will still be called. This ensures that there are no
internal data structures leftover after the failed configuration.
The regression test #26 was added to test for this bug.
This fixes #106.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Controller/Machine.py | 6 +++-
regression-tests/tests/26/desc | 7 +++++
regression-tests/tests/26/recipe1.xml | 46 +++++++++++++++++++++++++++++++++
regression-tests/tests/26/recipe2.xml | 46 +++++++++++++++++++++++++++++++++
regression-tests/tests/26/run.sh | 24 +++++++++++++++++
5 files changed, 127 insertions(+), 2 deletions(-)
---
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 409e61b..783d357 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -669,6 +669,8 @@ class Interface(object):
"It has been configured already." % (self.get_id(),
self._machine.get_id())
raise MachineError(msg)
+ else:
+ self._configured = True
logging.info("Configuring interface %s on machine %s", self.get_id(),
self._machine.get_id())
@@ -680,7 +682,6 @@ class Interface(object):
else:
self._machine._rpc_call("configure_interface", self.get_id(),
self._get_config())
- self._configured = True
def deconfigure(self):
if not self._configured:
@@ -881,6 +882,8 @@ class SoftInterface(Interface):
def configure(self):
if self._configured:
return
+ else:
+ self._configured = True
logging.info("Configuring interface %s on machine %s", self.get_id(),
self._machine.get_id())
@@ -904,7 +907,6 @@ class SoftInterface(Interface):
dev_name = self._machine._rpc_call("create_soft_interface",
self._id, self._get_config())
self.set_devname(dev_name)
- self._configured = True
def deconfigure(self):
if not self._configured:
diff --git a/regression-tests/tests/26/desc b/regression-tests/tests/26/desc
new file mode 100644
index 0000000..b4d1721
--- /dev/null
+++ b/regression-tests/tests/26/desc
@@ -0,0 +1,7 @@
+always call interface deconfiguration if configuration was called
+
+Interface deconfiguration should always be called if configuration was called,
+even if the configuration itself failed. This ensures that all internal data
+structures are cleaned up.
+
+https://github.com/jpirko/lnst/issues/106
diff --git a/regression-tests/tests/26/recipe1.xml b/regression-tests/tests/26/recipe1.xml
new file mode 100644
index 0000000..6f71463
--- /dev/null
+++ b/regression-tests/tests/26/recipe1.xml
@@ -0,0 +1,46 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet"/>
+ <eth id="phy2" label="testnet"/>
+ <bond id="nic1">
+ <options>
+ <option name="mode" value="alance-rr"/>
+ </options>
+ <slaves>
+ <slave id="phy1"/>
+ <slave id="phy2"/>
+ </slaves>
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </bond>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet"/>
+ <eth id="phy2" label="testnet"/>
+ <bond id="nic1">
+ <options>
+ <option name="mode" value="balance-rr"/>
+ </options>
+ <slaves>
+ <slave id="phy1"/>
+ <slave id="phy2"/>
+ </slaves>
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </bond>
+ </interfaces>
+ </host>
+ </network>
+
+ <task python="gre.py"/>
+</lnstrecipe>
diff --git a/regression-tests/tests/26/recipe2.xml b/regression-tests/tests/26/recipe2.xml
new file mode 100644
index 0000000..7b4cbce
--- /dev/null
+++ b/regression-tests/tests/26/recipe2.xml
@@ -0,0 +1,46 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet"/>
+ <eth id="phy2" label="testnet"/>
+ <bond id="nic1">
+ <options>
+ <option name="mode" value="balance-rr"/>
+ </options>
+ <slaves>
+ <slave id="phy1"/>
+ <slave id="phy2"/>
+ </slaves>
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </bond>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet"/>
+ <eth id="phy2" label="testnet"/>
+ <bond id="nic1">
+ <options>
+ <option name="mode" value="balance-rr"/>
+ </options>
+ <slaves>
+ <slave id="phy1"/>
+ <slave id="phy2"/>
+ </slaves>
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </bond>
+ </interfaces>
+ </host>
+ </network>
+
+ <task python="gre.py"/>
+</lnstrecipe>
diff --git a/regression-tests/tests/26/run.sh b/regression-tests/tests/26/run.sh
new file mode 100755
index 0000000..a961ba5
--- /dev/null
+++ b/regression-tests/tests/26/run.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+. ../lib.sh
+
+init_test
+
+lnst-ctl -d config_only recipe1.xml | tee test.log
+rv1=${PIPESTATUS[0]}
+log1=`cat test.log`
+
+lnst-ctl -d config_only recipe2.xml | tee test.log
+rv2=${PIPESTATUS[0]}
+log2=`cat test.log`
+
+lnst-ctl -d deconfigure
+
+print_separator
+assert_status "error" "$rv1"
+assert_log "ERROR" "CommandException: Slave testmachine1" "$log1"
+assert_status "pass" "$rv2"
+
+rm -f test.log
+
+end_test
9 years
[PATCH] regression-tests: update README.md
by Ondrej Lichtner
From: Ondrej Lichtner <olichtne(a)redhat.com>
This commit moves the wiki page describing regression tests into the
README.md file for regression tests. This makes it useful both when
viewing from github, since it's autmatically shown when you open the
regression-tests directory, and viewing locally after a git clone.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
regression-tests/README.md | 97 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/regression-tests/README.md b/regression-tests/README.md
index e2d7f70..7798333 100644
--- a/regression-tests/README.md
+++ b/regression-tests/README.md
@@ -4,6 +4,18 @@
Project. It contains a number of test cases and scenario to verify LNST
before releases and also to catch bugs and regressions.
+In case you're interested in contributing to our project you should be
+interested in this page as well since we won't be accepting contributions that
+break any of our tests.
+
+Currently there are two sets of tests that reside in our repository:
+* smoke tests, located in ```recipes/smoke/```
+* regression tests, located in ```regression-tests/```
+
+It is important to note that all of these tests were created to test LNST
+functionality for bugs. For this reason we assume that when running these
+tests, they're being run on stable systems.
+
## Required Non-default Packages on slave machines
* rsync
@@ -13,3 +25,88 @@ before releases and also to catch bugs and regressions.
* bzip2
* make
* gcc
+
+## Smoke tests
+
+Smoke tests were created to cover a wide area of basic LNST functionality, but
+avoid testing for more complex/in-depth bugs.
+
+As was mentioned before, smoke tests are located in the ```recipes/smoke/```
+directory. Here you can find a subdirectory ```lib/``` and a python script
+```generate-recipes.py```. The ```lib/``` directory contains 4 types of files:
+* ```recipe-temp.xml``` recipe template file,
+* ```conf-*.xml``` network configuration files,
+* ```task-*.xml``` task definition files,
+* ```variables.conf``` file.
+
+The generate-recipes script loads the remplate file and fills it with two
+configuration files and all the task files to create recipes for all possible
+configuration combinations. The generated recipes are placed in the
+```recipes/smoke/tests/``` directory.
+
+Finally the variables file defines values for some variables (e.g. result of a
+command), that are dependent on the combination of the configuration files.
+When a recipe file is generated these variables are replaced with their
+respective values.
+
+To run these recipes you need to have 2 machines available in the pool you've
+configured and you can use the following command:
+```
+lnst-ctl -d run recipes/smoke/tests/*
+```
+
+## Regression tests
+
+Regression tests were created as a means to test for specific bugs that we have
+already fixed. Our policy is to add a new regression test every time we fix a
+more serious bug, however this isn't always possible due to different reasons.
+If you find a bug in LNST and you want to contribute a patch that fixes it, it
+is **highly recommended** to also create a regression test.
+
+The directory structure for regression tests is as follows:
+* ```regression-tests/``` is the main directory where everything related to
+ regression tests is located.
+* ```regression-tests/env/``` contains a LNST environment that is used by the
+ regression tests. It contains a lnst-ctl configuration file and you're
+ expected to create a machine pool directory here.
+* ```regression-tests/tests/``` contains all the regression tests we currently
+ have, isolated in their own directories that are numbered. You can also find
+ the ```lib.sh``` file which contains definitions of some useful functions.
+* ```regression-tests/tests/<test_number>/``` represents a regression test. It
+ contains everything the tests needs. You can always find at least 2 files
+ here: the ```run.sh``` script that executes the test, and ```desc``` which is
+ a text file that contains the description of the test.
+* ```regression-tests/run-test.sh``` is the script that controls the execution
+ of regression tests.
+
+Before running the regression tests, you need to prepare the environment. As
+was mentioned the ```env/``` directory already contains the ```lnst-ctl.conf```
+file. In addition to that you are also expected to create a machine pool
+directory ```regression-tests/env/pool/``` and fill it with at least two slave
+machine description files that should be used. Alternatively you can also use
+your local configuration in ```~/.lnst/```, to do this you just need to use the
+**-c** argument of the run-test.sh script.
+
+In addition to this you need to ensure that the slave machines are running and
+you have configured automatic ssh access to them. This is all the preparation
+you need to do to run the regression tests, the ```run-test.sh``` script will
+take care of synchronizing LNST to all the necessary machines, running
+lnst-slave and lnst-ctl processes and cleaning them up in the end as well.
+
+When it comes to running the tests you first need to change to the
+```regression-tests``` directory and from here you have several options
+depending on how you run the ```run-test.sh``` script.
+```sh
+Usage: ./run-test.sh [-c] [-r revision] [-l logdir] [-t list_of_tests] [-u url] [-n]
+ -r revision Test a specific git branch/rev/tag
+ Note: ignored when -s is used
+ -l logdir Save test results to a directory
+ -t list_of_tests Run only these tests
+ Example: -t 0,1,2 will run tests 0, 1, and 2
+ -n Disable use of NetworkManager on slavemachines
+ Note: enabled by default
+ -u url URL pointing to LNST repository that should be used
+ Note: git clone and checkout by default
+ -s use rsync instead of git
+ -c use user configuration
+```
--
2.1.0
9 years
[PATCH 1/2] Machine: ensure interface deconfiguration if configure was called
by Ondrej Lichtner
From: Ondrej Lichtner <olichtne(a)redhat.com>
This commit moves the "self._configured = True" assignment to the top of
the Interface configure() methods, right after the check is it's already
set. This ensures that if the configuration raised an exception the
deconfigure method will still be called. This ensures that there are no
internal data structures leftover after the failed configuration.
The regression test #26 was added to test for this bug.
This fixes #106.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Machine.py | 6 +++--
regression-tests/tests/26/desc | 7 ++++++
regression-tests/tests/26/recipe1.xml | 46 +++++++++++++++++++++++++++++++++++
regression-tests/tests/26/recipe2.xml | 46 +++++++++++++++++++++++++++++++++++
regression-tests/tests/26/run.sh | 24 ++++++++++++++++++
5 files changed, 127 insertions(+), 2 deletions(-)
create mode 100644 regression-tests/tests/26/desc
create mode 100644 regression-tests/tests/26/recipe1.xml
create mode 100644 regression-tests/tests/26/recipe2.xml
create mode 100755 regression-tests/tests/26/run.sh
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 409e61b..783d357 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -669,6 +669,8 @@ class Interface(object):
"It has been configured already." % (self.get_id(),
self._machine.get_id())
raise MachineError(msg)
+ else:
+ self._configured = True
logging.info("Configuring interface %s on machine %s", self.get_id(),
self._machine.get_id())
@@ -680,7 +682,6 @@ class Interface(object):
else:
self._machine._rpc_call("configure_interface", self.get_id(),
self._get_config())
- self._configured = True
def deconfigure(self):
if not self._configured:
@@ -881,6 +882,8 @@ class SoftInterface(Interface):
def configure(self):
if self._configured:
return
+ else:
+ self._configured = True
logging.info("Configuring interface %s on machine %s", self.get_id(),
self._machine.get_id())
@@ -904,7 +907,6 @@ class SoftInterface(Interface):
dev_name = self._machine._rpc_call("create_soft_interface",
self._id, self._get_config())
self.set_devname(dev_name)
- self._configured = True
def deconfigure(self):
if not self._configured:
diff --git a/regression-tests/tests/26/desc b/regression-tests/tests/26/desc
new file mode 100644
index 0000000..b4d1721
--- /dev/null
+++ b/regression-tests/tests/26/desc
@@ -0,0 +1,7 @@
+always call interface deconfiguration if configuration was called
+
+Interface deconfiguration should always be called if configuration was called,
+even if the configuration itself failed. This ensures that all internal data
+structures are cleaned up.
+
+https://github.com/jpirko/lnst/issues/106
diff --git a/regression-tests/tests/26/recipe1.xml b/regression-tests/tests/26/recipe1.xml
new file mode 100644
index 0000000..6f71463
--- /dev/null
+++ b/regression-tests/tests/26/recipe1.xml
@@ -0,0 +1,46 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet"/>
+ <eth id="phy2" label="testnet"/>
+ <bond id="nic1">
+ <options>
+ <option name="mode" value="alance-rr"/>
+ </options>
+ <slaves>
+ <slave id="phy1"/>
+ <slave id="phy2"/>
+ </slaves>
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </bond>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet"/>
+ <eth id="phy2" label="testnet"/>
+ <bond id="nic1">
+ <options>
+ <option name="mode" value="balance-rr"/>
+ </options>
+ <slaves>
+ <slave id="phy1"/>
+ <slave id="phy2"/>
+ </slaves>
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </bond>
+ </interfaces>
+ </host>
+ </network>
+
+ <task python="gre.py"/>
+</lnstrecipe>
diff --git a/regression-tests/tests/26/recipe2.xml b/regression-tests/tests/26/recipe2.xml
new file mode 100644
index 0000000..7b4cbce
--- /dev/null
+++ b/regression-tests/tests/26/recipe2.xml
@@ -0,0 +1,46 @@
+<lnstrecipe>
+ <network>
+ <host id="testmachine1">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet"/>
+ <eth id="phy2" label="testnet"/>
+ <bond id="nic1">
+ <options>
+ <option name="mode" value="balance-rr"/>
+ </options>
+ <slaves>
+ <slave id="phy1"/>
+ <slave id="phy2"/>
+ </slaves>
+ <addresses>
+ <address>192.168.100.2/24</address>
+ <address>fe01::1/64</address>
+ </addresses>
+ </bond>
+ </interfaces>
+ </host>
+ <host id="testmachine2">
+ <params/>
+ <interfaces>
+ <eth id="phy1" label="testnet"/>
+ <eth id="phy2" label="testnet"/>
+ <bond id="nic1">
+ <options>
+ <option name="mode" value="balance-rr"/>
+ </options>
+ <slaves>
+ <slave id="phy1"/>
+ <slave id="phy2"/>
+ </slaves>
+ <addresses>
+ <address>192.168.100.3/24</address>
+ <address>fe01::2/64</address>
+ </addresses>
+ </bond>
+ </interfaces>
+ </host>
+ </network>
+
+ <task python="gre.py"/>
+</lnstrecipe>
diff --git a/regression-tests/tests/26/run.sh b/regression-tests/tests/26/run.sh
new file mode 100755
index 0000000..a961ba5
--- /dev/null
+++ b/regression-tests/tests/26/run.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+. ../lib.sh
+
+init_test
+
+lnst-ctl -d config_only recipe1.xml | tee test.log
+rv1=${PIPESTATUS[0]}
+log1=`cat test.log`
+
+lnst-ctl -d config_only recipe2.xml | tee test.log
+rv2=${PIPESTATUS[0]}
+log2=`cat test.log`
+
+lnst-ctl -d deconfigure
+
+print_separator
+assert_status "error" "$rv1"
+assert_log "ERROR" "CommandException: Slave testmachine1" "$log1"
+assert_status "pass" "$rv2"
+
+rm -f test.log
+
+end_test
--
2.1.0
9 years
[lnst] NetTestCommand: fix signal handling for bg commands
by Jiří Pírko
commit 60611c3e3264ad7efe47a54835ac1be081b328db
Author: Ondrej Lichtner <olichtne(a)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(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)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
9 years
[PATCH] NetTestCommand: fix signal handling for bg commands
by Ondrej Lichtner
From: Ondrej Lichtner <olichtne(a)redhat.com>
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(a)redhat.com>
---
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(-)
delete mode 100644 regression-tests/tests/25/lnst-ctl.conf
delete mode 100644 regression-tests/tests/25/recipe3.xml
delete mode 100644 regression-tests/tests/25/test_modules/IcmpPing.py
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/lnst-ctl.conf b/regression-tests/tests/25/lnst-ctl.conf
deleted file mode 100644
index a4d654d..0000000
--- a/regression-tests/tests/25/lnst-ctl.conf
+++ /dev/null
@@ -1,2 +0,0 @@
-[environment]
-test_module_dirs = ./test_modules
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/recipe3.xml b/regression-tests/tests/25/recipe3.xml
deleted file mode 100644
index 30452aa..0000000
--- a/regression-tests/tests/25/recipe3.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-<lnstrecipe>
- <network>
- <host id="tm1">
- <interfaces>
- <eth id="phy1" label="net1"/>
- <veth_pair>
- <veth id="in" netns="in">
- <addresses>
- <address value="192.168.0.3/24"/>
- </addresses>
- </veth>
- <veth id="out"/>
- </veth_pair>
- <bridge id="br">
- <slaves>
- <slave id="out"/>
- <slave id="phy1"/>
- </slaves>
- <addresses>
- <address value="192.168.0.1/24"/>
- </addresses>
- </bridge>
- </interfaces>
- </host>
- <host id="tm2">
- <interfaces>
- <eth id="phy1" label="net1">
- <addresses>
- <address value="192.168.0.10/24"/>
- </addresses>
- </eth>
- </interfaces>
- </host>
- </network>
- <task>
- <run module="PktCounter" host="tm1" netns="in" bg_id="ctr">
- <options>
- <option name="input_netdev_name" value="{devname(tm1,in)}"/>
- </options>
- </run>
- <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
diff --git a/regression-tests/tests/25/test_modules/IcmpPing.py b/regression-tests/tests/25/test_modules/IcmpPing.py
deleted file mode 100644
index 0469687..0000000
--- a/regression-tests/tests/25/test_modules/IcmpPing.py
+++ /dev/null
@@ -1,75 +0,0 @@
-"""
-This module defines icmp ping test
-
-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
-from lnst.Common.TestsCommon import TestGeneric
-from lnst.Common.ExecCmd import exec_cmd
-
-class IcmpPing(TestGeneric):
- def _compose_cmd(self):
- addr = self.get_mopt("addr", opt_type="addr")
- cmd = "ping %s" % addr
- count = self.get_opt("count")
- if count:
- cmd += " -c %s" % count
- interval = self.get_opt("interval")
- if interval:
- cmd += " -i %s" % interval
- iface = self.get_opt("iface")
- if iface:
- cmd += " -I %s" % iface
- size = self.get_opt("size")
- if size:
- cmd += " -s %s" % size
- return cmd
-
- def run(self):
- cmd = self._compose_cmd()
- limit_rate = self.get_opt("limit_rate", default=80)
-
- #run twice to test that we interrupt the entire bg command not just the
- #currently running exec_cmd
- data_stdout = exec_cmd(cmd, die_on_err=False)[0]
- data_stdout = exec_cmd(cmd, die_on_err=False)[0]
-
- stat_pttr1 = r'(\d+) packets transmitted, (\d+) received'
- stat_pttr2 = r'rtt min/avg/max/mdev = (\d+\.\d+)/(\d+\.\d+)/(\d+\.\d+)/(\d+\.\d+) ms'
-
- match = re.search(stat_pttr1, data_stdout)
- if not match:
- res_data = {"msg": "expected pattern not found"}
- return self.set_fail(res_data)
-
- trans_pkts, recv_pkts = match.groups()
- rate = int(round((float(recv_pkts) / float(trans_pkts)) * 100))
- logging.debug("Transmitted \"%s\", received \"%s\", "
- "rate \"%d%%\", limit_rate \"%d%%\""
- % (trans_pkts, recv_pkts, rate, limit_rate))
-
- res_data = {"rate": rate,
- "limit_rate": limit_rate}
-
- match = re.search(stat_pttr2, data_stdout)
- if match:
- tmin, tavg, tmax, tmdev = [float(x) for x in match.groups()]
- logging.debug("rtt min \"%.3f\", avg \"%.3f\", max \"%.3f\", "
- "mdev \"%.3f\"" % (tmin, tavg, tmax, tmdev))
-
- res_data["rtt_min"] = tmin
- res_data["rtt_max"] = tmax
-
- if rate < limit_rate:
- res_data["msg"] = "rate is lower than limit"
- return self.set_fail(res_data)
-
- return self.set_pass(res_data)
--
2.1.0
9 years