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
32 from osm_ro_plugin
import vimconn
33 from osm_rovim_openstack
.vimconn_openstack
import vimconnector
35 __author__
= "Igor D.C."
36 __date__
= "$23-aug-2017 23:59:59$"
39 class TestSfcOperations(unittest
.TestCase
):
41 # instantiate dummy VIM connector so we can test it
42 self
.vimconn
= vimconnector(
57 ingress_ports
=["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
58 egress_ports
=["230cdf1b-de37-4891-bc07-f9010cf1f967"],
60 # input to VIM connector
64 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
66 if sfc_encap
is not None:
70 # what OpenStack is assumed to respond (patch OpenStack"s return value)
73 "id": "3d7ddc13-923c-4332-971e-708ed82902ce",
76 "tenant_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
77 "project_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
78 "ingress": ingress_ports
[0] if len(ingress_ports
) else None,
79 "egress": egress_ports
[0] if len(egress_ports
) else None,
80 "service_function_parameters": {"correlation": correlation
},
83 create_sfc_port_pair
.return_value
= dict_from_neutron
85 # what the VIM connector is expected to
86 # send to OpenStack based on the input
90 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
91 "egress": "230cdf1b-de37-4891-bc07-f9010cf1f967",
92 "service_function_parameters": {"correlation": correlation
},
96 # call the VIM connector
98 result
= self
.vimconn
.new_sfi(name
, ingress_ports
, egress_ports
)
100 result
= self
.vimconn
.new_sfi(name
, ingress_ports
, egress_ports
, sfc_encap
)
102 # assert that the VIM connector made the expected call to OpenStack
103 create_sfc_port_pair
.assert_called_with(dict_to_neutron
)
104 # assert that the VIM connector had the expected result / return value
105 self
.assertEqual(result
, dict_from_neutron
["port_pair"]["id"])
107 def _test_new_sf(self
, create_sfc_port_pair_group
):
108 # input to VIM connector
111 "bbd01220-cf72-41f2-9e70-0669c2e5c4cd",
112 "12ba215e-3987-4892-bd3a-d0fd91eecf98",
113 "e25a7c79-14c8-469a-9ae1-f601c9371ffd",
116 # what OpenStack is assumed to respond (patch OpenStack"s return value)
117 dict_from_neutron
= {
119 "id": "3d7ddc13-923c-4332-971e-708ed82902ce",
122 "tenant_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
123 "project_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
124 "port_pairs": instances
,
126 "port_pair_group_parameters": {
128 "ppg_n_tuple_mapping": {
129 "ingress_n_tuple": {},
130 "egress_n_tuple": {},
135 create_sfc_port_pair_group
.return_value
= dict_from_neutron
137 # what the VIM connector is expected to
138 # send to OpenStack based on the input
143 "bbd01220-cf72-41f2-9e70-0669c2e5c4cd",
144 "12ba215e-3987-4892-bd3a-d0fd91eecf98",
145 "e25a7c79-14c8-469a-9ae1-f601c9371ffd",
150 # call the VIM connector
151 result
= self
.vimconn
.new_sf(name
, instances
)
153 # assert that the VIM connector made the expected call to OpenStack
154 create_sfc_port_pair_group
.assert_called_with(dict_to_neutron
)
155 # assert that the VIM connector had the expected result / return value
156 self
.assertEqual(result
, dict_from_neutron
["port_pair_group"]["id"])
158 def _test_new_sfp(self
, create_sfc_port_chain
, sfc_encap
, spi
):
159 # input to VIM connector
162 "2bd2a2e5-c5fd-4eac-a297-d5e255c35c19",
163 "00f23389-bdfa-43c2-8b16-5815f2582fa8",
166 "2314daec-c262-414a-86e3-69bb6fa5bc16",
167 "d8bfdb5d-195e-4f34-81aa-6135705317df",
170 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
176 # what OpenStack is assumed to respond (patch OpenStack"s return value)
177 dict_from_neutron
= {
179 "id": "5bc05721-079b-4b6e-a235-47cac331cbb6",
182 "tenant_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
183 "project_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
184 "chain_id": chain_id
,
185 "flow_classifiers": classifications
,
186 "port_pair_groups": sfs
,
187 "chain_parameters": {"correlation": correlation
},
190 create_sfc_port_chain
.return_value
= dict_from_neutron
192 # what the VIM connector is expected to
193 # send to OpenStack based on the input
197 "flow_classifiers": [
198 "2bd2a2e5-c5fd-4eac-a297-d5e255c35c19",
199 "00f23389-bdfa-43c2-8b16-5815f2582fa8",
201 "port_pair_groups": [
202 "2314daec-c262-414a-86e3-69bb6fa5bc16",
203 "d8bfdb5d-195e-4f34-81aa-6135705317df",
205 "chain_parameters": {"correlation": correlation
},
209 dict_to_neutron
["port_chain"]["chain_id"] = spi
211 # call the VIM connector
212 if sfc_encap
is None:
214 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
)
216 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
, spi
=spi
)
219 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
, sfc_encap
)
221 result
= self
.vimconn
.new_sfp(
222 name
, classifications
, sfs
, sfc_encap
, spi
225 # assert that the VIM connector made the expected call to OpenStack
226 create_sfc_port_chain
.assert_called_with(dict_to_neutron
)
227 # assert that the VIM connector had the expected result / return value
228 self
.assertEqual(result
, dict_from_neutron
["port_chain"]["id"])
230 def _test_new_classification(self
, create_sfc_flow_classifier
, ctype
):
231 # input to VIM connector
232 name
= "osm_classification"
235 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
237 "source_ip_prefix": "192.168.2.0/24",
238 "source_port_range_max": 99,
239 "source_port_range_min": 50,
242 # what OpenStack is assumed to respond (patch OpenStack"s return value)
243 dict_from_neutron
= {"flow_classifier": copy
.copy(definition
)}
244 dict_from_neutron
["flow_classifier"][
246 ] = "7735ec2c-fddf-4130-9712-32ed2ab6a372"
247 dict_from_neutron
["flow_classifier"]["name"] = name
248 dict_from_neutron
["flow_classifier"]["description"] = ""
249 dict_from_neutron
["flow_classifier"][
251 ] = "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c"
252 dict_from_neutron
["flow_classifier"][
254 ] = "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c"
255 create_sfc_flow_classifier
.return_value
= dict_from_neutron
257 # what the VIM connector is expected to
258 # send to OpenStack based on the input
259 dict_to_neutron
= {"flow_classifier": copy
.copy(definition
)}
260 dict_to_neutron
["flow_classifier"]["name"] = "osm_classification"
262 # call the VIM connector
263 result
= self
.vimconn
.new_classification(name
, ctype
, definition
)
265 # assert that the VIM connector made the expected call to OpenStack
266 create_sfc_flow_classifier
.assert_called_with(dict_to_neutron
)
267 # assert that the VIM connector had the expected result / return value
268 self
.assertEqual(result
, dict_from_neutron
["flow_classifier"]["id"])
270 @mock.patch
.object(Client
, "create_sfc_flow_classifier")
271 def test_new_classification(self
, create_sfc_flow_classifier
):
272 self
._test
_new
_classification
(
273 create_sfc_flow_classifier
, "legacy_flow_classifier"
276 @mock.patch
.object(Client
, "create_sfc_flow_classifier")
277 def test_new_classification_unsupported_type(self
, create_sfc_flow_classifier
):
279 vimconn
.VimConnNotSupportedException
,
280 self
._test
_new
_classification
,
281 create_sfc_flow_classifier
,
285 @mock.patch
.object(Client
, "create_sfc_port_pair")
286 def test_new_sfi_with_sfc_encap(self
, create_sfc_port_pair
):
287 self
._test
_new
_sfi
(create_sfc_port_pair
, True)
289 @mock.patch
.object(Client
, "create_sfc_port_pair")
290 def test_new_sfi_without_sfc_encap(self
, create_sfc_port_pair
):
291 self
._test
_new
_sfi
(create_sfc_port_pair
, False)
293 @mock.patch
.object(Client
, "create_sfc_port_pair")
294 def test_new_sfi_default_sfc_encap(self
, create_sfc_port_pair
):
295 self
._test
_new
_sfi
(create_sfc_port_pair
, None)
297 @mock.patch
.object(Client
, "create_sfc_port_pair")
298 def test_new_sfi_bad_ingress_ports(self
, create_sfc_port_pair
):
300 "5311c75d-d718-4369-bbda-cdcc6da60fcc",
301 "a0273f64-82c9-11e7-b08f-6328e53f0fa7",
304 vimconn
.VimConnNotSupportedException
,
306 create_sfc_port_pair
,
308 ingress_ports
=ingress_ports
,
312 vimconn
.VimConnNotSupportedException
,
314 create_sfc_port_pair
,
316 ingress_ports
=ingress_ports
,
319 @mock.patch
.object(Client
, "create_sfc_port_pair")
320 def test_new_sfi_bad_egress_ports(self
, create_sfc_port_pair
):
322 "230cdf1b-de37-4891-bc07-f9010cf1f967",
323 "b41228fe-82c9-11e7-9b44-17504174320b",
326 vimconn
.VimConnNotSupportedException
,
328 create_sfc_port_pair
,
330 egress_ports
=egress_ports
,
334 vimconn
.VimConnNotSupportedException
,
336 create_sfc_port_pair
,
338 egress_ports
=egress_ports
,
341 @mock.patch
.object(vimconnector
, "get_sfi")
342 @mock.patch
.object(Client
, "create_sfc_port_pair_group")
343 def test_new_sf(self
, create_sfc_port_pair_group
, get_sfi
):
344 get_sfi
.return_value
= {"sfc_encap": True}
345 self
._test
_new
_sf
(create_sfc_port_pair_group
)
347 @mock.patch
.object(vimconnector
, "get_sfi")
348 @mock.patch
.object(Client
, "create_sfc_port_pair_group")
349 def test_new_sf_inconsistent_sfc_encap(self
, create_sfc_port_pair_group
, get_sfi
):
350 get_sfi
.return_value
= {"sfc_encap": "nsh"}
352 vimconn
.VimConnNotSupportedException
,
354 create_sfc_port_pair_group
,
357 @mock.patch
.object(Client
, "create_sfc_port_chain")
358 def test_new_sfp_with_sfc_encap(self
, create_sfc_port_chain
):
359 self
._test
_new
_sfp
(create_sfc_port_chain
, True, None)
361 @mock.patch
.object(Client
, "create_sfc_port_chain")
362 def test_new_sfp_without_sfc_encap(self
, create_sfc_port_chain
):
363 self
._test
_new
_sfp
(create_sfc_port_chain
, False, None)
364 self
._test
_new
_sfp
(create_sfc_port_chain
, False, 25)
366 @mock.patch
.object(Client
, "create_sfc_port_chain")
367 def test_new_sfp_default_sfc_encap(self
, create_sfc_port_chain
):
368 self
._test
_new
_sfp
(create_sfc_port_chain
, None, None)
370 @mock.patch
.object(Client
, "create_sfc_port_chain")
371 def test_new_sfp_with_sfc_encap_spi(self
, create_sfc_port_chain
):
372 self
._test
_new
_sfp
(create_sfc_port_chain
, True, 25)
374 @mock.patch
.object(Client
, "create_sfc_port_chain")
375 def test_new_sfp_default_sfc_encap_spi(self
, create_sfc_port_chain
):
376 self
._test
_new
_sfp
(create_sfc_port_chain
, None, 25)
378 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
379 def test_get_classification_list(self
, list_sfc_flow_classifiers
):
380 # what OpenStack is assumed to return to the VIM connector
381 list_sfc_flow_classifiers
.return_value
= {
382 "flow_classifiers": [
384 "source_port_range_min": 2000,
385 "destination_ip_prefix": "192.168.3.0/24",
390 "source_port_range_max": 2000,
391 "destination_port_range_min": 3000,
392 "source_ip_prefix": "192.168.2.0/24",
393 "logical_destination_port": None,
394 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
395 "destination_port_range_max": None,
396 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
397 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
398 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
404 # call the VIM connector
405 filter_dict
= {"protocol": "tcp", "ethertype": "IPv4"}
406 result
= self
.vimconn
.get_classification_list(filter_dict
.copy())
408 # assert that VIM connector called OpenStack with the expected filter
409 list_sfc_flow_classifiers
.assert_called_with(**filter_dict
)
410 # assert that the VIM connector successfully
411 # translated and returned the OpenStack result
416 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
419 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
420 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
421 "ctype": "legacy_flow_classifier",
423 "source_port_range_min": 2000,
424 "destination_ip_prefix": "192.168.3.0/24",
428 "source_port_range_max": 2000,
429 "destination_port_range_min": 3000,
430 "source_ip_prefix": "192.168.2.0/24",
431 "logical_destination_port": None,
432 "destination_port_range_max": None,
433 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
439 def _test_get_sfi_list(self
, list_port_pair
, correlation
, sfc_encap
):
440 # what OpenStack is assumed to return to the VIM connector
441 list_port_pair
.return_value
= {
444 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
446 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
447 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
448 "service_function_parameters": {"correlation": correlation
},
449 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
450 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
456 # call the VIM connector
457 filter_dict
= {"name": "osm_sfi", "description": ""}
458 result
= self
.vimconn
.get_sfi_list(filter_dict
.copy())
460 # assert that VIM connector called OpenStack with the expected filter
461 list_port_pair
.assert_called_with(**filter_dict
)
462 # assert that the VIM connector successfully
463 # translated and returned the OpenStack result
468 "ingress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
470 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
471 "egress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
472 "sfc_encap": sfc_encap
,
473 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
474 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
480 @mock.patch
.object(Client
, "list_sfc_port_pairs")
481 def test_get_sfi_list_with_sfc_encap(self
, list_sfc_port_pairs
):
482 self
._test
_get
_sfi
_list
(list_sfc_port_pairs
, "nsh", True)
484 @mock.patch
.object(Client
, "list_sfc_port_pairs")
485 def test_get_sfi_list_without_sfc_encap(self
, list_sfc_port_pairs
):
486 self
._test
_get
_sfi
_list
(list_sfc_port_pairs
, None, False)
488 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
489 def test_get_sf_list(self
, list_sfc_port_pair_groups
):
490 # what OpenStack is assumed to return to the VIM connector
491 list_sfc_port_pair_groups
.return_value
= {
492 "port_pair_groups": [
495 "08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2",
496 "0d63799c-82d6-11e7-8deb-a746bb3ae9f5",
499 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
500 "port_pair_group_parameters": {},
501 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
502 "id": "f4a0bde8-82d5-11e7-90e1-a72b762fa27f",
508 # call the VIM connector
509 filter_dict
= {"name": "osm_sf", "description": ""}
510 result
= self
.vimconn
.get_sf_list(filter_dict
.copy())
512 # assert that VIM connector called OpenStack with the expected filter
513 list_sfc_port_pair_groups
.assert_called_with(**filter_dict
)
514 # assert that the VIM connector successfully
515 # translated and returned the OpenStack result
521 "08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2",
522 "0d63799c-82d6-11e7-8deb-a746bb3ae9f5",
525 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
526 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
527 "id": "f4a0bde8-82d5-11e7-90e1-a72b762fa27f",
533 def _test_get_sfp_list(self
, list_sfc_port_chains
, correlation
, sfc_encap
):
534 # what OpenStack is assumed to return to the VIM connector
535 list_sfc_port_chains
.return_value
= {
538 "port_pair_groups": [
539 "7d8e3bf8-82d6-11e7-a032-8ff028839d25",
540 "7dc9013e-82d6-11e7-a5a6-a3a8d78a5518",
542 "flow_classifiers": [
543 "1333c2f4-82d7-11e7-a5df-9327f33d104e",
544 "1387ab44-82d7-11e7-9bb0-476337183905",
547 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
548 "chain_parameters": {"correlation": correlation
},
550 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
551 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
557 # call the VIM connector
558 filter_dict
= {"name": "osm_sfp", "description": ""}
559 result
= self
.vimconn
.get_sfp_list(filter_dict
.copy())
561 # assert that VIM connector called OpenStack with the expected filter
562 list_sfc_port_chains
.assert_called_with(**filter_dict
)
563 # assert that the VIM connector successfully
564 # translated and returned the OpenStack result
569 "service_functions": [
570 "7d8e3bf8-82d6-11e7-a032-8ff028839d25",
571 "7dc9013e-82d6-11e7-a5a6-a3a8d78a5518",
574 "1333c2f4-82d7-11e7-a5df-9327f33d104e",
575 "1387ab44-82d7-11e7-9bb0-476337183905",
578 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
579 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
580 "sfc_encap": sfc_encap
,
582 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
588 @mock.patch
.object(Client
, "list_sfc_port_chains")
589 def test_get_sfp_list_with_sfc_encap(self
, list_sfc_port_chains
):
590 self
._test
_get
_sfp
_list
(list_sfc_port_chains
, "nsh", True)
592 @mock.patch
.object(Client
, "list_sfc_port_chains")
593 def test_get_sfp_list_without_sfc_encap(self
, list_sfc_port_chains
):
594 self
._test
_get
_sfp
_list
(list_sfc_port_chains
, None, False)
596 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
597 def test_get_classification(self
, list_sfc_flow_classifiers
):
598 # what OpenStack is assumed to return to the VIM connector
599 list_sfc_flow_classifiers
.return_value
= {
600 "flow_classifiers": [
602 "source_port_range_min": 2000,
603 "destination_ip_prefix": "192.168.3.0/24",
608 "source_port_range_max": 2000,
609 "destination_port_range_min": 3000,
610 "source_ip_prefix": "192.168.2.0/24",
611 "logical_destination_port": None,
612 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
613 "destination_port_range_max": None,
614 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
615 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
616 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
622 # call the VIM connector
623 result
= self
.vimconn
.get_classification("22198366-d4e8-4d6b-b4d2-637d5d6cbb7d")
625 # assert that VIM connector called OpenStack with the expected filter
626 list_sfc_flow_classifiers
.assert_called_with(
627 id="22198366-d4e8-4d6b-b4d2-637d5d6cbb7d"
629 # assert that VIM connector successfully returned the OpenStack result
633 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
636 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
637 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
638 "ctype": "legacy_flow_classifier",
640 "source_port_range_min": 2000,
641 "destination_ip_prefix": "192.168.3.0/24",
645 "source_port_range_max": 2000,
646 "destination_port_range_min": 3000,
647 "source_ip_prefix": "192.168.2.0/24",
648 "logical_destination_port": None,
649 "destination_port_range_max": None,
650 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
655 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
656 def test_get_classification_many_results(self
, list_sfc_flow_classifiers
):
657 # what OpenStack is assumed to return to the VIM connector
658 list_sfc_flow_classifiers
.return_value
= {
659 "flow_classifiers": [
661 "source_port_range_min": 2000,
662 "destination_ip_prefix": "192.168.3.0/24",
667 "source_port_range_max": 2000,
668 "destination_port_range_min": 3000,
669 "source_ip_prefix": "192.168.2.0/24",
670 "logical_destination_port": None,
671 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
672 "destination_port_range_max": None,
673 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
674 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
675 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
679 "source_port_range_min": 1000,
680 "destination_ip_prefix": "192.168.3.0/24",
685 "source_port_range_max": 1000,
686 "destination_port_range_min": 3000,
687 "source_ip_prefix": "192.168.2.0/24",
688 "logical_destination_port": None,
689 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
690 "destination_port_range_max": None,
691 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
692 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
693 "id": "3196bafc-82dd-11e7-a205-9bf6c14b0721",
699 # call the VIM connector
701 vimconn
.VimConnConflictException
,
702 self
.vimconn
.get_classification
,
703 "3196bafc-82dd-11e7-a205-9bf6c14b0721",
706 # assert the VIM connector called OpenStack with the expected filter
707 list_sfc_flow_classifiers
.assert_called_with(
708 id="3196bafc-82dd-11e7-a205-9bf6c14b0721"
711 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
712 def test_get_classification_no_results(self
, list_sfc_flow_classifiers
):
713 # what OpenStack is assumed to return to the VIM connector
714 list_sfc_flow_classifiers
.return_value
= {"flow_classifiers": []}
716 # call the VIM connector
718 vimconn
.VimConnNotFoundException
,
719 self
.vimconn
.get_classification
,
720 "3196bafc-82dd-11e7-a205-9bf6c14b0721",
723 # assert the VIM connector called OpenStack with the expected filter
724 list_sfc_flow_classifiers
.assert_called_with(
725 id="3196bafc-82dd-11e7-a205-9bf6c14b0721"
728 @mock.patch
.object(Client
, "list_sfc_port_pairs")
729 def test_get_sfi(self
, list_sfc_port_pairs
):
730 # what OpenStack is assumed to return to the VIM connector
731 list_sfc_port_pairs
.return_value
= {
734 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
736 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
737 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
738 "service_function_parameters": {"correlation": "nsh"},
739 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
740 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
746 # call the VIM connector
747 result
= self
.vimconn
.get_sfi("c121ebdd-7f2d-4213-b933-3325298a6966")
749 # assert the VIM connector called OpenStack with the expected filter
750 list_sfc_port_pairs
.assert_called_with(
751 id="c121ebdd-7f2d-4213-b933-3325298a6966"
753 # assert the VIM connector successfully returned the OpenStack result
757 "ingress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
758 "egress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
761 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
762 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
763 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
768 @mock.patch
.object(Client
, "list_sfc_port_pairs")
769 def test_get_sfi_many_results(self
, list_sfc_port_pairs
):
770 # what OpenStack is assumed to return to the VIM connector
771 list_sfc_port_pairs
.return_value
= {
774 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
776 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
777 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
778 "service_function_parameters": {"correlation": "nsh"},
779 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
780 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
784 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
786 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
787 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
788 "service_function_parameters": {"correlation": "nsh"},
789 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
790 "id": "c0436d92-82db-11e7-8f9c-5fa535f1261f",
796 # call the VIM connector
798 vimconn
.VimConnConflictException
,
799 self
.vimconn
.get_sfi
,
800 "c0436d92-82db-11e7-8f9c-5fa535f1261f",
803 # assert that VIM connector called OpenStack with the expected filter
804 list_sfc_port_pairs
.assert_called_with(
805 id="c0436d92-82db-11e7-8f9c-5fa535f1261f"
808 @mock.patch
.object(Client
, "list_sfc_port_pairs")
809 def test_get_sfi_no_results(self
, list_sfc_port_pairs
):
810 # what OpenStack is assumed to return to the VIM connector
811 list_sfc_port_pairs
.return_value
= {"port_pairs": []}
813 # call the VIM connector
815 vimconn
.VimConnNotFoundException
,
816 self
.vimconn
.get_sfi
,
817 "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
820 # assert that VIM connector called OpenStack with the expected filter
821 list_sfc_port_pairs
.assert_called_with(
822 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
825 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
826 def test_get_sf(self
, list_sfc_port_pair_groups
):
827 # what OpenStack is assumed to return to the VIM connector
828 list_sfc_port_pair_groups
.return_value
= {
829 "port_pair_groups": [
831 "port_pairs": ["08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2"],
833 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
834 "port_pair_group_parameters": {},
835 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
836 "id": "aabba8a6-82d9-11e7-a18a-d3c7719b742d",
842 # call the VIM connector
843 result
= self
.vimconn
.get_sf("b22892fc-82d9-11e7-ae85-0fea6a3b3757")
845 # assert that VIM connector called OpenStack with the expected filter
846 list_sfc_port_pair_groups
.assert_called_with(
847 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
849 # assert that VIM connector successfully returned the OpenStack result
854 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
855 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
856 "sfis": ["08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2"],
857 "id": "aabba8a6-82d9-11e7-a18a-d3c7719b742d",
862 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
863 def test_get_sf_many_results(self
, list_sfc_port_pair_groups
):
864 # what OpenStack is assumed to return to the VIM connector
865 list_sfc_port_pair_groups
.return_value
= {
866 "port_pair_groups": [
868 "port_pairs": ["08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2"],
870 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
871 "port_pair_group_parameters": {},
872 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
873 "id": "aabba8a6-82d9-11e7-a18a-d3c7719b742d",
877 "port_pairs": ["0d63799c-82d6-11e7-8deb-a746bb3ae9f5"],
879 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
880 "port_pair_group_parameters": {},
881 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
882 "id": "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
888 # call the VIM connector
890 vimconn
.VimConnConflictException
,
892 "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
895 # assert that VIM connector called OpenStack with the expected filter
896 list_sfc_port_pair_groups
.assert_called_with(
897 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
900 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
901 def test_get_sf_no_results(self
, list_sfc_port_pair_groups
):
902 # what OpenStack is assumed to return to the VIM connector
903 list_sfc_port_pair_groups
.return_value
= {"port_pair_groups": []}
905 # call the VIM connector
907 vimconn
.VimConnNotFoundException
,
909 "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
912 # assert that VIM connector called OpenStack with the expected filter
913 list_sfc_port_pair_groups
.assert_called_with(
914 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
917 @mock.patch
.object(Client
, "list_sfc_port_chains")
918 def test_get_sfp(self
, list_sfc_port_chains
):
919 # what OpenStack is assumed to return to the VIM connector
920 list_sfc_port_chains
.return_value
= {
923 "port_pair_groups": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
924 "flow_classifiers": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
926 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
927 "chain_parameters": {"correlation": "nsh"},
929 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
930 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
936 # call the VIM connector
937 result
= self
.vimconn
.get_sfp("821bc9be-82d7-11e7-8ce3-23a08a27ab47")
939 # assert that VIM connector called OpenStack with the expected filter
940 list_sfc_port_chains
.assert_called_with(
941 id="821bc9be-82d7-11e7-8ce3-23a08a27ab47"
943 # assert that VIM connector successfully returned the OpenStack result
947 "service_functions": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
948 "classifications": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
950 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
951 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
954 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
959 @mock.patch
.object(Client
, "list_sfc_port_chains")
960 def test_get_sfp_many_results(self
, list_sfc_port_chains
):
961 # what OpenStack is assumed to return to the VIM connector
962 list_sfc_port_chains
.return_value
= {
965 "port_pair_groups": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
966 "flow_classifiers": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
968 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
969 "chain_parameters": {"correlation": "nsh"},
971 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
972 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
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": "5d002f38-82de-11e7-a770-f303f11ce66a",
989 # call the VIM connector
991 vimconn
.VimConnConflictException
,
992 self
.vimconn
.get_sfp
,
993 "5d002f38-82de-11e7-a770-f303f11ce66a",
996 # assert that VIM connector called OpenStack with the expected filter
997 list_sfc_port_chains
.assert_called_with(
998 id="5d002f38-82de-11e7-a770-f303f11ce66a"
1001 @mock.patch
.object(Client
, "list_sfc_port_chains")
1002 def test_get_sfp_no_results(self
, list_sfc_port_chains
):
1003 # what OpenStack is assumed to return to the VIM connector
1004 list_sfc_port_chains
.return_value
= {"port_chains": []}
1006 # call the VIM connector
1008 vimconn
.VimConnNotFoundException
,
1009 self
.vimconn
.get_sfp
,
1010 "5d002f38-82de-11e7-a770-f303f11ce66a",
1013 # assert that VIM connector called OpenStack with the expected filter
1014 list_sfc_port_chains
.assert_called_with(
1015 id="5d002f38-82de-11e7-a770-f303f11ce66a"
1018 @mock.patch
.object(Client
, "delete_sfc_flow_classifier")
1019 def test_delete_classification(self
, delete_sfc_flow_classifier
):
1020 result
= self
.vimconn
.delete_classification(
1021 "638f957c-82df-11e7-b7c8-132706021464"
1023 delete_sfc_flow_classifier
.assert_called_with(
1024 "638f957c-82df-11e7-b7c8-132706021464"
1026 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1028 @mock.patch
.object(Client
, "delete_sfc_port_pair")
1029 def test_delete_sfi(self
, delete_sfc_port_pair
):
1030 result
= self
.vimconn
.delete_sfi("638f957c-82df-11e7-b7c8-132706021464")
1031 delete_sfc_port_pair
.assert_called_with("638f957c-82df-11e7-b7c8-132706021464")
1032 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1034 @mock.patch
.object(Client
, "delete_sfc_port_pair_group")
1035 def test_delete_sf(self
, delete_sfc_port_pair_group
):
1036 result
= self
.vimconn
.delete_sf("638f957c-82df-11e7-b7c8-132706021464")
1037 delete_sfc_port_pair_group
.assert_called_with(
1038 "638f957c-82df-11e7-b7c8-132706021464"
1040 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1042 @mock.patch
.object(Client
, "delete_sfc_port_chain")
1043 def test_delete_sfp(self
, delete_sfc_port_chain
):
1044 result
= self
.vimconn
.delete_sfp("638f957c-82df-11e7-b7c8-132706021464")
1045 delete_sfc_port_chain
.assert_called_with("638f957c-82df-11e7-b7c8-132706021464")
1046 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1049 if __name__
== "__main__":