X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Fnetworking%2Fnetperf.py;h=08d5dd166323abeb0ca793ae061eafbeb353db35;hb=80c1d81ead5a5416e7e40f49ffc80a525e5737e0;hp=3121fdaf294cc3df1a16f32a60279a49d6538de4;hpb=15e8300a8e85d5907c5ea90da505929b8ca85ca0;p=yardstick.git diff --git a/yardstick/benchmark/scenarios/networking/netperf.py b/yardstick/benchmark/scenarios/networking/netperf.py index 3121fdaf2..08d5dd166 100755 --- a/yardstick/benchmark/scenarios/networking/netperf.py +++ b/yardstick/benchmark/scenarios/networking/netperf.py @@ -7,9 +7,13 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## # bulk data test and req/rsp test are supported -import pkg_resources +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.benchmark.scenarios import base @@ -50,46 +54,45 @@ class Netperf(base.Scenario): TARGET_SCRIPT = 'netperf_benchmark.bash' - def __init__(self, context): - self.context = context + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg self.setup_done = False def setup(self): - '''scenario setup''' + """scenario setup""" self.target_script = pkg_resources.resource_filename( 'yardstick.benchmark.scenarios.networking', Netperf.TARGET_SCRIPT) - user = self.context.get('user', 'ubuntu') - host = self.context.get('host', None) - target = self.context.get('target', None) - key_filename = self.context.get('key_filename', '~/.ssh/id_rsa') + host = self.context_cfg['host'] + target = self.context_cfg['target'] # netserver start automatically during the vm boot - LOG.info("user:%s, target:%s", user, target) - self.server = ssh.SSH(user, target, key_filename=key_filename) + LOG.info("user:%s, target:%s", target['user'], target['ip']) + self.server = ssh.SSH.from_node(target, defaults={"user": "ubuntu"}) self.server.wait(timeout=600) - LOG.info("user:%s, host:%s", user, host) - self.client = ssh.SSH(user, host, key_filename=key_filename) + LOG.info("user:%s, host:%s", host['user'], host['ip']) + self.client = ssh.SSH.from_node(host, defaults={"user": "ubuntu"}) self.client.wait(timeout=600) # copy script to host - self.client.run("cat > ~/netperf.sh", - stdin=open(self.target_script, "rb")) + self.client._put_file_shell(self.target_script, '~/netperf.sh') self.setup_done = True - def run(self, args): + def run(self, result): """execute the benchmark""" if not self.setup_done: self.setup() # get global options - ipaddr = args.get("ipaddr", '127.0.0.1') - options = args['options'] + ipaddr = self.context_cfg['target'].get("ipaddr", '127.0.0.1') + options = self.scenario_cfg['options'] testname = options.get("testname", 'TCP_STREAM') - duration_time = self.context.get("duration", None) + duration_time = self.scenario_cfg["runner"].get("duration", None) \ + if "runner" in self.scenario_cfg else None arithmetic_time = options.get("duration", None) if duration_time: testlen = duration_time @@ -118,46 +121,54 @@ class Netperf(base.Scenario): if status: raise RuntimeError(stderr) - data = json.loads(stdout) - if data['mean_latency'] == '': + result.update(jsonutils.loads(stdout)) + + if result['mean_latency'] == '': raise RuntimeError(stdout) # sla check - mean_latency = float(data['mean_latency']) - if "sla" in args: - sla_max_mean_latency = int(args["sla"]["mean_latency"]) + mean_latency = float(result['mean_latency']) + if "sla" in self.scenario_cfg: + sla_max_mean_latency = int( + self.scenario_cfg["sla"]["mean_latency"]) assert mean_latency <= sla_max_mean_latency, \ - "mean_latency %f > sla_max_mean_latency(%f)" % \ + "mean_latency %f > sla_max_mean_latency(%f); " % \ (mean_latency, sla_max_mean_latency) - return data - def _test(): - '''internal test function''' - logger = logging.getLogger('yardstick') + """internal test function""" + key_filename = pkg_resources.resource_filename("yardstick.resources", + "files/yardstick_key") + ctx = { + "host": { + "ip": "10.229.47.137", + "user": "root", + "key_filename": key_filename + }, + "target": { + "ip": "10.229.47.137", + "user": "root", + "key_filename": key_filename, + "ipaddr": "10.229.47.137" + } + } + + logger = logging.getLogger("yardstick") logger.setLevel(logging.DEBUG) - key_filename = pkg_resources.resource_filename('yardstick.resources', - 'files/yardstick_key') - runner_cfg = {} - runner_cfg['type'] = 'Duration' - runner_cfg['duration'] = 5 - runner_cfg['clinet'] = '10.0.2.33' - runner_cfg['server'] = '10.0.2.53' - runner_cfg['user'] = 'ubuntu' - runner_cfg['output_filename'] = "/tmp/yardstick.out" - runner_cfg['key_filename'] = key_filename - - scenario_args = {} - scenario_args['options'] = {"testname": 'TCP_STREAM'} - - from yardstick.benchmark.runners import base as base_runner - runner = base_runner.Runner.get(runner_cfg) - runner.run("Netperf", scenario_args) - runner.join() - base_runner.Runner.release(runner) + options = { + "testname": 'TCP_STREAM' + } + + args = {"options": options} + result = {} + + netperf = Netperf(args, ctx) + netperf.run(result) + print(result) + if __name__ == '__main__': _test()