[PATCH] Fixed long parameters parsing in lnst-slave
by Jiri Prochazka
--port and --pidfile didn't have '=' in getopt options.
Signed-off-by: Jiri Prochazka <jprochaz(a)redhat.com>
---
lnst-slave | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lnst-slave b/lnst-slave
index ce6c390..d4345c3 100755
--- a/lnst-slave
+++ b/lnst-slave
@@ -43,7 +43,7 @@ def main():
opts = getopt.getopt(
sys.argv[1:],
"dhei:p:m",
- ["debug", "help", "daemonize", "pidfile", "port", "no-colours"]
+ ["debug", "help", "daemonize", "pidfile=", "port=", "no-colours"]
)[0]
except getopt.GetoptError as err:
print str(err)
--
2.1.0
9 years, 1 month
[PATCH 1/6] NetTestResultSerializer: fix seconds calculation for time remaining
by Ondrej Lichtner
From: Ondrej Lichtner <olichtne(a)redhat.com>
When calculating the remaining seconds of the total test time I didn't
subtract seconds for the hours. This commit fixes that.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/NetTestResultSerializer.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lnst/Controller/NetTestResultSerializer.py b/lnst/Controller/NetTestResultSerializer.py
index 62d4e43..4ac45dc 100644
--- a/lnst/Controller/NetTestResultSerializer.py
+++ b/lnst/Controller/NetTestResultSerializer.py
@@ -129,7 +129,7 @@ class NetTestResultSerializer:
days = dif_time.days
hours = dif_time.seconds/3600
minutes = dif_time.seconds/60 - hours*60
- seconds = dif_time.seconds - minutes*60
+ seconds = dif_time.seconds - hours*60 - minutes*60
logging.info("Total test time: %d days, %d hours, %d minutes, "\
"%d seconds" % (days, hours, minutes, seconds))
--
2.1.0
9 years, 1 month
[lnst] regression-tests: extend test 25 to include the PktCounter test
by Jiří Pírko
commit 895d6c5aecab8ecc4df2685fbdfa5451c498abc5
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Thu Feb 12 17:47:01 2015 +0100
regression-tests: extend test 25 to include the PktCounter test
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
regression-tests/tests/25/recipe3.xml | 53 +++++++++++++++++++++++++++++++++
regression-tests/tests/25/run.sh | 5 +++
2 files changed, 58 insertions(+), 0 deletions(-)
---
diff --git a/regression-tests/tests/25/recipe3.xml b/regression-tests/tests/25/recipe3.xml
new file mode 100644
index 0000000..30452aa
--- /dev/null
+++ b/regression-tests/tests/25/recipe3.xml
@@ -0,0 +1,53 @@
+<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 3efc33a..34c1dc6 100755
--- a/regression-tests/tests/25/run.sh
+++ b/regression-tests/tests/25/run.sh
@@ -12,9 +12,14 @@ lnst-ctl -c lnst-ctl.conf -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, 1 month
[lnst] VirtUtils: include libvirt nic driver info into debug log
by Jiří Pírko
commit 66cdc038a5959e54b773c8325e1fb028db300d23
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Wed Feb 4 13:29:00 2015 +0100
VirtUtils: include libvirt nic driver info into debug log
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Controller/VirtUtils.py | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
---
diff --git a/lnst/Controller/VirtUtils.py b/lnst/Controller/VirtUtils.py
index dd04781..544de3b 100644
--- a/lnst/Controller/VirtUtils.py
+++ b/lnst/Controller/VirtUtils.py
@@ -94,7 +94,8 @@ class VirtDomainCtl:
net_name,
driver)
self._domain.attachDevice(device_xml)
- logging.debug("libvirt device with hwaddr '%s' attached" % hw_addr)
+ logging.debug("libvirt device with hwaddr '%s'"
+ "driver '%s' attached" % (hw_addr, driver))
self._created_interfaces[hw_addr] = device_xml
return True
except libvirtError as e:
9 years, 1 month
[PATCH] regression-tests: extend test 25 to include the PktCounter test
by Jan Tluka
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
regression-tests/tests/25/recipe3.xml | 53 +++++++++++++++++++++++++++++++++++
regression-tests/tests/25/run.sh | 5 ++++
2 files changed, 58 insertions(+)
create mode 100644 regression-tests/tests/25/recipe3.xml
diff --git a/regression-tests/tests/25/recipe3.xml b/regression-tests/tests/25/recipe3.xml
new file mode 100644
index 0000000..30452aa
--- /dev/null
+++ b/regression-tests/tests/25/recipe3.xml
@@ -0,0 +1,53 @@
+<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 3efc33a..34c1dc6 100755
--- a/regression-tests/tests/25/run.sh
+++ b/regression-tests/tests/25/run.sh
@@ -12,9 +12,14 @@ lnst-ctl -c lnst-ctl.conf -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
--
1.9.3
9 years, 1 month
[lnst] Utils: process only Name nodes in get_module_tools
by Jiří Pírko
commit 0f88d6d6d0dd9d1ce5abb7f324fdd65687ef958a
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Thu Feb 12 16:09:11 2015 +0100
Utils: process only Name nodes in get_module_tools
PktgenTx test module code made Python ast module crashing.
This was due to unhandled case while walking the code tree.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Common/Utils.py | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
---
diff --git a/lnst/Common/Utils.py b/lnst/Common/Utils.py
index d7dcda3..19ac898 100644
--- a/lnst/Common/Utils.py
+++ b/lnst/Common/Utils.py
@@ -182,6 +182,8 @@ def get_module_tools(module_path):
fn = getattr(node, 'func')
if isinstance(fn, Attribute):
val = getattr(fn, 'value')
+ if not isinstance(val, ast.Name):
+ continue
if ('self' == getattr(val, 'id')):
if ( 'exec_from' == getattr(fn, 'attr')):
tool = getattr((getattr(node, 'args')[0]), 's')
9 years, 1 month
[lnst] VirtUtils: change default libvirt nic driver to virtio
by Jiří Pírko
commit e55f3efeeb901d3bab9696e90d590a4a317d1326
Author: Jan Tluka <jtluka(a)redhat.com>
Date: Thu Feb 12 16:29:25 2015 +0100
VirtUtils: change default libvirt nic driver to virtio
Fixes issue #98
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Controller/Machine.py | 2 +-
lnst/Controller/VirtUtils.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py
index 9a5d243..409e61b 100644
--- a/lnst/Controller/Machine.py
+++ b/lnst/Controller/Machine.py
@@ -789,7 +789,7 @@ class VirtualInterface(Interface):
"""
def __init__(self, machine, if_id, if_type):
super(VirtualInterface, self).__init__(machine, if_id, if_type)
- self._driver = "rtl8139"
+ self._driver = "virtio"
def set_driver(self, driver):
self._driver = driver
diff --git a/lnst/Controller/VirtUtils.py b/lnst/Controller/VirtUtils.py
index f602c99..dd04781 100644
--- a/lnst/Controller/VirtUtils.py
+++ b/lnst/Controller/VirtUtils.py
@@ -88,7 +88,7 @@ class VirtDomainCtl:
def restart(self):
self._domain.reboot()
- def attach_interface(self, hw_addr, net_name, driver="rtl8139"):
+ def attach_interface(self, hw_addr, net_name, driver="virtio"):
try:
device_xml = self._net_device_template.format(hw_addr,
net_name,
9 years, 1 month
[PATCH] VirtUtils: change default libvirt nic driver to virtio
by Jan Tluka
Fixes issue #98
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Controller/VirtUtils.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lnst/Controller/VirtUtils.py b/lnst/Controller/VirtUtils.py
index f602c99..dd04781 100644
--- a/lnst/Controller/VirtUtils.py
+++ b/lnst/Controller/VirtUtils.py
@@ -88,7 +88,7 @@ class VirtDomainCtl:
def restart(self):
self._domain.reboot()
- def attach_interface(self, hw_addr, net_name, driver="rtl8139"):
+ def attach_interface(self, hw_addr, net_name, driver="virtio"):
try:
device_xml = self._net_device_template.format(hw_addr,
net_name,
--
1.9.3
9 years, 1 month
[PATCH] Utils: process only Name nodes in get_module_tools
by Jan Tluka
PktgenTx test module code made Python ast module crashing.
This was due to unhandled case while walking the code tree.
Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
---
lnst/Common/Utils.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lnst/Common/Utils.py b/lnst/Common/Utils.py
index d7dcda3..19ac898 100644
--- a/lnst/Common/Utils.py
+++ b/lnst/Common/Utils.py
@@ -182,6 +182,8 @@ def get_module_tools(module_path):
fn = getattr(node, 'func')
if isinstance(fn, Attribute):
val = getattr(fn, 'value')
+ if not isinstance(val, ast.Name):
+ continue
if ('self' == getattr(val, 'id')):
if ( 'exec_from' == getattr(fn, 'attr')):
tool = getattr((getattr(node, 'args')[0]), 's')
--
1.9.3
9 years, 1 month
[lnst] NetTestCommand: signal handling for bg cmds in netns
by Jiří Pírko
commit 7b7a88a54b79c812a711bc05de6e2a5956aee784
Author: Ondrej Lichtner <olichtne(a)redhat.com>
Date: Wed Feb 11 16:12:45 2015 +0100
NetTestCommand: signal handling for bg cmds in netns
Background commands in a network namespace inherited signal handlers
from the lnst-slave process that manages that namespace, this resulted
in wrong handling of the interrupt command for the bg command.
This commit fixes these issues by changing the signal handlers after the
bg cmd fork to raise a KeyboardInterrupt. It also changes the default
SIGINT handler (which was deprecated for a long time) to also raise a
KeyboardInterrupt. Because of this the wait_on_interrupt method was
modified and the read/write was removed from the TestGeneric class.
Finally the commit also adds a new regression test for this bug. The
test consists of running two recipes that differ in the type of the
background command. The first one is a 'run command' that runs an
infinite ping and the seconf one is a 'run module' that runs a modified
version of the IcmpPing module for an infinite ping. The modification is
simple - run the ping twice, this tests if we interrupt the bg cmd
process as well as the exec-ed command.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
Signed-off-by: Jiri Pirko <jiri(a)resnulli.us>
lnst/Common/NetTestCommand.py | 8 ++-
lnst/Common/TestsCommon.py | 19 ++---
regression-tests/tests/25/desc | 12 +++
regression-tests/tests/25/lnst-ctl.conf | 2 +
regression-tests/tests/25/recipe1.xml | 44 ++++++++++++
regression-tests/tests/25/recipe2.xml | 49 +++++++++++++
regression-tests/tests/25/run.sh | 21 ++++++
regression-tests/tests/25/test_modules/IcmpPing.py | 75 ++++++++++++++++++++
8 files changed, 217 insertions(+), 13 deletions(-)
---
diff --git a/lnst/Common/NetTestCommand.py b/lnst/Common/NetTestCommand.py
index 04d6e86..0f7c2a3 100644
--- a/lnst/Common/NetTestCommand.py
+++ b/lnst/Common/NetTestCommand.py
@@ -137,8 +137,14 @@ 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()
self._connection_pipe = self._write_pipe
@@ -149,7 +155,7 @@ class NetTestCommand:
result = {}
try:
self._cmd_cls.run()
- except KeyboardInterrupt:
+ except (KeyboardInterrupt, SystemExit):
pass
except:
type, value, tb = sys.exc_info()
diff --git a/lnst/Common/TestsCommon.py b/lnst/Common/TestsCommon.py
index 8086121..2504ecf 100644
--- a/lnst/Common/TestsCommon.py
+++ b/lnst/Common/TestsCommon.py
@@ -15,6 +15,7 @@ import logging
import sys
import os
import signal
+import time
from lnst.Common.NetTestCommand import NetTestCommandGeneric
class testLogger(logging.Logger):
@@ -56,13 +57,8 @@ class TestOptionMissing(Exception):
class TestGeneric(NetTestCommandGeneric):
def __init__(self, command):
self._testLogger = logging.getLogger("root.testLogger")
- self._read_pipe, self._write_pipe = os.pipe()
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
@@ -71,18 +67,17 @@ class TestGeneric(NetTestCommandGeneric):
signal.signal(signal.SIGINT, self._signal_intr_handler)
def _signal_intr_handler(self, signum, frame):
- os.write(self._write_pipe, "a")
+ raise KeyboardInterrupt()
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
+ try:
+ while True:
+ time.sleep(1)
+ except KeyboardInterrupt:
+ pass
def _get_val(self, value, opt_type, default):
if opt_type == "addr":
diff --git a/regression-tests/tests/25/desc b/regression-tests/tests/25/desc
new file mode 100644
index 0000000..fd7c6b2
--- /dev/null
+++ b/regression-tests/tests/25/desc
@@ -0,0 +1,12 @@
+proper signal handling for bg processes in net namespaces
+
+When running a background process in a new network namespace signal handlers
+were inherited from the namespace process lnst-slave which caused issues when
+calling the interrupt command on the background process.
+
+This test uses two recipes - one for run command and one for run test module.
+It also uses a custom IcmpPing test module that runs the ping twice this way we
+can test that the whole background process is interrupted, not just the
+currently running ping process.
+
+https://github.com/jpirko/lnst/issues/99
diff --git a/regression-tests/tests/25/lnst-ctl.conf b/regression-tests/tests/25/lnst-ctl.conf
new file mode 100644
index 0000000..a4d654d
--- /dev/null
+++ b/regression-tests/tests/25/lnst-ctl.conf
@@ -0,0 +1,2 @@
+[environment]
+test_module_dirs = ./test_modules
diff --git a/regression-tests/tests/25/recipe1.xml b/regression-tests/tests/25/recipe1.xml
new file mode 100644
index 0000000..8b9aee3
--- /dev/null
+++ b/regression-tests/tests/25/recipe1.xml
@@ -0,0 +1,44 @@
+<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 command="ping -c 4 {ip(tm2,phy1)}" host="tm1" netns="in"/>
+ <run command="ping {ip(tm2,phy1)}" host="tm1" netns="in" bg_id="on_bg"/>
+ <ctl_wait seconds="2"/>
+ <run command="pstree -p" host="tm1" netns="in"/>
+ <ctl_wait seconds="2"/>
+ <intr host="tm1" bg_id="on_bg"/>
+ </task>
+</lnstrecipe>
+
diff --git a/regression-tests/tests/25/recipe2.xml b/regression-tests/tests/25/recipe2.xml
new file mode 100644
index 0000000..fd8b3f6
--- /dev/null
+++ b/regression-tests/tests/25/recipe2.xml
@@ -0,0 +1,49 @@
+<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 command="ping -c 4 {ip(tm2,phy1)}" host="tm1" netns="in"/>
+ <run host="tm1" module="IcmpPing" bg_id="on_bg" netns="in">
+ <options>
+ <option name="addr" value="{ip(tm2,phy1)}"/>
+ <option name="interval" value="1"/>
+ </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"/>
+ </task>
+</lnstrecipe>
+
diff --git a/regression-tests/tests/25/run.sh b/regression-tests/tests/25/run.sh
new file mode 100755
index 0000000..3efc33a
--- /dev/null
+++ b/regression-tests/tests/25/run.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+. ../lib.sh
+
+init_test
+
+lnst-ctl -c lnst-ctl.conf -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
+rv2=${PIPESTATUS[0]}
+log2=`cat test.log`
+
+print_separator
+assert_status "pass" "$rv1"
+assert_status "pass" "$rv2"
+
+rm -f test.log
+
+end_test
diff --git a/regression-tests/tests/25/test_modules/IcmpPing.py b/regression-tests/tests/25/test_modules/IcmpPing.py
new file mode 100644
index 0000000..0469687
--- /dev/null
+++ b/regression-tests/tests/25/test_modules/IcmpPing.py
@@ -0,0 +1,75 @@
+"""
+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)
9 years, 1 month