Merge "Updating yaml file to match other standalone test cases"
[yardstick.git] / yardstick / tests / unit / network_services / vnf_generic / vnf / test_prox_irq.py
1 # Copyright (c) 2017-2018 Intel Corporation
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import unittest
16 import mock
17 import errno
18
19 from yardstick.tests import STL_MOCKS
20 from yardstick.common import exceptions as y_exceptions
21 from yardstick.network_services.vnf_generic.vnf.prox_irq import ProxIrqGen
22 from yardstick.network_services.vnf_generic.vnf.prox_irq import ProxIrqVNF
23 from yardstick.benchmark.contexts import base as ctx_base
24
25 SSH_HELPER = 'yardstick.network_services.vnf_generic.vnf.sample_vnf.VnfSshHelper'
26
27 STLClient = mock.MagicMock()
28 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
29 stl_patch.start()
30
31 if stl_patch:
32     from yardstick.network_services.vnf_generic.vnf import prox_vnf
33     from yardstick.tests.unit.network_services.vnf_generic.vnf.test_base import mock_ssh
34
35 VNF_NAME = "vnf__1"
36
37 class TestProxIrqVNF(unittest.TestCase):
38
39     SCENARIO_CFG = {
40         'task_path': "",
41         'nodes': {
42             'tg__1': 'trafficgen_1.yardstick',
43             'vnf__1': 'vnf.yardstick'},
44         'runner': {
45             'duration': 600, 'type': 'Duration'},
46         'topology': 'prox-tg-topology-2.yaml',
47         'traffic_profile': '../../traffic_profiles/prox_binsearch.yaml',
48         'type': 'NSPerf',
49         'options': {
50             'tg__1': {'prox_args': {'-e': '',
51                                     '-t': ''},
52                       'prox_config': 'configs/l3-gen-2.cfg',
53                       'prox_path':
54                           '/root/dppd-PROX-v035/build/prox'},
55             'vnf__1': {
56                 'prox_args': {'-t': ''},
57                 'prox_config': 'configs/l3-swap-2.cfg',
58                 'prox_path': '/root/dppd-PROX-v035/build/prox'}}}
59
60     VNFD_0 = {
61         'short-name': 'VpeVnf',
62         'vdu': [
63             {
64                 'routing_table': [
65                     {
66                         'network': '152.16.100.20',
67                         'netmask': '255.255.255.0',
68                         'gateway': '152.16.100.20',
69                         'if': 'xe0'
70                     },
71                     {
72                         'network': '152.16.40.20',
73                         'netmask': '255.255.255.0',
74                         'gateway': '152.16.40.20',
75                         'if': 'xe1'
76                     },
77                 ],
78                 'description': 'VPE approximation using DPDK',
79                 'name': 'vpevnf-baremetal',
80                 'nd_route_tbl': [
81                     {
82                         'network': '0064:ff9b:0:0:0:0:9810:6414',
83                         'netmask': '112',
84                         'gateway': '0064:ff9b:0:0:0:0:9810:6414',
85                         'if': 'xe0'
86                     },
87                     {
88                         'network': '0064:ff9b:0:0:0:0:9810:2814',
89                         'netmask': '112',
90                         'gateway': '0064:ff9b:0:0:0:0:9810:2814',
91                         'if': 'xe1'
92                     },
93                 ],
94                 'id': 'vpevnf-baremetal',
95                 'external-interface': [
96                     {
97                         'virtual-interface': {
98                             'dst_mac': '00:00:00:00:00:03',
99                             'vpci': '0000:05:00.0',
100                             'local_ip': '152.16.100.19',
101                             'type': 'PCI-PASSTHROUGH',
102                             'netmask': '255.255.255.0',
103                             'dpdk_port_num': 0,
104                             'bandwidth': '10 Gbps',
105                             'dst_ip': '152.16.100.20',
106                             'local_mac': '00:00:00:00:00:01'
107                         },
108                         'vnfd-connection-point-ref': 'xe0',
109                         'name': 'xe0'
110                     },
111                     {
112                         'virtual-interface': {
113                             'dst_mac': '00:00:00:00:00:04',
114                             'vpci': '0000:05:00.1',
115                             'local_ip': '152.16.40.19',
116                             'type': 'PCI-PASSTHROUGH',
117                             'netmask': '255.255.255.0',
118                             'dpdk_port_num': 1,
119                             'bandwidth': '10 Gbps',
120                             'dst_ip': '152.16.40.20',
121                             'local_mac': '00:00:00:00:00:02'
122                         },
123                         'vnfd-connection-point-ref': 'xe1',
124                         'name': 'xe1'
125                     },
126                 ],
127             },
128         ],
129         'description': 'Vpe approximation using DPDK',
130         'mgmt-interface': {
131             'vdu-id': 'vpevnf-baremetal',
132             'host': '1.1.1.1',
133             'password': 'r00t',
134             'user': 'root',
135             'ip': '1.1.1.1'
136         },
137         'benchmark': {
138             'kpi': [
139                 'packets_in',
140                 'packets_fwd',
141                 'packets_dropped',
142             ],
143         },
144         'connection-point': [
145             {
146                 'type': 'VPORT',
147                 'name': 'xe0',
148             },
149             {
150                 'type': 'VPORT',
151                 'name': 'xe1',
152             },
153         ],
154         'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'
155     }
156
157     VNFD = {
158         'vnfd:vnfd-catalog': {
159             'vnfd': [
160                 VNFD_0,
161             ]
162         }
163     }
164
165     TRAFFIC_PROFILE = {
166         "schema": "isb:traffic_profile:0.1",
167         "name": "fixed",
168         "description": "Fixed traffic profile to run UDP traffic",
169         "traffic_profile": {
170             "traffic_type": "FixedTraffic",
171             "frame_rate": 100,  # pps
172             "flow_number": 10,
173             "frame_size": 64,
174         },
175     }
176
177     CONTEXT_CFG = {
178         'nodes': {
179             'tg__2': {
180                 'member-vnf-index': '3',
181                 'role': 'TrafficGen',
182                 'name': 'trafficgen_2.yardstick',
183                 'vnfd-id-ref': 'tg__2',
184                 'ip': '1.2.1.1',
185                 'interfaces': {
186                     'xe0': {
187                         'local_iface_name': 'ens513f0',
188                         'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK,
189                         'netmask': '255.255.255.0',
190                         'local_ip': '152.16.40.20',
191                         'dst_mac': '00:00:00:00:00:01',
192                         'local_mac': '00:00:00:00:00:03',
193                         'dst_ip': '152.16.40.19',
194                         'driver': 'ixgbe',
195                         'vpci': '0000:02:00.0',
196                         'dpdk_port_num': 0,
197                     },
198                     'xe1': {
199                         'local_iface_name': 'ens513f1',
200                         'netmask': '255.255.255.0',
201                         'network': '202.16.100.0',
202                         'local_ip': '202.16.100.20',
203                         'local_mac': '00:1e:67:d0:60:5d',
204                         'driver': 'ixgbe',
205                         'vpci': '0000:02:00.1',
206                         'dpdk_port_num': 1,
207                     },
208                 },
209                 'password': 'r00t',
210                 'VNF model': 'l3fwd_vnf.yaml',
211                 'user': 'root',
212             },
213             'tg__1': {
214                 'member-vnf-index': '1',
215                 'role': 'TrafficGen',
216                 'name': 'trafficgen_1.yardstick',
217                 'vnfd-id-ref': 'tg__1',
218                 'ip': '1.2.1.1',
219                 'interfaces': {
220                     'xe0': {
221                         'local_iface_name': 'ens785f0',
222                         'vld_id': prox_vnf.ProxApproxVnf.UPLINK,
223                         'netmask': '255.255.255.0',
224                         'local_ip': '152.16.100.20',
225                         'dst_mac': '00:00:00:00:00:02',
226                         'local_mac': '00:00:00:00:00:04',
227                         'dst_ip': '152.16.100.19',
228                         'driver': 'i40e',
229                         'vpci': '0000:05:00.0',
230                         'dpdk_port_num': 0,
231                     },
232                     'xe1': {
233                         'local_iface_name': 'ens785f1',
234                         'netmask': '255.255.255.0',
235                         'local_ip': '152.16.100.21',
236                         'local_mac': '00:00:00:00:00:01',
237                         'driver': 'i40e',
238                         'vpci': '0000:05:00.1',
239                         'dpdk_port_num': 1,
240                     },
241                 },
242                 'password': 'r00t',
243                 'VNF model': 'tg_rfc2544_tpl.yaml',
244                 'user': 'root',
245             },
246             'vnf__1': {
247                 'name': 'vnf.yardstick',
248                 'vnfd-id-ref': 'vnf__1',
249                 'ip': '1.2.1.1',
250                 'interfaces': {
251                     'xe0': {
252                         'local_iface_name': 'ens786f0',
253                         'vld_id': prox_vnf.ProxApproxVnf.UPLINK,
254                         'netmask': '255.255.255.0',
255                         'local_ip': '152.16.100.19',
256                         'dst_mac': '00:00:00:00:00:04',
257                         'local_mac': '00:00:00:00:00:02',
258                         'dst_ip': '152.16.100.20',
259                         'driver': 'i40e',
260                         'vpci': '0000:05:00.0',
261                         'dpdk_port_num': 0,
262                     },
263                     'xe1': {
264                         'local_iface_name': 'ens786f1',
265                         'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK,
266                         'netmask': '255.255.255.0',
267                         'local_ip': '152.16.40.19',
268                         'dst_mac': '00:00:00:00:00:03',
269                         'local_mac': '00:00:00:00:00:01',
270                         'dst_ip': '152.16.40.20',
271                         'driver': 'i40e',
272                         'vpci': '0000:05:00.1',
273                         'dpdk_port_num': 1,
274                     },
275                 },
276                 'routing_table': [
277                     {
278                         'netmask': '255.255.255.0',
279                         'gateway': '152.16.100.20',
280                         'network': '152.16.100.20',
281                         'if': 'xe0',
282                     },
283                     {
284                         'netmask': '255.255.255.0',
285                         'gateway': '152.16.40.20',
286                         'network': '152.16.40.20',
287                         'if': 'xe1',
288                     },
289                 ],
290                 'member-vnf-index': '2',
291                 'host': '1.2.1.1',
292                 'role': 'vnf',
293                 'user': 'root',
294                 'nd_route_tbl': [
295                     {
296                         'netmask': '112',
297                         'gateway': '0064:ff9b:0:0:0:0:9810:6414',
298                         'network': '0064:ff9b:0:0:0:0:9810:6414',
299                         'if': 'xe0',
300                     },
301                     {
302                         'netmask': '112',
303                         'gateway': '0064:ff9b:0:0:0:0:9810:2814',
304                         'network': '0064:ff9b:0:0:0:0:9810:2814',
305                         'if': 'xe1',
306                     },
307                 ],
308                 'password': 'r00t',
309                 'VNF model': 'prox_vnf.yaml',
310             },
311         },
312     }
313
314     def test___init__(self):
315         prox_irq_vnf = ProxIrqVNF('vnf1', self.VNFD_0, 'task_id')
316
317         self.assertEqual(prox_irq_vnf.name, 'vnf1')
318         self.assertDictEqual(prox_irq_vnf.vnfd_helper, self.VNFD_0)
319
320     @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
321     @mock.patch(SSH_HELPER)
322     def test_collect_kpi(self, ssh, *args):
323         mock_ssh(ssh)
324
325         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
326         resource_helper = mock.MagicMock()
327
328         resource_helper = mock.MagicMock()
329
330         core_1 = {'bucket_1': 1, 'bucket_2': 2, 'bucket_3': 3, 'bucket_4': 4, 'bucket_5': 5,
331                   'bucket_6': 6, 'bucket_7': 7, 'bucket_8': 8, 'bucket_9': 9, 'bucket_10': 10,
332                   'bucket_11': 11, 'bucket_12': 12, 'bucket_0': 100, 'cpu': 1, 'max_irq': 12,
333                   'overflow': 10}
334         core_2 = {'bucket_1': 1, 'bucket_2': 2, 'bucket_3': 3, 'bucket_4': 4, 'bucket_5': 5,
335                   'bucket_6': 0, 'bucket_7': 0, 'bucket_8': 0, 'bucket_9': 0, 'bucket_10': 0,
336                   'bucket_11': 0, 'bucket_12': 0, 'bucket_0': 100, 'cpu': 2, 'max_irq': 12,
337                   'overflow': 10}
338
339         irq_data = {'core_1': core_1, 'core_2': core_2}
340         resource_helper.execute.return_value = (irq_data)
341
342         build_config_file = mock.MagicMock()
343         build_config_file.return_value = None
344
345         prox_irq_vnf = ProxIrqVNF(VNF_NAME, vnfd, 'task_id')
346
347         startup = ["global", [["eal", "-4"]]]
348         master_0 = ["core 0", [["mode", "master"]]]
349         core_1 = ["core 1", [["mode", "irq"]]]
350         core_2 = ["core 2", [["mode", "irq"], ["task", "2"]]]
351
352         prox_irq_vnf.setup_helper._prox_config_data = \
353             [startup, master_0, core_1, core_2]
354
355         prox_irq_vnf.scenario_helper.scenario_cfg = self.SCENARIO_CFG
356         prox_irq_vnf.resource_helper = resource_helper
357         prox_irq_vnf.setup_helper.build_config_file = build_config_file
358
359         result = prox_irq_vnf.collect_kpi()
360         self.assertDictEqual(result["collect_stats"], {})
361
362         result = prox_irq_vnf.collect_kpi()
363         self.assertFalse('bucket_10' in result["collect_stats"]['core_2'])
364         self.assertFalse('bucket_11' in result["collect_stats"]['core_2'])
365         self.assertFalse('bucket_12' in result["collect_stats"]['core_2'])
366         self.assertEqual(result["collect_stats"]['core_2']['max_irq'], 12)
367
368
369     @mock.patch(SSH_HELPER)
370     def test_vnf_execute_oserror(self, ssh, *args):
371         mock_ssh(ssh)
372
373         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
374         prox_irq_vnf = ProxIrqVNF(VNF_NAME, vnfd, 'task_id')
375         prox_irq_vnf.resource_helper = resource_helper = mock.Mock()
376
377         resource_helper.execute.side_effect = OSError(errno.EPIPE, "")
378         prox_irq_vnf.vnf_execute("", _ignore_errors=True)
379
380         resource_helper.execute.side_effect = OSError(errno.ESHUTDOWN, "")
381         prox_irq_vnf.vnf_execute("", _ignore_errors=True)
382
383         resource_helper.execute.side_effect = OSError(errno.EADDRINUSE, "")
384         with self.assertRaises(OSError):
385             prox_irq_vnf.vnf_execute("", _ignore_errors=True)
386
387     @mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket')
388     @mock.patch(SSH_HELPER)
389     def test_terminate(self, ssh, *args):
390         mock_ssh(ssh)
391         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
392
393         mock_ssh(ssh, exec_result=(1, "", ""))
394         prox_irq_vnf = ProxIrqVNF(VNF_NAME, vnfd, 'task_id')
395
396         prox_irq_vnf._terminated = mock.MagicMock()
397         prox_irq_vnf._traffic_process = mock.MagicMock()
398         prox_irq_vnf._traffic_process.terminate = mock.Mock()
399         prox_irq_vnf.ssh_helper = mock.MagicMock()
400         prox_irq_vnf.setup_helper = mock.MagicMock()
401         prox_irq_vnf.resource_helper = mock.MagicMock()
402         prox_irq_vnf._vnf_wrapper.setup_helper = mock.MagicMock()
403         prox_irq_vnf._vnf_wrapper._vnf_process = mock.MagicMock(**{"is_alive.return_value": False})
404         prox_irq_vnf._vnf_wrapper.resource_helper = mock.MagicMock()
405
406         prox_irq_vnf._run_prox = mock.Mock(return_value=0)
407         prox_irq_vnf.q_in = mock.Mock()
408         prox_irq_vnf.q_out = mock.Mock()
409
410         self.assertIsNone(prox_irq_vnf.terminate())
411
412     @mock.patch(SSH_HELPER)
413     def test_wait_for_instantiate_panic(self, ssh, *args):
414         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
415
416         mock_ssh(ssh, exec_result=(1, "", ""))
417         prox_irq_vnf = ProxIrqVNF(VNF_NAME, vnfd, 'task_id')
418
419         prox_irq_vnf._terminated = mock.MagicMock()
420         prox_irq_vnf._traffic_process = mock.MagicMock()
421         prox_irq_vnf._traffic_process.terminate = mock.Mock()
422         prox_irq_vnf.ssh_helper = mock.MagicMock()
423         prox_irq_vnf.setup_helper = mock.MagicMock()
424         prox_irq_vnf.resource_helper = mock.MagicMock()
425         prox_irq_vnf._vnf_wrapper.setup_helper = mock.MagicMock()
426         prox_irq_vnf._vnf_wrapper._vnf_process = mock.MagicMock(**{"is_alive.return_value": False})
427         prox_irq_vnf._vnf_wrapper.resource_helper = mock.MagicMock()
428
429         prox_irq_vnf._run_prox = mock.Mock(return_value=0)
430         prox_irq_vnf.q_in = mock.Mock()
431         prox_irq_vnf.q_out = mock.Mock()
432         prox_irq_vnf.WAIT_TIME = 0
433         with self.assertRaises(RuntimeError):
434             prox_irq_vnf.wait_for_instantiate()
435
436 class TestProxIrqGen(unittest.TestCase):
437
438     SCENARIO_CFG = {
439         'task_path': "",
440         'nodes': {
441             'tg__1': 'trafficgen_1.yardstick',
442             'vnf__1': 'vnf.yardstick'},
443         'runner': {
444             'duration': 600, 'type': 'Duration'},
445         'topology': 'prox-tg-topology-2.yaml',
446         'traffic_profile': '../../traffic_profiles/prox_binsearch.yaml',
447         'type': 'NSPerf',
448         'options': {
449             'tg__1': {'prox_args': {'-e': '',
450                                     '-t': ''},
451                       'prox_config': 'configs/l3-gen-2.cfg',
452                       'prox_path':
453                           '/root/dppd-PROX-v035/build/prox'},
454             'vnf__1': {
455                 'prox_args': {'-t': ''},
456                 'prox_config': 'configs/l3-swap-2.cfg',
457                 'prox_path': '/root/dppd-PROX-v035/build/prox'}}}
458
459     VNFD_0 = {
460         'short-name': 'VpeVnf',
461         'vdu': [
462             {
463                 'routing_table': [
464                     {
465                         'network': '152.16.100.20',
466                         'netmask': '255.255.255.0',
467                         'gateway': '152.16.100.20',
468                         'if': 'xe0'
469                     },
470                     {
471                         'network': '152.16.40.20',
472                         'netmask': '255.255.255.0',
473                         'gateway': '152.16.40.20',
474                         'if': 'xe1'
475                     },
476                 ],
477                 'description': 'VPE approximation using DPDK',
478                 'name': 'vpevnf-baremetal',
479                 'nd_route_tbl': [
480                     {
481                         'network': '0064:ff9b:0:0:0:0:9810:6414',
482                         'netmask': '112',
483                         'gateway': '0064:ff9b:0:0:0:0:9810:6414',
484                         'if': 'xe0'
485                     },
486                     {
487                         'network': '0064:ff9b:0:0:0:0:9810:2814',
488                         'netmask': '112',
489                         'gateway': '0064:ff9b:0:0:0:0:9810:2814',
490                         'if': 'xe1'
491                     },
492                 ],
493                 'id': 'vpevnf-baremetal',
494                 'external-interface': [
495                     {
496                         'virtual-interface': {
497                             'dst_mac': '00:00:00:00:00:03',
498                             'vpci': '0000:05:00.0',
499                             'driver': 'i40e',
500                             'local_ip': '152.16.100.19',
501                             'type': 'PCI-PASSTHROUGH',
502                             'netmask': '255.255.255.0',
503                             'dpdk_port_num': 0,
504                             'bandwidth': '10 Gbps',
505                             'dst_ip': '152.16.100.20',
506                             'local_mac': '00:00:00:00:00:01'
507                         },
508                         'vnfd-connection-point-ref': 'xe0',
509                         'name': 'xe0'
510                     },
511                     {
512                         'virtual-interface': {
513                             'dst_mac': '00:00:00:00:00:04',
514                             'vpci': '0000:05:00.1',
515                             'driver': 'ixgbe',
516                             'local_ip': '152.16.40.19',
517                             'type': 'PCI-PASSTHROUGH',
518                             'netmask': '255.255.255.0',
519                             'dpdk_port_num': 1,
520                             'bandwidth': '10 Gbps',
521                             'dst_ip': '152.16.40.20',
522                             'local_mac': '00:00:00:00:00:02'
523                         },
524                         'vnfd-connection-point-ref': 'xe1',
525                         'name': 'xe1'
526                     },
527                 ],
528             },
529         ],
530         'description': 'Vpe approximation using DPDK',
531         'mgmt-interface': {
532             'vdu-id': 'vpevnf-baremetal',
533             'host': '1.1.1.1',
534             'password': 'r00t',
535             'user': 'root',
536             'ip': '1.1.1.1'
537         },
538         'benchmark': {
539             'kpi': [
540                 'packets_in',
541                 'packets_fwd',
542                 'packets_dropped',
543             ],
544         },
545         'connection-point': [
546             {
547                 'type': 'VPORT',
548                 'name': 'xe0',
549             },
550             {
551                 'type': 'VPORT',
552                 'name': 'xe1',
553             },
554         ],
555         'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'
556     }
557
558     VNFD = {
559         'vnfd:vnfd-catalog': {
560             'vnfd': [
561                 VNFD_0,
562             ],
563         },
564     }
565
566     TRAFFIC_PROFILE = {
567         "schema": "isb:traffic_profile:0.1",
568         "name": "fixed",
569         "description": "Fixed traffic profile to run UDP traffic",
570         "traffic_profile": {
571             "traffic_type": "FixedTraffic",
572             "frame_rate": 100,  # pps
573             "flow_number": 10,
574             "frame_size": 64,
575         },
576     }
577
578     CONTEXT_CFG = {
579         'nodes': {
580             'tg__2': {
581                 'member-vnf-index': '3',
582                 'role': 'TrafficGen',
583                 'name': 'trafficgen_2.yardstick',
584                 'vnfd-id-ref': 'tg__2',
585                 'ip': '1.2.1.1',
586                 'interfaces': {
587                     'xe0': {
588                         'local_iface_name': 'ens513f0',
589                         'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK,
590                         'netmask': '255.255.255.0',
591                         'local_ip': '152.16.40.20',
592                         'dst_mac': '00:00:00:00:00:01',
593                         'local_mac': '00:00:00:00:00:03',
594                         'dst_ip': '152.16.40.19',
595                         'driver': 'ixgbe',
596                         'vpci': '0000:02:00.0',
597                         'dpdk_port_num': 0,
598                     },
599                     'xe1': {
600                         'local_iface_name': 'ens513f1',
601                         'netmask': '255.255.255.0',
602                         'network': '202.16.100.0',
603                         'local_ip': '202.16.100.20',
604                         'local_mac': '00:1e:67:d0:60:5d',
605                         'driver': 'ixgbe',
606                         'vpci': '0000:02:00.1',
607                         'dpdk_port_num': 1,
608                     },
609                 },
610                 'password': 'r00t',
611                 'VNF model': 'l3fwd_vnf.yaml',
612                 'user': 'root',
613             },
614             'tg__1': {
615                 'member-vnf-index': '1',
616                 'role': 'TrafficGen',
617                 'name': 'trafficgen_1.yardstick',
618                 'vnfd-id-ref': 'tg__1',
619                 'ip': '1.2.1.1',
620                 'interfaces': {
621                     'xe0': {
622                         'local_iface_name': 'ens785f0',
623                         'vld_id': prox_vnf.ProxApproxVnf.UPLINK,
624                         'netmask': '255.255.255.0',
625                         'local_ip': '152.16.100.20',
626                         'dst_mac': '00:00:00:00:00:02',
627                         'local_mac': '00:00:00:00:00:04',
628                         'dst_ip': '152.16.100.19',
629                         'driver': 'i40e',
630                         'vpci': '0000:05:00.0',
631                         'dpdk_port_num': 0,
632                     },
633                     'xe1': {
634                         'local_iface_name': 'ens785f1',
635                         'netmask': '255.255.255.0',
636                         'local_ip': '152.16.100.21',
637                         'local_mac': '00:00:00:00:00:01',
638                         'driver': 'i40e',
639                         'vpci': '0000:05:00.1',
640                         'dpdk_port_num': 1,
641                     },
642                 },
643                 'password': 'r00t',
644                 'VNF model': 'tg_rfc2544_tpl.yaml',
645                 'user': 'root',
646             },
647             'vnf__1': {
648                 'name': 'vnf.yardstick',
649                 'vnfd-id-ref': 'vnf__1',
650                 'ip': '1.2.1.1',
651                 'interfaces': {
652                     'xe0': {
653                         'local_iface_name': 'ens786f0',
654                         'vld_id': prox_vnf.ProxApproxVnf.UPLINK,
655                         'netmask': '255.255.255.0',
656                         'local_ip': '152.16.100.19',
657                         'dst_mac': '00:00:00:00:00:04',
658                         'local_mac': '00:00:00:00:00:02',
659                         'dst_ip': '152.16.100.20',
660                         'driver': 'i40e',
661                         'vpci': '0000:05:00.0',
662                         'dpdk_port_num': 0,
663                     },
664                     'xe1': {
665                         'local_iface_name': 'ens786f1',
666                         'vld_id': prox_vnf.ProxApproxVnf.DOWNLINK,
667                         'netmask': '255.255.255.0',
668                         'local_ip': '152.16.40.19',
669                         'dst_mac': '00:00:00:00:00:03',
670                         'local_mac': '00:00:00:00:00:01',
671                         'dst_ip': '152.16.40.20',
672                         'driver': 'i40e',
673                         'vpci': '0000:05:00.1',
674                         'dpdk_port_num': 1,
675                     },
676                 },
677                 'routing_table': [
678                     {
679                         'netmask': '255.255.255.0',
680                         'gateway': '152.16.100.20',
681                         'network': '152.16.100.20',
682                         'if': 'xe0',
683                     },
684                     {
685                         'netmask': '255.255.255.0',
686                         'gateway': '152.16.40.20',
687                         'network': '152.16.40.20',
688                         'if': 'xe1',
689                     },
690                 ],
691                 'member-vnf-index': '2',
692                 'host': '1.2.1.1',
693                 'role': 'vnf',
694                 'user': 'root',
695                 'nd_route_tbl': [
696                     {
697                         'netmask': '112',
698                         'gateway': '0064:ff9b:0:0:0:0:9810:6414',
699                         'network': '0064:ff9b:0:0:0:0:9810:6414',
700                         'if': 'xe0',
701                     },
702                     {
703                         'netmask': '112',
704                         'gateway': '0064:ff9b:0:0:0:0:9810:2814',
705                         'network': '0064:ff9b:0:0:0:0:9810:2814',
706                         'if': 'xe1',
707                     },
708                 ],
709                 'password': 'r00t',
710                 'VNF model': 'prox_vnf.yaml',
711             },
712         },
713     }
714
715
716     def test__check_status(self):
717         prox_irq_gen = ProxIrqGen('tg1', self.VNFD_0, 'task_id')
718
719         with self.assertRaises(NotImplementedError):
720             prox_irq_gen._check_status()
721
722     def test_listen_traffic(self):
723         prox_irq_gen = ProxIrqGen('tg1', self.VNFD_0, 'task_id')
724
725         prox_irq_gen.listen_traffic(mock.Mock())
726
727     def test_verify_traffic(self):
728         prox_irq_gen = ProxIrqGen('tg1', self.VNFD_0, 'task_id')
729
730         prox_irq_gen.verify_traffic(mock.Mock())
731
732     mock.patch('yardstick.network_services.vnf_generic.vnf.prox_helpers.socket')
733     @mock.patch(SSH_HELPER)
734     def test_terminate(self, ssh, *args):
735         mock_ssh(ssh)
736         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
737         prox_traffic_gen = ProxIrqGen(VNF_NAME, vnfd, 'task_id')
738         prox_traffic_gen._terminated = mock.MagicMock()
739         prox_traffic_gen._traffic_process = mock.MagicMock()
740         prox_traffic_gen._traffic_process.terminate = mock.Mock()
741         prox_traffic_gen.ssh_helper = mock.MagicMock()
742         prox_traffic_gen.setup_helper = mock.MagicMock()
743         prox_traffic_gen.resource_helper = mock.MagicMock()
744         prox_traffic_gen._vnf_wrapper.setup_helper = mock.MagicMock()
745         prox_traffic_gen._vnf_wrapper._vnf_process = mock.MagicMock()
746         prox_traffic_gen._vnf_wrapper.resource_helper = mock.MagicMock()
747         self.assertIsNone(prox_traffic_gen.terminate())
748
749     def test__wait_for_process(self):
750         prox_irq_gen = ProxIrqGen('tg1', self.VNFD_0, 'task_id')
751         with mock.patch.object(prox_irq_gen, '_check_status',
752                                return_value=0) as mock_status, \
753                 mock.patch.object(prox_irq_gen, '_tg_process') as mock_proc:
754             mock_proc.is_alive.return_value = True
755             mock_proc.exitcode = 234
756             self.assertEqual(prox_irq_gen._wait_for_process(), 234)
757             mock_proc.is_alive.assert_called_once()
758             mock_status.assert_called_once()
759
760     def test__wait_for_process_not_alive(self):
761         prox_irq_gen = ProxIrqGen('tg1', self.VNFD_0, 'task_id')
762         with mock.patch.object(prox_irq_gen, '_tg_process') as mock_proc:
763             mock_proc.is_alive.return_value = False
764             self.assertRaises(RuntimeError, prox_irq_gen._wait_for_process)
765             mock_proc.is_alive.assert_called_once()
766
767     def test__wait_for_process_delayed(self):
768         prox_irq_gen = ProxIrqGen('tg1', self.VNFD_0, 'task_id')
769         with mock.patch.object(prox_irq_gen, '_check_status',
770                                side_effect=[1, 0]) as mock_status, \
771                 mock.patch.object(prox_irq_gen,
772                                   '_tg_process') as mock_proc:
773             mock_proc.is_alive.return_value = True
774             mock_proc.exitcode = 234
775             self.assertEqual(prox_irq_gen._wait_for_process(), 234)
776             mock_proc.is_alive.assert_has_calls([mock.call(), mock.call()])
777             mock_status.assert_has_calls([mock.call(), mock.call()])
778
779     def test_scale(self):
780         prox_irq_gen = ProxIrqGen('tg1', self.VNFD_0, 'task_id')
781         self.assertRaises(y_exceptions.FunctionNotImplemented,
782                           prox_irq_gen.scale)
783
784     @mock.patch.object(ctx_base.Context, 'get_physical_node_from_server', return_value='mock_node')
785     @mock.patch(SSH_HELPER)
786     def test_collect_kpi(self, ssh, *args):
787         mock_ssh(ssh)
788
789         vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
790         resource_helper = mock.MagicMock()
791
792         core_1 = {'bucket_1': 1, 'bucket_2': 2, 'bucket_3': 3, 'bucket_4': 4, 'bucket_5': 5,
793                   'bucket_6': 6, 'bucket_7': 7, 'bucket_8': 8, 'bucket_9': 9, 'bucket_10': 10,
794                   'bucket_11': 11, 'bucket_12': 12, 'bucket_0': 100, 'cpu': 1, 'max_irq': 12,
795                   'overflow': 10}
796         core_2 = {'bucket_1': 1, 'bucket_2': 2, 'bucket_3': 3, 'bucket_4': 4, 'bucket_5': 5,
797                   'bucket_6': 0, 'bucket_7': 0, 'bucket_8': 0, 'bucket_9': 0, 'bucket_10': 0,
798                   'bucket_11': 0, 'bucket_12': 0, 'bucket_0': 100, 'cpu': 2, 'max_irq': 12,
799                   'overflow': 10}
800
801         irq_data = {'core_1': core_1, 'core_2': core_2}
802         resource_helper.sut.irq_core_stats.return_value = (irq_data)
803
804         build_config_file = mock.MagicMock()
805         build_config_file.return_value = None
806
807         prox_irq_gen = ProxIrqGen(VNF_NAME, vnfd, 'task_id')
808
809         startup = ["global", [["eal", "-4"]]]
810         master_0 = ["core 0", [["mode", "master"]]]
811         core_1 = ["core 1", [["mode", "irq"]]]
812         core_2 = ["core 2", [["mode", "irq"], ["task", "2"]]]
813
814         prox_irq_gen.setup_helper._prox_config_data = \
815             [startup, master_0, core_1, core_2]
816
817         prox_irq_gen.scenario_helper.scenario_cfg = self.SCENARIO_CFG
818         prox_irq_gen.resource_helper = resource_helper
819         prox_irq_gen.setup_helper.build_config_file = build_config_file
820
821         result = prox_irq_gen.collect_kpi()
822         self.assertDictEqual(result["collect_stats"], {})
823
824         result = prox_irq_gen.collect_kpi()
825         self.assertFalse('bucket_10' in result["collect_stats"]['core_2'])
826         self.assertFalse('bucket_11' in result["collect_stats"]['core_2'])
827         self.assertFalse('bucket_12' in result["collect_stats"]['core_2'])
828         self.assertEqual(result["collect_stats"]['core_2']['max_irq'], 12)