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 ##############################################################################
10 from __future__ import absolute_import
14 import yardstick.ssh as ssh
15 from yardstick.benchmark.scenarios import base
17 LOG = logging.getLogger(__name__)
20 class Ping6(base.Scenario): # pragma: no cover
21 """Execute ping6 between two hosts
23 read link below for more ipv6 info description:
24 http://wiki.opnfv.org/ipv6_opnfv_project
26 __scenario_type__ = "Ping6"
28 TARGET_SCRIPT = 'ping6_benchmark.bash'
29 PRE_SETUP_SCRIPT = 'ping6_pre_setup.bash'
30 SETUP_SCRIPT = 'ping6_setup.bash'
31 SETUP_ODL_SCRIPT = 'ping6_setup_with_odl.bash'
32 FIND_HOST_SCRIPT = 'ping6_find_host.bash'
33 TEARDOWN_SCRIPT = 'ping6_teardown.bash'
34 METADATA_SCRIPT = 'ping6_metadata.txt'
35 RADVD_SCRIPT = 'ping6_radvd.conf'
36 POST_TEARDOWN_SCRIPT = 'ping6_post_teardown.bash'
38 def __init__(self, scenario_cfg, context_cfg):
39 self.scenario_cfg = scenario_cfg
40 self.context_cfg = context_cfg
41 self.nodes = context_cfg['nodes']
42 self.options = scenario_cfg['options']
43 self.setup_done = False
45 self.external_network = self.options.get("external_network", "ext-net")
46 self.ping_options = "-s %s -c %s" % \
47 (self.options.get("packetsize", '56'),
48 self.options.get("ping_count", '5'))
49 self.openrc = self.options.get("openrc", "/opt/admin-openrc.sh")
51 def _ssh_host(self, node_name):
53 node = self.nodes.get(node_name, None)
54 self.client = ssh.SSH.from_node(node, defaults={"user": "ubuntu"})
55 self.client.wait(timeout=60)
58 for node_name in self.host_list:
59 self._ssh_host(node_name)
60 self.client._put_file_shell(
61 self.pre_setup_script, '~/pre_setup.sh')
62 status, stdout, stderr = self.client.execute(
63 "sudo bash pre_setup.sh")
65 def _get_controller_node(self, host_list):
66 for host_name in host_list:
67 node = self.nodes.get(host_name, None)
68 node_role = node.get('role', None)
69 if node_role == 'Controller':
75 self.setup_script = pkg_resources.resource_filename(
76 'yardstick.benchmark.scenarios.networking',
79 self.setup_odl_script = pkg_resources.resource_filename(
80 'yardstick.benchmark.scenarios.networking',
81 Ping6.SETUP_ODL_SCRIPT)
83 self.pre_setup_script = pkg_resources.resource_filename(
84 'yardstick.benchmark.scenarios.networking',
85 Ping6.PRE_SETUP_SCRIPT)
87 self.ping6_metadata_script = pkg_resources.resource_filename(
88 'yardstick.benchmark.scenarios.networking',
89 Ping6.METADATA_SCRIPT)
91 self.ping6_radvd_script = pkg_resources.resource_filename(
92 'yardstick.benchmark.scenarios.networking',
95 host_str = self.options.get("host", 'host1')
96 self.host_list = host_str.split(',')
98 pre_setup = self.options.get("pre_setup", True)
102 # log in a contronller node to setup
103 controller_node_name = self._get_controller_node(self.host_list)
104 LOG.debug("The Controller Node is: %s", controller_node_name)
105 if controller_node_name is None:
106 LOG.exception("Can't find controller node in the context!!!")
107 self._ssh_host(controller_node_name)
108 self.client._put_file_shell(
109 self.ping6_metadata_script, '~/metadata.txt')
111 # run script to setup ipv6 with nosdn or odl
112 sdn = self.options.get("sdn", 'nosdn')
114 self.client._put_file_shell(
115 self.ping6_radvd_script, '~/br-ex.radvd.conf')
116 self.client._put_file_shell(
117 self.setup_odl_script, '~/setup_odl.sh')
118 setup_bash_file = "setup_odl.sh"
120 self.client._put_file_shell(self.setup_script, '~/setup.sh')
121 setup_bash_file = "setup.sh"
122 cmd = "sudo bash %s %s %s" % \
123 (setup_bash_file, self.openrc, self.external_network)
124 LOG.debug("Executing setup command: %s", cmd)
125 status, stdout, stderr = self.client.execute(cmd)
127 self.setup_done = True
129 def run(self, result):
130 """execute the benchmark"""
132 self.ping6_script = pkg_resources.resource_filename(
133 'yardstick.benchmark.scenarios.networking',
136 self.ping6_find_host_script = pkg_resources.resource_filename(
137 'yardstick.benchmark.scenarios.networking',
138 Ping6.FIND_HOST_SCRIPT)
139 if not self.setup_done:
140 host_str = self.options.get("host", 'host1')
141 self.host_list = host_str.split(',')
142 self.host_list.sort()
143 self._ssh_host(self.host_list[0])
145 # find ipv4-int-network1 to ssh VM
146 self.client._put_file_shell(
147 self.ping6_find_host_script, '~/find_host.sh')
148 cmd = "sudo bash find_host.sh %s" % self.openrc
149 LOG.debug("Executing find_host command: %s", cmd)
150 status, stdout, stderr = self.client.execute(cmd)
151 host_name = stdout.strip()
153 # copy vRouterKey to target host
154 self.client.run("cat ~/vRouterKey",
155 stdout=open("/tmp/vRouterKey", "w"))
156 self._ssh_host(host_name)
157 self.client.run("cat > ~/vRouterKey",
158 stdin=open("/tmp/vRouterKey", "rb"))
160 # run ping6 benchmark
161 self.client._put_file_shell(self.ping6_script, '~/ping6.sh')
162 cmd = "sudo bash ping6.sh %s %s" % (self.openrc, self.ping_options)
163 LOG.debug("Executing ping6 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 host_str = self.options.get("host", 'node1')
188 self.host_list = host_str.split(',')
189 self.host_list.sort()
191 if not self.run_done:
192 self._ssh_host(self.host_list[0])
194 self.teardown_script = pkg_resources.resource_filename(
195 'yardstick.benchmark.scenarios.networking',
196 Ping6.TEARDOWN_SCRIPT)
197 self.client._put_file_shell(self.teardown_script, '~/teardown.sh')
198 cmd = "sudo bash teardown.sh %s %s" % \
199 (self.openrc, self.external_network)
200 status, stdout, stderr = self.client.execute(cmd)
202 post_teardown = self.options.get("post_teardown", True)
204 self._post_teardown()
207 raise RuntimeError(stderr)
212 LOG.error("ping6 teardown failed")
214 def _post_teardown(self):
215 for node_name in self.host_list:
216 self._ssh_host(node_name)
217 self.client._put_file_shell(
218 self.post_teardown_script, '~/post_teardown.sh')
219 status, stdout, stderr = self.client.execute(
220 "sudo bash post_teardown.sh")