From: Ondrej Lichtner <olichtne(a)redhat.com>
The following is a patch series fixing bugs in the test_modules that I've
encountered while I was creating the wiki documentation for them.
Ondrej Lichtner (5):
TestPacketAssert: minor bug fixes
TestPktCounter: fix error when dport option is None
TestTCPConnect: option parsing bug fixes
TestTCPListen: option parsing bug fixes
TestIperf: bind option not specified bug
test_modules/TestIperf.py | 5 ++++-
test_modules/TestPacketAssert.py | 35 +++++++++++++++++++++++++++++------
test_modules/TestPktCounter.py | 5 ++++-
test_modules/TestTCPConnect.py | 10 ++++++----
test_modules/TestTCPListen.py | 4 ++--
5 files changed, 45 insertions(+), 14 deletions(-)
--
1.7.11.7
Show replies by thread
From: Ondrej Lichtner <olichtne(a)redhat.com>
When the TestPacketAssert module was interrupted it didn't read the
remaining tcpdump output. Because of that the recieved packets count
would be less than what was really recieved.
This patch fixes that by making the variable line an attribute of the
class and adding the code for output handling to the interrupt handler.
There is also a minor change here, the "filter" option of the command is
no longer mandatory as it is not needed for correct execution of the
tcpdump command.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
test_modules/TestPacketAssert.py | 35 +++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)
diff --git a/test_modules/TestPacketAssert.py b/test_modules/TestPacketAssert.py
index 1524800..32884a4 100644
--- a/test_modules/TestPacketAssert.py
+++ b/test_modules/TestPacketAssert.py
@@ -40,6 +40,26 @@ class TestPacketAssert(TestGeneric):
""" Kill tcpdump when interrupted """
self._tcpdump.terminate()
+ tcpdump_output = self._tcpdump.stdout
+ while True:
+ try:
+ next_line = tcpdump_output.readline()
+ except IOError: # Interrupted system call
+ break
+
+ if next_line == "":
+ break
+
+ next_line = next_line.strip("\n")
+
+ if re.match("[0-9]+\:[0-9]+\:[0-9\.]+", next_line) and\
+ self.line != "":
+ self._process_captured_line(self.line)
+ self.line = next_line
+ else:
+ self.line += next_line
+
+
def _prepare_grep_filters(self):
""" Parse `grep_for' test options """
filters = self.get_multi_opt("grep_for")
@@ -64,7 +84,9 @@ class TestPacketAssert(TestGeneric):
cmd = ""
interface = self.get_mopt("interface")
- pcap_filter = self.get_mopt("filter")
+ pcap_filter = self.get_opt("filter")
+ if not pcap_filter:
+ pcap_filter = ""
cmd = "tcpdump -p -nn -i %s \"%s\"" % (interface,
pcap_filter)
self._cmd = cmd
@@ -104,7 +126,7 @@ class TestPacketAssert(TestGeneric):
logging.info("Capturing started")
- line = ""
+ self.line = ""
tcpdump_output = self._tcpdump.stdout
while True:
if self._tcpdump.poll() != None:
@@ -123,11 +145,12 @@ class TestPacketAssert(TestGeneric):
next_line = next_line.strip("\n")
- if re.match("[0-9]+\:[0-9]+\:[0-9\.]+", next_line) and line !=
"":
- self._process_captured_line(line)
- line = next_line
+ if re.match("[0-9]+\:[0-9]+\:[0-9\.]+", next_line) and\
+ self.line != "":
+ self._process_captured_line(self.line)
+ self.line = next_line
else:
- line += next_line
+ self.line += next_line
logging.info("Capturing finished. Received %d packets",
self._num_recv)
res = {"received": self._num_recv,
--
1.7.11.7
From: Ondrej Lichtner <olichtne(a)redhat.com>
The dport option is not mandatory, but when not specified the
constructed iptables command would contain the string "None" where the
dport value would be. This commnit fixes that.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
test_modules/TestPktCounter.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/test_modules/TestPktCounter.py b/test_modules/TestPktCounter.py
index 727d472..7eec92c 100644
--- a/test_modules/TestPktCounter.py
+++ b/test_modules/TestPktCounter.py
@@ -23,7 +23,10 @@ def get_pkt_count(indev_name, dport, proto):
p_indev_name = "\*"
if proto:
p_proto = proto
- p_protodport = "%s dpt:%s" % (proto, dport)
+ if dport:
+ p_protodport = "%s dpt:%s" % (proto, dport)
+ else:
+ p_protodport = ""
else:
p_proto = "all"
p_protodport = ""
--
1.7.11.7
From: Ondrej Lichtner <olichtne(a)redhat.com>
This commit fixes two bugs during option parsing:
* option "sleep" is not mandatory but when not specified the module
* crashes
* option "port" needs to be an integer value, and the function extend
* was used on the port list, splitting the port string into individual
* characters
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
test_modules/TestTCPConnect.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/test_modules/TestTCPConnect.py b/test_modules/TestTCPConnect.py
index 4a5dc5c..4da2600 100644
--- a/test_modules/TestTCPConnect.py
+++ b/test_modules/TestTCPConnect.py
@@ -123,7 +123,7 @@ class TestTCPConnect(TestGeneric):
# either port or port_range should be set
port = self.get_opt("port")
if port:
- self._port = port
+ self._port = int(port)
else:
port_range = self.get_opt("port_range")
if port_range:
@@ -132,9 +132,11 @@ class TestTCPConnect(TestGeneric):
e = TestOptionMissing()
raise e
- sleep_time = float(self.get_opt("sleep"))
+ sleep_time = self.get_opt("sleep")
if sleep_time:
- self._sleep_time = sleep_time
+ self._sleep_time = float(sleep_time)
+ else:
+ self._sleep_time = 0
cont = self.get_opt("cont")
if cont:
@@ -177,7 +179,7 @@ class TestTCPConnect(TestGeneric):
ports = []
if self._port:
- ports.extend(self._port)
+ ports.append(self._port)
else:
r = self.parse_port_range()
ports.extend(r)
--
1.7.11.7
From: Ondrej Lichtner <olichtne(a)redhat.com>
This commit fixes the same bug with the "port" option as in the
TestTCPConnect.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
test_modules/TestTCPListen.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/test_modules/TestTCPListen.py b/test_modules/TestTCPListen.py
index 3aa4d47..eb1697b 100644
--- a/test_modules/TestTCPListen.py
+++ b/test_modules/TestTCPListen.py
@@ -48,7 +48,7 @@ class TestTCPListen(TestGeneric):
# either port or port_range should be set
port = self.get_opt("port")
if port:
- self._port = port
+ self._port = int(port)
else:
port_range = self.get_opt("port_range")
if port_range:
@@ -169,7 +169,7 @@ class TestTCPListen(TestGeneric):
ports = []
if self._port:
- ports.extend(self._port)
+ ports.append(self._port)
else:
r = self._parse_port_range()
ports.extend(r)
--
1.7.11.7
From: Ondrej Lichtner <olichtne(a)redhat.com>
When the module is run in the 'server' role and the option 'bind' is not
specified, the constructed command contains 'None' instead, creating an
invalid command.
This commit fixes that.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
test_modules/TestIperf.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/test_modules/TestIperf.py b/test_modules/TestIperf.py
index 0a9b047..462c48c 100644
--- a/test_modules/TestIperf.py
+++ b/test_modules/TestIperf.py
@@ -26,7 +26,10 @@ class TestIperf(TestGeneric):
cmd = "iperf --%s %s -t %s %s" % (role, iperf_server,
self.duration, iperf_options)
elif role == "server":
bind = self.get_opt("bind", opt_type="addr")
- cmd = "iperf --%s -B %s %s" % (role, bind, iperf_options)
+ if bind != None:
+ cmd = "iperf --%s -B %s %s" % (role, bind, iperf_options)
+ else:
+ cmd = "iperf --%s %s" % (role, iperf_options)
return cmd
--
1.7.11.7