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_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_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_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_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_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_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_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)
148 if sfc_encap
is not None:
154 # what OpenStack is assumed to respond (patch OpenStack's return value)
155 dict_from_neutron
= {'port_chain': {
156 'id': '5bc05721-079b-4b6e-a235-47cac331cbb6',
159 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
160 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c',
161 'chain_id': chain_id
,
162 'flow_classifiers': classifications
,
163 'port_pair_groups': sfs
,
164 'chain_parameters': {'correlation': correlation
}
166 create_port_chain
.return_value
= dict_from_neutron
168 # what the VIM connector is expected to
169 # send to OpenStack based on the input
170 dict_to_neutron
= {'port_chain': {
172 'flow_classifiers': ['2bd2a2e5-c5fd-4eac-a297-d5e255c35c19',
173 '00f23389-bdfa-43c2-8b16-5815f2582fa8'],
174 'port_pair_groups': ['2314daec-c262-414a-86e3-69bb6fa5bc16',
175 'd8bfdb5d-195e-4f34-81aa-6135705317df'],
176 'chain_parameters': {'correlation': correlation
}
179 dict_to_neutron
['port_chain']['chain_id'] = spi
181 # call the VIM connector
182 if sfc_encap
is None:
184 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
)
186 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
,
190 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
,
193 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
,
196 # assert that the VIM connector made the expected call to OpenStack
197 create_port_chain
.assert_called_with(dict_to_neutron
)
198 # assert that the VIM connector had the expected result / return value
199 self
.assertEqual(result
, dict_from_neutron
['port_chain']['id'])
201 def _test_new_classification(self
, create_flow_classifier
, ctype
):
202 # input to VIM connector
203 name
= 'osm_classification'
204 definition
= {'ethertype': 'IPv4',
205 'logical_source_port':
206 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
208 'source_ip_prefix': '192.168.2.0/24',
209 'source_port_range_max': 99,
210 'source_port_range_min': 50}
212 # what OpenStack is assumed to respond (patch OpenStack's return value)
213 dict_from_neutron
= {'flow_classifier': copy
.copy(definition
)}
214 dict_from_neutron
['flow_classifier'][
215 'id'] = '7735ec2c-fddf-4130-9712-32ed2ab6a372'
216 dict_from_neutron
['flow_classifier']['name'] = name
217 dict_from_neutron
['flow_classifier']['description'] = ''
218 dict_from_neutron
['flow_classifier'][
219 'tenant_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c'
220 dict_from_neutron
['flow_classifier'][
221 'project_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c'
222 create_flow_classifier
.return_value
= dict_from_neutron
224 # what the VIM connector is expected to
225 # send to OpenStack based on the input
226 dict_to_neutron
= {'flow_classifier': copy
.copy(definition
)}
227 dict_to_neutron
['flow_classifier']['name'] = 'osm_classification'
229 # call the VIM connector
230 result
= self
.vimconn
.new_classification(name
, ctype
, definition
)
232 # assert that the VIM connector made the expected call to OpenStack
233 create_flow_classifier
.assert_called_with(dict_to_neutron
)
234 # assert that the VIM connector had the expected result / return value
235 self
.assertEqual(result
, dict_from_neutron
['flow_classifier']['id'])
237 @mock.patch
.object(Client
, 'create_flow_classifier')
238 def test_new_classification(self
, create_flow_classifier
):
239 self
._test
_new
_classification
(create_flow_classifier
,
240 'legacy_flow_classifier')
242 @mock.patch
.object(Client
, 'create_flow_classifier')
243 def test_new_classification_unsupported_type(self
, create_flow_classifier
):
244 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
245 self
._test
_new
_classification
,
246 create_flow_classifier
, 'h265')
248 @mock.patch
.object(Client
, 'create_port_pair')
249 def test_new_sfi_with_sfc_encap(self
, create_port_pair
):
250 self
._test
_new
_sfi
(create_port_pair
, True)
252 @mock.patch
.object(Client
, 'create_port_pair')
253 def test_new_sfi_without_sfc_encap(self
, create_port_pair
):
254 self
._test
_new
_sfi
(create_port_pair
, False)
256 @mock.patch
.object(Client
, 'create_port_pair')
257 def test_new_sfi_default_sfc_encap(self
, create_port_pair
):
258 self
._test
_new
_sfi
(create_port_pair
, None)
260 @mock.patch
.object(Client
, 'create_port_pair')
261 def test_new_sfi_bad_ingress_ports(self
, create_port_pair
):
262 ingress_ports
= ['5311c75d-d718-4369-bbda-cdcc6da60fcc',
263 'a0273f64-82c9-11e7-b08f-6328e53f0fa7']
264 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
266 create_port_pair
, True, ingress_ports
=ingress_ports
)
268 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
270 create_port_pair
, True, ingress_ports
=ingress_ports
)
272 @mock.patch
.object(Client
, 'create_port_pair')
273 def test_new_sfi_bad_egress_ports(self
, create_port_pair
):
274 egress_ports
= ['230cdf1b-de37-4891-bc07-f9010cf1f967',
275 'b41228fe-82c9-11e7-9b44-17504174320b']
276 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
278 create_port_pair
, True, egress_ports
=egress_ports
)
280 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
282 create_port_pair
, True, egress_ports
=egress_ports
)
284 @mock.patch
.object(vimconnector
, 'get_sfi')
285 @mock.patch
.object(Client
, 'create_port_pair_group')
286 def test_new_sf(self
, create_port_pair_group
, get_sfi
):
287 get_sfi
.return_value
= {'sfc_encap': 'mpls'}
288 self
._test
_new
_sf
(create_port_pair_group
)
290 @mock.patch
.object(vimconnector
, 'get_sfi')
291 @mock.patch
.object(Client
, 'create_port_pair_group')
292 def test_new_sf_inconsistent_sfc_encap(self
, create_port_pair_group
,
294 get_sfi
.return_value
= {'sfc_encap': 'nsh'}
295 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
296 self
._test
_new
_sf
, create_port_pair_group
)
298 @mock.patch
.object(Client
, 'create_port_chain')
299 def test_new_sfp_with_sfc_encap(self
, create_port_chain
):
300 self
._test
_new
_sfp
(create_port_chain
, True, None)
302 @mock.patch
.object(Client
, 'create_port_chain')
303 def test_new_sfp_without_sfc_encap(self
, create_port_chain
):
304 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
306 create_port_chain
, False, None)
307 self
.assertRaises(vimconn
.vimconnNotSupportedException
,
309 create_port_chain
, False, 25)
311 @mock.patch
.object(Client
, 'create_port_chain')
312 def test_new_sfp_default_sfc_encap(self
, create_port_chain
):
313 self
._test
_new
_sfp
(create_port_chain
, None, None)
315 @mock.patch
.object(Client
, 'create_port_chain')
316 def test_new_sfp_with_sfc_encap_spi(self
, create_port_chain
):
317 self
._test
_new
_sfp
(create_port_chain
, True, 25)
319 @mock.patch
.object(Client
, 'create_port_chain')
320 def test_new_sfp_default_sfc_encap_spi(self
, create_port_chain
):
321 self
._test
_new
_sfp
(create_port_chain
, None, 25)
323 @mock.patch
.object(Client
, 'list_flow_classifier')
324 def test_get_classification_list(self
, list_flow_classifier
):
325 # what OpenStack is assumed to return to the VIM connector
326 list_flow_classifier
.return_value
= {'flow_classifiers': [
327 {'source_port_range_min': 2000,
328 'destination_ip_prefix': '192.168.3.0/24',
333 'source_port_range_max': 2000,
334 'destination_port_range_min': 3000,
335 'source_ip_prefix': '192.168.2.0/24',
336 'logical_destination_port': None,
337 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
338 'destination_port_range_max': None,
339 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
340 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
341 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
344 # call the VIM connector
345 filter_dict
= {'protocol': 'tcp', 'ethertype': 'IPv4'}
346 result
= self
.vimconn
.get_classification_list(filter_dict
.copy())
348 # assert that VIM connector called OpenStack with the expected filter
349 list_flow_classifier
.assert_called_with(**filter_dict
)
350 # assert that the VIM connector successfully
351 # translated and returned the OpenStack result
352 self
.assertEqual(result
, [
353 {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
356 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
357 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
358 'ctype': 'legacy_flow_classifier',
360 'source_port_range_min': 2000,
361 'destination_ip_prefix': '192.168.3.0/24',
365 'source_port_range_max': 2000,
366 'destination_port_range_min': 3000,
367 'source_ip_prefix': '192.168.2.0/24',
368 'logical_destination_port': None,
369 'destination_port_range_max': None,
370 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'}
373 def _test_get_sfi_list(self
, list_port_pair
, correlation
, sfc_encap
):
374 # what OpenStack is assumed to return to the VIM connector
375 list_port_pair
.return_value
= {'port_pairs': [
376 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
378 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
379 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
380 'service_function_parameters': {'correlation': correlation
},
381 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
382 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
385 # call the VIM connector
386 filter_dict
= {'name': 'osm_sfi', 'description': ''}
387 result
= self
.vimconn
.get_sfi_list(filter_dict
.copy())
389 # assert that VIM connector called OpenStack with the expected filter
390 list_port_pair
.assert_called_with(**filter_dict
)
391 # assert that the VIM connector successfully
392 # translated and returned the OpenStack result
393 self
.assertEqual(result
, [
394 {'ingress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
396 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
397 'egress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'],
398 'sfc_encap': sfc_encap
,
399 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
400 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
403 @mock.patch
.object(Client
, 'list_port_pair')
404 def test_get_sfi_list_with_sfc_encap(self
, list_port_pair
):
405 self
._test
_get
_sfi
_list
(list_port_pair
, 'nsh', True)
407 @mock.patch
.object(Client
, 'list_port_pair')
408 def test_get_sfi_list_without_sfc_encap(self
, list_port_pair
):
409 self
._test
_get
_sfi
_list
(list_port_pair
, None, False)
411 @mock.patch
.object(Client
, 'list_port_pair_group')
412 def test_get_sf_list(self
, list_port_pair_group
):
413 # what OpenStack is assumed to return to the VIM connector
414 list_port_pair_group
.return_value
= {'port_pair_groups': [
415 {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
416 '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
418 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
419 'port_pair_group_parameters': {},
420 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
421 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
424 # call the VIM connector
425 filter_dict
= {'name': 'osm_sf', 'description': ''}
426 result
= self
.vimconn
.get_sf_list(filter_dict
.copy())
428 # assert that VIM connector called OpenStack with the expected filter
429 list_port_pair_group
.assert_called_with(**filter_dict
)
430 # assert that the VIM connector successfully
431 # translated and returned the OpenStack result
432 self
.assertEqual(result
, [
433 {'instances': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2',
434 '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
436 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
437 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
438 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f',
441 def _test_get_sfp_list(self
, list_port_chain
, correlation
, sfc_encap
):
442 # what OpenStack is assumed to return to the VIM connector
443 list_port_chain
.return_value
= {'port_chains': [
444 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25',
445 '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'],
446 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e',
447 '1387ab44-82d7-11e7-9bb0-476337183905'],
449 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
450 'chain_parameters': {'correlation': correlation
},
452 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
453 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
456 # call the VIM connector
457 filter_dict
= {'name': 'osm_sfp', 'description': ''}
458 result
= self
.vimconn
.get_sfp_list(filter_dict
.copy())
460 # assert that VIM connector called OpenStack with the expected filter
461 list_port_chain
.assert_called_with(**filter_dict
)
462 # assert that the VIM connector successfully
463 # translated and returned the OpenStack result
464 self
.assertEqual(result
, [
465 {'service_functions': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25',
466 '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'],
467 'classifications': ['1333c2f4-82d7-11e7-a5df-9327f33d104e',
468 '1387ab44-82d7-11e7-9bb0-476337183905'],
470 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
471 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
472 'sfc_encap': sfc_encap
,
474 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
477 @mock.patch
.object(Client
, 'list_port_chain')
478 def test_get_sfp_list_with_sfc_encap(self
, list_port_chain
):
479 self
._test
_get
_sfp
_list
(list_port_chain
, 'nsh', True)
481 @mock.patch
.object(Client
, 'list_port_chain')
482 def test_get_sfp_list_without_sfc_encap(self
, list_port_chain
):
483 self
._test
_get
_sfp
_list
(list_port_chain
, None, False)
485 @mock.patch
.object(Client
, 'list_flow_classifier')
486 def test_get_classification(self
, list_flow_classifier
):
487 # what OpenStack is assumed to return to the VIM connector
488 list_flow_classifier
.return_value
= {'flow_classifiers': [
489 {'source_port_range_min': 2000,
490 'destination_ip_prefix': '192.168.3.0/24',
495 'source_port_range_max': 2000,
496 'destination_port_range_min': 3000,
497 'source_ip_prefix': '192.168.2.0/24',
498 'logical_destination_port': None,
499 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
500 'destination_port_range_max': None,
501 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
502 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
503 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
507 # call the VIM connector
508 result
= self
.vimconn
.get_classification(
509 '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d')
511 # assert that VIM connector called OpenStack with the expected filter
512 list_flow_classifier
.assert_called_with(
513 id='22198366-d4e8-4d6b-b4d2-637d5d6cbb7d')
514 # assert that VIM connector successfully returned the OpenStack result
515 self
.assertEqual(result
,
516 {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
519 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
520 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
521 'ctype': 'legacy_flow_classifier',
523 'source_port_range_min': 2000,
524 'destination_ip_prefix': '192.168.3.0/24',
528 'source_port_range_max': 2000,
529 'destination_port_range_min': 3000,
530 'source_ip_prefix': '192.168.2.0/24',
531 'logical_destination_port': None,
532 'destination_port_range_max': None,
533 'logical_source_port':
534 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'}
537 @mock.patch
.object(Client
, 'list_flow_classifier')
538 def test_get_classification_many_results(self
, list_flow_classifier
):
539 # what OpenStack is assumed to return to the VIM connector
540 list_flow_classifier
.return_value
= {'flow_classifiers': [
541 {'source_port_range_min': 2000,
542 'destination_ip_prefix': '192.168.3.0/24',
547 'source_port_range_max': 2000,
548 'destination_port_range_min': 3000,
549 'source_ip_prefix': '192.168.2.0/24',
550 'logical_destination_port': None,
551 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
552 'destination_port_range_max': None,
553 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
554 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
555 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d',
557 {'source_port_range_min': 1000,
558 'destination_ip_prefix': '192.168.3.0/24',
563 'source_port_range_max': 1000,
564 'destination_port_range_min': 3000,
565 'source_ip_prefix': '192.168.2.0/24',
566 'logical_destination_port': None,
567 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
568 'destination_port_range_max': None,
569 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
570 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b',
571 'id': '3196bafc-82dd-11e7-a205-9bf6c14b0721',
575 # call the VIM connector
576 self
.assertRaises(vimconn
.vimconnConflictException
,
577 self
.vimconn
.get_classification
,
578 '3196bafc-82dd-11e7-a205-9bf6c14b0721')
580 # assert the VIM connector called OpenStack with the expected filter
581 list_flow_classifier
.assert_called_with(
582 id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
584 @mock.patch
.object(Client
, 'list_flow_classifier')
585 def test_get_classification_no_results(self
, list_flow_classifier
):
586 # what OpenStack is assumed to return to the VIM connector
587 list_flow_classifier
.return_value
= {'flow_classifiers': []}
589 # call the VIM connector
590 self
.assertRaises(vimconn
.vimconnNotFoundException
,
591 self
.vimconn
.get_classification
,
592 '3196bafc-82dd-11e7-a205-9bf6c14b0721')
594 # assert the VIM connector called OpenStack with the expected filter
595 list_flow_classifier
.assert_called_with(
596 id='3196bafc-82dd-11e7-a205-9bf6c14b0721')
598 @mock.patch
.object(Client
, 'list_port_pair')
599 def test_get_sfi(self
, list_port_pair
):
600 # what OpenStack is assumed to return to the VIM connector
601 list_port_pair
.return_value
= {'port_pairs': [
602 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
604 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
605 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
606 'service_function_parameters': {'correlation': 'nsh'},
607 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
608 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
612 # call the VIM connector
613 result
= self
.vimconn
.get_sfi('c121ebdd-7f2d-4213-b933-3325298a6966')
615 # assert the VIM connector called OpenStack with the expected filter
616 list_port_pair
.assert_called_with(
617 id='c121ebdd-7f2d-4213-b933-3325298a6966')
618 # assert the VIM connector successfully returned the OpenStack result
619 self
.assertEqual(result
,
621 '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
623 '5311c75d-d718-4369-bbda-cdcc6da60fcc'],
626 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
627 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
628 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
631 @mock.patch
.object(Client
, 'list_port_pair')
632 def test_get_sfi_many_results(self
, list_port_pair
):
633 # what OpenStack is assumed to return to the VIM connector
634 list_port_pair
.return_value
= {'port_pairs': [
635 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
637 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
638 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
639 'service_function_parameters': {'correlation': 'nsh'},
640 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
641 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966',
643 {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
645 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
646 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc',
647 'service_function_parameters': {'correlation': 'nsh'},
648 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
649 'id': 'c0436d92-82db-11e7-8f9c-5fa535f1261f',
653 # call the VIM connector
654 self
.assertRaises(vimconn
.vimconnConflictException
,
655 self
.vimconn
.get_sfi
,
656 'c0436d92-82db-11e7-8f9c-5fa535f1261f')
658 # assert that VIM connector called OpenStack with the expected filter
659 list_port_pair
.assert_called_with(
660 id='c0436d92-82db-11e7-8f9c-5fa535f1261f')
662 @mock.patch
.object(Client
, 'list_port_pair')
663 def test_get_sfi_no_results(self
, list_port_pair
):
664 # what OpenStack is assumed to return to the VIM connector
665 list_port_pair
.return_value
= {'port_pairs': []}
667 # call the VIM connector
668 self
.assertRaises(vimconn
.vimconnNotFoundException
,
669 self
.vimconn
.get_sfi
,
670 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
672 # assert that VIM connector called OpenStack with the expected filter
673 list_port_pair
.assert_called_with(
674 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
676 @mock.patch
.object(Client
, 'list_port_pair_group')
677 def test_get_sf(self
, list_port_pair_group
):
678 # what OpenStack is assumed to return to the VIM connector
679 list_port_pair_group
.return_value
= {'port_pair_groups': [
680 {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
682 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
683 'port_pair_group_parameters': {},
684 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
685 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
689 # call the VIM connector
690 result
= self
.vimconn
.get_sf('b22892fc-82d9-11e7-ae85-0fea6a3b3757')
692 # assert that VIM connector called OpenStack with the expected filter
693 list_port_pair_group
.assert_called_with(
694 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
695 # assert that VIM connector successfully returned the OpenStack result
696 self
.assertEqual(result
,
698 '08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
700 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
701 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
702 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
705 @mock.patch
.object(Client
, 'list_port_pair_group')
706 def test_get_sf_many_results(self
, list_port_pair_group
):
707 # what OpenStack is assumed to return to the VIM connector
708 list_port_pair_group
.return_value
= {'port_pair_groups': [
709 {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'],
711 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
712 'port_pair_group_parameters': {},
713 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
714 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d',
716 {'port_pairs': ['0d63799c-82d6-11e7-8deb-a746bb3ae9f5'],
718 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
719 'port_pair_group_parameters': {},
720 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
721 'id': 'b22892fc-82d9-11e7-ae85-0fea6a3b3757',
725 # call the VIM connector
726 self
.assertRaises(vimconn
.vimconnConflictException
,
728 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
730 # assert that VIM connector called OpenStack with the expected filter
731 list_port_pair_group
.assert_called_with(
732 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
734 @mock.patch
.object(Client
, 'list_port_pair_group')
735 def test_get_sf_no_results(self
, list_port_pair_group
):
736 # what OpenStack is assumed to return to the VIM connector
737 list_port_pair_group
.return_value
= {'port_pair_groups': []}
739 # call the VIM connector
740 self
.assertRaises(vimconn
.vimconnNotFoundException
,
742 'b22892fc-82d9-11e7-ae85-0fea6a3b3757')
744 # assert that VIM connector called OpenStack with the expected filter
745 list_port_pair_group
.assert_called_with(
746 id='b22892fc-82d9-11e7-ae85-0fea6a3b3757')
748 @mock.patch
.object(Client
, 'list_port_chain')
749 def test_get_sfp(self
, list_port_chain
):
750 # what OpenStack is assumed to return to the VIM connector
751 list_port_chain
.return_value
= {'port_chains': [
752 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
753 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
755 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
756 'chain_parameters': {'correlation': 'nsh'},
758 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
759 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
760 'name': 'osm_sfp1'}]}
762 # call the VIM connector
763 result
= self
.vimconn
.get_sfp('821bc9be-82d7-11e7-8ce3-23a08a27ab47')
765 # assert that VIM connector called OpenStack with the expected filter
766 list_port_chain
.assert_called_with(
767 id='821bc9be-82d7-11e7-8ce3-23a08a27ab47')
768 # assert that VIM connector successfully returned the OpenStack result
769 self
.assertEqual(result
,
770 {'service_functions': [
771 '7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
773 '1333c2f4-82d7-11e7-a5df-9327f33d104e'],
775 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
776 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
779 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
782 @mock.patch
.object(Client
, 'list_port_chain')
783 def test_get_sfp_many_results(self
, list_port_chain
):
784 # what OpenStack is assumed to return to the VIM connector
785 list_port_chain
.return_value
= {'port_chains': [
786 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
787 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
789 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
790 'chain_parameters': {'correlation': 'nsh'},
792 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
793 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47',
795 {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'],
796 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'],
798 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b',
799 'chain_parameters': {'correlation': 'nsh'},
801 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b',
802 'id': '5d002f38-82de-11e7-a770-f303f11ce66a',
806 # call the VIM connector
807 self
.assertRaises(vimconn
.vimconnConflictException
,
808 self
.vimconn
.get_sfp
,
809 '5d002f38-82de-11e7-a770-f303f11ce66a')
811 # assert that VIM connector called OpenStack with the expected filter
812 list_port_chain
.assert_called_with(
813 id='5d002f38-82de-11e7-a770-f303f11ce66a')
815 @mock.patch
.object(Client
, 'list_port_chain')
816 def test_get_sfp_no_results(self
, list_port_chain
):
817 # what OpenStack is assumed to return to the VIM connector
818 list_port_chain
.return_value
= {'port_chains': []}
820 # call the VIM connector
821 self
.assertRaises(vimconn
.vimconnNotFoundException
,
822 self
.vimconn
.get_sfp
,
823 '5d002f38-82de-11e7-a770-f303f11ce66a')
825 # assert that VIM connector called OpenStack with the expected filter
826 list_port_chain
.assert_called_with(
827 id='5d002f38-82de-11e7-a770-f303f11ce66a')
829 @mock.patch
.object(Client
, 'delete_flow_classifier')
830 def test_delete_classification(self
, delete_flow_classifier
):
831 result
= self
.vimconn
.delete_classification(
832 '638f957c-82df-11e7-b7c8-132706021464')
833 delete_flow_classifier
.assert_called_with(
834 '638f957c-82df-11e7-b7c8-132706021464')
835 self
.assertEqual(result
, '638f957c-82df-11e7-b7c8-132706021464')
837 @mock.patch
.object(Client
, 'delete_port_pair')
838 def test_delete_sfi(self
, delete_port_pair
):
839 result
= self
.vimconn
.delete_sfi(
840 '638f957c-82df-11e7-b7c8-132706021464')
841 delete_port_pair
.assert_called_with(
842 '638f957c-82df-11e7-b7c8-132706021464')
843 self
.assertEqual(result
, '638f957c-82df-11e7-b7c8-132706021464')
845 @mock.patch
.object(Client
, 'delete_port_pair_group')
846 def test_delete_sf(self
, delete_port_pair_group
):
847 result
= self
.vimconn
.delete_sf('638f957c-82df-11e7-b7c8-132706021464')
848 delete_port_pair_group
.assert_called_with(
849 '638f957c-82df-11e7-b7c8-132706021464')
850 self
.assertEqual(result
, '638f957c-82df-11e7-b7c8-132706021464')
852 @mock.patch
.object(Client
, 'delete_port_chain')
853 def test_delete_sfp(self
, delete_port_chain
):
854 result
= self
.vimconn
.delete_sfp(
855 '638f957c-82df-11e7-b7c8-132706021464')
856 delete_port_chain
.assert_called_with(
857 '638f957c-82df-11e7-b7c8-132706021464')
858 self
.assertEqual(result
, '638f957c-82df-11e7-b7c8-132706021464')
861 if __name__
== '__main__':