add yardstick iruya 9.0.0 release notes
[yardstick.git] / yardstick / tests / unit / network_services / traffic_profile / test_fixed.py
1 # Copyright (c) 2016-2017 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
16 import mock
17 import unittest
18
19 from yardstick.tests import STL_MOCKS
20
21 STLClient = mock.MagicMock()
22 stl_patch = mock.patch.dict("sys.modules", STL_MOCKS)
23 stl_patch.start()
24
25 if stl_patch:
26     from yardstick.network_services.traffic_profile.base import TrafficProfile
27     from yardstick.network_services.traffic_profile.fixed import FixedProfile
28
29
30 class TestFixedProfile(unittest.TestCase):
31     TRAFFIC_PROFILE = {
32         "schema": "isb:traffic_profile:0.1",
33         "name": "fixed",
34         "description": "Fixed traffic profile to run UDP traffic",
35         "traffic_profile": {
36             "traffic_type": "FixedTraffic",
37             "frame_rate": 100,  # pps
38             "flow_number": 10,
39             "frame_size": 64}}
40
41     VNFD = {'vnfd:vnfd-catalog':
42             {'vnfd':
43              [{'short-name': 'VpeVnf',
44                'vdu':
45                [{'routing_table':
46                  [{'network': '152.16.100.20',
47                    'netmask': '255.255.255.0',
48                    'gateway': '152.16.100.20',
49                    'if': 'xe0'},
50                   {'network': '152.16.40.20',
51                    'netmask': '255.255.255.0',
52                    'gateway': '152.16.40.20',
53                    'if': 'xe1'}],
54                  'description': 'VPE approximation using DPDK',
55                  'name': 'vpevnf-baremetal',
56                  'nd_route_tbl':
57                  [{'network': '0064:ff9b:0:0:0:0:9810:6414',
58                    'netmask': '112',
59                    'gateway': '0064:ff9b:0:0:0:0:9810:6414',
60                    'if': 'xe0'},
61                   {'network': '0064:ff9b:0:0:0:0:9810:2814',
62                    'netmask': '112',
63                    'gateway': '0064:ff9b:0:0:0:0:9810:2814',
64                    'if': 'xe1'}],
65                  'id': 'vpevnf-baremetal',
66                  'external-interface':
67                  [{'virtual-interface':
68                    {'dst_mac': '00:00:00:00:00:04',
69                     'vpci': '0000:05:00.0',
70                     'local_ip': '152.16.100.19',
71                     'type': 'PCI-PASSTHROUGH',
72                     'netmask': '255.255.255.0',
73                     'dpdk_port_num': 0,
74                     'bandwidth': '10 Gbps',
75                     'dst_ip': '152.16.100.20',
76                     'local_mac': '00:00:00:00:00:01'},
77                    'vnfd-connection-point-ref': 'xe0',
78                    'name': 'xe0'},
79                   {'virtual-interface':
80                    {'dst_mac': '00:00:00:00:00:03',
81                     'vpci': '0000:05:00.1',
82                     'local_ip': '152.16.40.19',
83                     'type': 'PCI-PASSTHROUGH',
84                     'netmask': '255.255.255.0',
85                     'dpdk_port_num': 1,
86                     'bandwidth': '10 Gbps',
87                     'dst_ip': '152.16.40.20',
88                     'local_mac': '00:00:00:00:00:02'},
89                    'vnfd-connection-point-ref': 'xe1',
90                    'name': 'xe1'}]}],
91                'description': 'Vpe approximation using DPDK',
92                'mgmt-interface':
93                    {'vdu-id': 'vpevnf-baremetal',
94                     'host': '1.1.1.1',
95                     'password': 'r00t',
96                     'user': 'root',
97                     'ip': '1.1.1.1'},
98                'benchmark':
99                    {'kpi': ['packets_in', 'packets_fwd', 'packets_dropped']},
100                'connection-point': [{'type': 'VPORT', 'name': 'xe0'},
101                                     {'type': 'VPORT', 'name': 'xe1'}],
102                'id': 'VpeApproxVnf', 'name': 'VPEVnfSsh'}]}}
103
104     def test___init__(self):
105         fixed_profile = FixedProfile(self.TRAFFIC_PROFILE)
106         self.assertIsNotNone(fixed_profile)
107
108     def test_execute(self):
109         traffic_generator = mock.Mock(autospec=TrafficProfile)
110         traffic_generator.my_ports = [0, 1]
111         traffic_generator.vnfd = self.VNFD['vnfd:vnfd-catalog']['vnfd'][0]
112         traffic_generator.client = \
113             mock.Mock(return_value=True)
114         fixed_profile = FixedProfile(self.TRAFFIC_PROFILE)
115         fixed_profile.params = self.TRAFFIC_PROFILE
116         fixed_profile.first_run = True
117         self.assertIsNone(fixed_profile.execute(traffic_generator))