Use "protocol" parameters in iperf3 yaml and task file 53/44853/1
authorAce Lee <liyin11@huawei.com>
Fri, 15 Sep 2017 06:14:19 +0000 (06:14 +0000)
committerJing Lu <lvjing5@huawei.com>
Thu, 12 Oct 2017 01:38:29 +0000 (01:38 +0000)
JIRA: YARDSTICK-755

There is a history problem that iperf use udp to set a net protocol.
This code will change it to protocol.
so you could use 'tcp','udp' and other protocol.

Change-Id: I1a101013dfe58165a3ed08aa77f0aa2f73d57a12
Signed-off-by: Ace Lee <liyin11@huawei.com>
(cherry picked from commit 10f85b332c4b1f55e651aeb9c45b328e1ebdc2af)

tests/opnfv/test_cases/opnfv_yardstick_tc011.yaml
tests/unit/benchmark/scenarios/networking/test_iperf3.py
yardstick/benchmark/scenarios/networking/iperf3.py

index b2077d5..ee36c6c 100644 (file)
@@ -13,7 +13,7 @@ description: >
     Yardstick TC011 config file;
     Measure packet delay variation (jitter) using iperf3.
 
-{% set udp = udp or "udp" %}
+{% set protocol = protocol or "udp" %}
 {% set bandwidth = bandwidth or "20m" %}
 {% set length = length or "8K" %}
 {% set window = window or 29200 %}
@@ -25,7 +25,7 @@ scenarios:
 -
   type: Iperf3
   options:
-    udp: {{udp}}
+    protocol: {{protocol}}
     bandwidth: {{bandwidth}}
     length: {{length}}
     window: {{window}}
index 3312453..4d37452 100644 (file)
@@ -123,7 +123,7 @@ class IperfTestCase(unittest.TestCase):
         self.assertRaises(AssertionError, p.run, result)
 
     def test_iperf_successful_sla_jitter(self, mock_ssh):
-        options = {"udp": "udp", "bandwidth": "20m"}
+        options = {"protocol": "udp", "bandwidth": "20m"}
         args = {
             'options': options,
             'sla': {'jitter': 10}
@@ -141,7 +141,7 @@ class IperfTestCase(unittest.TestCase):
         self.assertEqual(result, expected_result)
 
     def test_iperf_unsuccessful_sla_jitter(self, mock_ssh):
-        options = {"udp": "udp", "bandwidth": "20m"}
+        options = {"protocol": "udp", "bandwidth": "20m"}
         args = {
             'options': options,
             'sla': {'jitter': 0.0001}
@@ -156,6 +156,24 @@ class IperfTestCase(unittest.TestCase):
         mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
         self.assertRaises(AssertionError, p.run, result)
 
+    def test_iperf_successful_tcp_protocal(self, mock_ssh):
+        options = {"protocol": "tcp", "nodelay": "yes"}
+        args = {
+            'options': options,
+            'sla': {'bytes_per_second': 15000000}
+        }
+        result = {}
+
+        p = iperf3.Iperf(args, self.ctx)
+        mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
+        p.host = mock_ssh.SSH.from_node()
+
+        sample_output = self._read_sample_output(self.output_name_tcp)
+        mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
+        expected_result = utils.flatten_dict_key(jsonutils.loads(sample_output))
+        p.run(result)
+        self.assertEqual(result, expected_result)
+
     def test_iperf_unsuccessful_script_error(self, mock_ssh):
 
         options = {}
index a3d2737..98c4599 100644 (file)
@@ -111,18 +111,22 @@ For more info see http://software.es.net/iperf
 
         # If there are no options specified
         if not options:
-            options = ""
+            options = {}
 
         use_UDP = False
-        if "udp" in options:
-            cmd += " --udp"
-            use_UDP = True
-            if "bandwidth" in options:
-                cmd += " --bandwidth %s" % options["bandwidth"]
-        else:
-            # tcp obviously
+        try:
+            protocol = options.get("protocol")
+            bandwidth = options.get('bandwidth')
+            use_UDP = protocol == 'udp'
+            if protocol:
+                cmd += " --" + protocol
+            if use_UDP and bandwidth:
+                cmd += " --bandwidth " + bandwidth
+            # if nodelay in the option, protocal maybe null or 'tcp'
             if "nodelay" in options:
                 cmd += " --nodelay"
+        except AttributeError:
+            LOG.warning("Can't parser the options in your config file!!!")
 
         # these options are mutually exclusive in iperf3
         if time: