1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
##############################################################################
# Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import pkg_resources
import logging
import yardstick.ssh as ssh
from yardstick.benchmark.scenarios import base
LOG = logging.getLogger(__name__)
class Ping6(base.Scenario): # pragma: no cover
"""Execute ping6 between two hosts
read link below for more ipv6 info description:
http://wiki.opnfv.org/ipv6_opnfv_project
"""
__scenario_type__ = "Ping6"
TARGET_SCRIPT = 'ping6_benchmark.bash'
PRE_SETUP_SCRIPT = 'ping6_pre_setup.bash'
SETUP_SCRIPT = 'ping6_setup.bash'
SETUP_ODL_SCRIPT = 'ping6_setup_with_odl.bash'
FIND_HOST_SCRIPT = 'ping6_find_host.bash'
TEARDOWN_SCRIPT = 'ping6_teardown.bash'
METADATA_SCRIPT = 'ping6_metadata.txt'
RADVD_SCRIPT = 'ping6_radvd.conf'
POST_TEARDOWN_SCRIPT = 'ping6_post_teardown.bash'
def __init__(self, scenario_cfg, context_cfg):
self.scenario_cfg = scenario_cfg
self.context_cfg = context_cfg
self.setup_done = False
self.run_done = False
self.ping_options = ''
def _pre_setup(self):
for node_name in self.host_list:
self._ssh_host(node_name)
self.client.run("cat > ~/pre_setup.sh",
stdin=open(self.pre_setup_script, "rb"))
status, stdout, stderr = self.client.execute(
"sudo bash pre_setup.sh")
def _ssh_host(self, node_name):
# ssh host
print node_name
nodes = self.context_cfg['nodes']
node = nodes.get(node_name, None)
host_user = node.get('user', 'ubuntu')
host_ip = node.get('ip', None)
host_pwd = node.get('password', 'root')
LOG.debug("user:%s, host:%s", host_user, host_ip)
self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
self.client.wait(timeout=600)
def setup(self):
'''scenario setup'''
self.setup_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.SETUP_SCRIPT)
self.setup_odl_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.SETUP_ODL_SCRIPT)
self.pre_setup_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.PRE_SETUP_SCRIPT)
self.ping6_metadata_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.METADATA_SCRIPT)
self.ping6_radvd_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.RADVD_SCRIPT)
options = self.scenario_cfg['options']
self.ping_options = "-s %s" % \
options.get("packetsize", '56') + \
"-c %s" % \
options.get("ping_count", '5')
host_str = options.get("host", 'host1')
self.host_list = host_str.split(',')
self.host_list.sort()
pre_setup = options.get("pre_setup", True)
if pre_setup:
self._pre_setup()
# ssh host1
self._ssh_host(self.host_list[0])
self.client.run("cat > ~/metadata.txt",
stdin=open(self.ping6_metadata_script, "rb"))
# run script to setup ipv6 with nosdn or odl
sdn = options.get("sdn", 'nosdn')
if 'odl' in sdn:
self.client.run("cat > ~/br-ex.radvd.conf",
stdin=open(self.ping6_radvd_script, "rb"))
self.client.run("cat > ~/setup_odl.sh",
stdin=open(self.setup_odl_script, "rb"))
cmd = "sudo bash setup_odl.sh"
else:
self.client.run("cat > ~/setup.sh",
stdin=open(self.setup_script, "rb"))
cmd = "sudo bash setup.sh"
status, stdout, stderr = self.client.execute(cmd)
self.setup_done = True
def run(self, result):
"""execute the benchmark"""
# ssh vm1
self.ping6_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.TARGET_SCRIPT)
self.ping6_find_host_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.FIND_HOST_SCRIPT)
if not self.setup_done:
options = self.scenario_cfg['options']
self.ping_options = "-s %s" % \
options.get("packetsize", '56') + \
"-c %s" % \
options.get("ping_count", '5')
host_str = options.get("host", 'host1')
self.host_list = host_str.split(',')
self.host_list.sort()
self._ssh_host(self.host_list[0])
# find ipv4-int-network1 to ssh VM
self.client.run("cat > ~/find_host.sh",
stdin=open(self.ping6_find_host_script, "rb"))
cmd = "sudo bash find_host.sh"
LOG.debug("Executing command: %s", cmd)
status, stdout, stderr = self.client.execute(cmd)
host_name = stdout.strip()
# copy vRouterKey to target host
self.client.run("cat ~/vRouterKey",
stdout=open("/tmp/vRouterKey", "w"))
self._ssh_host(host_name)
self.client.run("cat > ~/vRouterKey",
stdin=open("/tmp/vRouterKey", "rb"))
# run ping6 benchmark
self.client.run("cat > ~/ping6.sh",
stdin=open(self.ping6_script, "rb"))
cmd_args = "%s" % (self.ping_options)
cmd = "sudo bash ping6.sh %s" % (cmd_args)
LOG.debug("Executing command: %s", cmd)
status, stdout, stderr = self.client.execute(cmd)
if status:
raise RuntimeError(stderr)
# sla
if stdout:
result["rtt"] = float(stdout)
if "sla" in self.scenario_cfg:
sla_max_rtt = int(self.scenario_cfg["sla"]["max_rtt"])
assert result["rtt"] <= sla_max_rtt, \
"rtt %f > sla:max_rtt(%f); " % (result["rtt"], sla_max_rtt)
else:
LOG.error("ping6 timeout")
self.run_done = True
def teardown(self):
"""teardown the benchmark"""
self.post_teardown_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.POST_TEARDOWN_SCRIPT)
options = self.scenario_cfg['options']
host_str = options.get("host", 'node1')
self.host_list = host_str.split(',')
self.host_list.sort()
if not self.run_done:
self._ssh_host(self.host_list[0])
self.teardown_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.TEARDOWN_SCRIPT)
self.client.run("cat > ~/teardown.sh",
stdin=open(self.teardown_script, "rb"))
cmd = "sudo bash teardown.sh"
status, stdout, stderr = self.client.execute(cmd)
post_teardown = options.get("post_teardown", True)
if post_teardown:
self._post_teardown()
if status:
raise RuntimeError(stderr)
if stdout:
pass
else:
LOG.error("ping6 teardown failed")
def _post_teardown(self):
for node_name in self.host_list:
self._ssh_host(node_name)
self.client.run("cat > ~/post_teardown.sh",
stdin=open(self.post_teardown_script, "rb"))
status, stdout, stderr = self.client.execute(
"sudo bash post_teardown.sh")
|