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 PRE_SETUP_SCRIPT = 'ping6_pre_setup.bash'
29 SETUP_SCRIPT = 'ping6_setup.bash'
30 SETUP_ODL_SCRIPT = 'ping6_setup_with_odl.bash'
31 FIND_HOST_SCRIPT = 'ping6_find_host.bash'
32 TEARDOWN_SCRIPT = 'ping6_teardown.bash'
33 METADATA_SCRIPT = 'ping6_metadata.txt'
34 RADVD_SCRIPT = 'ping6_radvd.conf'
35 POST_TEARDOWN_SCRIPT = 'ping6_post_teardown.bash'
37 def __init__(self, scenario_cfg, context_cfg):
38 self.scenario_cfg = scenario_cfg
39 self.context_cfg = context_cfg
40 self.setup_done = False
42 self.ping_options = ''
45 for node_name in self.host_list:
46 self._ssh_host(node_name)
47 self.client.run("cat > ~/pre_setup.sh",
48 stdin=open(self.pre_setup_script, "rb"))
49 status, stdout, stderr = self.client.execute(
50 "sudo bash pre_setup.sh")
52 def _ssh_host(self, node_name):
55 nodes = self.context_cfg['nodes']
56 node = nodes.get(node_name, None)
57 host_user = node.get('user', 'ubuntu')
58 host_ip = node.get('ip', None)
59 host_pwd = node.get('password', 'root')
60 LOG.debug("user:%s, host:%s", host_user, host_ip)
61 self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
62 self.client.wait(timeout=600)
66 self.setup_script = pkg_resources.resource_filename(
67 'yardstick.benchmark.scenarios.networking',
70 self.setup_odl_script = pkg_resources.resource_filename(
71 'yardstick.benchmark.scenarios.networking',
72 Ping6.SETUP_ODL_SCRIPT)
74 self.pre_setup_script = pkg_resources.resource_filename(
75 'yardstick.benchmark.scenarios.networking',
76 Ping6.PRE_SETUP_SCRIPT)
78 self.ping6_metadata_script = pkg_resources.resource_filename(
79 'yardstick.benchmark.scenarios.networking',
80 Ping6.METADATA_SCRIPT)
82 self.ping6_radvd_script = pkg_resources.resource_filename(
83 'yardstick.benchmark.scenarios.networking',
86 options = self.scenario_cfg['options']
87 self.ping_options = "-s %s" % \
88 options.get("packetsize", '56') + \
90 options.get("ping_count", '5')
91 host_str = options.get("host", 'host1')
92 self.host_list = host_str.split(',')
94 pre_setup = options.get("pre_setup", True)
99 self._ssh_host(self.host_list[0])
101 self.client.run("cat > ~/metadata.txt",
102 stdin=open(self.ping6_metadata_script, "rb"))
104 # run script to setup ipv6 with nosdn or odl
105 sdn = options.get("sdn", 'nosdn')
107 self.client.run("cat > ~/br-ex.radvd.conf",
108 stdin=open(self.ping6_radvd_script, "rb"))
109 self.client.run("cat > ~/setup_odl.sh",
110 stdin=open(self.setup_odl_script, "rb"))
111 cmd = "sudo bash setup_odl.sh"
113 self.client.run("cat > ~/setup.sh",
114 stdin=open(self.setup_script, "rb"))
115 cmd = "sudo bash setup.sh"
117 status, stdout, stderr = self.client.execute(cmd)
119 self.setup_done = True
121 def run(self, result):
122 """execute the benchmark"""
124 self.ping6_script = pkg_resources.resource_filename(
125 'yardstick.benchmark.scenarios.networking',
128 self.ping6_find_host_script = pkg_resources.resource_filename(
129 'yardstick.benchmark.scenarios.networking',
130 Ping6.FIND_HOST_SCRIPT)
132 if not self.setup_done:
133 options = self.scenario_cfg['options']
134 self.ping_options = "-s %s" % \
135 options.get("packetsize", '56') + \
137 options.get("ping_count", '5')
138 host_str = options.get("host", 'host1')
139 self.host_list = host_str.split(',')
140 self.host_list.sort()
141 self._ssh_host(self.host_list[0])
143 # find ipv4-int-network1 to ssh VM
144 self.client.run("cat > ~/find_host.sh",
145 stdin=open(self.ping6_find_host_script, "rb"))
146 cmd = "sudo bash find_host.sh"
147 LOG.debug("Executing command: %s", cmd)
148 status, stdout, stderr = self.client.execute(cmd)
149 host_name = stdout.strip()
151 # copy vRouterKey to target host
152 self.client.run("cat ~/vRouterKey",
153 stdout=open("/tmp/vRouterKey", "w"))
154 self._ssh_host(host_name)
155 self.client.run("cat > ~/vRouterKey",
156 stdin=open("/tmp/vRouterKey", "rb"))
158 # run ping6 benchmark
159 self.client.run("cat > ~/ping6.sh",
160 stdin=open(self.ping6_script, "rb"))
161 cmd_args = "%s" % (self.ping_options)
162 cmd = "sudo bash ping6.sh %s" % (cmd_args)
163 LOG.debug("Executing command: %s", cmd)
164 status, stdout, stderr = self.client.execute(cmd)
167 raise RuntimeError(stderr)
171 result["rtt"] = float(stdout)
172 if "sla" in self.scenario_cfg:
173 sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"])
174 assert result["rtt"] <= sla_max_rtt, \
175 "rtt %f > sla:max_rtt(%f); " % (result["rtt"], sla_max_rtt)
177 LOG.error("ping6 timeout")
181 """teardown the benchmark"""
183 self.post_teardown_script = pkg_resources.resource_filename(
184 'yardstick.benchmark.scenarios.networking',
185 Ping6.POST_TEARDOWN_SCRIPT)
187 options = self.scenario_cfg['options']
188 host_str = options.get("host", 'node1')
189 self.host_list = host_str.split(',')
190 self.host_list.sort()
192 if not self.run_done:
193 self._ssh_host(self.host_list[0])
195 self.teardown_script = pkg_resources.resource_filename(
196 'yardstick.benchmark.scenarios.networking',
197 Ping6.TEARDOWN_SCRIPT)
198 self.client.run("cat > ~/teardown.sh",
199 stdin=open(self.teardown_script, "rb"))
200 cmd = "sudo bash teardown.sh"
201 status, stdout, stderr = self.client.execute(cmd)
203 post_teardown = options.get("post_teardown", True)
205 self._post_teardown()
208 raise RuntimeError(stderr)
213 LOG.error("ping6 teardown failed")
215 def _post_teardown(self):
216 for node_name in self.host_list:
217 self._ssh_host(node_name)
218 self.client.run("cat > ~/post_teardown.sh",
219 stdin=open(self.post_teardown_script, "rb"))
220 status, stdout, stderr = self.client.execute(
221 "sudo bash post_teardown.sh")