1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 # bulk data test and req/rsp test are supported
10 from __future__ import absolute_import
11 from __future__ import print_function
16 from oslo_serialization import jsonutils
18 import yardstick.ssh as ssh
19 from yardstick.benchmark.scenarios import base
21 LOG = logging.getLogger(__name__)
24 class Netperf(base.Scenario):
25 """Execute netperf between two hosts
28 testname - to specify the test you wish to perform.
29 the valid testnames are TCP_STREAM, TCP_RR, UDP_STREAM, UDP_RR
33 send_msg_size - value set the local send size to value bytes.
37 recv_msg_size - setting the receive size for the remote system.
41 req_rsp_size - set the request and/or response sizes based on sizespec.
45 duration - duration of the test
50 read link below for more netperf args description:
51 http://www.netperf.org/netperf/training/Netperf.html
53 __scenario_type__ = "Netperf"
55 TARGET_SCRIPT = 'netperf_benchmark.bash'
57 def __init__(self, scenario_cfg, context_cfg):
58 self.scenario_cfg = scenario_cfg
59 self.context_cfg = context_cfg
60 self.setup_done = False
64 self.target_script = pkg_resources.resource_filename(
65 'yardstick.benchmark.scenarios.networking',
66 Netperf.TARGET_SCRIPT)
67 host = self.context_cfg['host']
68 host_user = host.get('user', 'ubuntu')
69 host_ssh_port = host.get('ssh_port', ssh.DEFAULT_PORT)
70 host_ip = host.get('ip', None)
71 host_key_filename = host.get('key_filename', '~/.ssh/id_rsa')
72 target = self.context_cfg['target']
73 target_user = target.get('user', 'ubuntu')
74 target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
75 target_ip = target.get('ip', None)
76 target_key_filename = target.get('key_filename', '~/.ssh/id_rsa')
78 # netserver start automatically during the vm boot
79 LOG.info("user:%s, target:%s", target_user, target_ip)
80 self.server = ssh.SSH(target_user, target_ip,
81 key_filename=target_key_filename,
83 self.server.wait(timeout=600)
85 LOG.info("user:%s, host:%s", host_user, host_ip)
86 self.client = ssh.SSH(host_user, host_ip,
87 key_filename=host_key_filename,
89 self.client.wait(timeout=600)
92 self.client._put_file_shell(self.target_script, '~/netperf.sh')
94 self.setup_done = True
96 def run(self, result):
97 """execute the benchmark"""
99 if not self.setup_done:
103 ipaddr = self.context_cfg['target'].get("ipaddr", '127.0.0.1')
104 options = self.scenario_cfg['options']
105 testname = options.get("testname", 'TCP_STREAM')
106 duration_time = self.scenario_cfg["runner"].get("duration", None) \
107 if "runner" in self.scenario_cfg else None
108 arithmetic_time = options.get("duration", None)
110 testlen = duration_time
111 elif arithmetic_time:
112 testlen = arithmetic_time
116 cmd_args = "-H %s -l %s -t %s" % (ipaddr, testlen, testname)
118 # get test specific options
119 default_args = "-O 'THROUGHPUT,THROUGHPUT_UNITS,MEAN_LATENCY'"
120 cmd_args += " -- %s" % default_args
121 option_pair_list = [("send_msg_size", "-m"),
122 ("recv_msg_size", "-M"),
123 ("req_rsp_size", "-r")]
124 for option_pair in option_pair_list:
125 if option_pair[0] in options:
126 cmd_args += " %s %s" % (option_pair[1],
127 options[option_pair[0]])
129 cmd = "sudo bash netperf.sh %s" % (cmd_args)
130 LOG.debug("Executing command: %s", cmd)
131 status, stdout, stderr = self.client.execute(cmd)
134 raise RuntimeError(stderr)
136 result.update(jsonutils.loads(stdout))
138 if result['mean_latency'] == '':
139 raise RuntimeError(stdout)
142 mean_latency = float(result['mean_latency'])
143 if "sla" in self.scenario_cfg:
144 sla_max_mean_latency = int(
145 self.scenario_cfg["sla"]["mean_latency"])
147 assert mean_latency <= sla_max_mean_latency, \
148 "mean_latency %f > sla_max_mean_latency(%f); " % \
149 (mean_latency, sla_max_mean_latency)
153 """internal test function"""
154 key_filename = pkg_resources.resource_filename("yardstick.resources",
155 "files/yardstick_key")
158 "ip": "10.229.47.137",
160 "key_filename": key_filename
163 "ip": "10.229.47.137",
165 "key_filename": key_filename,
166 "ipaddr": "10.229.47.137"
170 logger = logging.getLogger("yardstick")
171 logger.setLevel(logging.DEBUG)
174 "testname": 'TCP_STREAM'
177 args = {"options": options}
180 netperf = Netperf(args, ctx)
185 if __name__ == '__main__':