1 # -*- coding: utf-8 -*-
4 # Copyright 2017 Intel Corporation.
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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
18 # For those usages not covered by the Apache License, Version 2.0 please
19 # contact with: nfvlabs@tid.es
23 This module contains unit tests for the OpenStack VIM connector
24 Run this directly with python2 or python3.
31 from neutronclient
.v2_0
.client
import Client
33 from osm_ro
import vimconn
34 from osm_ro
.vimconn_openstack
import vimconnector
37 __author__
= "Igor D.C."
38 __date__
= "$23-aug-2017 23:59:59$"
41 class TestSfcOperations(unittest
.TestCase
):
43 # instantiate dummy VIM connector so we can test it
44 self
.vimconn
= vimconnector(
45 '123', 'openstackvim', '456', '789', 'http://dummy.url', None,
48 def _test_new_sfi(self
, create_sfc_port_pair
, sfc_encap
,
49 ingress_ports
=['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
50 egress_ports
=['230cdf1b-de37-4891-bc07-f9010cf1f967']):
51 # input to VIM connector
55 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
57 if sfc_encap
is not None:
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',
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
}
72 create_sfc_port_pair
.return_value
= dict_from_neutron
74 # what the VIM connector is expected to
75 # send to OpenStack based on the input
76 dict_to_neutron
= {'port_pair': {
78 'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
79 'egress': '230cdf1b-de37-4891-bc07-f9010cf1f967',
80 'service_function_parameters': {'correlation': correlation
}
83 # call the VIM connector
85 result
= self
.vimconn
.new_sfi(name
, ingress_ports
, egress_ports
)
87 result
= self
.vimconn
.new_sfi(name
, ingress_ports
, egress_ports
,
90 # assert that the VIM connector made the expected call to OpenStack
91 create_sfc_port_pair
.assert_called_with(dict_to_neutron
)
92 # assert that the VIM connector had the expected result / return value
93 self
.assertEqual(result
, dict_from_neutron
['port_pair']['id'])
95 def _test_new_sf(self
, create_sfc_port_pair_group
):
96 # input to VIM connector
98 instances
= ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd',
99 '12ba215e-3987-4892-bd3a-d0fd91eecf98',
100 'e25a7c79-14c8-469a-9ae1-f601c9371ffd']
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',
107 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
108 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
109 'port_pairs': instances
,
111 'port_pair_group_parameters': {
113 "ppg_n_tuple_mapping": {
114 "ingress_n_tuple": {},
118 create_sfc_port_pair_group
.return_value
= dict_from_neutron
120 # what the VIM connector is expected to
121 # send to OpenStack based on the input
122 dict_to_neutron
= {'port_pair_group': {
124 'port_pairs': ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd',
125 '12ba215e-3987-4892-bd3a-d0fd91eecf98',
126 'e25a7c79-14c8-469a-9ae1-f601c9371ffd']
129 # call the VIM connector
130 result
= self
.vimconn
.new_sf(name
, instances
)
132 # assert that the VIM connector made the expected call to OpenStack
133 create_sfc_port_pair_group
.assert_called_with(dict_to_neutron
)
134 # assert that the VIM connector had the expected result / return value
135 self
.assertEqual(result
, dict_from_neutron
['port_pair_group']['id'])
137 def _test_new_sfp(self
, create_sfc_port_chain
, sfc_encap
, spi
):
138 # input to VIM connector
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']
145 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
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',
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
}
163 create_sfc_port_chain
.return_value
= dict_from_neutron
165 # what the VIM connector is expected to
166 # send to OpenStack based on the input
167 dict_to_neutron
= {'port_chain': {
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
}
176 dict_to_neutron
['port_chain']['chain_id'] = spi
178 # call the VIM connector
179 if sfc_encap
is None:
181 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
)
183 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
,
187 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
,
190 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
,
193 # assert that the VIM connector made the expected call to OpenStack
194 create_sfc_port_chain
.assert_called_with(dict_to_neutron
)
195 # assert that the VIM connector had the expected result / return value
196 self
.assertEqual(result
, dict_from_neutron
['port_chain']['id'])
198 def _test_new_classification(self
, create_sfc_flow_classifier
, ctype
):
199 # input to VIM connector
200 name
= 'osm_classification'
201 definition
= {'ethertype': 'IPv4',
202 'logical_source_port':
203 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
205 'source_ip_prefix': '192.168.2.0/24',
206 'source_port_range_max': 99,
207 'source_port_range_min': 50}
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'
219 create_sfc_flow_classifier
.return_value
= dict_from_neutron
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'
226 # call the VIM connector
227 result
= self
.vimconn
.new_classification(name
, ctype
, definition
)
229 # assert that the VIM connector made the expected call to OpenStack
230 create_sfc_flow_classifier
.assert_called_with(dict_to_neutron
)
231 # assert that the VIM connector had the expected result / return value
232 self
.assertEqual(result
, dict_from_neutron
['flow_classifier']['id'])
234 @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
,
237 'legacy_flow_classifier')
239 @mock.patch
.object(Client
, 'create_sfc_flow_classifier')
240 def test_new_classification_unsupported_type(self
, create_sfc_flow_classifier
):
241 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
242 self
._test
_new
_classification
,
243 create_sfc_flow_classifier
, 'h265')
245 @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)
249 @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)
253 @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)
257 @mock.patch
.object(Client
, 'create_sfc_port_pair')
258 def test_new_sfi_bad_ingress_ports(self
, create_sfc_port_pair
):
259 ingress_ports
= ['5311c75d-d718-4369-bbda-cdcc6da60fcc',
260 'a0273f64-82c9-11e7-b08f-6328e53f0fa7']
261 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
263 create_sfc_port_pair
, True, ingress_ports
=ingress_ports
)
265 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
267 create_sfc_port_pair
, True, ingress_ports
=ingress_ports
)
269 @mock.patch
.object(Client
, 'create_sfc_port_pair')
270 def test_new_sfi_bad_egress_ports(self
, create_sfc_port_pair
):
271 egress_ports
= ['230cdf1b-de37-4891-bc07-f9010cf1f967',
272 'b41228fe-82c9-11e7-9b44-17504174320b']
273 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
275 create_sfc_port_pair
, True, egress_ports
=egress_ports
)
277 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
279 create_sfc_port_pair
, True, egress_ports
=egress_ports
)
281 @mock.patch
.object(vimconnector
, 'get_sfi')
282 @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
)
287 @mock.patch
.object(vimconnector
, 'get_sfi')
288 @mock.patch
.object(Client
, 'create_sfc_port_pair_group')
289 def test_new_sf_inconsistent_sfc_encap(self
, create_sfc_port_pair_group
,
291 get_sfi
.return_value
= {'sfc_encap': 'nsh'}
292 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
293 self
._test
_new
_sf
, create_sfc_port_pair_group
)
295 @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)
299 @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)
304 @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)
308 @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)
312 @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)
316 @mock.patch
.object(Client
, 'list_sfc_flow_classifiers')
317 def test_get_classification_list(self
, list_sfc_flow_classifiers
):
318 # what OpenStack is assumed to return to the VIM connector
319 list_sfc_flow_classifiers
.return_value
= {'flow_classifiers': [
320 {'source_port_range_min': 2000,
321 'destination_ip_prefix': '192.168.3.0/24',
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',
337 # call the VIM connector
338 filter_dict
= {'protocol': 'tcp', 'ethertype': 'IPv4'}
339 result
= self
.vimconn
.get_classification_list(filter_dict
.copy())
341 # assert that VIM connector called OpenStack with the expected filter
342 list_sfc_flow_classifiers
.assert_called_with(**filter_dict
)
343 # assert that the VIM connector successfully
344 # translated and returned the OpenStack result
345 self
.assertEqual(result
, [
346 {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
349 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
350 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
351 'ctype': 'legacy_flow_classifier',
353 'source_port_range_min': 2000,
354 'destination_ip_prefix': '192.168.3.0/24',
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'}
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',
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',
378 # call the VIM connector
379 filter_dict
= {'name': 'osm_sfi', 'description': ''}
380 result
= self
.vimconn
.get_sfi_list(filter_dict
.copy())
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'],
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',
396 @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)
400 @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)
404 @mock.patch
.object(Client
, 'list_sfc_port_pair_groups')
405 def test_get_sf_list(self
, list_sfc_port_pair_groups
):
406 # what OpenStack is assumed to return to the VIM connector
407 list_sfc_port_pair_groups
.return_value
= {'port_pair_groups': [
408 {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
409 '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
411 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
412 'port_pair_group_parameters': {},
413 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
414 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
417 # call the VIM connector
418 filter_dict
= {'name': 'osm_sf', 'description': ''}
419 result
= self
.vimconn
.get_sf_list(filter_dict
.copy())
421 # assert that VIM connector called OpenStack with the expected filter
422 list_sfc_port_pair_groups
.assert_called_with(**filter_dict
)
423 # assert that the VIM connector successfully
424 # translated and returned the OpenStack result
425 self
.assertEqual(result
, [
426 {'sfis': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
427 '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
429 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
430 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
431 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
434 def _test_get_sfp_list(self
, list_sfc_port_chains
, correlation
, sfc_encap
):
435 # what OpenStack is assumed to return to the VIM connector
436 list_sfc_port_chains
.return_value
= {'port_chains': [
437 {'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'],
442 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
443 'chain_parameters': {'correlation': correlation
},
445 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
446 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
449 # call the VIM connector
450 filter_dict
= {'name': 'osm_sfp', 'description': ''}
451 result
= self
.vimconn
.get_sfp_list(filter_dict
.copy())
453 # assert that VIM connector called OpenStack with the expected filter
454 list_sfc_port_chains
.assert_called_with(**filter_dict
)
455 # 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'],
463 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
464 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
465 'sfc_encap': sfc_encap
,
467 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
470 @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)
474 @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)
478 @mock.patch
.object(Client
, 'list_sfc_flow_classifiers')
479 def test_get_classification(self
, list_sfc_flow_classifiers
):
480 # what OpenStack is assumed to return to the VIM connector
481 list_sfc_flow_classifiers
.return_value
= {'flow_classifiers': [
482 {'source_port_range_min': 2000,
483 'destination_ip_prefix': '192.168.3.0/24',
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',
500 # call the VIM connector
501 result
= self
.vimconn
.get_classification(
502 '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d')
504 # assert that VIM connector called OpenStack with the expected filter
505 list_sfc_flow_classifiers
.assert_called_with(
506 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',
512 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
513 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
514 'ctype': 'legacy_flow_classifier',
516 'source_port_range_min': 2000,
517 'destination_ip_prefix': '192.168.3.0/24',
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'}
530 @mock.patch
.object(Client
, 'list_sfc_flow_classifiers')
531 def test_get_classification_many_results(self
, list_sfc_flow_classifiers
):
532 # what OpenStack is assumed to return to the VIM connector
533 list_sfc_flow_classifiers
.return_value
= {'flow_classifiers': [
534 {'source_port_range_min': 2000,
535 'destination_ip_prefix': '192.168.3.0/24',
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',
550 {'source_port_range_min': 1000,
551 'destination_ip_prefix': '192.168.3.0/24',
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',
568 # call the VIM connector
569 self
.assertRaises(vimconn
.vimconnConflictException
,
570 self
.vimconn
.get_classification
,
571 '3196bafc-82dd-11e7-a205-9bf6c14b0721')
573 # assert the VIM connector called OpenStack with the expected filter
574 list_sfc_flow_classifiers
.assert_called_with(
575 id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
577 @mock.patch
.object(Client
, 'list_sfc_flow_classifiers')
578 def test_get_classification_no_results(self
, list_sfc_flow_classifiers
):
579 # what OpenStack is assumed to return to the VIM connector
580 list_sfc_flow_classifiers
.return_value
= {'flow_classifiers': []}
582 # call the VIM connector
583 self
.assertRaises(vimconn
.vimconnNotFoundException
,
584 self
.vimconn
.get_classification
,
585 '3196bafc-82dd-11e7-a205-9bf6c14b0721')
587 # assert the VIM connector called OpenStack with the expected filter
588 list_sfc_flow_classifiers
.assert_called_with(
589 id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
591 @mock.patch
.object(Client
, 'list_sfc_port_pairs')
592 def test_get_sfi(self
, list_sfc_port_pairs
):
593 # what OpenStack is assumed to return to the VIM connector
594 list_sfc_port_pairs
.return_value
= {'port_pairs': [
595 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
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',
605 # call the VIM connector
606 result
= self
.vimconn
.get_sfi('c121ebdd-7f2d-4213-b933-3325298a6966')
608 # assert the VIM connector called OpenStack with the expected filter
609 list_sfc_port_pairs
.assert_called_with(
610 id='c121ebdd-7f2d-4213-b933-3325298a6966')
611 # assert the VIM connector successfully returned the OpenStack result
612 self
.assertEqual(result
,
614 '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
616 '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
619 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
620 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
621 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
624 @mock.patch
.object(Client
, 'list_sfc_port_pairs')
625 def test_get_sfi_many_results(self
, list_sfc_port_pairs
):
626 # what OpenStack is assumed to return to the VIM connector
627 list_sfc_port_pairs
.return_value
= {'port_pairs': [
628 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
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',
636 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
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',
646 # call the VIM connector
647 self
.assertRaises(vimconn
.vimconnConflictException
,
648 self
.vimconn
.get_sfi
,
649 'c0436d92-82db-11e7-8f9c-5fa535f1261f')
651 # assert that VIM connector called OpenStack with the expected filter
652 list_sfc_port_pairs
.assert_called_with(
653 id='c0436d92-82db-11e7-8f9c-5fa535f1261f')
655 @mock.patch
.object(Client
, 'list_sfc_port_pairs')
656 def test_get_sfi_no_results(self
, list_sfc_port_pairs
):
657 # what OpenStack is assumed to return to the VIM connector
658 list_sfc_port_pairs
.return_value
= {'port_pairs': []}
660 # call the VIM connector
661 self
.assertRaises(vimconn
.vimconnNotFoundException
,
662 self
.vimconn
.get_sfi
,
663 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
665 # assert that VIM connector called OpenStack with the expected filter
666 list_sfc_port_pairs
.assert_called_with(
667 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
669 @mock.patch
.object(Client
, 'list_sfc_port_pair_groups')
670 def test_get_sf(self
, list_sfc_port_pair_groups
):
671 # what OpenStack is assumed to return to the VIM connector
672 list_sfc_port_pair_groups
.return_value
= {'port_pair_groups': [
673 {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
675 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
676 'port_pair_group_parameters': {},
677 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
678 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
682 # call the VIM connector
683 result
= self
.vimconn
.get_sf('b22892fc-82d9-11e7-ae85-0fea6a3b3757')
685 # assert that VIM connector called OpenStack with the expected filter
686 list_sfc_port_pair_groups
.assert_called_with(
687 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
688 # assert that VIM connector successfully returned the OpenStack result
689 self
.assertEqual(result
,
691 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
692 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
693 'sfis': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
694 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
697 @mock.patch
.object(Client
, 'list_sfc_port_pair_groups')
698 def test_get_sf_many_results(self
, list_sfc_port_pair_groups
):
699 # what OpenStack is assumed to return to the VIM connector
700 list_sfc_port_pair_groups
.return_value
= {'port_pair_groups': [
701 {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
703 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
704 'port_pair_group_parameters': {},
705 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
706 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
708 {'port_pairs': ['0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
710 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
711 'port_pair_group_parameters': {},
712 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
713 'id': 'b22892fc-82d9-11e7-ae85-0fea6a3b3757',
717 # call the VIM connector
718 self
.assertRaises(vimconn
.vimconnConflictException
,
720 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
722 # assert that VIM connector called OpenStack with the expected filter
723 list_sfc_port_pair_groups
.assert_called_with(
724 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
726 @mock.patch
.object(Client
, 'list_sfc_port_pair_groups')
727 def test_get_sf_no_results(self
, list_sfc_port_pair_groups
):
728 # what OpenStack is assumed to return to the VIM connector
729 list_sfc_port_pair_groups
.return_value
= {'port_pair_groups': []}
731 # call the VIM connector
732 self
.assertRaises(vimconn
.vimconnNotFoundException
,
734 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
736 # assert that VIM connector called OpenStack with the expected filter
737 list_sfc_port_pair_groups
.assert_called_with(
738 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
740 @mock.patch
.object(Client
, 'list_sfc_port_chains')
741 def test_get_sfp(self
, list_sfc_port_chains
):
742 # what OpenStack is assumed to return to the VIM connector
743 list_sfc_port_chains
.return_value
= {'port_chains': [
744 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
745 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
747 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
748 'chain_parameters': {'correlation': 'nsh'},
750 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
751 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
752 'name': 'osm_sfp1'}]}
754 # call the VIM connector
755 result
= self
.vimconn
.get_sfp('821bc9be-82d7-11e7-8ce3-23a08a27ab47')
757 # assert that VIM connector called OpenStack with the expected filter
758 list_sfc_port_chains
.assert_called_with(
759 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'],
765 '1333c2f4-82d7-11e7-a5df-9327f33d104e'],
767 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
768 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
771 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
774 @mock.patch
.object(Client
, 'list_sfc_port_chains')
775 def test_get_sfp_many_results(self
, list_sfc_port_chains
):
776 # what OpenStack is assumed to return to the VIM connector
777 list_sfc_port_chains
.return_value
= {'port_chains': [
778 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
779 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
781 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
782 'chain_parameters': {'correlation': 'nsh'},
784 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
785 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
787 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
788 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
790 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
791 'chain_parameters': {'correlation': 'nsh'},
793 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
794 'id': '5d002f38-82de-11e7-a770-f303f11ce66a',
798 # call the VIM connector
799 self
.assertRaises(vimconn
.vimconnConflictException
,
800 self
.vimconn
.get_sfp
,
801 '5d002f38-82de-11e7-a770-f303f11ce66a')
803 # assert that VIM connector called OpenStack with the expected filter
804 list_sfc_port_chains
.assert_called_with(
805 id='5d002f38-82de-11e7-a770-f303f11ce66a')
807 @mock.patch
.object(Client
, 'list_sfc_port_chains')
808 def test_get_sfp_no_results(self
, list_sfc_port_chains
):
809 # what OpenStack is assumed to return to the VIM connector
810 list_sfc_port_chains
.return_value
= {'port_chains': []}
812 # call the VIM connector
813 self
.assertRaises(vimconn
.vimconnNotFoundException
,
814 self
.vimconn
.get_sfp
,
815 '5d002f38-82de-11e7-a770-f303f11ce66a')
817 # assert that VIM connector called OpenStack with the expected filter
818 list_sfc_port_chains
.assert_called_with(
819 id='5d002f38-82de-11e7-a770-f303f11ce66a')
821 @mock.patch
.object(Client
, 'delete_sfc_flow_classifier')
822 def test_delete_classification(self
, delete_sfc_flow_classifier
):
823 result
= self
.vimconn
.delete_classification(
824 '638f957c-82df-11e7-b7c8-132706021464')
825 delete_sfc_flow_classifier
.assert_called_with(
826 '638f957c-82df-11e7-b7c8-132706021464')
827 self
.assertEqual(result
, '638f957c-82df-11e7-b7c8-132706021464')
829 @mock.patch
.object(Client
, 'delete_sfc_port_pair')
830 def test_delete_sfi(self
, delete_sfc_port_pair
):
831 result
= self
.vimconn
.delete_sfi(
832 '638f957c-82df-11e7-b7c8-132706021464')
833 delete_sfc_port_pair
.assert_called_with(
834 '638f957c-82df-11e7-b7c8-132706021464')
835 self
.assertEqual(result
, '638f957c-82df-11e7-b7c8-132706021464')
837 @mock.patch
.object(Client
, 'delete_sfc_port_pair_group')
838 def test_delete_sf(self
, delete_sfc_port_pair_group
):
839 result
= self
.vimconn
.delete_sf('638f957c-82df-11e7-b7c8-132706021464')
840 delete_sfc_port_pair_group
.assert_called_with(
841 '638f957c-82df-11e7-b7c8-132706021464')
842 self
.assertEqual(result
, '638f957c-82df-11e7-b7c8-132706021464')
844 @mock.patch
.object(Client
, 'delete_sfc_port_chain')
845 def test_delete_sfp(self
, delete_sfc_port_chain
):
846 result
= self
.vimconn
.delete_sfp(
847 '638f957c-82df-11e7-b7c8-132706021464')
848 delete_sfc_port_chain
.assert_called_with(
849 '638f957c-82df-11e7-b7c8-132706021464')
850 self
.assertEqual(result
, '638f957c-82df-11e7-b7c8-132706021464')
853 if __name__
== '__main__':