1 # Copyright (c) 2019 Viosoft 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.
18 from yardstick.network_services.vnf_generic.vnf.base import VnfdHelper
19 from yardstick.network_services.vnf_generic.vnf.vpp_helpers import \
23 class TestVppSetupEnvHelper(unittest.TestCase):
42 "description": "VPP IPsec",
43 "id": "VipsecApproxVnf",
48 "vdu-id": "ipsecvnf-baremetal"
51 "short-name": "IpsecVnf",
54 "description": "VPP Ipsec",
55 "external-interface": [
58 "virtual-interface": {
60 "dst_ip": "192.168.100.1",
61 "dst_mac": "90:e2:ba:7c:30:e8",
63 "local_ip": "192.168.100.2",
64 "local_mac": "90:e2:ba:7c:41:a8",
65 "netmask": "255.255.255.0",
67 "node_name": "vnf__0",
72 "dst_ip": "192.168.100.2",
73 "dst_mac": "90:e2:ba:7c:41:a8",
75 "local_ip": "192.168.100.1",
76 "local_mac": "90:e2:ba:7c:30:e8",
77 "netmask": "255.255.255.0",
81 "peer_name": "vnf__0",
83 "vpci": "0000:81:00.0"
87 "vpci": "0000:ff:06.0"
89 "vnfd-connection-point-ref": "xe0"
93 "virtual-interface": {
96 "dst_mac": "0a:b1:ec:fd:a2:66",
98 "local_ip": "1.1.1.1",
99 "local_mac": "4e:90:85:d3:c5:13",
100 "netmask": "255.255.255.0",
102 "node_name": "vnf__0",
103 "peer_ifname": "xe1",
107 "dst_mac": "4e:90:85:d3:c5:13",
109 "local_ip": "1.1.1.2",
110 "local_mac": "0a:b1:ec:fd:a2:66",
111 "netmask": "255.255.255.0",
113 "node_name": "vnf__1",
114 "peer_ifname": "xe1",
115 "peer_name": "vnf__0",
116 "vld_id": "ciphertext",
117 "vpci": "0000:00:07.0"
119 "peer_name": "vnf__1",
120 "vld_id": "ciphertext",
121 "vpci": "0000:ff:07.0"
123 "vnfd-connection-point-ref": "xe1"
126 "id": "ipsecvnf-baremetal",
127 "name": "ipsecvnf-baremetal",
134 'vnfd:vnfd-catalog': {
141 VPP_INTERFACES_DUMP = [
144 "sup_sw_if_index": 0,
145 "l2_address_length": 0,
146 "l2_address": [0, 0, 0, 0, 0, 0, 0, 0],
147 "interface_name": "local0",
155 "sub_number_of_tags": 0,
156 "sub_outer_vlan_id": 0,
157 "sub_inner_vlan_id": 0,
158 "sub_exact_match": 0,
160 "sub_outer_vlan_id_any": 0,
161 "sub_inner_vlan_id_any": 0,
169 "sup_sw_if_index": 1,
170 "l2_address_length": 6,
171 "l2_address": [144, 226, 186, 124, 65, 168, 0, 0],
172 "interface_name": "TenGigabitEthernetff/6/0",
180 "sub_number_of_tags": 0,
181 "sub_outer_vlan_id": 0,
182 "sub_inner_vlan_id": 0,
183 "sub_exact_match": 0,
185 "sub_outer_vlan_id_any": 0,
186 "sub_inner_vlan_id_any": 0,
194 "sup_sw_if_index": 2,
195 "l2_address_length": 6,
196 "l2_address": [78, 144, 133, 211, 197, 19, 0, 0],
197 "interface_name": "VirtualFunctionEthernetff/7/0",
205 "sub_number_of_tags": 0,
206 "sub_outer_vlan_id": 0,
207 "sub_inner_vlan_id": 0,
208 "sub_exact_match": 0,
210 "sub_outer_vlan_id_any": 0,
211 "sub_inner_vlan_id_any": 0,
219 def test_kill_vnf(self):
220 vnfd_helper = VnfdHelper(self.VNFD_0)
221 ssh_helper = mock.Mock()
222 ssh_helper.execute.return_value = 0, 0, 0
223 scenario_helper = mock.Mock()
224 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
226 vpp_setup_env_helper.kill_vnf()
228 def test_kill_vnf_error(self):
229 vnfd_helper = VnfdHelper(self.VNFD_0)
230 ssh_helper = mock.Mock()
231 ssh_helper.execute.return_value = 1, 0, 0
232 scenario_helper = mock.Mock()
233 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
235 with self.assertRaises(RuntimeError) as raised:
236 vpp_setup_env_helper.kill_vnf()
238 self.assertIn('Failed to stop service vpp', str(raised.exception))
240 def test_tear_down(self):
241 vnfd_helper = VnfdHelper(self.VNFD_0)
242 ssh_helper = mock.Mock()
243 scenario_helper = mock.Mock()
244 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
246 vpp_setup_env_helper.tear_down()
248 def test_start_vpp_service(self):
249 vnfd_helper = VnfdHelper(self.VNFD_0)
250 ssh_helper = mock.Mock()
251 ssh_helper.execute.return_value = 0, 0, 0
252 scenario_helper = mock.Mock()
253 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
255 vpp_setup_env_helper.start_vpp_service()
257 def test_start_vpp_service_error(self):
258 vnfd_helper = VnfdHelper(self.VNFD_0)
259 ssh_helper = mock.Mock()
260 ssh_helper.execute.return_value = 1, 0, 0
261 scenario_helper = mock.Mock()
262 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
264 with self.assertRaises(RuntimeError) as raised:
265 vpp_setup_env_helper.start_vpp_service()
267 self.assertIn('Failed to start service vpp', str(raised.exception))
269 def test__update_vnfd_helper(self):
270 vnfd_helper = VnfdHelper(self.VNFD_0)
271 ssh_helper = mock.Mock()
272 scenario_helper = mock.Mock()
273 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
275 vpp_setup_env_helper._update_vnfd_helper(
276 {'vpp-data': {'vpp-key': 'vpp-value'}})
278 self.assertEqual({'vpp-key': 'vpp-value'},
279 vpp_setup_env_helper.vnfd_helper.get('vpp-data', {}))
281 def test__update_vnfd_helper_with_key(self):
282 vnfd_helper = VnfdHelper(self.VNFD_0)
283 ssh_helper = mock.Mock()
284 scenario_helper = mock.Mock()
285 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
287 vpp_setup_env_helper._update_vnfd_helper({'driver': 'qat'}, 'xe0')
289 self.assertEqual('qat',
290 vpp_setup_env_helper.get_value_by_interface_key(
293 def test__update_vnfd_helper_dict_without_key(self):
294 vnfd_helper = VnfdHelper(self.VNFD_0)
295 ssh_helper = mock.Mock()
296 scenario_helper = mock.Mock()
297 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
299 vpp_setup_env_helper._update_vnfd_helper(
300 {'mgmt-interface': {'name': 'net'}})
302 self.assertEqual({'ip': '10.10.10.101',
306 'vdu-id': 'ipsecvnf-baremetal'},
307 vpp_setup_env_helper.vnfd_helper.get('mgmt-interface',
310 def test_get_value_by_interface_key(self):
311 vnfd_helper = VnfdHelper(self.VNFD_0)
312 ssh_helper = mock.Mock()
314 scenario_helper = mock.Mock()
315 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
317 vpp_setup_env_helper._update_vnfd_helper(
318 {'vpp-data': {'vpp-key': 'vpp-value'}}, 'xe0')
320 self.assertEqual({'vpp-key': 'vpp-value'},
321 vpp_setup_env_helper.get_value_by_interface_key(
324 def test_get_value_by_interface_key_error(self):
325 vnfd_helper = VnfdHelper(self.VNFD_0)
326 ssh_helper = mock.Mock()
328 scenario_helper = mock.Mock()
329 vpp_setup_env_helper = VppSetupEnvHelper(vnfd_helper, ssh_helper,
331 vpp_setup_env_helper._update_vnfd_helper(
332 {'vpp-data': {'vpp-key': 'vpp-value'}}, 'xe0')
334 self.assertIsNone(vpp_setup_env_helper.get_value_by_interface_key(