X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Fnetworking%2Fping.py;h=54c19229467928c026981591b62bbcfb79fd84ad;hb=545ac267f0080a456984f7975febff28ef4c61c7;hp=630b007c21de447dcd4f3135632f5d3fca43b6e1;hpb=d7fd300e9a9bd480ad9f1500494021c42ec6ecee;p=yardstick.git diff --git a/yardstick/benchmark/scenarios/networking/ping.py b/yardstick/benchmark/scenarios/networking/ping.py index 630b007c2..54c192294 100644 --- a/yardstick/benchmark/scenarios/networking/ping.py +++ b/yardstick/benchmark/scenarios/networking/ping.py @@ -32,43 +32,93 @@ class Ping(base.Scenario): TARGET_SCRIPT = 'ping_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.target_script = pkg_resources.resource_filename( 'yardstick.benchmark.scenarios.networking', Ping.TARGET_SCRIPT) - user = self.context.get('user', 'ubuntu') - host = self.context.get('host', None) - key_filename = self.context.get('key_filename', '~/.ssh/id_rsa') - - LOG.debug("user:%s, host:%s", user, host) + host = self.context_cfg['host'] + user = host.get('user', 'ubuntu') + ip = host.get('ip', None) + key_filename = host.get('key_filename', '/root/.ssh/id_rsa') + password = host.get('password', None) + + if password is not None: + LOG.info("Log in via pw, user:%s, host:%s, pw:%s", + user, ip, password) + self.connection = ssh.SSH(user, ip, password=password) + else: + LOG.info("Log in via key, user:%s, host:%s, key_filename:%s", + user, ip, key_filename) + self.connection = ssh.SSH(user, ip, key_filename=key_filename) - self.connection = ssh.SSH(user, host, key_filename=key_filename) self.connection.wait() - def run(self, args): + def run(self, result): """execute the benchmark""" - if "options" in args: - options = "-s %s" % args['options'].get("packetsize", '56') + if "options" in self.scenario_cfg: + options = "-s %s" % \ + self.scenario_cfg['options'].get("packetsize", '56') else: options = "" - destination = args.get("ipaddr", '127.0.0.1') - - LOG.debug("ping '%s' '%s'", options, destination) - - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s {0} {1}".format(destination, options), - stdin=open(self.target_script, "r")) - - if exit_status != 0: - raise RuntimeError(stderr) - - rtt = float(stdout) - - if "sla" in args: - sla_max_rtt = int(args["sla"]["max_rtt"]) - assert rtt <= sla_max_rtt, "rtt %f > sla:max_rtt(%f)" % \ - (rtt, sla_max_rtt) - - return rtt + destination = self.context_cfg['target'].get('ipaddr', '127.0.0.1') + dest_list = [s.strip() for s in destination.split(',')] + + result["rtt"] = {} + rtt_result = result["rtt"] + + for pos, dest in enumerate(dest_list): + if 'targets' in self.scenario_cfg: + target_vm = self.scenario_cfg['targets'][pos] + else: + target_vm = self.scenario_cfg['target'] + + LOG.debug("ping '%s' '%s'", options, dest) + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s {0} {1}".format(dest, options), + stdin=open(self.target_script, "r")) + + if exit_status != 0: + raise RuntimeError(stderr) + + if stdout: + target_vm_name = target_vm.split('.')[0] + rtt_result[target_vm_name] = float(stdout) + if "sla" in self.scenario_cfg: + sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"]) + assert rtt_result[target_vm_name] <= sla_max_rtt,\ + "rtt %f > sla: max_rtt(%f); " % \ + (rtt_result[target_vm_name], sla_max_rtt) + else: + LOG.error("ping '%s' '%s' timeout", options, target_vm) + + +def _test(): # pragma: no cover + '''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": { + "ipaddr": "10.229.17.105", + } + } + + logger = logging.getLogger("yardstick") + logger.setLevel(logging.DEBUG) + + args = {} + result = {} + + p = Ping(args, ctx) + p.run(result) + print result + +if __name__ == '__main__': # pragma: no cover + _test()