Merge "DRAFT: update yardstick generic test cases dashboard"
[yardstick.git] / yardstick / benchmark / scenarios / networking / iperf3.py
index 4d4c7e7..a3d2737 100644 (file)
@@ -19,6 +19,7 @@ import pkg_resources
 from oslo_serialization import jsonutils
 
 import yardstick.ssh as ssh
+from yardstick.common import utils
 from yardstick.benchmark.scenarios import base
 
 LOG = logging.getLogger(__name__)
@@ -49,6 +50,17 @@ For more info see http://software.es.net/iperf
         type:    int
         unit:    bytes
         default: -
+    length - length of buffer to read or write,
+      (default 128 KB for TCP, 8 KB for UDP)
+        type:    int
+        unit:    k
+        default: -
+    window - set window size / socket buffer size
+      set TCP windows size. for UDP way to test, this will set to accept UDP
+      packet buffer size, limit the max size of acceptable data packet.
+        type:    int
+        unit:    k
+        default: -
     """
     __scenario_type__ = "Iperf3"
 
@@ -59,25 +71,14 @@ For more info see http://software.es.net/iperf
 
     def setup(self):
         host = self.context_cfg['host']
-        host_user = host.get('user', 'ubuntu')
-        host_ssh_port = host.get('ssh_port', ssh.DEFAULT_PORT)
-        host_ip = host.get('ip', None)
-        host_key_filename = host.get('key_filename', '~/.ssh/id_rsa')
         target = self.context_cfg['target']
-        target_user = target.get('user', 'ubuntu')
-        target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
-        target_ip = target.get('ip', None)
-        target_key_filename = target.get('key_filename', '~/.ssh/id_rsa')
-
-        LOG.info("user:%s, target:%s", target_user, target_ip)
-        self.target = ssh.SSH(target_user, target_ip,
-                              key_filename=target_key_filename,
-                              port=target_ssh_port)
+
+        LOG.info("user:%s, target:%s", target['user'], target['ip'])
+        self.target = ssh.SSH.from_node(target, defaults={"user": "ubuntu"})
         self.target.wait(timeout=600)
 
-        LOG.info("user:%s, host:%s", host_user, host_ip)
-        self.host = ssh.SSH(host_user, host_ip,
-                            key_filename=host_key_filename, port=host_ssh_port)
+        LOG.info("user:%s, host:%s", host['user'], host['ip'])
+        self.host = ssh.SSH.from_node(host, defaults={"user": "ubuntu"})
         self.host.wait(timeout=600)
 
         cmd = "iperf3 -s -D"
@@ -132,6 +133,12 @@ For more info see http://software.es.net/iperf
         elif "blockcount" in options:
             cmd += " --blockcount %d" % options["blockcount"]
 
+        if "length" in options:
+            cmd += " --length %s" % options["length"]
+
+        if "window" in options:
+            cmd += " --window %s" % options["window"]
+
         LOG.debug("Executing command: %s", cmd)
 
         status, stdout, stderr = self.host.execute(cmd)
@@ -142,8 +149,8 @@ For more info see http://software.es.net/iperf
         # Note: convert all ints to floats in order to avoid
         # schema conflicts in influxdb. We probably should add
         # a format func in the future.
-        result.update(
-            jsonutils.loads(stdout, parse_int=float))
+        iperf_result = jsonutils.loads(stdout, parse_int=float)
+        result.update(utils.flatten_dict_key(iperf_result))
 
         if "sla" in self.scenario_cfg:
             sla_iperf = self.scenario_cfg["sla"]
@@ -152,7 +159,7 @@ For more info see http://software.es.net/iperf
 
                 # convert bits per second to bytes per second
                 bit_per_second = \
-                    int(result["end"]["sum_received"]["bits_per_second"])
+                    int(iperf_result["end"]["sum_received"]["bits_per_second"])
                 bytes_per_second = bit_per_second / 8
                 assert bytes_per_second >= sla_bytes_per_second, \
                     "bytes_per_second %d < sla:bytes_per_second (%d); " % \
@@ -160,7 +167,7 @@ For more info see http://software.es.net/iperf
             else:
                 sla_jitter = float(sla_iperf["jitter"])
 
-                jitter_ms = float(result["end"]["sum"]["jitter_ms"])
+                jitter_ms = float(iperf_result["end"]["sum"]["jitter_ms"])
                 assert jitter_ms <= sla_jitter, \
                     "jitter_ms  %f > sla:jitter %f; " % \
                     (jitter_ms, sla_jitter)