X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Fnetworking%2Fiperf3.py;h=a3d273750b43ac9f381406fd39cd0c0d753ea28a;hb=c894c814d62f0c839d381b7370f3d20bf02db0b0;hp=13fa0155b584c1a96165fe1db5c2d4d1bf19e26e;hpb=21b07271035916aca13761945c33362cf78f43c7;p=yardstick.git diff --git a/yardstick/benchmark/scenarios/networking/iperf3.py b/yardstick/benchmark/scenarios/networking/iperf3.py index 13fa0155b..a3d273750 100644 --- a/yardstick/benchmark/scenarios/networking/iperf3.py +++ b/yardstick/benchmark/scenarios/networking/iperf3.py @@ -10,11 +10,16 @@ # iperf3 scenario # iperf3 homepage at: http://software.es.net/iperf/ +from __future__ import absolute_import +from __future__ import print_function + import logging -import json + 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__) @@ -45,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" @@ -55,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" @@ -89,7 +94,7 @@ For more info see http://software.es.net/iperf self.host.close() status, stdout, stderr = self.target.execute("pkill iperf3") if status: - LOG.warn(stderr) + LOG.warning(stderr) self.target.close() def run(self, result): @@ -128,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) @@ -138,7 +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(json.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"] @@ -147,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); " % \ @@ -155,14 +167,14 @@ 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) def _test(): - '''internal test function''' + """internal test function""" key_filename = pkg_resources.resource_filename('yardstick.resources', 'files/yardstick_key') ctx = { @@ -188,7 +200,8 @@ def _test(): p = Iperf(args, ctx) p.run(result) - print result + print(result) + if __name__ == '__main__': _test()