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 ##############################################################################
13 import yardstick.ssh as ssh
14 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
19 class Ping6(base.Scenario): # pragma: no cover
20 """Execute ping6 between two hosts
22 read link below for more ipv6 info description:
23 http://wiki.opnfv.org/ipv6_opnfv_project
25 __scenario_type__ = "Ping6"
27 TARGET_SCRIPT = 'ping6_benchmark.bash'
28 SETUP_SCRIPT = 'ping6_setup.bash'
29 TEARDOWN_SCRIPT = 'ping6_teardown.bash'
30 METADATA_SCRIPT = 'ping6_metadata.txt'
32 def __init__(self, scenario_cfg, context_cfg):
33 self.scenario_cfg = scenario_cfg
34 self.context_cfg = context_cfg
35 self.setup_done = False
40 host = self.context_cfg['host']
41 host_user = host.get('user', 'ubuntu')
42 host_ip = host.get('ip', None)
43 host_pwd = host.get('password', 'root')
44 LOG.info("user:%s, host:%s", host_user, host_ip)
45 self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
46 self.client.wait(timeout=600)
50 self.setup_script = pkg_resources.resource_filename(
51 'yardstick.benchmark.scenarios.networking',
54 self.ping6_metadata_script = pkg_resources.resource_filename(
55 'yardstick.benchmark.scenarios.networking',
56 Ping6.METADATA_SCRIPT)
59 # run script to setup ipv6
60 self.client.run("cat > ~/setup.sh",
61 stdin=open(self.setup_script, "rb"))
62 self.client.run("cat > ~/metadata.txt",
63 stdin=open(self.ping6_metadata_script, "rb"))
64 cmd = "sudo bash setup.sh"
65 status, stdout, stderr = self.client.execute(cmd)
67 self.setup_done = True
69 def run(self, result):
70 """execute the benchmark"""
72 self.ping6_script = pkg_resources.resource_filename(
73 'yardstick.benchmark.scenarios.networking',
76 if not self.setup_done:
79 self.client.run("cat > ~/ping6.sh",
80 stdin=open(self.ping6_script, "rb"))
81 cmd = "sudo bash ping6.sh"
82 LOG.debug("Executing command: %s", cmd)
83 status, stdout, stderr = self.client.execute(cmd)
86 raise RuntimeError(stderr)
89 result["rtt"] = float(stdout)
91 if "sla" in self.scenario_cfg:
92 sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"])
93 assert result["rtt"] <= sla_max_rtt, "rtt %f > sla:max_rtt(%f); " % \
94 (result["rtt"], sla_max_rtt)
96 LOG.error("ping6 timeout")
100 """teardown the benchmark"""
102 if not self.run_done:
105 self.teardown_script = pkg_resources.resource_filename(
106 'yardstick.benchmark.scenarios.networking',
107 Ping6.TEARDOWN_SCRIPT)
108 self.client.run("cat > ~/teardown.sh",
109 stdin=open(self.teardown_script, "rb"))
110 cmd = "sudo bash teardown.sh"
111 status, stdout, stderr = self.client.execute(cmd)
114 raise RuntimeError(stderr)
119 LOG.error("ping6 teardown failed")