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