3 # Copyright (c) 2016-2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # Unittest for yardstick.benchmark.scenarios.networking.test_vnf_generic
20 from __future__ import absolute_import
27 from yardstick.benchmark.scenarios.networking.vnf_generic import \
28 SshManager, NetworkServiceTestCase, IncorrectConfig, \
29 IncorrectSetup, open_relative_file
30 from yardstick.network_services.collector.subscriber import Collector
31 from yardstick.network_services.vnf_generic.vnf.base import \
32 GenericTrafficGen, GenericVNF
35 'stl': mock.MagicMock(),
36 'stl.trex_stl_lib': mock.MagicMock(),
37 'stl.trex_stl_lib.base64': mock.MagicMock(),
38 'stl.trex_stl_lib.binascii': mock.MagicMock(),
39 'stl.trex_stl_lib.collections': mock.MagicMock(),
40 'stl.trex_stl_lib.copy': mock.MagicMock(),
41 'stl.trex_stl_lib.datetime': mock.MagicMock(),
42 'stl.trex_stl_lib.functools': mock.MagicMock(),
43 'stl.trex_stl_lib.imp': mock.MagicMock(),
44 'stl.trex_stl_lib.inspect': mock.MagicMock(),
45 'stl.trex_stl_lib.json': mock.MagicMock(),
46 'stl.trex_stl_lib.linecache': mock.MagicMock(),
47 'stl.trex_stl_lib.math': mock.MagicMock(),
48 'stl.trex_stl_lib.os': mock.MagicMock(),
49 'stl.trex_stl_lib.platform': mock.MagicMock(),
50 'stl.trex_stl_lib.pprint': mock.MagicMock(),
51 'stl.trex_stl_lib.random': mock.MagicMock(),
52 'stl.trex_stl_lib.re': mock.MagicMock(),
53 'stl.trex_stl_lib.scapy': mock.MagicMock(),
54 'stl.trex_stl_lib.socket': mock.MagicMock(),
55 'stl.trex_stl_lib.string': mock.MagicMock(),
56 'stl.trex_stl_lib.struct': mock.MagicMock(),
57 'stl.trex_stl_lib.sys': mock.MagicMock(),
58 'stl.trex_stl_lib.threading': mock.MagicMock(),
59 'stl.trex_stl_lib.time': mock.MagicMock(),
60 'stl.trex_stl_lib.traceback': mock.MagicMock(),
61 'stl.trex_stl_lib.trex_stl_async_client': mock.MagicMock(),
62 'stl.trex_stl_lib.trex_stl_client': mock.MagicMock(),
63 'stl.trex_stl_lib.trex_stl_exceptions': mock.MagicMock(),
64 'stl.trex_stl_lib.trex_stl_ext': mock.MagicMock(),
65 'stl.trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(),
66 'stl.trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(),
67 'stl.trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(),
68 'stl.trex_stl_lib.trex_stl_port': mock.MagicMock(),
69 'stl.trex_stl_lib.trex_stl_stats': mock.MagicMock(),
70 'stl.trex_stl_lib.trex_stl_streams': mock.MagicMock(),
71 'stl.trex_stl_lib.trex_stl_types': mock.MagicMock(),
72 'stl.trex_stl_lib.types': mock.MagicMock(),
73 'stl.trex_stl_lib.utils': mock.MagicMock(),
74 'stl.trex_stl_lib.utils.argparse': mock.MagicMock(),
75 'stl.trex_stl_lib.utils.collections': mock.MagicMock(),
76 'stl.trex_stl_lib.utils.common': mock.MagicMock(),
77 'stl.trex_stl_lib.utils.json': mock.MagicMock(),
78 'stl.trex_stl_lib.utils.os': mock.MagicMock(),
79 'stl.trex_stl_lib.utils.parsing_opts': mock.MagicMock(),
80 'stl.trex_stl_lib.utils.pwd': mock.MagicMock(),
81 'stl.trex_stl_lib.utils.random': mock.MagicMock(),
82 'stl.trex_stl_lib.utils.re': mock.MagicMock(),
83 'stl.trex_stl_lib.utils.string': mock.MagicMock(),
84 'stl.trex_stl_lib.utils.sys': mock.MagicMock(),
85 'stl.trex_stl_lib.utils.text_opts': mock.MagicMock(),
86 'stl.trex_stl_lib.utils.text_tables': mock.MagicMock(),
87 'stl.trex_stl_lib.utils.texttable': mock.MagicMock(),
88 'stl.trex_stl_lib.warnings': mock.MagicMock(),
89 'stl.trex_stl_lib.yaml': mock.MagicMock(),
90 'stl.trex_stl_lib.zlib': mock.MagicMock(),
91 'stl.trex_stl_lib.zmq': mock.MagicMock(),
94 COMPLETE_TREX_VNFD = {
95 'vnfd:vnfd-catalog': {
102 'tx_throughput_mbps',
103 'rx_throughput_mbps',
104 'tx_throughput_pc_linerate',
105 'rx_throughput_pc_linerate',
111 'connection-point': [
121 'description': 'TRex stateless traffic generator for RFC2544',
122 'id': 'TrexTrafficGen',
127 'vdu-id': 'trexgen-baremetal',
130 'short-name': 'trexgen',
131 'class-name': 'TrexTrafficGen',
134 'description': 'TRex stateless traffic generator for RFC2544',
135 'external-interface': [
138 'virtual-interface': {
139 'bandwidth': '10 Gbps',
141 'dst_mac': '00:01:02:03:04:05',
142 'local_ip': '1.1.1.2',
143 'local_mac': '00:01:02:03:05:05',
144 'type': 'PCI-PASSTHROUGH',
145 'netmask': "255.255.255.0",
147 'vpci': '0000:00:10.2',
149 'vnfd-connection-point-ref': 'xe0',
153 'virtual-interface': {
154 'bandwidth': '10 Gbps',
156 'dst_mac': '00:01:02:03:04:06',
157 'local_ip': '2.1.1.2',
158 'local_mac': '00:01:02:03:05:06',
159 'type': 'PCI-PASSTHROUGH',
160 'netmask': "255.255.255.0",
162 'vpci': '0000:00:10.1',
164 'vnfd-connection-point-ref': 'xe1',
167 'id': 'trexgen-baremetal',
168 'name': 'trexgen-baremetal',
177 28: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP \
178 group default qlen 1000
179 link/ether 90:e2:ba:a7:6a:c8 brd ff:ff:ff:ff:ff:ff
180 inet 1.1.1.1/8 brd 1.255.255.255 scope global eth1
181 inet6 fe80::92e2:baff:fea7:6ac8/64 scope link
182 valid_lft forever preferred_lft forever
183 29: eth5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP \
184 group default qlen 1000
185 link/ether 90:e2:ba:a7:6a:c9 brd ff:ff:ff:ff:ff:ff
186 inet 2.1.1.1/8 brd 2.255.255.255 scope global eth5
187 inet6 fe80::92e2:baff:fea7:6ac9/64 scope link tentative
188 valid_lft forever preferred_lft forever
192 lrwxrwxrwx 1 root root 0 sie 10 14:16 eth1 -> \
193 ../../devices/pci0000:80/0000:80:02.2/0000:84:00.1/net/eth1
194 lrwxrwxrwx 1 root root 0 sie 3 10:37 eth2 -> \
195 ../../devices/pci0000:00/0000:00:01.1/0000:84:00.2/net/eth5
199 "schema": "isb:traffic_profile:0.1",
201 "description": "Fixed traffic profile to run UDP traffic",
203 "traffic_type": "FixedTraffic",
204 "frame_rate": 100, # pps
211 class TestNetworkServiceTestCase(unittest.TestCase):
215 'name': 'trafficgen_1.yardstick',
217 'role': 'TrafficGen',
222 'netmask': '255.255.255.0',
223 'local_ip': '152.16.100.20',
224 'local_mac': '00:00:00:00:00:01',
226 'vpci': '0000:07:00.0',
230 'netmask': '255.255.255.0',
231 'local_ip': '152.16.40.20',
232 'local_mac': '00:00:00:00:00:02',
234 'vpci': '0000:07:00.1',
241 'name': 'vnf.yardstick',
243 'host': '10.223.197.164',
249 'netmask': '255.255.255.0',
250 'local_ip': '152.16.100.19',
251 'local_mac': '00:00:00:00:00:03',
253 'vpci': '0000:07:00.0',
257 'netmask': '255.255.255.0',
258 'local_ip': '152.16.40.19',
259 'local_mac': '00:00:00:00:00:04',
261 'vpci': '0000:07:00.1',
267 'netmask': '255.255.255.0',
268 'gateway': '152.16.100.20',
269 'network': '152.16.100.20',
273 'netmask': '255.255.255.0',
274 'gateway': '152.16.40.20',
275 'network': '152.16.40.20',
282 'gateway': '0064:ff9b:0:0:0:0:9810:6414',
283 'network': '0064:ff9b:0:0:0:0:9810:6414',
288 'gateway': '0064:ff9b:0:0:0:0:9810:2814',
289 'network': '0064:ff9b:0:0:0:0:9810:2814',
298 'vnf__1': self.vnf__1,
311 'vnfd-connection-point-ref': [
313 'vnfd-connection-point-ref': 'xe0',
314 'member-vnf-index-ref': '1',
315 'vnfd-id-ref': 'trexgen'
318 'vnfd-connection-point-ref': 'xe0',
319 'member-vnf-index-ref': '2',
320 'vnfd-id-ref': 'trexgen'
325 'name': 'tg__1 to vnf__1 link 1'
329 'vnfd-connection-point-ref': [
331 'vnfd-connection-point-ref': 'xe1',
332 'member-vnf-index-ref': '1',
333 'vnfd-id-ref': 'trexgen'
336 'vnfd-connection-point-ref': 'xe1',
337 'member-vnf-index-ref': '2',
338 'vnfd-id-ref': 'trexgen'
343 'name': 'vnf__1 to tg__1 link 2'
347 'id': 'trex-tg-topology',
348 'short-name': 'trex-tg-topology',
349 'name': 'trex-tg-topology',
350 'description': 'trex-tg-topology',
351 'constituent-vnfd': [
353 'member-vnf-index': '1',
354 'VNF model': 'tg_trex_tpl.yaml',
355 'vnfd-id-ref': 'tg__1',
358 'member-vnf-index': '2',
359 'VNF model': 'tg_trex_tpl.yaml',
360 'vnfd-id-ref': 'vnf__1',
363 'vld': [self.vld0, self.vld1],
366 self.scenario_cfg = {
368 "topology": self._get_file_abspath("vpe_vnf_topology.yaml"),
369 'task_id': 'a70bdf4a-8e67-47a3-9dc1-273c14506eb7',
370 'tc': 'tc_ipv4_1Mflow_64B_packetsize',
371 'traffic_profile': 'ipv4_throughput_vpe.yaml',
375 'allowed_drop_rate': '0.8 - 1',
379 'object': 'NetworkServiceTestCase',
381 'output_filename': 'yardstick.out',
387 'flow': 'ipv4_1flow_Packets_vpe.yaml',
388 'imix': 'imix_voice.yaml'
391 'tg__2': 'trafficgen_2.yardstick',
392 'tg__1': 'trafficgen_1.yardstick',
393 'vnf__1': 'vnf.yardstick',
397 self.s = NetworkServiceTestCase(self.scenario_cfg, self.context_cfg)
399 def _get_file_abspath(self, filename):
400 curr_path = os.path.dirname(os.path.abspath(__file__))
401 file_path = os.path.join(curr_path, filename)
404 def test_ssh_manager(self):
405 with mock.patch("yardstick.ssh.SSH") as ssh:
406 ssh_mock = mock.Mock(autospec=ssh.SSH)
408 mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
409 ssh.from_node.return_value = ssh_mock
410 for node, node_dict in self.context_cfg["nodes"].items():
411 with SshManager(node_dict) as conn:
412 self.assertIsNotNone(conn)
414 def test___init__(self):
417 def test___get_traffic_flow(self):
418 self.scenario_cfg["traffic_options"]["flow"] = \
419 self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml")
420 result = {'flow': {'dstip4_range': '152.40.0.20',
421 'srcip4_range': '152.16.0.20', 'count': 1}}
422 self.assertEqual(result, self.s._get_traffic_flow())
424 def test___get_traffic_flow_error(self):
425 self.scenario_cfg["traffic_options"]["flow"] = \
426 "ipv4_1flow_Packets_vpe.yaml1"
427 self.assertEqual({}, self.s._get_traffic_flow())
429 def test_get_vnf_imp(self):
430 vnfd = COMPLETE_TREX_VNFD['vnfd:vnfd-catalog']['vnfd'][0]['class-name']
431 with mock.patch.dict("sys.modules", STL_MOCKS):
432 self.assertIsNotNone(self.s.get_vnf_impl(vnfd))
434 with self.assertRaises(IncorrectConfig) as raised:
435 self.s.get_vnf_impl('NonExistentClass')
437 exc_str = str(raised.exception)
439 self.assertIn('No implementation', exc_str)
440 self.assertIn('found in', exc_str)
442 def test_load_vnf_models_invalid(self):
443 self.context_cfg["nodes"]['tg__1']['VNF model'] = \
444 self._get_file_abspath("tg_trex_tpl.yaml")
445 self.context_cfg["nodes"]['vnf__1']['VNF model'] = \
446 self._get_file_abspath("tg_trex_tpl.yaml")
448 vnf = mock.Mock(autospec=GenericVNF)
449 self.s.get_vnf_impl = mock.Mock(return_value=vnf)
451 self.assertIsNotNone(
452 self.s.load_vnf_models(self.scenario_cfg, self.context_cfg))
454 def test_map_topology_to_infrastructure(self):
455 with mock.patch("yardstick.ssh.SSH") as ssh:
456 ssh_mock = mock.Mock(autospec=ssh.SSH)
458 mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
459 ssh.from_node.return_value = ssh_mock
460 self.s.map_topology_to_infrastructure()
462 nodes = self.context_cfg["nodes"]
463 self.assertEqual("../../vnf_descriptors/tg_rfc2544_tpl.yaml", nodes['tg__1']['VNF model'])
464 self.assertEqual("../../vnf_descriptors/vpe_vnf.yaml", nodes['vnf__1']['VNF model'])
466 def test_map_topology_to_infrastructure_insufficient_nodes(self):
467 del self.context_cfg['nodes']['vnf__1']
468 with mock.patch("yardstick.ssh.SSH") as ssh:
469 ssh_mock = mock.Mock(autospec=ssh.SSH)
471 mock.Mock(return_value=(1, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
472 ssh.from_node.return_value = ssh_mock
474 with self.assertRaises(IncorrectSetup):
475 self.s.map_topology_to_infrastructure()
477 def test_map_topology_to_infrastructure_config_invalid(self):
478 cfg = dict(self.context_cfg)
479 del cfg['nodes']['vnf__1']['interfaces']['xe0']['local_mac']
480 with mock.patch("yardstick.ssh.SSH") as ssh:
481 ssh_mock = mock.Mock(autospec=ssh.SSH)
483 mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
484 ssh.from_node.return_value = ssh_mock
486 with self.assertRaises(IncorrectConfig):
487 self.s.map_topology_to_infrastructure()
489 def test__resolve_topology_invalid_config(self):
490 with mock.patch("yardstick.ssh.SSH") as ssh:
491 ssh_mock = mock.Mock(autospec=ssh.SSH)
493 mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
494 ssh.from_node.return_value = ssh_mock
496 # purge an important key from the data structure
497 for interface in self.tg__1['interfaces'].values():
498 del interface['local_mac']
501 "yardstick.benchmark.scenarios.networking.vnf_generic.LOG") as mock_log:
502 with self.assertRaises(IncorrectConfig) as raised:
503 self.s._resolve_topology()
505 self.assertIn('not found', str(raised.exception))
508 for index, interface in enumerate(self.tg__1['interfaces'].values()):
509 interface['local_mac'] = '00:00:00:00:00:{:2x}'.format(index)
511 # make a connection point ref with 3 points
512 self.s.topology["vld"][0]['vnfd-connection-point-ref'].append(
513 self.s.topology["vld"][0]['vnfd-connection-point-ref'][0])
516 "yardstick.benchmark.scenarios.networking.vnf_generic.LOG") as mock_log:
517 with self.assertRaises(IncorrectConfig) as raised:
518 self.s._resolve_topology()
520 self.assertIn('wrong endpoint count', str(raised.exception))
522 # make a connection point ref with 1 point
523 self.s.topology["vld"][0]['vnfd-connection-point-ref'] = \
524 self.s.topology["vld"][0]['vnfd-connection-point-ref'][:1]
527 "yardstick.benchmark.scenarios.networking.vnf_generic.LOG") as mock_log:
528 with self.assertRaises(IncorrectConfig) as raised:
529 self.s._resolve_topology()
531 self.assertIn('wrong endpoint count', str(raised.exception))
534 tgen = mock.Mock(autospec=GenericTrafficGen)
535 tgen.traffic_finished = True
536 verified_dict = {"verified": True}
537 tgen.verify_traffic = lambda x: verified_dict
538 tgen.name = "tgen__1"
539 vnf = mock.Mock(autospec=GenericVNF)
540 vnf.runs_traffic = False
541 self.s.vnfs = [tgen, vnf]
542 self.s.traffic_profile = mock.Mock()
543 self.s.collector = mock.Mock(autospec=Collector)
544 self.s.collector.get_kpi = \
545 mock.Mock(return_value={tgen.name: verified_dict})
548 self.assertDictEqual(result, {tgen.name: verified_dict})
550 def test_setup(self):
551 with mock.patch("yardstick.ssh.SSH") as ssh:
552 ssh_mock = mock.Mock(autospec=ssh.SSH)
554 mock.Mock(return_value=(0, SYS_CLASS_NET + IP_ADDR_SHOW, ""))
555 ssh.from_node.return_value = ssh_mock
557 tgen = mock.Mock(autospec=GenericTrafficGen)
558 tgen.traffic_finished = True
559 verified_dict = {"verified": True}
560 tgen.verify_traffic = lambda x: verified_dict
561 tgen.terminate = mock.Mock(return_value=True)
562 tgen.name = "tgen__1"
563 vnf = mock.Mock(autospec=GenericVNF)
564 vnf.runs_traffic = False
565 vnf.terminate = mock.Mock(return_value=True)
566 self.s.vnfs = [tgen, vnf]
567 self.s.traffic_profile = mock.Mock()
568 self.s.collector = mock.Mock(autospec=Collector)
569 self.s.collector.get_kpi = \
570 mock.Mock(return_value={tgen.name: verified_dict})
571 self.s.map_topology_to_infrastructure = mock.Mock(return_value=0)
572 self.s.load_vnf_models = mock.Mock(return_value=self.s.vnfs)
573 self.s._fill_traffic_profile = \
574 mock.Mock(return_value=TRAFFIC_PROFILE)
575 self.assertEqual(None, self.s.setup())
577 def test__get_traffic_profile(self):
578 self.scenario_cfg["traffic_profile"] = \
579 self._get_file_abspath("ipv4_throughput_vpe.yaml")
580 self.assertIsNotNone(self.s._get_traffic_profile())
582 def test__get_traffic_profile_exception(self):
583 with mock.patch.dict(self.scenario_cfg, {'traffic_profile': ''}):
584 with self.assertRaises(IOError):
585 self.s._get_traffic_profile()
587 def test___get_traffic_imix_exception(self):
588 with mock.patch.dict(self.scenario_cfg["traffic_options"], {'imix': ''}):
589 self.assertEqual({}, self.s._get_traffic_imix())
591 def test__fill_traffic_profile(self):
592 with mock.patch.dict("sys.modules", STL_MOCKS):
593 self.scenario_cfg["traffic_profile"] = \
594 self._get_file_abspath("ipv4_throughput_vpe.yaml")
595 self.scenario_cfg["traffic_options"]["flow"] = \
596 self._get_file_abspath("ipv4_1flow_Packets_vpe.yaml")
597 self.scenario_cfg["traffic_options"]["imix"] = \
598 self._get_file_abspath("imix_voice.yaml")
599 self.assertIsNotNone(self.s._fill_traffic_profile())
601 def test_teardown(self):
602 vnf = mock.Mock(autospec=GenericVNF)
604 mock.Mock(return_value=True)
606 self.s.traffic_profile = mock.Mock()
607 self.s.collector = mock.Mock(autospec=Collector)
608 self.s.collector.stop = \
609 mock.Mock(return_value=True)
610 self.assertIsNone(self.s.teardown())
614 'address': '0a:de:ad:be:ef:f5',
618 'interface_name': 'enp11s0',
620 'pci_bus_id': '0000:0b:00.0',
621 'subsystem_device': '0x1533',
622 'subsystem_vendor': '0x15d9',
626 'address': '0a:de:ad:be:ef:f4',
630 'interface_name': 'lan',
632 'pci_bus_id': '0000:00:19.0',
633 'subsystem_device': '0x153a',
634 'subsystem_vendor': '0x15d9',
639 SAMPLE_VM_NETDEVS = {
641 'address': 'fa:de:ad:be:ef:5b',
643 'driver': 'virtio_net',
645 'interface_name': 'eth1',
647 'pci_bus_id': '0000:00:04.0',
652 def test_parse_netdev_info(self):
654 /sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/ifindex:2
655 /sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/address:0a:de:ad:be:ef:f5
656 /sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/operstate:down
657 /sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/vendor:0x8086
658 /sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/device:0x1533
659 /sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/subsystem_vendor:0x15d9
660 /sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/device/subsystem_device:0x1533
661 /sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/driver:igb
662 /sys/devices/pci0000:00/0000:00:1c.3/0000:0b:00.0/net/enp11s0/pci_bus_id:0000:0b:00.0
663 /sys/devices/pci0000:00/0000:00:19.0/net/lan/ifindex:3
664 /sys/devices/pci0000:00/0000:00:19.0/net/lan/address:0a:de:ad:be:ef:f4
665 /sys/devices/pci0000:00/0000:00:19.0/net/lan/operstate:up
666 /sys/devices/pci0000:00/0000:00:19.0/net/lan/device/vendor:0x8086
667 /sys/devices/pci0000:00/0000:00:19.0/net/lan/device/device:0x153a
668 /sys/devices/pci0000:00/0000:00:19.0/net/lan/device/subsystem_vendor:0x15d9
669 /sys/devices/pci0000:00/0000:00:19.0/net/lan/device/subsystem_device:0x153a
670 /sys/devices/pci0000:00/0000:00:19.0/net/lan/driver:e1000e
671 /sys/devices/pci0000:00/0000:00:19.0/net/lan/pci_bus_id:0000:00:19.0
673 res = NetworkServiceTestCase.parse_netdev_info(output)
674 assert res == self.SAMPLE_NETDEVS
676 def test_parse_netdev_info_virtio(self):
678 /sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/ifindex:3
679 /sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/address:fa:de:ad:be:ef:5b
680 /sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/operstate:down
681 /sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/device/vendor:0x1af4
682 /sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/device/device:0x0001
683 /sys/devices/pci0000:00/0000:00:04.0/virtio1/net/eth1/driver:virtio_net
685 res = NetworkServiceTestCase.parse_netdev_info(output)
686 assert res == self.SAMPLE_VM_NETDEVS
688 def test_sort_dpdk_port_num(self):
689 netdevs = self.SAMPLE_NETDEVS.copy()
690 NetworkServiceTestCase._sort_dpdk_port_num(netdevs)
691 assert netdevs['lan']['dpdk_port_num'] == 0
692 assert netdevs['enp11s0']['dpdk_port_num'] == 1
694 def test_probe_missing_values(self):
695 netdevs = self.SAMPLE_NETDEVS.copy()
696 network = {'local_mac': '0a:de:ad:be:ef:f5'}
697 NetworkServiceTestCase._probe_missing_values(netdevs, network, set())
698 assert network['vpci'] == '0000:0b:00.0'
700 network = {'local_mac': '0a:de:ad:be:ef:f4'}
701 NetworkServiceTestCase._probe_missing_values(netdevs, network, set())
702 assert network['vpci'] == '0000:00:19.0'
704 def test_open_relative_path(self):
705 mock_open = mock.mock_open()
706 mock_open_result = mock_open()
707 mock_open_call_count = 1 # initial call to get result
710 'yardstick.benchmark.scenarios.networking.vnf_generic.open'
713 with mock.patch(module_name, mock_open, create=True):
714 self.assertEqual(open_relative_file('foo', 'bar'), mock_open_result)
716 mock_open_call_count += 1 # one more call expected
717 self.assertEqual(mock_open.call_count, mock_open_call_count)
718 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
719 self.assertNotIn('bar', mock_open.call_args_list[-1][0][0])
721 def open_effect(*args, **kwargs):
722 if kwargs.get('name', args[0]) == os.path.join('bar', 'foo'):
723 return mock_open_result
724 raise IOError(errno.ENOENT, 'not found')
726 mock_open.side_effect = open_effect
727 self.assertEqual(open_relative_file('foo', 'bar'), mock_open_result)
729 mock_open_call_count += 2 # two more calls expected
730 self.assertEqual(mock_open.call_count, mock_open_call_count)
731 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
732 self.assertIn('bar', mock_open.call_args_list[-1][0][0])
734 # test an IOError of type ENOENT
735 mock_open.side_effect = IOError(errno.ENOENT, 'not found')
736 with self.assertRaises(IOError):
737 # the second call still raises
738 open_relative_file('foo', 'bar')
740 mock_open_call_count += 2 # two more calls expected
741 self.assertEqual(mock_open.call_count, mock_open_call_count)
742 self.assertIn('foo', mock_open.call_args_list[-1][0][0])
743 self.assertIn('bar', mock_open.call_args_list[-1][0][0])
745 # test an IOError other than ENOENT
746 mock_open.side_effect = IOError(errno.EBUSY, 'busy')
747 with self.assertRaises(IOError):
748 open_relative_file('foo', 'bar')
750 mock_open_call_count += 1 # one more call expected
751 self.assertEqual(mock_open.call_count, mock_open_call_count)