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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Unittest for yardstick.benchmark.contexts.standalone.standaloneovs
from __future__ import absolute_import
import os
import unittest
import errno
import mock
from yardstick.common import constants as consts
from yardstick.benchmark.contexts.standalone import ovs_dpdk
from yardstick.network_services.utils import PciAddress
class OvsDpdkContextTestCase(unittest.TestCase):
NODES_SAMPLE = "nodes_sample.yaml"
NODES_ovs_dpdk_SAMPLE = "nodes_ovs_dpdk_sample.yaml"
NODES_DUPLICATE_SAMPLE = "nodes_duplicate_sample.yaml"
ATTRS = {
'name': 'StandaloneOvsDpdk',
'file': 'pod',
'flavor': {},
'servers': {},
'networks': {},
}
NETWORKS = {
'mgmt': {'cidr': '152.16.100.10/24'},
'private_0': {
'phy_port': "0000:05:00.0",
'vpci': "0000:00:07.0",
'cidr': '152.16.100.10/24',
'interface': 'if0',
'mac': "00:00:00:00:00:01",
'vf_pci': {'vf_pci': 0},
'gateway_ip': '152.16.100.20'},
'public_0': {
'phy_port': "0000:05:00.1",
'vpci': "0000:00:08.0",
'cidr': '152.16.40.10/24',
'interface': 'if0',
'vf_pci': {'vf_pci': 0},
'mac': "00:00:00:00:00:01",
'gateway_ip': '152.16.100.20'},
}
def setUp(self):
self.ovs_dpdk = ovs_dpdk.OvsDpdkContext()
@mock.patch('yardstick.benchmark.contexts.standalone.model.StandaloneContextHelper')
@mock.patch('yardstick.benchmark.contexts.standalone.model.Server')
def test___init__(self, mock_helper, mock_server):
self.ovs_dpdk.helper = mock_helper
self.ovs_dpdk.vnf_node = mock_server
self.assertIsNone(self.ovs_dpdk.file_path)
self.assertEqual(self.ovs_dpdk.first_run, True)
def test_init(self):
self.ovs_dpdk.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}])
self.assertIsNone(self.ovs_dpdk.init(self.ATTRS))
def test_setup_ovs(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.ovs_properties = {}
self.assertIsNone(self.ovs_dpdk.setup_ovs())
def test_start_ovs_serverswitch(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.ovs_properties = {}
self.ovs_dpdk.wait_for_vswitchd = 0
self.assertIsNone(self.ovs_dpdk.start_ovs_serverswitch())
def test_setup_ovs_bridge_add_flows(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.ovs_properties = {
'version': {'ovs': '2.7.0'}
}
self.ovs_dpdk.wait_for_vswitchd = 0
self.assertIsNone(self.ovs_dpdk.setup_ovs_bridge_add_flows())
def test_cleanup_ovs_dpdk_env(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.ovs_properties = {
'version': {'ovs': '2.7.0'}
}
self.ovs_dpdk.wait_for_vswitchd = 0
self.assertIsNone(self.ovs_dpdk.cleanup_ovs_dpdk_env())
@mock.patch('yardstick.benchmark.contexts.standalone.model.OvsDeploy')
def test_check_ovs_dpdk_env(self, mock_ovs):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(1, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.ovs_properties = {
'version': {'ovs': '2.7.0', 'dpdk': '16.11.1'}
}
self.ovs_dpdk.wait_for_vswitchd = 0
self.ovs_dpdk.cleanup_ovs_dpdk_env = mock.Mock()
self.assertIsNone(self.ovs_dpdk.check_ovs_dpdk_env())
self.ovs_dpdk.ovs_properties = {
'version': {'ovs': '2.0.0'}
}
self.ovs_dpdk.wait_for_vswitchd = 0
self.cleanup_ovs_dpdk_env = mock.Mock()
mock_ovs.deploy = mock.Mock()
self.assertRaises(Exception, self.ovs_dpdk.check_ovs_dpdk_env)
@mock.patch('yardstick.ssh.SSH')
def test_deploy(self, mock_ssh):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.vm_deploy = False
self.assertIsNone(self.ovs_dpdk.deploy())
self.ovs_dpdk.vm_deploy = True
self.ovs_dpdk.host_mgmt = {}
self.ovs_dpdk.install_req_libs = mock.Mock()
self.ovs_dpdk.helper.get_nic_details = mock.Mock(return_value={})
self.ovs_dpdk.check_ovs_dpdk_env = mock.Mock(return_value={})
self.ovs_dpdk.setup_ovs = mock.Mock(return_value={})
self.ovs_dpdk.start_ovs_serverswitch = mock.Mock(return_value={})
self.ovs_dpdk.setup_ovs_bridge_add_flows = mock.Mock(return_value={})
self.ovs_dpdk.setup_ovs_dpdk_context = mock.Mock(return_value={})
self.ovs_dpdk.wait_for_vnfs_to_start = mock.Mock(return_value={})
self.assertIsNone(self.ovs_dpdk.deploy())
@mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.Libvirt')
@mock.patch('yardstick.ssh.SSH')
def test_undeploy(self, mock_ssh, mock_libvirt):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.vm_deploy = False
self.assertIsNone(self.ovs_dpdk.undeploy())
self.ovs_dpdk.vm_deploy = True
self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.vm_names = ['vm_0', 'vm_1']
self.ovs_dpdk.drivers = ['vm_0', 'vm_1']
self.ovs_dpdk.cleanup_ovs_dpdk_env = mock.Mock()
self.ovs_dpdk.networks = self.NETWORKS
self.assertIsNone(self.ovs_dpdk.undeploy())
def _get_file_abspath(self, filename):
curr_path = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(curr_path, filename)
return file_path
def test__get_server_with_dic_attr_name(self):
attrs = {
'name': 'foo',
'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE)
}
self.ovs_dpdk.init(attrs)
attr_name = {'name': 'foo.bar'}
result = self.ovs_dpdk._get_server(attr_name)
self.assertEqual(result, None)
def test__get_server_not_found(self):
attrs = {
'name': 'foo',
'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE)
}
self.ovs_dpdk.helper.parse_pod_file = mock.Mock(return_value=[{}, {}, {}])
self.ovs_dpdk.init(attrs)
attr_name = 'bar.foo'
result = self.ovs_dpdk._get_server(attr_name)
self.assertEqual(result, None)
def test__get_server_mismatch(self):
attrs = {
'name': 'foo',
'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE)
}
self.ovs_dpdk.init(attrs)
attr_name = 'bar.foo1'
result = self.ovs_dpdk._get_server(attr_name)
self.assertEqual(result, None)
def test__get_server_duplicate(self):
attrs = {
'name': 'foo',
'file': self._get_file_abspath(self.NODES_DUPLICATE_SAMPLE)
}
self.ovs_dpdk.init(attrs)
attr_name = 'node1.foo'
with self.assertRaises(ValueError):
self.ovs_dpdk._get_server(attr_name)
def test__get_server_found(self):
attrs = {
'name': 'foo',
'file': self._get_file_abspath(self.NODES_ovs_dpdk_SAMPLE)
}
self.ovs_dpdk.init(attrs)
attr_name = 'node1.foo'
result = self.ovs_dpdk._get_server(attr_name)
self.assertEqual(result['ip'], '10.229.47.137')
self.assertEqual(result['name'], 'node1.foo')
self.assertEqual(result['user'], 'root')
self.assertEqual(result['key_filename'], '/root/.yardstick_key')
def test__get_network(self):
network1 = {
'name': 'net_1',
'vld_id': 'vld111',
'segmentation_id': 'seg54',
'network_type': 'type_a',
'physical_network': 'phys',
}
network2 = {
'name': 'net_2',
'vld_id': 'vld999',
}
self.ovs_dpdk.networks = {
'a': network1,
'b': network2,
}
attr_name = {}
self.assertIsNone(self.ovs_dpdk._get_network(attr_name))
attr_name = {'vld_id': 'vld777'}
self.assertIsNone(self.ovs_dpdk._get_network(attr_name))
self.assertIsNone(self.ovs_dpdk._get_network(None))
attr_name = 'vld777'
self.assertIsNone(self.ovs_dpdk._get_network(attr_name))
attr_name = {'vld_id': 'vld999'}
expected = {
"name": 'net_2',
"vld_id": 'vld999',
"segmentation_id": None,
"network_type": None,
"physical_network": None,
}
result = self.ovs_dpdk._get_network(attr_name)
self.assertDictEqual(result, expected)
attr_name = 'a'
expected = network1
result = self.ovs_dpdk._get_network(attr_name)
self.assertDictEqual(result, expected)
def test_configure_nics_for_ovs_dpdk(self):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.vm_deploy = True
self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.vm_names = ['vm_0', 'vm_1']
self.ovs_dpdk.drivers = []
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.helper.get_mac_address = mock.Mock(return_value="")
self.ovs_dpdk.get_vf_datas = mock.Mock(return_value="")
self.assertIsNone(self.ovs_dpdk.configure_nics_for_ovs_dpdk())
@mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.Libvirt')
def test__enable_interfaces(self, mock_add_ovs_interface):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.vm_deploy = True
self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.vm_names = ['vm_0', 'vm_1']
self.ovs_dpdk.drivers = []
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.get_vf_datas = mock.Mock(return_value="")
self.assertIsNone(self.ovs_dpdk._enable_interfaces(0, ["private_0"], 'test'))
@mock.patch('yardstick.benchmark.contexts.standalone.ovs_dpdk.Libvirt')
@mock.patch('yardstick.benchmark.contexts.standalone.model.Server')
def test_setup_ovs_dpdk_context(self, mock_server, mock_libvirt):
with mock.patch("yardstick.ssh.SSH") as ssh:
ssh_mock = mock.Mock(autospec=ssh.SSH)
ssh_mock.execute = \
mock.Mock(return_value=(0, "a", ""))
ssh_mock.put = \
mock.Mock(return_value=(0, "a", ""))
ssh.return_value = ssh_mock
self.ovs_dpdk.vm_deploy = True
self.ovs_dpdk.connection = ssh_mock
self.ovs_dpdk.vm_names = ['vm_0', 'vm_1']
self.ovs_dpdk.drivers = []
self.ovs_dpdk.servers = {
'vnf_0': {
'network_ports': {
'mgmt': {'cidr': '152.16.100.10/24'},
'xe0': ['private_0'],
'xe1': ['public_0']
}
}
}
self.ovs_dpdk.networks = self.NETWORKS
self.ovs_dpdk.host_mgmt = {}
self.ovs_dpdk.flavor = {}
self.ovs_dpdk.configure_nics_for_ovs_dpdk = mock.Mock(return_value="")
mock_libvirt.check_if_vm_exists_and_delete = mock.Mock(return_value="")
mock_libvirt.build_vm_xml = mock.Mock(return_value=[6, "00:00:00:00:00:01"])
self.ovs_dpdk._enable_interfaces = mock.Mock(return_value="")
mock_libvirt.virsh_create_vm = mock.Mock(return_value="")
mock_libvirt.pin_vcpu_for_perf= mock.Mock(return_value="")
self.ovs_dpdk.vnf_node.generate_vnf_instance = mock.Mock(return_value={})
self.assertIsNotNone(self.ovs_dpdk.setup_ovs_dpdk_context())
|