Ido Barkan has uploaded a new change for review.

Change subject: wip iperf tests
......................................................................

wip iperf tests

Change-Id: I50833cec19e4c366c8b6d0834d282e0b7de3021d
Signed-off-by: Ido Barkan <[email protected]>
---
M configure.ac
M lib/vdsm/constants.py.in
M tests/nettestlib.py
M tests/tcTests.py
4 files changed, 81 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/45528/1

diff --git a/configure.ac b/configure.ac
index ae2b722..8a233aa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -285,6 +285,7 @@
 AC_PATH_PROG([IFUP_PATH], [ifup], [/sbin/ifup])
 AC_PATH_PROG([IONICE_PATH], [ionice], [/usr/bin/ionice])
 AC_PATH_PROG([IP_PATH], [ip], [/sbin/ip])
+AC_PATH_PROG([IPERF3_PATH], [iperf3], [/usr/bin/iperf3])
 AC_PATH_PROG([ISCSIADM_PATH], [iscsiadm], [/sbin/iscsiadm])
 AC_PATH_PROG([KILL_PATH], [kill], [/bin/kill])
 AC_PATH_PROG([LVM_PATH], [lvm], [/sbin/lvm])
diff --git a/lib/vdsm/constants.py.in b/lib/vdsm/constants.py.in
index 541786b..376e9e3 100644
--- a/lib/vdsm/constants.py.in
+++ b/lib/vdsm/constants.py.in
@@ -114,6 +114,7 @@
 EXT_IFDOWN = '@IFDOWN_PATH@'
 EXT_IFUP = '@IFUP_PATH@'
 EXT_IONICE = '@IONICE_PATH@'
+EXT_IPERF3 = '@IPERF3_PATH@'
 EXT_ISCSIADM = '@ISCSIADM_PATH@'
 EXT_TC = '@TC_PATH@'
 
diff --git a/tests/nettestlib.py b/tests/nettestlib.py
index 2ffb11a..a2a7453 100644
--- a/tests/nettestlib.py
+++ b/tests/nettestlib.py
@@ -29,12 +29,14 @@
 
 from nose.plugins.skip import SkipTest
 
-from vdsm.constants import EXT_BRCTL, EXT_TC
+from vdsm.constants import EXT_BRCTL, EXT_TC, EXT_IPERF3
 from vdsm.ipwrapper import addrAdd, linkSet, linkAdd, linkDel, IPRoute2Error
 from vdsm.netlink import monitor
-from vdsm.utils import execCmd, random_iface_name
+from vdsm.utils import (execCmd, random_iface_name, pgrep, kill_and_rm_pid,
+                        CommandPath)
 
 EXT_IP = "/sbin/ip"
+_IPERF3_BINARY = CommandPath('iperf3', EXT_IPERF3)
 
 
 class ExecError(RuntimeError):
@@ -228,6 +230,38 @@
             raise SkipTest(message)
 
 
+class _Iperf(object):
+    def stop(self):
+        pids = pgrep(_IPERF3_BINARY.name)
+        for pid in pids:
+            kill_and_rm_pid(pid, pid_file=None)
+
+
+class IperfServer(_Iperf):
+    def __init__(self, host):
+        self._bind_to = host
+
+    def start(self):
+        """starts iperf as a daemon"""
+        cmd = [EXT_IPERF3, '--server', '--bind', self._bind_to, '--daemon']
+        rc, out, err = execCmd(cmd)
+        return rc
+
+
+class IperfClient(_Iperf):
+    def __init__(self, server_ip, bind_to):
+        self._server_ip = server_ip
+        self._bind_to = bind_to
+        self._out = None
+
+    def start(self):
+        cmd = [EXT_IPERF3, '--client', self._server_ip, '--version4',
+               '--bind', self._bind_to]
+        rc, out, err = execCmd(cmd)
+        self._out = out
+        return rc
+
+
 @contextmanager
 def dummy_device(prefix='dummy_', max_length=11):
     dummy_interface = Dummy(prefix, max_length)
@@ -295,3 +329,21 @@
         check_tc()
         return f(*a, **kw)
     return wrapper
+
+
+def check_iperf():
+    try:
+        execCmd([_IPERF3_BINARY.cmd, "--version"])
+    except OSError as e:
+        if e.errno == errno.ENOENT:
+            raise SkipTest("Cannot run %r: %s\nDo you have iperf3 installed?"
+                           % (_IPERF3_BINARY.cmd, e))
+        raise
+
+
+def requires_iperf3(f):
+    @functools.wraps(f)
+    def wrapper(*a, **kw):
+        check_iperf()
+        return f(*a, **kw)
+    return wrapper
diff --git a/tests/tcTests.py b/tests/tcTests.py
index 4ce6cd4..2dcf9eb 100644
--- a/tests/tcTests.py
+++ b/tests/tcTests.py
@@ -32,11 +32,15 @@
 from testlib import (VdsmTestCase as TestCaseBase, permutations,
                      expandPermutations)
 from testValidation import ValidateRunningAsRoot
-from nettestlib import Bridge, Dummy, Tap, vlan_device, requires_tc
+from nettestlib import (Bridge, Dummy, Tap, vlan_device, requires_tc, 
veth_pair,
+                        IperfServer, IperfClient, requires_iperf3,
+                        bridge_device)
 
 from vdsm.constants import EXT_TC
 from network import tc
 from network.configurators import qos
+from vdsm.ipwrapper import addrAdd, linkSet
+from vdsm.utils import running
 
 
 class TestQdisc(TestCaseBase):
@@ -441,6 +445,26 @@
                 self.assertEqual(current_tagged_filters_flow_id,
                                  expected_flow_ids)
 
+    @requires_iperf3
+    def test_iperf_upper_limit(self):
+        limit = 1000  # 1 MBps (in kBps)
+        server_ip = '192.0.2.1'
+        client_ip = '192.0.2.10'
+        qos_out = {'ul': {'m2': limit}, 'ls': {'m2': limit}}
+        with bridge_device() as bridge:
+            with veth_pair() as (server_dev, server_peer):
+                with veth_pair() as (client_dev, client_peer):
+                    bridge.addIf(server_peer)
+                    bridge.addIf(client_peer)
+                    linkSet(server_dev, ['up'])
+                    linkSet(client_dev, ['up'])
+                    addrAdd(server_dev, server_ip, 24)
+                    addrAdd(client_dev, client_ip, 24)
+                    qos.configure_outbound(qos_out, client_dev, None)
+                    with running(IperfServer(server_ip)):
+                        with running(IperfClient(server_ip, client_ip)) as 
client:
+                            print client._out
+
     def _analise_qos_and_general_assertions(self):
         tc_classes = self._analise_classes()
         tc_qdiscs = self._analise_qdiscs()


-- 
To view, visit https://gerrit.ovirt.org/45528
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I50833cec19e4c366c8b6d0834d282e0b7de3021d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ido Barkan <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to