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.
32 from neutronclient
.v2_0
.client
import Client
33 from osm_ro_plugin
import vimconn
34 from osm_rovim_openstack
.vimconn_openstack
import vimconnector
36 __author__
= "Igor D.C."
37 __date__
= "$23-aug-2017 23:59:59$"
40 class TestSfcOperations(unittest
.TestCase
):
41 @mock.patch("logging.getLogger", autospec
=True)
42 def setUp(self
, mock_logger
):
43 # Instantiate dummy VIM connector so we can test it
44 # It throws exception because of dummy parameters,
45 # We are disabling the logging of exception not to print them to console.
46 mock_logger
= logging
.getLogger()
47 mock_logger
.disabled
= True
48 self
.vimconn
= vimconnector(
63 ingress_ports
=["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
64 egress_ports
=["230cdf1b-de37-4891-bc07-f9010cf1f967"],
66 # input to VIM connector
70 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
72 if sfc_encap
is not None:
76 # what OpenStack is assumed to respond (patch OpenStack"s return value)
79 "id": "3d7ddc13-923c-4332-971e-708ed82902ce",
82 "tenant_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
83 "project_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
84 "ingress": ingress_ports
[0] if len(ingress_ports
) else None,
85 "egress": egress_ports
[0] if len(egress_ports
) else None,
86 "service_function_parameters": {"correlation": correlation
},
89 create_sfc_port_pair
.return_value
= dict_from_neutron
91 # what the VIM connector is expected to
92 # send to OpenStack based on the input
96 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
97 "egress": "230cdf1b-de37-4891-bc07-f9010cf1f967",
98 "service_function_parameters": {"correlation": correlation
},
102 # call the VIM connector
103 if sfc_encap
is None:
104 result
= self
.vimconn
.new_sfi(name
, ingress_ports
, egress_ports
)
106 result
= self
.vimconn
.new_sfi(name
, ingress_ports
, egress_ports
, sfc_encap
)
108 # assert that the VIM connector made the expected call to OpenStack
109 create_sfc_port_pair
.assert_called_with(dict_to_neutron
)
110 # assert that the VIM connector had the expected result / return value
111 self
.assertEqual(result
, dict_from_neutron
["port_pair"]["id"])
113 def _test_new_sf(self
, create_sfc_port_pair_group
):
114 # input to VIM connector
117 "bbd01220-cf72-41f2-9e70-0669c2e5c4cd",
118 "12ba215e-3987-4892-bd3a-d0fd91eecf98",
119 "e25a7c79-14c8-469a-9ae1-f601c9371ffd",
122 # what OpenStack is assumed to respond (patch OpenStack"s return value)
123 dict_from_neutron
= {
125 "id": "3d7ddc13-923c-4332-971e-708ed82902ce",
128 "tenant_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
129 "project_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
130 "port_pairs": instances
,
132 "port_pair_group_parameters": {
134 "ppg_n_tuple_mapping": {
135 "ingress_n_tuple": {},
136 "egress_n_tuple": {},
141 create_sfc_port_pair_group
.return_value
= dict_from_neutron
143 # what the VIM connector is expected to
144 # send to OpenStack based on the input
149 "bbd01220-cf72-41f2-9e70-0669c2e5c4cd",
150 "12ba215e-3987-4892-bd3a-d0fd91eecf98",
151 "e25a7c79-14c8-469a-9ae1-f601c9371ffd",
156 # call the VIM connector
157 result
= self
.vimconn
.new_sf(name
, instances
)
159 # assert that the VIM connector made the expected call to OpenStack
160 create_sfc_port_pair_group
.assert_called_with(dict_to_neutron
)
161 # assert that the VIM connector had the expected result / return value
162 self
.assertEqual(result
, dict_from_neutron
["port_pair_group"]["id"])
164 def _test_new_sfp(self
, create_sfc_port_chain
, sfc_encap
, spi
):
165 # input to VIM connector
168 "2bd2a2e5-c5fd-4eac-a297-d5e255c35c19",
169 "00f23389-bdfa-43c2-8b16-5815f2582fa8",
172 "2314daec-c262-414a-86e3-69bb6fa5bc16",
173 "d8bfdb5d-195e-4f34-81aa-6135705317df",
176 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
182 # what OpenStack is assumed to respond (patch OpenStack"s return value)
183 dict_from_neutron
= {
185 "id": "5bc05721-079b-4b6e-a235-47cac331cbb6",
188 "tenant_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
189 "project_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
190 "chain_id": chain_id
,
191 "flow_classifiers": classifications
,
192 "port_pair_groups": sfs
,
193 "chain_parameters": {"correlation": correlation
},
196 create_sfc_port_chain
.return_value
= dict_from_neutron
198 # what the VIM connector is expected to
199 # send to OpenStack based on the input
203 "flow_classifiers": [
204 "2bd2a2e5-c5fd-4eac-a297-d5e255c35c19",
205 "00f23389-bdfa-43c2-8b16-5815f2582fa8",
207 "port_pair_groups": [
208 "2314daec-c262-414a-86e3-69bb6fa5bc16",
209 "d8bfdb5d-195e-4f34-81aa-6135705317df",
211 "chain_parameters": {"correlation": correlation
},
215 dict_to_neutron
["port_chain"]["chain_id"] = spi
217 # call the VIM connector
218 if sfc_encap
is None:
219 dict_to_neutron
["port_chain"]["chain_parameters"] = {"correlation": "mpls"}
221 result
= self
.vimconn
.new_sfp(
222 name
, classifications
, sfs
, sfc_encap
=False
225 result
= self
.vimconn
.new_sfp(
226 name
, classifications
, sfs
, sfc_encap
=False, spi
=spi
230 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
, sfc_encap
)
232 result
= self
.vimconn
.new_sfp(
233 name
, classifications
, sfs
, sfc_encap
, spi
236 # assert that the VIM connector made the expected call to OpenStack
237 create_sfc_port_chain
.assert_called_with(dict_to_neutron
)
238 # assert that the VIM connector had the expected result / return value
239 self
.assertEqual(result
, dict_from_neutron
["port_chain"]["id"])
241 def _test_new_classification(self
, create_sfc_flow_classifier
, ctype
):
242 # input to VIM connector
243 name
= "osm_classification"
246 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
248 "source_ip_prefix": "192.168.2.0/24",
249 "source_port_range_max": 99,
250 "source_port_range_min": 50,
253 # what OpenStack is assumed to respond (patch OpenStack"s return value)
254 dict_from_neutron
= {"flow_classifier": copy
.copy(definition
)}
255 dict_from_neutron
["flow_classifier"][
257 ] = "7735ec2c-fddf-4130-9712-32ed2ab6a372"
258 dict_from_neutron
["flow_classifier"]["name"] = name
259 dict_from_neutron
["flow_classifier"]["description"] = ""
260 dict_from_neutron
["flow_classifier"][
262 ] = "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c"
263 dict_from_neutron
["flow_classifier"][
265 ] = "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c"
266 create_sfc_flow_classifier
.return_value
= dict_from_neutron
268 # what the VIM connector is expected to
269 # send to OpenStack based on the input
270 dict_to_neutron
= {"flow_classifier": copy
.copy(definition
)}
271 dict_to_neutron
["flow_classifier"]["name"] = "osm_classification"
273 # call the VIM connector
274 result
= self
.vimconn
.new_classification(name
, ctype
, definition
)
276 # assert that the VIM connector made the expected call to OpenStack
277 create_sfc_flow_classifier
.assert_called_with(dict_to_neutron
)
278 # assert that the VIM connector had the expected result / return value
279 self
.assertEqual(result
, dict_from_neutron
["flow_classifier"]["id"])
281 @mock.patch
.object(Client
, "create_sfc_flow_classifier")
282 def test_new_classification(self
, create_sfc_flow_classifier
):
283 self
._test
_new
_classification
(
284 create_sfc_flow_classifier
, "legacy_flow_classifier"
287 @mock.patch
.object(Client
, "create_sfc_flow_classifier")
288 def test_new_classification_unsupported_type(self
, create_sfc_flow_classifier
):
290 vimconn
.VimConnNotSupportedException
,
291 self
._test
_new
_classification
,
292 create_sfc_flow_classifier
,
296 @mock.patch
.object(Client
, "create_sfc_port_pair")
297 def test_new_sfi_with_sfc_encap(self
, create_sfc_port_pair
):
298 self
._test
_new
_sfi
(create_sfc_port_pair
, True)
300 @mock.patch
.object(Client
, "create_sfc_port_pair")
301 def test_new_sfi_without_sfc_encap(self
, create_sfc_port_pair
):
302 self
._test
_new
_sfi
(create_sfc_port_pair
, False)
304 @mock.patch
.object(Client
, "create_sfc_port_pair")
305 def test_new_sfi_default_sfc_encap(self
, create_sfc_port_pair
):
306 self
._test
_new
_sfi
(create_sfc_port_pair
, None)
308 @mock.patch
.object(Client
, "create_sfc_port_pair")
309 def test_new_sfi_bad_ingress_ports(self
, create_sfc_port_pair
):
311 "5311c75d-d718-4369-bbda-cdcc6da60fcc",
312 "a0273f64-82c9-11e7-b08f-6328e53f0fa7",
315 vimconn
.VimConnNotSupportedException
,
317 create_sfc_port_pair
,
319 ingress_ports
=ingress_ports
,
323 vimconn
.VimConnNotSupportedException
,
325 create_sfc_port_pair
,
327 ingress_ports
=ingress_ports
,
330 @mock.patch
.object(Client
, "create_sfc_port_pair")
331 def test_new_sfi_bad_egress_ports(self
, create_sfc_port_pair
):
333 "230cdf1b-de37-4891-bc07-f9010cf1f967",
334 "b41228fe-82c9-11e7-9b44-17504174320b",
337 vimconn
.VimConnNotSupportedException
,
339 create_sfc_port_pair
,
341 egress_ports
=egress_ports
,
345 vimconn
.VimConnNotSupportedException
,
347 create_sfc_port_pair
,
349 egress_ports
=egress_ports
,
352 @mock.patch
.object(vimconnector
, "get_sfi")
353 @mock.patch
.object(Client
, "create_sfc_port_pair_group")
354 def test_new_sf(self
, create_sfc_port_pair_group
, get_sfi
):
355 get_sfi
.return_value
= {"sfc_encap": True}
356 self
._test
_new
_sf
(create_sfc_port_pair_group
)
358 @mock.patch
.object(vimconnector
, "get_sfi")
359 @mock.patch
.object(Client
, "create_sfc_port_pair_group")
360 def test_new_sf_inconsistent_sfc_encap(self
, create_sfc_port_pair_group
, get_sfi
):
361 get_sfi
.return_value
= {"sfc_encap": "nsh"}
363 vimconn
.VimConnNotSupportedException
,
365 create_sfc_port_pair_group
,
368 @mock.patch
.object(Client
, "create_sfc_port_chain")
369 def test_new_sfp_with_sfc_encap(self
, create_sfc_port_chain
):
370 self
._test
_new
_sfp
(create_sfc_port_chain
, True, None)
372 @mock.patch
.object(Client
, "create_sfc_port_chain")
373 def test_new_sfp_without_sfc_encap(self
, create_sfc_port_chain
):
374 self
._test
_new
_sfp
(create_sfc_port_chain
, None, None)
375 self
._test
_new
_sfp
(create_sfc_port_chain
, None, 25)
377 @mock.patch
.object(Client
, "create_sfc_port_chain")
378 def test_new_sfp_default_sfc_encap(self
, create_sfc_port_chain
):
379 self
._test
_new
_sfp
(create_sfc_port_chain
, None, None)
381 @mock.patch
.object(Client
, "create_sfc_port_chain")
382 def test_new_sfp_with_sfc_encap_spi(self
, create_sfc_port_chain
):
383 self
._test
_new
_sfp
(create_sfc_port_chain
, True, 25)
385 @mock.patch
.object(Client
, "create_sfc_port_chain")
386 def test_new_sfp_default_sfc_encap_spi(self
, create_sfc_port_chain
):
387 self
._test
_new
_sfp
(create_sfc_port_chain
, None, 25)
389 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
390 def test_get_classification_list(self
, list_sfc_flow_classifiers
):
391 # what OpenStack is assumed to return to the VIM connector
392 list_sfc_flow_classifiers
.return_value
= {
393 "flow_classifiers": [
395 "source_port_range_min": 2000,
396 "destination_ip_prefix": "192.168.3.0/24",
401 "source_port_range_max": 2000,
402 "destination_port_range_min": 3000,
403 "source_ip_prefix": "192.168.2.0/24",
404 "logical_destination_port": None,
405 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
406 "destination_port_range_max": None,
407 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
408 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
409 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
415 # call the VIM connector
416 filter_dict
= {"protocol": "tcp", "ethertype": "IPv4"}
417 result
= self
.vimconn
.get_classification_list(filter_dict
.copy())
419 # assert that VIM connector called OpenStack with the expected filter
420 list_sfc_flow_classifiers
.assert_called_with(**filter_dict
)
421 # assert that the VIM connector successfully
422 # translated and returned the OpenStack result
427 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
430 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
431 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
432 "ctype": "legacy_flow_classifier",
434 "source_port_range_min": 2000,
435 "destination_ip_prefix": "192.168.3.0/24",
439 "source_port_range_max": 2000,
440 "destination_port_range_min": 3000,
441 "source_ip_prefix": "192.168.2.0/24",
442 "logical_destination_port": None,
443 "destination_port_range_max": None,
444 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
450 def _test_get_sfi_list(self
, list_port_pair
, correlation
, sfc_encap
):
451 # what OpenStack is assumed to return to the VIM connector
452 list_port_pair
.return_value
= {
455 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
457 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
458 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
459 "service_function_parameters": {"correlation": correlation
},
460 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
461 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
467 # call the VIM connector
468 filter_dict
= {"name": "osm_sfi", "description": ""}
469 result
= self
.vimconn
.get_sfi_list(filter_dict
.copy())
471 # assert that VIM connector called OpenStack with the expected filter
472 list_port_pair
.assert_called_with(**filter_dict
)
473 # assert that the VIM connector successfully
474 # translated and returned the OpenStack result
479 "ingress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
481 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
482 "egress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
483 "sfc_encap": sfc_encap
,
484 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
485 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
491 @mock.patch
.object(Client
, "list_sfc_port_pairs")
492 def test_get_sfi_list_with_sfc_encap(self
, list_sfc_port_pairs
):
493 self
._test
_get
_sfi
_list
(list_sfc_port_pairs
, "nsh", True)
495 @mock.patch
.object(Client
, "list_sfc_port_pairs")
496 def test_get_sfi_list_without_sfc_encap(self
, list_sfc_port_pairs
):
497 self
._test
_get
_sfi
_list
(list_sfc_port_pairs
, None, False)
499 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
500 def test_get_sf_list(self
, list_sfc_port_pair_groups
):
501 # what OpenStack is assumed to return to the VIM connector
502 list_sfc_port_pair_groups
.return_value
= {
503 "port_pair_groups": [
506 "08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2",
507 "0d63799c-82d6-11e7-8deb-a746bb3ae9f5",
510 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
511 "port_pair_group_parameters": {},
512 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
513 "id": "f4a0bde8-82d5-11e7-90e1-a72b762fa27f",
519 # call the VIM connector
520 filter_dict
= {"name": "osm_sf", "description": ""}
521 result
= self
.vimconn
.get_sf_list(filter_dict
.copy())
523 # assert that VIM connector called OpenStack with the expected filter
524 list_sfc_port_pair_groups
.assert_called_with(**filter_dict
)
525 # assert that the VIM connector successfully
526 # translated and returned the OpenStack result
532 "08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2",
533 "0d63799c-82d6-11e7-8deb-a746bb3ae9f5",
536 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
537 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
538 "id": "f4a0bde8-82d5-11e7-90e1-a72b762fa27f",
544 def _test_get_sfp_list(self
, list_sfc_port_chains
, correlation
, sfc_encap
):
545 # what OpenStack is assumed to return to the VIM connector
546 list_sfc_port_chains
.return_value
= {
549 "port_pair_groups": [
550 "7d8e3bf8-82d6-11e7-a032-8ff028839d25",
551 "7dc9013e-82d6-11e7-a5a6-a3a8d78a5518",
553 "flow_classifiers": [
554 "1333c2f4-82d7-11e7-a5df-9327f33d104e",
555 "1387ab44-82d7-11e7-9bb0-476337183905",
558 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
559 "chain_parameters": {"correlation": correlation
},
561 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
562 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
568 # call the VIM connector
569 filter_dict
= {"name": "osm_sfp", "description": ""}
570 result
= self
.vimconn
.get_sfp_list(filter_dict
.copy())
572 # assert that VIM connector called OpenStack with the expected filter
573 list_sfc_port_chains
.assert_called_with(**filter_dict
)
574 # assert that the VIM connector successfully
575 # translated and returned the OpenStack result
580 "service_functions": [
581 "7d8e3bf8-82d6-11e7-a032-8ff028839d25",
582 "7dc9013e-82d6-11e7-a5a6-a3a8d78a5518",
585 "1333c2f4-82d7-11e7-a5df-9327f33d104e",
586 "1387ab44-82d7-11e7-9bb0-476337183905",
589 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
590 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
591 "sfc_encap": sfc_encap
,
593 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
599 @mock.patch
.object(Client
, "list_sfc_port_chains")
600 def test_get_sfp_list_with_sfc_encap(self
, list_sfc_port_chains
):
601 self
._test
_get
_sfp
_list
(list_sfc_port_chains
, "nsh", True)
603 @mock.patch
.object(Client
, "list_sfc_port_chains")
604 def test_get_sfp_list_without_sfc_encap(self
, list_sfc_port_chains
):
605 self
._test
_get
_sfp
_list
(list_sfc_port_chains
, None, False)
607 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
608 def test_get_classification(self
, list_sfc_flow_classifiers
):
609 # what OpenStack is assumed to return to the VIM connector
610 list_sfc_flow_classifiers
.return_value
= {
611 "flow_classifiers": [
613 "source_port_range_min": 2000,
614 "destination_ip_prefix": "192.168.3.0/24",
619 "source_port_range_max": 2000,
620 "destination_port_range_min": 3000,
621 "source_ip_prefix": "192.168.2.0/24",
622 "logical_destination_port": None,
623 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
624 "destination_port_range_max": None,
625 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
626 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
627 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
633 # call the VIM connector
634 result
= self
.vimconn
.get_classification("22198366-d4e8-4d6b-b4d2-637d5d6cbb7d")
636 # assert that VIM connector called OpenStack with the expected filter
637 list_sfc_flow_classifiers
.assert_called_with(
638 id="22198366-d4e8-4d6b-b4d2-637d5d6cbb7d"
640 # assert that VIM connector successfully returned the OpenStack result
644 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
647 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
648 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
649 "ctype": "legacy_flow_classifier",
651 "source_port_range_min": 2000,
652 "destination_ip_prefix": "192.168.3.0/24",
656 "source_port_range_max": 2000,
657 "destination_port_range_min": 3000,
658 "source_ip_prefix": "192.168.2.0/24",
659 "logical_destination_port": None,
660 "destination_port_range_max": None,
661 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
666 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
667 def test_get_classification_many_results(self
, list_sfc_flow_classifiers
):
668 # what OpenStack is assumed to return to the VIM connector
669 list_sfc_flow_classifiers
.return_value
= {
670 "flow_classifiers": [
672 "source_port_range_min": 2000,
673 "destination_ip_prefix": "192.168.3.0/24",
678 "source_port_range_max": 2000,
679 "destination_port_range_min": 3000,
680 "source_ip_prefix": "192.168.2.0/24",
681 "logical_destination_port": None,
682 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
683 "destination_port_range_max": None,
684 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
685 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
686 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
690 "source_port_range_min": 1000,
691 "destination_ip_prefix": "192.168.3.0/24",
696 "source_port_range_max": 1000,
697 "destination_port_range_min": 3000,
698 "source_ip_prefix": "192.168.2.0/24",
699 "logical_destination_port": None,
700 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
701 "destination_port_range_max": None,
702 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
703 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
704 "id": "3196bafc-82dd-11e7-a205-9bf6c14b0721",
710 # call the VIM connector
712 vimconn
.VimConnConflictException
,
713 self
.vimconn
.get_classification
,
714 "3196bafc-82dd-11e7-a205-9bf6c14b0721",
717 # assert the VIM connector called OpenStack with the expected filter
718 list_sfc_flow_classifiers
.assert_called_with(
719 id="3196bafc-82dd-11e7-a205-9bf6c14b0721"
722 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
723 def test_get_classification_no_results(self
, list_sfc_flow_classifiers
):
724 # what OpenStack is assumed to return to the VIM connector
725 list_sfc_flow_classifiers
.return_value
= {"flow_classifiers": []}
727 # call the VIM connector
729 vimconn
.VimConnNotFoundException
,
730 self
.vimconn
.get_classification
,
731 "3196bafc-82dd-11e7-a205-9bf6c14b0721",
734 # assert the VIM connector called OpenStack with the expected filter
735 list_sfc_flow_classifiers
.assert_called_with(
736 id="3196bafc-82dd-11e7-a205-9bf6c14b0721"
739 @mock.patch
.object(Client
, "list_sfc_port_pairs")
740 def test_get_sfi(self
, list_sfc_port_pairs
):
741 # what OpenStack is assumed to return to the VIM connector
742 list_sfc_port_pairs
.return_value
= {
745 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
747 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
748 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
749 "service_function_parameters": {"correlation": "nsh"},
750 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
751 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
757 # call the VIM connector
758 result
= self
.vimconn
.get_sfi("c121ebdd-7f2d-4213-b933-3325298a6966")
760 # assert the VIM connector called OpenStack with the expected filter
761 list_sfc_port_pairs
.assert_called_with(
762 id="c121ebdd-7f2d-4213-b933-3325298a6966"
764 # assert the VIM connector successfully returned the OpenStack result
768 "ingress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
769 "egress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
772 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
773 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
774 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
779 @mock.patch
.object(Client
, "list_sfc_port_pairs")
780 def test_get_sfi_many_results(self
, list_sfc_port_pairs
):
781 # what OpenStack is assumed to return to the VIM connector
782 list_sfc_port_pairs
.return_value
= {
785 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
787 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
788 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
789 "service_function_parameters": {"correlation": "nsh"},
790 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
791 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
795 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
797 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
798 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
799 "service_function_parameters": {"correlation": "nsh"},
800 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
801 "id": "c0436d92-82db-11e7-8f9c-5fa535f1261f",
807 # call the VIM connector
809 vimconn
.VimConnConflictException
,
810 self
.vimconn
.get_sfi
,
811 "c0436d92-82db-11e7-8f9c-5fa535f1261f",
814 # assert that VIM connector called OpenStack with the expected filter
815 list_sfc_port_pairs
.assert_called_with(
816 id="c0436d92-82db-11e7-8f9c-5fa535f1261f"
819 @mock.patch
.object(Client
, "list_sfc_port_pairs")
820 def test_get_sfi_no_results(self
, list_sfc_port_pairs
):
821 # what OpenStack is assumed to return to the VIM connector
822 list_sfc_port_pairs
.return_value
= {"port_pairs": []}
824 # call the VIM connector
826 vimconn
.VimConnNotFoundException
,
827 self
.vimconn
.get_sfi
,
828 "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
831 # assert that VIM connector called OpenStack with the expected filter
832 list_sfc_port_pairs
.assert_called_with(
833 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
836 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
837 def test_get_sf(self
, list_sfc_port_pair_groups
):
838 # what OpenStack is assumed to return to the VIM connector
839 list_sfc_port_pair_groups
.return_value
= {
840 "port_pair_groups": [
842 "port_pairs": ["08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2"],
844 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
845 "port_pair_group_parameters": {},
846 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
847 "id": "aabba8a6-82d9-11e7-a18a-d3c7719b742d",
853 # call the VIM connector
854 result
= self
.vimconn
.get_sf("b22892fc-82d9-11e7-ae85-0fea6a3b3757")
856 # assert that VIM connector called OpenStack with the expected filter
857 list_sfc_port_pair_groups
.assert_called_with(
858 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
860 # assert that VIM connector successfully returned the OpenStack result
865 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
866 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
867 "sfis": ["08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2"],
868 "id": "aabba8a6-82d9-11e7-a18a-d3c7719b742d",
873 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
874 def test_get_sf_many_results(self
, list_sfc_port_pair_groups
):
875 # what OpenStack is assumed to return to the VIM connector
876 list_sfc_port_pair_groups
.return_value
= {
877 "port_pair_groups": [
879 "port_pairs": ["08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2"],
881 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
882 "port_pair_group_parameters": {},
883 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
884 "id": "aabba8a6-82d9-11e7-a18a-d3c7719b742d",
888 "port_pairs": ["0d63799c-82d6-11e7-8deb-a746bb3ae9f5"],
890 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
891 "port_pair_group_parameters": {},
892 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
893 "id": "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
899 # call the VIM connector
901 vimconn
.VimConnConflictException
,
903 "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
906 # assert that VIM connector called OpenStack with the expected filter
907 list_sfc_port_pair_groups
.assert_called_with(
908 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
911 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
912 def test_get_sf_no_results(self
, list_sfc_port_pair_groups
):
913 # what OpenStack is assumed to return to the VIM connector
914 list_sfc_port_pair_groups
.return_value
= {"port_pair_groups": []}
916 # call the VIM connector
918 vimconn
.VimConnNotFoundException
,
920 "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
923 # assert that VIM connector called OpenStack with the expected filter
924 list_sfc_port_pair_groups
.assert_called_with(
925 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
928 @mock.patch
.object(Client
, "list_sfc_port_chains")
929 def test_get_sfp(self
, list_sfc_port_chains
):
930 # what OpenStack is assumed to return to the VIM connector
931 list_sfc_port_chains
.return_value
= {
934 "port_pair_groups": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
935 "flow_classifiers": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
937 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
938 "chain_parameters": {"correlation": "nsh"},
940 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
941 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
947 # call the VIM connector
948 result
= self
.vimconn
.get_sfp("821bc9be-82d7-11e7-8ce3-23a08a27ab47")
950 # assert that VIM connector called OpenStack with the expected filter
951 list_sfc_port_chains
.assert_called_with(
952 id="821bc9be-82d7-11e7-8ce3-23a08a27ab47"
954 # assert that VIM connector successfully returned the OpenStack result
958 "service_functions": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
959 "classifications": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
961 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
962 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
965 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
970 @mock.patch
.object(Client
, "list_sfc_port_chains")
971 def test_get_sfp_many_results(self
, list_sfc_port_chains
):
972 # what OpenStack is assumed to return to the VIM connector
973 list_sfc_port_chains
.return_value
= {
976 "port_pair_groups": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
977 "flow_classifiers": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
979 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
980 "chain_parameters": {"correlation": "nsh"},
982 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
983 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
987 "port_pair_groups": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
988 "flow_classifiers": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
990 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
991 "chain_parameters": {"correlation": "nsh"},
993 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
994 "id": "5d002f38-82de-11e7-a770-f303f11ce66a",
1000 # call the VIM connector
1002 vimconn
.VimConnConflictException
,
1003 self
.vimconn
.get_sfp
,
1004 "5d002f38-82de-11e7-a770-f303f11ce66a",
1007 # assert that VIM connector called OpenStack with the expected filter
1008 list_sfc_port_chains
.assert_called_with(
1009 id="5d002f38-82de-11e7-a770-f303f11ce66a"
1012 @mock.patch
.object(Client
, "list_sfc_port_chains")
1013 def test_get_sfp_no_results(self
, list_sfc_port_chains
):
1014 # what OpenStack is assumed to return to the VIM connector
1015 list_sfc_port_chains
.return_value
= {"port_chains": []}
1017 # call the VIM connector
1019 vimconn
.VimConnNotFoundException
,
1020 self
.vimconn
.get_sfp
,
1021 "5d002f38-82de-11e7-a770-f303f11ce66a",
1024 # assert that VIM connector called OpenStack with the expected filter
1025 list_sfc_port_chains
.assert_called_with(
1026 id="5d002f38-82de-11e7-a770-f303f11ce66a"
1029 @mock.patch
.object(Client
, "delete_sfc_flow_classifier")
1030 def test_delete_classification(self
, delete_sfc_flow_classifier
):
1031 result
= self
.vimconn
.delete_classification(
1032 "638f957c-82df-11e7-b7c8-132706021464"
1034 delete_sfc_flow_classifier
.assert_called_with(
1035 "638f957c-82df-11e7-b7c8-132706021464"
1037 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1039 @mock.patch
.object(Client
, "delete_sfc_port_pair")
1040 def test_delete_sfi(self
, delete_sfc_port_pair
):
1041 result
= self
.vimconn
.delete_sfi("638f957c-82df-11e7-b7c8-132706021464")
1042 delete_sfc_port_pair
.assert_called_with("638f957c-82df-11e7-b7c8-132706021464")
1043 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1045 @mock.patch
.object(Client
, "delete_sfc_port_pair_group")
1046 def test_delete_sf(self
, delete_sfc_port_pair_group
):
1047 result
= self
.vimconn
.delete_sf("638f957c-82df-11e7-b7c8-132706021464")
1048 delete_sfc_port_pair_group
.assert_called_with(
1049 "638f957c-82df-11e7-b7c8-132706021464"
1051 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1053 @mock.patch
.object(Client
, "delete_sfc_port_chain")
1054 def test_delete_sfp(self
, delete_sfc_port_chain
):
1055 result
= self
.vimconn
.delete_sfp("638f957c-82df-11e7-b7c8-132706021464")
1056 delete_sfc_port_chain
.assert_called_with("638f957c-82df-11e7-b7c8-132706021464")
1057 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1060 if __name__
== "__main__":