blob: 5eb23f074f4993d17d8a21d38de9a1e41843f64c [file] [log] [blame]
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +00001# -*- coding: utf-8 -*-
2
3##
4# Copyright 2017 Intel Corporation.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17#
18# For those usages not covered by the Apache License, Version 2.0 please
19# contact with: nfvlabs@tid.es
20##
21
22"""
23This module contains unit tests for the OpenStack VIM connector
24Run this directly with python2 or python3.
25"""
26
27import copy
28import unittest
29
30import mock
31from neutronclient.v2_0.client import Client
32
33from osm_ro import vimconn
34from osm_ro.vimconn_openstack import vimconnector
35
36
37__author__ = "Igor D.C."
38__date__ = "$23-aug-2017 23:59:59$"
39
40
41class TestSfcOperations(unittest.TestCase):
42 def setUp(self):
43 # instantiate dummy VIM connector so we can test it
44 self.vimconn = vimconnector(
45 '123', 'openstackvim', '456', '789', 'http://dummy.url', None,
46 'user', 'pass')
47
anwars50e43042018-09-28 16:00:13 +053048 def _test_new_sfi(self, create_sfc_port_pair, sfc_encap,
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +000049 ingress_ports=['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
50 egress_ports=['230cdf1b-de37-4891-bc07-f9010cf1f967']):
51 # input to VIM connector
52 name = 'osm_sfi'
53 # + ingress_ports
54 # + egress_ports
55 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
anwars50e43042018-09-28 16:00:13 +053056 correlation = 'nsh'
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +000057 if sfc_encap is not None:
58 if not sfc_encap:
59 correlation = None
60
61 # what OpenStack is assumed to respond (patch OpenStack's return value)
62 dict_from_neutron = {'port_pair': {
63 'id': '3d7ddc13-923c-4332-971e-708ed82902ce',
64 'name': name,
65 'description': '',
66 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
67 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
68 'ingress': ingress_ports[0] if len(ingress_ports) else None,
69 'egress': egress_ports[0] if len(egress_ports) else None,
70 'service_function_parameters': {'correlation': correlation}
71 }}
anwars50e43042018-09-28 16:00:13 +053072 create_sfc_port_pair.return_value = dict_from_neutron
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +000073
74 # what the VIM connector is expected to
75 # send to OpenStack based on the input
76 dict_to_neutron = {'port_pair': {
77 'name': name,
78 'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
79 'egress': '230cdf1b-de37-4891-bc07-f9010cf1f967',
80 'service_function_parameters': {'correlation': correlation}
81 }}
82
83 # call the VIM connector
84 if sfc_encap is None:
85 result = self.vimconn.new_sfi(name, ingress_ports, egress_ports)
86 else:
87 result = self.vimconn.new_sfi(name, ingress_ports, egress_ports,
88 sfc_encap)
89
90 # assert that the VIM connector made the expected call to OpenStack
anwars50e43042018-09-28 16:00:13 +053091 create_sfc_port_pair.assert_called_with(dict_to_neutron)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +000092 # assert that the VIM connector had the expected result / return value
93 self.assertEqual(result, dict_from_neutron['port_pair']['id'])
94
anwars50e43042018-09-28 16:00:13 +053095 def _test_new_sf(self, create_sfc_port_pair_group):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +000096 # input to VIM connector
97 name = 'osm_sf'
98 instances = ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd',
99 '12ba215e-3987-4892-bd3a-d0fd91eecf98',
100 'e25a7c79-14c8-469a-9ae1-f601c9371ffd']
101
102 # what OpenStack is assumed to respond (patch OpenStack's return value)
103 dict_from_neutron = {'port_pair_group': {
104 'id': '3d7ddc13-923c-4332-971e-708ed82902ce',
105 'name': name,
106 'description': '',
107 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
108 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
109 'port_pairs': instances,
110 'group_id': 1,
111 'port_pair_group_parameters': {
112 "lb_fields": [],
113 "ppg_n_tuple_mapping": {
114 "ingress_n_tuple": {},
115 "egress_n_tuple": {}
116 }}
117 }}
anwars50e43042018-09-28 16:00:13 +0530118 create_sfc_port_pair_group.return_value = dict_from_neutron
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000119
120 # what the VIM connector is expected to
121 # send to OpenStack based on the input
122 dict_to_neutron = {'port_pair_group': {
123 'name': name,
124 'port_pairs': ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd',
125 '12ba215e-3987-4892-bd3a-d0fd91eecf98',
126 'e25a7c79-14c8-469a-9ae1-f601c9371ffd']
127 }}
128
129 # call the VIM connector
130 result = self.vimconn.new_sf(name, instances)
131
132 # assert that the VIM connector made the expected call to OpenStack
anwars50e43042018-09-28 16:00:13 +0530133 create_sfc_port_pair_group.assert_called_with(dict_to_neutron)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000134 # assert that the VIM connector had the expected result / return value
135 self.assertEqual(result, dict_from_neutron['port_pair_group']['id'])
136
anwars50e43042018-09-28 16:00:13 +0530137 def _test_new_sfp(self, create_sfc_port_chain, sfc_encap, spi):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000138 # input to VIM connector
139 name = 'osm_sfp'
140 classifications = ['2bd2a2e5-c5fd-4eac-a297-d5e255c35c19',
141 '00f23389-bdfa-43c2-8b16-5815f2582fa8']
142 sfs = ['2314daec-c262-414a-86e3-69bb6fa5bc16',
143 'd8bfdb5d-195e-4f34-81aa-6135705317df']
144
145 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
anwars50e43042018-09-28 16:00:13 +0530146 correlation = 'nsh'
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000147 chain_id = 33
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000148 if spi:
149 chain_id = spi
150
151 # what OpenStack is assumed to respond (patch OpenStack's return value)
152 dict_from_neutron = {'port_chain': {
153 'id': '5bc05721-079b-4b6e-a235-47cac331cbb6',
154 'name': name,
155 'description': '',
156 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
157 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
158 'chain_id': chain_id,
159 'flow_classifiers': classifications,
160 'port_pair_groups': sfs,
161 'chain_parameters': {'correlation': correlation}
162 }}
anwars50e43042018-09-28 16:00:13 +0530163 create_sfc_port_chain.return_value = dict_from_neutron
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000164
165 # what the VIM connector is expected to
166 # send to OpenStack based on the input
167 dict_to_neutron = {'port_chain': {
168 'name': name,
169 'flow_classifiers': ['2bd2a2e5-c5fd-4eac-a297-d5e255c35c19',
170 '00f23389-bdfa-43c2-8b16-5815f2582fa8'],
171 'port_pair_groups': ['2314daec-c262-414a-86e3-69bb6fa5bc16',
172 'd8bfdb5d-195e-4f34-81aa-6135705317df'],
173 'chain_parameters': {'correlation': correlation}
174 }}
175 if spi:
176 dict_to_neutron['port_chain']['chain_id'] = spi
177
178 # call the VIM connector
179 if sfc_encap is None:
180 if spi is None:
181 result = self.vimconn.new_sfp(name, classifications, sfs)
182 else:
183 result = self.vimconn.new_sfp(name, classifications, sfs,
184 spi=spi)
185 else:
186 if spi is None:
187 result = self.vimconn.new_sfp(name, classifications, sfs,
188 sfc_encap)
189 else:
190 result = self.vimconn.new_sfp(name, classifications, sfs,
191 sfc_encap, spi)
192
193 # assert that the VIM connector made the expected call to OpenStack
anwars50e43042018-09-28 16:00:13 +0530194 create_sfc_port_chain.assert_called_with(dict_to_neutron)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000195 # assert that the VIM connector had the expected result / return value
196 self.assertEqual(result, dict_from_neutron['port_chain']['id'])
197
anwars50e43042018-09-28 16:00:13 +0530198 def _test_new_classification(self, create_sfc_flow_classifier, ctype):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000199 # input to VIM connector
200 name = 'osm_classification'
201 definition = {'ethertype': 'IPv4',
202 'logical_source_port':
203 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
204 'protocol': 'tcp',
205 'source_ip_prefix': '192.168.2.0/24',
206 'source_port_range_max': 99,
207 'source_port_range_min': 50}
208
209 # what OpenStack is assumed to respond (patch OpenStack's return value)
210 dict_from_neutron = {'flow_classifier': copy.copy(definition)}
211 dict_from_neutron['flow_classifier'][
212 'id'] = '7735ec2c-fddf-4130-9712-32ed2ab6a372'
213 dict_from_neutron['flow_classifier']['name'] = name
214 dict_from_neutron['flow_classifier']['description'] = ''
215 dict_from_neutron['flow_classifier'][
216 'tenant_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c'
217 dict_from_neutron['flow_classifier'][
218 'project_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c'
anwars50e43042018-09-28 16:00:13 +0530219 create_sfc_flow_classifier.return_value = dict_from_neutron
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000220
221 # what the VIM connector is expected to
222 # send to OpenStack based on the input
223 dict_to_neutron = {'flow_classifier': copy.copy(definition)}
224 dict_to_neutron['flow_classifier']['name'] = 'osm_classification'
225
226 # call the VIM connector
227 result = self.vimconn.new_classification(name, ctype, definition)
228
229 # assert that the VIM connector made the expected call to OpenStack
anwars50e43042018-09-28 16:00:13 +0530230 create_sfc_flow_classifier.assert_called_with(dict_to_neutron)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000231 # assert that the VIM connector had the expected result / return value
232 self.assertEqual(result, dict_from_neutron['flow_classifier']['id'])
233
anwars50e43042018-09-28 16:00:13 +0530234 @mock.patch.object(Client, 'create_sfc_flow_classifier')
235 def test_new_classification(self, create_sfc_flow_classifier):
236 self._test_new_classification(create_sfc_flow_classifier,
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000237 'legacy_flow_classifier')
238
anwars50e43042018-09-28 16:00:13 +0530239 @mock.patch.object(Client, 'create_sfc_flow_classifier')
240 def test_new_classification_unsupported_type(self, create_sfc_flow_classifier):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000241 self.assertRaises(vimconn.vimconnNotSupportedException,
242 self._test_new_classification,
anwars50e43042018-09-28 16:00:13 +0530243 create_sfc_flow_classifier, 'h265')
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000244
anwars50e43042018-09-28 16:00:13 +0530245 @mock.patch.object(Client, 'create_sfc_port_pair')
246 def test_new_sfi_with_sfc_encap(self, create_sfc_port_pair):
247 self._test_new_sfi(create_sfc_port_pair, True)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000248
anwars50e43042018-09-28 16:00:13 +0530249 @mock.patch.object(Client, 'create_sfc_port_pair')
250 def test_new_sfi_without_sfc_encap(self, create_sfc_port_pair):
251 self._test_new_sfi(create_sfc_port_pair, False)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000252
anwars50e43042018-09-28 16:00:13 +0530253 @mock.patch.object(Client, 'create_sfc_port_pair')
254 def test_new_sfi_default_sfc_encap(self, create_sfc_port_pair):
255 self._test_new_sfi(create_sfc_port_pair, None)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000256
anwars50e43042018-09-28 16:00:13 +0530257 @mock.patch.object(Client, 'create_sfc_port_pair')
258 def test_new_sfi_bad_ingress_ports(self, create_sfc_port_pair):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000259 ingress_ports = ['5311c75d-d718-4369-bbda-cdcc6da60fcc',
260 'a0273f64-82c9-11e7-b08f-6328e53f0fa7']
261 self.assertRaises(vimconn.vimconnNotSupportedException,
262 self._test_new_sfi,
anwars50e43042018-09-28 16:00:13 +0530263 create_sfc_port_pair, True, ingress_ports=ingress_ports)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000264 ingress_ports = []
265 self.assertRaises(vimconn.vimconnNotSupportedException,
266 self._test_new_sfi,
anwars50e43042018-09-28 16:00:13 +0530267 create_sfc_port_pair, True, ingress_ports=ingress_ports)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000268
anwars50e43042018-09-28 16:00:13 +0530269 @mock.patch.object(Client, 'create_sfc_port_pair')
270 def test_new_sfi_bad_egress_ports(self, create_sfc_port_pair):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000271 egress_ports = ['230cdf1b-de37-4891-bc07-f9010cf1f967',
272 'b41228fe-82c9-11e7-9b44-17504174320b']
273 self.assertRaises(vimconn.vimconnNotSupportedException,
274 self._test_new_sfi,
anwars50e43042018-09-28 16:00:13 +0530275 create_sfc_port_pair, True, egress_ports=egress_ports)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000276 egress_ports = []
277 self.assertRaises(vimconn.vimconnNotSupportedException,
278 self._test_new_sfi,
anwars50e43042018-09-28 16:00:13 +0530279 create_sfc_port_pair, True, egress_ports=egress_ports)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000280
281 @mock.patch.object(vimconnector, 'get_sfi')
anwars50e43042018-09-28 16:00:13 +0530282 @mock.patch.object(Client, 'create_sfc_port_pair_group')
283 def test_new_sf(self, create_sfc_port_pair_group, get_sfi):
284 get_sfi.return_value = {'sfc_encap': True}
285 self._test_new_sf(create_sfc_port_pair_group)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000286
287 @mock.patch.object(vimconnector, 'get_sfi')
anwars50e43042018-09-28 16:00:13 +0530288 @mock.patch.object(Client, 'create_sfc_port_pair_group')
289 def test_new_sf_inconsistent_sfc_encap(self, create_sfc_port_pair_group,
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000290 get_sfi):
291 get_sfi.return_value = {'sfc_encap': 'nsh'}
292 self.assertRaises(vimconn.vimconnNotSupportedException,
anwars50e43042018-09-28 16:00:13 +0530293 self._test_new_sf, create_sfc_port_pair_group)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000294
anwars50e43042018-09-28 16:00:13 +0530295 @mock.patch.object(Client, 'create_sfc_port_chain')
296 def test_new_sfp_with_sfc_encap(self, create_sfc_port_chain):
297 self._test_new_sfp(create_sfc_port_chain, True, None)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000298
anwars50e43042018-09-28 16:00:13 +0530299 @mock.patch.object(Client, 'create_sfc_port_chain')
300 def test_new_sfp_without_sfc_encap(self, create_sfc_port_chain):
301 self._test_new_sfp(create_sfc_port_chain, False, None)
302 self._test_new_sfp(create_sfc_port_chain, False, 25)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000303
anwars50e43042018-09-28 16:00:13 +0530304 @mock.patch.object(Client, 'create_sfc_port_chain')
305 def test_new_sfp_default_sfc_encap(self, create_sfc_port_chain):
306 self._test_new_sfp(create_sfc_port_chain, None, None)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000307
anwars50e43042018-09-28 16:00:13 +0530308 @mock.patch.object(Client, 'create_sfc_port_chain')
309 def test_new_sfp_with_sfc_encap_spi(self, create_sfc_port_chain):
310 self._test_new_sfp(create_sfc_port_chain, True, 25)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000311
anwars50e43042018-09-28 16:00:13 +0530312 @mock.patch.object(Client, 'create_sfc_port_chain')
313 def test_new_sfp_default_sfc_encap_spi(self, create_sfc_port_chain):
314 self._test_new_sfp(create_sfc_port_chain, None, 25)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000315
anwars50e43042018-09-28 16:00:13 +0530316 @mock.patch.object(Client, 'list_sfc_flow_classifiers')
317 def test_get_classification_list(self, list_sfc_flow_classifiers):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000318 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530319 list_sfc_flow_classifiers.return_value = {'flow_classifiers': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000320 {'source_port_range_min': 2000,
321 'destination_ip_prefix': '192.168.3.0/24',
322 'protocol': 'udp',
323 'description': '',
324 'ethertype': 'IPv4',
325 'l7_parameters': {},
326 'source_port_range_max': 2000,
327 'destination_port_range_min': 3000,
328 'source_ip_prefix': '192.168.2.0/24',
329 'logical_destination_port': None,
330 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
331 'destination_port_range_max': None,
332 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
333 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
334 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
335 'name': 'fc1'}]}
336
337 # call the VIM connector
338 filter_dict = {'protocol': 'tcp', 'ethertype': 'IPv4'}
339 result = self.vimconn.get_classification_list(filter_dict.copy())
340
341 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530342 list_sfc_flow_classifiers.assert_called_with(**filter_dict)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000343 # assert that the VIM connector successfully
344 # translated and returned the OpenStack result
345 self.assertEqual(result, [
346 {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
347 'name': 'fc1',
348 'description': '',
349 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
350 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
351 'ctype': 'legacy_flow_classifier',
352 'definition': {
353 'source_port_range_min': 2000,
354 'destination_ip_prefix': '192.168.3.0/24',
355 'protocol': 'udp',
356 'ethertype': 'IPv4',
357 'l7_parameters': {},
358 'source_port_range_max': 2000,
359 'destination_port_range_min': 3000,
360 'source_ip_prefix': '192.168.2.0/24',
361 'logical_destination_port': None,
362 'destination_port_range_max': None,
363 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'}
364 }])
365
366 def _test_get_sfi_list(self, list_port_pair, correlation, sfc_encap):
367 # what OpenStack is assumed to return to the VIM connector
368 list_port_pair.return_value = {'port_pairs': [
369 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
370 'description': '',
371 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
372 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
373 'service_function_parameters': {'correlation': correlation},
374 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
375 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
376 'name': 'osm_sfi'}]}
377
378 # call the VIM connector
379 filter_dict = {'name': 'osm_sfi', 'description': ''}
380 result = self.vimconn.get_sfi_list(filter_dict.copy())
381
382 # assert that VIM connector called OpenStack with the expected filter
383 list_port_pair.assert_called_with(**filter_dict)
384 # assert that the VIM connector successfully
385 # translated and returned the OpenStack result
386 self.assertEqual(result, [
387 {'ingress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
388 'description': '',
389 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
390 'egress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
391 'sfc_encap': sfc_encap,
392 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
393 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
394 'name': 'osm_sfi'}])
395
anwars50e43042018-09-28 16:00:13 +0530396 @mock.patch.object(Client, 'list_sfc_port_pairs')
397 def test_get_sfi_list_with_sfc_encap(self, list_sfc_port_pairs):
398 self._test_get_sfi_list(list_sfc_port_pairs, 'nsh', True)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000399
anwars50e43042018-09-28 16:00:13 +0530400 @mock.patch.object(Client, 'list_sfc_port_pairs')
401 def test_get_sfi_list_without_sfc_encap(self, list_sfc_port_pairs):
402 self._test_get_sfi_list(list_sfc_port_pairs, None, False)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000403
anwars50e43042018-09-28 16:00:13 +0530404 @mock.patch.object(Client, 'list_sfc_port_pair_groups')
405 def test_get_sf_list(self, list_sfc_port_pair_groups):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000406 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530407 list_sfc_port_pair_groups.return_value = {'port_pair_groups': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000408 {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
409 '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
410 'description': '',
411 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
412 'port_pair_group_parameters': {},
413 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
414 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
415 'name': 'osm_sf'}]}
416
417 # call the VIM connector
418 filter_dict = {'name': 'osm_sf', 'description': ''}
419 result = self.vimconn.get_sf_list(filter_dict.copy())
420
421 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530422 list_sfc_port_pair_groups.assert_called_with(**filter_dict)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000423 # assert that the VIM connector successfully
424 # translated and returned the OpenStack result
425 self.assertEqual(result, [
anwars50e43042018-09-28 16:00:13 +0530426 {'sfis': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000427 '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
428 'description': '',
429 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
430 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
431 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
432 'name': 'osm_sf'}])
433
anwars50e43042018-09-28 16:00:13 +0530434 def _test_get_sfp_list(self, list_sfc_port_chains, correlation, sfc_encap):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000435 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530436 list_sfc_port_chains.return_value = {'port_chains': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000437 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25',
438 '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'],
439 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e',
440 '1387ab44-82d7-11e7-9bb0-476337183905'],
441 'description': '',
442 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
443 'chain_parameters': {'correlation': correlation},
444 'chain_id': 40,
445 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
446 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
447 'name': 'osm_sfp'}]}
448
449 # call the VIM connector
450 filter_dict = {'name': 'osm_sfp', 'description': ''}
451 result = self.vimconn.get_sfp_list(filter_dict.copy())
452
453 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530454 list_sfc_port_chains.assert_called_with(**filter_dict)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000455 # assert that the VIM connector successfully
456 # translated and returned the OpenStack result
457 self.assertEqual(result, [
458 {'service_functions': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25',
459 '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'],
460 'classifications': ['1333c2f4-82d7-11e7-a5df-9327f33d104e',
461 '1387ab44-82d7-11e7-9bb0-476337183905'],
462 'description': '',
463 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
464 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
465 'sfc_encap': sfc_encap,
466 'spi': 40,
467 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
468 'name': 'osm_sfp'}])
469
anwars50e43042018-09-28 16:00:13 +0530470 @mock.patch.object(Client, 'list_sfc_port_chains')
471 def test_get_sfp_list_with_sfc_encap(self, list_sfc_port_chains):
472 self._test_get_sfp_list(list_sfc_port_chains, 'nsh', True)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000473
anwars50e43042018-09-28 16:00:13 +0530474 @mock.patch.object(Client, 'list_sfc_port_chains')
475 def test_get_sfp_list_without_sfc_encap(self, list_sfc_port_chains):
476 self._test_get_sfp_list(list_sfc_port_chains, None, False)
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000477
anwars50e43042018-09-28 16:00:13 +0530478 @mock.patch.object(Client, 'list_sfc_flow_classifiers')
479 def test_get_classification(self, list_sfc_flow_classifiers):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000480 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530481 list_sfc_flow_classifiers.return_value = {'flow_classifiers': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000482 {'source_port_range_min': 2000,
483 'destination_ip_prefix': '192.168.3.0/24',
484 'protocol': 'udp',
485 'description': '',
486 'ethertype': 'IPv4',
487 'l7_parameters': {},
488 'source_port_range_max': 2000,
489 'destination_port_range_min': 3000,
490 'source_ip_prefix': '192.168.2.0/24',
491 'logical_destination_port': None,
492 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
493 'destination_port_range_max': None,
494 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
495 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
496 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
497 'name': 'fc1'}
498 ]}
499
500 # call the VIM connector
501 result = self.vimconn.get_classification(
502 '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d')
503
504 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530505 list_sfc_flow_classifiers.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000506 id='22198366-d4e8-4d6b-b4d2-637d5d6cbb7d')
507 # assert that VIM connector successfully returned the OpenStack result
508 self.assertEqual(result,
509 {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
510 'name': 'fc1',
511 'description': '',
512 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
513 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
514 'ctype': 'legacy_flow_classifier',
515 'definition': {
516 'source_port_range_min': 2000,
517 'destination_ip_prefix': '192.168.3.0/24',
518 'protocol': 'udp',
519 'ethertype': 'IPv4',
520 'l7_parameters': {},
521 'source_port_range_max': 2000,
522 'destination_port_range_min': 3000,
523 'source_ip_prefix': '192.168.2.0/24',
524 'logical_destination_port': None,
525 'destination_port_range_max': None,
526 'logical_source_port':
527 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'}
528 })
529
anwars50e43042018-09-28 16:00:13 +0530530 @mock.patch.object(Client, 'list_sfc_flow_classifiers')
531 def test_get_classification_many_results(self, list_sfc_flow_classifiers):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000532 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530533 list_sfc_flow_classifiers.return_value = {'flow_classifiers': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000534 {'source_port_range_min': 2000,
535 'destination_ip_prefix': '192.168.3.0/24',
536 'protocol': 'udp',
537 'description': '',
538 'ethertype': 'IPv4',
539 'l7_parameters': {},
540 'source_port_range_max': 2000,
541 'destination_port_range_min': 3000,
542 'source_ip_prefix': '192.168.2.0/24',
543 'logical_destination_port': None,
544 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
545 'destination_port_range_max': None,
546 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
547 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
548 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
549 'name': 'fc1'},
550 {'source_port_range_min': 1000,
551 'destination_ip_prefix': '192.168.3.0/24',
552 'protocol': 'udp',
553 'description': '',
554 'ethertype': 'IPv4',
555 'l7_parameters': {},
556 'source_port_range_max': 1000,
557 'destination_port_range_min': 3000,
558 'source_ip_prefix': '192.168.2.0/24',
559 'logical_destination_port': None,
560 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
561 'destination_port_range_max': None,
562 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
563 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
564 'id': '3196bafc-82dd-11e7-a205-9bf6c14b0721',
565 'name': 'fc2'}
566 ]}
567
568 # call the VIM connector
569 self.assertRaises(vimconn.vimconnConflictException,
570 self.vimconn.get_classification,
571 '3196bafc-82dd-11e7-a205-9bf6c14b0721')
572
573 # assert the VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530574 list_sfc_flow_classifiers.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000575 id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
576
anwars50e43042018-09-28 16:00:13 +0530577 @mock.patch.object(Client, 'list_sfc_flow_classifiers')
578 def test_get_classification_no_results(self, list_sfc_flow_classifiers):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000579 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530580 list_sfc_flow_classifiers.return_value = {'flow_classifiers': []}
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000581
582 # call the VIM connector
583 self.assertRaises(vimconn.vimconnNotFoundException,
584 self.vimconn.get_classification,
585 '3196bafc-82dd-11e7-a205-9bf6c14b0721')
586
587 # assert the VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530588 list_sfc_flow_classifiers.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000589 id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
590
anwars50e43042018-09-28 16:00:13 +0530591 @mock.patch.object(Client, 'list_sfc_port_pairs')
592 def test_get_sfi(self, list_sfc_port_pairs):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000593 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530594 list_sfc_port_pairs.return_value = {'port_pairs': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000595 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
596 'description': '',
597 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
598 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
599 'service_function_parameters': {'correlation': 'nsh'},
600 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
601 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
602 'name': 'osm_sfi1'},
603 ]}
604
605 # call the VIM connector
606 result = self.vimconn.get_sfi('c121ebdd-7f2d-4213-b933-3325298a6966')
607
608 # assert the VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530609 list_sfc_port_pairs.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000610 id='c121ebdd-7f2d-4213-b933-3325298a6966')
611 # assert the VIM connector successfully returned the OpenStack result
612 self.assertEqual(result,
613 {'ingress_ports': [
614 '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
615 'egress_ports': [
616 '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
617 'sfc_encap': True,
618 'description': '',
619 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
620 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
621 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
622 'name': 'osm_sfi1'})
623
anwars50e43042018-09-28 16:00:13 +0530624 @mock.patch.object(Client, 'list_sfc_port_pairs')
625 def test_get_sfi_many_results(self, list_sfc_port_pairs):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000626 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530627 list_sfc_port_pairs.return_value = {'port_pairs': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000628 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
629 'description': '',
630 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
631 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
632 'service_function_parameters': {'correlation': 'nsh'},
633 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
634 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
635 'name': 'osm_sfi1'},
636 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
637 'description': '',
638 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
639 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
640 'service_function_parameters': {'correlation': 'nsh'},
641 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
642 'id': 'c0436d92-82db-11e7-8f9c-5fa535f1261f',
643 'name': 'osm_sfi2'}
644 ]}
645
646 # call the VIM connector
647 self.assertRaises(vimconn.vimconnConflictException,
648 self.vimconn.get_sfi,
649 'c0436d92-82db-11e7-8f9c-5fa535f1261f')
650
651 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530652 list_sfc_port_pairs.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000653 id='c0436d92-82db-11e7-8f9c-5fa535f1261f')
654
anwars50e43042018-09-28 16:00:13 +0530655 @mock.patch.object(Client, 'list_sfc_port_pairs')
656 def test_get_sfi_no_results(self, list_sfc_port_pairs):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000657 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530658 list_sfc_port_pairs.return_value = {'port_pairs': []}
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000659
660 # call the VIM connector
661 self.assertRaises(vimconn.vimconnNotFoundException,
662 self.vimconn.get_sfi,
663 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
664
665 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530666 list_sfc_port_pairs.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000667 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
668
anwars50e43042018-09-28 16:00:13 +0530669 @mock.patch.object(Client, 'list_sfc_port_pair_groups')
670 def test_get_sf(self, list_sfc_port_pair_groups):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000671 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530672 list_sfc_port_pair_groups.return_value = {'port_pair_groups': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000673 {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
674 'description': '',
675 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
676 'port_pair_group_parameters': {},
677 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
678 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
679 'name': 'osm_sf1'}
680 ]}
681
682 # call the VIM connector
683 result = self.vimconn.get_sf('b22892fc-82d9-11e7-ae85-0fea6a3b3757')
684
685 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530686 list_sfc_port_pair_groups.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000687 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
688 # assert that VIM connector successfully returned the OpenStack result
689 self.assertEqual(result,
anwars50e43042018-09-28 16:00:13 +0530690 {'description': '',
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000691 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
692 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
anwars50e43042018-09-28 16:00:13 +0530693 'sfis': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000694 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
695 'name': 'osm_sf1'})
696
anwars50e43042018-09-28 16:00:13 +0530697 @mock.patch.object(Client, 'list_sfc_port_pair_groups')
698 def test_get_sf_many_results(self, list_sfc_port_pair_groups):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000699 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530700 list_sfc_port_pair_groups.return_value = {'port_pair_groups': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000701 {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
702 'description': '',
703 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
704 'port_pair_group_parameters': {},
705 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
706 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
707 'name': 'osm_sf1'},
708 {'port_pairs': ['0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
709 'description': '',
710 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
711 'port_pair_group_parameters': {},
712 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
713 'id': 'b22892fc-82d9-11e7-ae85-0fea6a3b3757',
714 'name': 'osm_sf2'}
715 ]}
716
717 # call the VIM connector
718 self.assertRaises(vimconn.vimconnConflictException,
719 self.vimconn.get_sf,
720 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
721
722 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530723 list_sfc_port_pair_groups.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000724 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
725
anwars50e43042018-09-28 16:00:13 +0530726 @mock.patch.object(Client, 'list_sfc_port_pair_groups')
727 def test_get_sf_no_results(self, list_sfc_port_pair_groups):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000728 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530729 list_sfc_port_pair_groups.return_value = {'port_pair_groups': []}
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000730
731 # call the VIM connector
732 self.assertRaises(vimconn.vimconnNotFoundException,
733 self.vimconn.get_sf,
734 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
735
736 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530737 list_sfc_port_pair_groups.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000738 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
739
anwars50e43042018-09-28 16:00:13 +0530740 @mock.patch.object(Client, 'list_sfc_port_chains')
741 def test_get_sfp(self, list_sfc_port_chains):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000742 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530743 list_sfc_port_chains.return_value = {'port_chains': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000744 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
745 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
746 'description': '',
747 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
748 'chain_parameters': {'correlation': 'nsh'},
749 'chain_id': 40,
750 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
751 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
752 'name': 'osm_sfp1'}]}
753
754 # call the VIM connector
755 result = self.vimconn.get_sfp('821bc9be-82d7-11e7-8ce3-23a08a27ab47')
756
757 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530758 list_sfc_port_chains.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000759 id='821bc9be-82d7-11e7-8ce3-23a08a27ab47')
760 # assert that VIM connector successfully returned the OpenStack result
761 self.assertEqual(result,
762 {'service_functions': [
763 '7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
764 'classifications': [
765 '1333c2f4-82d7-11e7-a5df-9327f33d104e'],
766 'description': '',
767 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
768 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
769 'sfc_encap': True,
770 'spi': 40,
771 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
772 'name': 'osm_sfp1'})
773
anwars50e43042018-09-28 16:00:13 +0530774 @mock.patch.object(Client, 'list_sfc_port_chains')
775 def test_get_sfp_many_results(self, list_sfc_port_chains):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000776 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530777 list_sfc_port_chains.return_value = {'port_chains': [
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000778 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
779 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
780 'description': '',
781 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
782 'chain_parameters': {'correlation': 'nsh'},
783 'chain_id': 40,
784 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
785 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
786 'name': 'osm_sfp1'},
787 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
788 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
789 'description': '',
790 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
791 'chain_parameters': {'correlation': 'nsh'},
792 'chain_id': 50,
793 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
794 'id': '5d002f38-82de-11e7-a770-f303f11ce66a',
795 'name': 'osm_sfp2'}
796 ]}
797
798 # call the VIM connector
799 self.assertRaises(vimconn.vimconnConflictException,
800 self.vimconn.get_sfp,
801 '5d002f38-82de-11e7-a770-f303f11ce66a')
802
803 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530804 list_sfc_port_chains.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000805 id='5d002f38-82de-11e7-a770-f303f11ce66a')
806
anwars50e43042018-09-28 16:00:13 +0530807 @mock.patch.object(Client, 'list_sfc_port_chains')
808 def test_get_sfp_no_results(self, list_sfc_port_chains):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000809 # what OpenStack is assumed to return to the VIM connector
anwars50e43042018-09-28 16:00:13 +0530810 list_sfc_port_chains.return_value = {'port_chains': []}
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000811
812 # call the VIM connector
813 self.assertRaises(vimconn.vimconnNotFoundException,
814 self.vimconn.get_sfp,
815 '5d002f38-82de-11e7-a770-f303f11ce66a')
816
817 # assert that VIM connector called OpenStack with the expected filter
anwars50e43042018-09-28 16:00:13 +0530818 list_sfc_port_chains.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000819 id='5d002f38-82de-11e7-a770-f303f11ce66a')
820
anwars50e43042018-09-28 16:00:13 +0530821 @mock.patch.object(Client, 'delete_sfc_flow_classifier')
822 def test_delete_classification(self, delete_sfc_flow_classifier):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000823 result = self.vimconn.delete_classification(
824 '638f957c-82df-11e7-b7c8-132706021464')
anwars50e43042018-09-28 16:00:13 +0530825 delete_sfc_flow_classifier.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000826 '638f957c-82df-11e7-b7c8-132706021464')
827 self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
828
anwars50e43042018-09-28 16:00:13 +0530829 @mock.patch.object(Client, 'delete_sfc_port_pair')
830 def test_delete_sfi(self, delete_sfc_port_pair):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000831 result = self.vimconn.delete_sfi(
832 '638f957c-82df-11e7-b7c8-132706021464')
anwars50e43042018-09-28 16:00:13 +0530833 delete_sfc_port_pair.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000834 '638f957c-82df-11e7-b7c8-132706021464')
835 self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
836
anwars50e43042018-09-28 16:00:13 +0530837 @mock.patch.object(Client, 'delete_sfc_port_pair_group')
838 def test_delete_sf(self, delete_sfc_port_pair_group):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000839 result = self.vimconn.delete_sf('638f957c-82df-11e7-b7c8-132706021464')
anwars50e43042018-09-28 16:00:13 +0530840 delete_sfc_port_pair_group.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000841 '638f957c-82df-11e7-b7c8-132706021464')
842 self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
843
anwars50e43042018-09-28 16:00:13 +0530844 @mock.patch.object(Client, 'delete_sfc_port_chain')
845 def test_delete_sfp(self, delete_sfc_port_chain):
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000846 result = self.vimconn.delete_sfp(
847 '638f957c-82df-11e7-b7c8-132706021464')
anwars50e43042018-09-28 16:00:13 +0530848 delete_sfc_port_chain.assert_called_with(
Igor Duarte Cardoso3cf9bcd2017-08-14 16:39:34 +0000849 '638f957c-82df-11e7-b7c8-132706021464')
850 self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464')
851
852
853if __name__ == '__main__':
854 unittest.main()