1 # Copyright (c) 2016-2017 Intel Corporation
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
20 from copy import deepcopy
22 from yardstick.tests import STL_MOCKS
23 from yardstick.benchmark.contexts import base as ctx_base
26 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
28 STLClient = mock.MagicMock()
29 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
33 from yardstick.network_services.vnf_generic.vnf import prox_vnf
34 from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
40 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.time')
41 class TestProxApproxVnf(unittest.TestCase):
44 'short-name': 'ProxVnf',
49 'network': '152.16.100.20',
50 'netmask': '255.255.255.0',
51 'gateway': '152.16.100.20',
55 'network': '152.16.40.20',
56 'netmask': '255.255.255.0',
57 'gateway': '152.16.40.20',
61 'description': 'PROX approximation using DPDK',
62 'name': 'proxvnf-baremetal',
65 'network': '0064:ff9b:0:0:0:0:9810:6414',
67 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
71 'network': '0064:ff9b:0:0:0:0:9810:2814',
73 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
77 'id': 'proxvnf-baremetal',
78 'external-interface': [
80 'virtual-interface': {
81 'dst_mac': '00:00:00:00:00:04',
82 'vpci': '0000:05:00.0',
83 'local_ip': '152.16.100.19',
84 'type': 'PCI-PASSTHROUGH',
85 'vld_id': 'downlink_0',
87 'netmask': '255.255.255.0',
89 'bandwidth': '10 Gbps',
91 'dst_ip': '152.16.100.20',
92 'local_iface_name': 'xe0',
93 'local_mac': '00:00:00:00:00:02',
95 'vnfd-connection-point-ref': 'xe0',
99 'virtual-interface': {
100 'dst_mac': '00:00:00:00:00:03',
101 'vpci': '0000:05:00.1',
102 'local_ip': '152.16.40.19',
103 'type': 'PCI-PASSTHROUGH',
104 'vld_id': 'uplink_0',
107 'netmask': '255.255.255.0',
109 'bandwidth': '10 Gbps',
110 'dst_ip': '152.16.40.20',
111 'local_iface_name': 'xe1',
112 'local_mac': '00:00:00:00:00:01',
114 'vnfd-connection-point-ref': 'xe1',
120 'description': 'PROX approximation using DPDK',
122 'vdu-id': 'proxvnf-baremetal',
137 'connection-point': [
147 'id': 'ProxApproxVnf',
152 'vnfd:vnfd-catalog': {
162 'tg__1': 'trafficgen_1.yardstick',
163 'vnf__1': 'vnf.yardstick'},
165 'duration': 600, 'type': 'Duration'},
166 'topology': 'prox-tg-topology-2.yaml',
167 'traffic_profile': '../../traffic_profiles/prox_binsearch.yaml',
170 'tg__1': {'prox_args': {'-e': '',
172 'prox_config': 'configs/l3-gen-2.cfg',
174 '/root/dppd-PROX-v035/build/prox'},
176 'prox_args': {'-t': ''},
177 'prox_config': 'configs/l3-swap-2.cfg',
178 'prox_path': '/root/dppd-PROX-v035/build/prox'}}}
183 'member-vnf-index': '3',
184 'role': 'TrafficGen',
185 'name': 'trafficgen_2.yardstick',
186 'vnfd-id-ref': 'tg__2',
190 'local_iface_name': 'ens513f0',
191 'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK,
192 'netmask': '255.255.255.0',
193 'local_ip': '152.16.40.20',
194 'dst_mac': '00:00:00:00:00:01',
195 'local_mac': '00:00:00:00:00:03',
196 'dst_ip': '152.16.40.19',
198 'vpci': '0000:02:00.0',
202 'local_iface_name': 'ens513f1',
203 'netmask': '255.255.255.0',
204 'network': '202.16.100.0',
205 'local_ip': '202.16.100.20',
206 'local_mac': '00:1e:67:d0:60:5d',
208 'vpci': '0000:02:00.1',
213 'VNF model': 'l3fwd_vnf.yaml',
217 'member-vnf-index': '1',
218 'role': 'TrafficGen',
219 'name': 'trafficgen_1.yardstick',
220 'vnfd-id-ref': 'tg__1',
224 'local_iface_name': 'ens785f0',
225 'vld_id': prox_vnf.ProxApproxVnf.UPLINK,
226 'netmask': '255.255.255.0',
227 'local_ip': '152.16.100.20',
228 'dst_mac': '00:00:00:00:00:02',
229 'local_mac': '00:00:00:00:00:04',
230 'dst_ip': '152.16.100.19',
232 'vpci': '0000:05:00.0',
236 'local_iface_name': 'ens785f1',
237 'netmask': '255.255.255.0',
238 'local_ip': '152.16.100.21',
239 'local_mac': '00:00:00:00:00:01',
241 'vpci': '0000:05:00.1',
246 'VNF model': 'tg_rfc2544_tpl.yaml',
250 'name': 'vnf.yardstick',
251 'vnfd-id-ref': 'vnf__1',
255 'local_iface_name': 'ens786f0',
256 'vld_id': prox_vnf.ProxApproxVnf.UPLINK,
257 'netmask': '255.255.255.0',
258 'local_ip': '152.16.100.19',
259 'dst_mac': '00:00:00:00:00:04',
260 'local_mac': '00:00:00:00:00:02',
261 'dst_ip': '152.16.100.20',
263 'vpci': '0000:05:00.0',
267 'local_iface_name': 'ens786f1',
268 'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK,
269 'netmask': '255.255.255.0',
270 'local_ip': '152.16.40.19',
271 'dst_mac': '00:00:00:00:00:03',
272 'local_mac': '00:00:00:00:00:01',
273 'dst_ip': '152.16.40.20',
275 'vpci': '0000:05:00.1',
281 'netmask': '255.255.255.0',
282 'gateway': '152.16.100.20',
283 'network': '152.16.100.20',
287 'netmask': '255.255.255.0',
288 'gateway': '152.16.40.20',
289 'network': '152.16.40.20',
293 'member-vnf-index': '2',
300 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
301 'network': '0064:ff9b:0:0:0:0:9810:6414',
306 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
307 'network': '0064:ff9b:0:0:0:0:9810:2814',
312 'VNF model': 'prox_vnf.yaml',
317 @mock.patch(SSH_HELPER)
318 def test___init__(self, ssh, *args):
320 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0, 'task_id')
321 self.assertIsNone(prox_approx_vnf._vnf_process)
323 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
324 @mock.patch(SSH_HELPER)
325 def test_collect_kpi_no_client(self, ssh, *args):
328 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0, 'task_id')
329 prox_approx_vnf.scenario_helper.scenario_cfg = {
330 'nodes': {prox_approx_vnf.name: "mock"}
332 prox_approx_vnf.resource_helper = None
334 'physical_node': 'mock_node',
336 'packets_dropped': 0,
338 'collect_stats': {'core': {}}
340 result = prox_approx_vnf.collect_kpi()
341 self.assertEqual(result, expected)
343 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
344 @mock.patch(SSH_HELPER)
345 def test_collect_kpi(self, ssh, *args):
348 resource_helper = mock.MagicMock()
349 resource_helper.execute.return_value = [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5],
350 [2, 1, 2, 3, 4, 5], [3, 1, 2, 3, 4, 5]]
351 resource_helper.collect_collectd_kpi.return_value = {'core': {'result': 234}}
353 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0, 'task_id')
354 prox_approx_vnf.scenario_helper.scenario_cfg = {
355 'nodes': {prox_approx_vnf.name: "mock"}
357 prox_approx_vnf.resource_helper = resource_helper
360 'physical_node': 'mock_node',
362 'packets_dropped': 4,
364 'collect_stats': {'core': {'result': 234}},
366 result = prox_approx_vnf.collect_kpi()
367 self.assertEqual(result['packets_in'], expected['packets_in'])
368 self.assertEqual(result['packets_dropped'], expected['packets_dropped'])
369 self.assertEqual(result['packets_fwd'], expected['packets_fwd'])
370 self.assertNotEqual(result['packets_fwd'], 0)
371 self.assertNotEqual(result['packets_fwd'], 0)
373 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
374 @mock.patch(SSH_HELPER)
375 def test_collect_kpi_error(self, ssh, *args):
378 resource_helper = mock.MagicMock()
379 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, deepcopy(self.VNFD0),
381 prox_approx_vnf.scenario_helper.scenario_cfg = {
382 'nodes': {prox_approx_vnf.name: "mock"}
384 prox_approx_vnf.resource_helper = resource_helper
385 prox_approx_vnf.vnfd_helper['vdu'][0]['external-interface'] = []
386 prox_approx_vnf.vnfd_helper.port_pairs.interfaces = []
388 with self.assertRaises(RuntimeError):
389 prox_approx_vnf.collect_kpi()
391 def _get_file_abspath(self, filename, *args):
392 curr_path = os.path.dirname(os.path.abspath(__file__))
393 file_path = os.path.join(curr_path, filename)
396 @mock.patch('yardstick.common.utils.open', create=True)
397 @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True)
398 @mock.patch('yardstick.network_services.helpers.iniparser.open', create=True)
399 @mock.patch(SSH_HELPER)
400 def test_run_prox(self, ssh, *_):
403 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0, 'task_id')
404 prox_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
405 prox_approx_vnf.ssh_helper.join_bin_path.return_value = '/tool_path12/tool_file34'
406 prox_approx_vnf.setup_helper.remote_path = 'configs/file56.cfg'
408 expected = "sudo bash -c 'cd /tool_path12; " \
409 "/tool_path12/tool_file34 -o cli -t -f /tmp/l3-swap-2.cfg '"
411 prox_approx_vnf._run()
412 result = prox_approx_vnf.ssh_helper.run.call_args[0][0]
413 self.assertEqual(result, expected)
415 @mock.patch(SSH_HELPER)
416 def bad_test_instantiate(self, *args):
417 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0, 'task_id')
418 prox_approx_vnf.scenario_helper = mock.MagicMock()
419 prox_approx_vnf.setup_helper = mock.MagicMock()
420 # we can't mock super
421 prox_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)
422 prox_approx_vnf.setup_helper.build_config.assert_called_once()
424 @mock.patch(SSH_HELPER)
425 def test_wait_for_instantiate_panic(self, ssh, *args):
426 mock_ssh(ssh, exec_result=(1, "", ""))
427 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0, 'task_id')
428 prox_approx_vnf._vnf_process = mock.MagicMock(**{"is_alive.return_value": True})
429 prox_approx_vnf._run_prox = mock.Mock(return_value=0)
430 prox_approx_vnf.WAIT_TIME = 0
431 prox_approx_vnf.q_out.put("PANIC")
432 with self.assertRaises(RuntimeError):
433 prox_approx_vnf.wait_for_instantiate()
435 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket')
436 @mock.patch(SSH_HELPER)
437 def test_terminate(self, ssh, *args):
439 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0, 'task_id')
440 prox_approx_vnf._vnf_process = mock.MagicMock()
441 prox_approx_vnf._vnf_process.terminate = mock.Mock()
442 prox_approx_vnf.ssh_helper = mock.MagicMock()
443 prox_approx_vnf.setup_helper = mock.Mock()
444 prox_approx_vnf.resource_helper = mock.MagicMock()
446 self.assertIsNone(prox_approx_vnf.terminate())
448 @mock.patch(SSH_HELPER)
449 def test__vnf_up_post(self, ssh, *args):
451 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0, 'task_id')
452 prox_approx_vnf.resource_helper = resource_helper = mock.Mock()
454 prox_approx_vnf._vnf_up_post()
455 resource_helper.up_post.assert_called_once()
457 @mock.patch(SSH_HELPER)
458 def test_vnf_execute_oserror(self, ssh, *args):
460 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0, 'task_id')
461 prox_approx_vnf.resource_helper = resource_helper = mock.Mock()
463 resource_helper.execute.side_effect = OSError(errno.EPIPE, "")
464 prox_approx_vnf.vnf_execute("", _ignore_errors=True)
466 resource_helper.execute.side_effect = OSError(errno.ESHUTDOWN, "")
467 prox_approx_vnf.vnf_execute("", _ignore_errors=True)
469 resource_helper.execute.side_effect = OSError(errno.EADDRINUSE, "")
470 with self.assertRaises(OSError):
471 prox_approx_vnf.vnf_execute("", _ignore_errors=True)