1 # Copyright (c) 2016-2019 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)
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)
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 'curr_packets_in': 0,
339 'curr_packets_fwd': 0,
340 'collect_stats': {'core': {}}
342 result = prox_approx_vnf.collect_kpi()
343 self.assertEqual(result, expected)
345 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
346 @mock.patch(SSH_HELPER)
347 def test_collect_kpi(self, ssh, *args):
350 resource_helper = mock.MagicMock()
351 resource_helper.execute.return_value = (True,
352 [[0, 1, 2, 3, 4, 5], [1, 1, 2, 3, 4, 5]])
353 resource_helper.collect_collectd_kpi.return_value = {'core': {'result': 234}}
355 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
356 prox_approx_vnf.scenario_helper.scenario_cfg = {
357 'nodes': {prox_approx_vnf.name: "mock"}
359 prox_approx_vnf.resource_helper = resource_helper
360 prox_approx_vnf.tsc_hz = 1000
363 'curr_packets_in': 200,
364 'curr_packets_fwd': 400,
365 'physical_node': 'mock_node',
367 'packets_dropped': 2,
369 'collect_stats': {'core': {'result': 234}},
371 result = prox_approx_vnf.collect_kpi()
372 self.assertEqual(result['packets_in'], expected['packets_in'])
373 self.assertEqual(result['packets_dropped'], expected['packets_dropped'])
374 self.assertEqual(result['packets_fwd'], expected['packets_fwd'])
375 self.assertEqual(result['curr_packets_in'], expected['curr_packets_in'])
376 self.assertEqual(result['curr_packets_fwd'], expected['curr_packets_fwd'])
378 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
379 @mock.patch(SSH_HELPER)
380 def test_collect_kpi_bad_input(self, ssh, *args):
383 resource_helper = mock.MagicMock()
384 resource_helper.execute.return_value = (True,
385 [[0, 'A', 'B', 'C', 'D', 'E'],
386 ['F', 1, 2, 3, 4, 5]])
388 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
389 prox_approx_vnf.scenario_helper.scenario_cfg = {
390 'nodes': {prox_approx_vnf.name: "mock"}
392 prox_approx_vnf.resource_helper = resource_helper
394 result = prox_approx_vnf.collect_kpi()
395 self.assertDictEqual(result, {})
397 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
398 @mock.patch(SSH_HELPER)
399 def test_collect_kpi_bad_input2(self, ssh, *args):
402 resource_helper = mock.MagicMock()
403 resource_helper.execute.return_value = (False,
404 [[0, 'A', 'B', 'C', 'D', 'E'],
405 ['F', 1, 2, 3, 4, 5]])
407 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
408 prox_approx_vnf.scenario_helper.scenario_cfg = {
409 'nodes': {prox_approx_vnf.name: "mock"}
411 prox_approx_vnf.resource_helper = resource_helper
413 result = prox_approx_vnf.collect_kpi()
414 self.assertDictEqual(result, {})
416 @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
417 @mock.patch(SSH_HELPER)
418 def test_collect_kpi_error(self, ssh, *args):
421 resource_helper = mock.MagicMock()
422 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, deepcopy(self.VNFD0))
423 prox_approx_vnf.scenario_helper.scenario_cfg = {
424 'nodes': {prox_approx_vnf.name: "mock"}
426 prox_approx_vnf.resource_helper = resource_helper
427 prox_approx_vnf.vnfd_helper['vdu'][0]['external-interface'] = []
428 prox_approx_vnf.vnfd_helper.port_pairs.interfaces = []
430 with self.assertRaises(RuntimeError):
431 prox_approx_vnf.collect_kpi()
433 def _get_file_abspath(self, filename, *args):
434 curr_path = os.path.dirname(os.path.abspath(__file__))
435 file_path = os.path.join(curr_path, filename)
438 @mock.patch('yardstick.common.utils.open', create=True)
439 @mock.patch('yardstick.benchmark.scenarios.networking.vnf_generic.open', create=True)
440 @mock.patch('yardstick.network_services.helpers.iniparser.open', create=True)
441 @mock.patch(SSH_HELPER)
442 def test_run_prox(self, ssh, *_):
445 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
446 prox_approx_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
447 prox_approx_vnf.ssh_helper.join_bin_path.return_value = '/tool_path12/tool_file34'
448 prox_approx_vnf.setup_helper.remote_path = 'configs/file56.cfg'
450 expected = "sudo bash -c 'cd /tool_path12; " \
451 "/tool_path12/tool_file34 -o cli -t -f /tmp/l3-swap-2.cfg '"
453 prox_approx_vnf._run()
454 result = prox_approx_vnf.ssh_helper.run.call_args[0][0]
455 self.assertEqual(result, expected)
457 @mock.patch(SSH_HELPER)
458 def bad_test_instantiate(self, *args):
459 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
460 prox_approx_vnf.scenario_helper = mock.MagicMock()
461 prox_approx_vnf.setup_helper = mock.MagicMock()
462 # we can't mock super
463 prox_approx_vnf.instantiate(self.SCENARIO_CFG, self.CONTEXT_CFG)
464 prox_approx_vnf.setup_helper.build_config.assert_called_once()
466 @mock.patch(SSH_HELPER)
467 def test_wait_for_instantiate_panic(self, ssh, *args):
468 mock_ssh(ssh, exec_result=(1, "", ""))
469 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
470 prox_approx_vnf._vnf_process = mock.MagicMock(**{"is_alive.return_value": True})
471 prox_approx_vnf._run_prox = mock.Mock(return_value=0)
472 prox_approx_vnf.WAIT_TIME = 0
473 prox_approx_vnf.q_out.put("PANIC")
474 with self.assertRaises(RuntimeError):
475 prox_approx_vnf.wait_for_instantiate()
477 @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket')
478 @mock.patch(SSH_HELPER)
479 def test_terminate(self, ssh, *args):
481 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
482 prox_approx_vnf._vnf_process = mock.MagicMock()
483 prox_approx_vnf._vnf_process.terminate = mock.Mock()
484 prox_approx_vnf.ssh_helper = mock.MagicMock()
485 prox_approx_vnf.setup_helper = mock.Mock()
486 prox_approx_vnf.resource_helper = mock.MagicMock()
488 self.assertIsNone(prox_approx_vnf.terminate())
490 @mock.patch(SSH_HELPER)
491 def test__vnf_up_post(self, ssh, *args):
493 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
494 prox_approx_vnf.resource_helper = resource_helper = mock.Mock()
496 prox_approx_vnf._vnf_up_post()
497 resource_helper.up_post.assert_called_once()
499 @mock.patch(SSH_HELPER)
500 def test_vnf_execute_oserror(self, ssh, *args):
502 prox_approx_vnf = prox_vnf.ProxApproxVnf(NAME, self.VNFD0)
503 prox_approx_vnf.resource_helper = resource_helper = mock.Mock()
505 resource_helper.execute.side_effect = OSError(errno.EPIPE, "")
506 prox_approx_vnf.vnf_execute("", _ignore_errors=True)
508 resource_helper.execute.side_effect = OSError(errno.ESHUTDOWN, "")
509 prox_approx_vnf.vnf_execute("", _ignore_errors=True)
511 resource_helper.execute.side_effect = OSError(errno.EADDRINUSE, "")
512 with self.assertRaises(OSError):
513 prox_approx_vnf.vnf_execute("", _ignore_errors=True)