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_plugin
import vimconn
34 from osm_rovim_openstack
.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(
59 ingress_ports
=["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
60 egress_ports
=["230cdf1b-de37-4891-bc07-f9010cf1f967"],
62 # input to VIM connector
66 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
68 if sfc_encap
is not None:
72 # what OpenStack is assumed to respond (patch OpenStack"s return value)
75 "id": "3d7ddc13-923c-4332-971e-708ed82902ce",
78 "tenant_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
79 "project_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
80 "ingress": ingress_ports
[0] if len(ingress_ports
) else None,
81 "egress": egress_ports
[0] if len(egress_ports
) else None,
82 "service_function_parameters": {"correlation": correlation
},
85 create_sfc_port_pair
.return_value
= dict_from_neutron
87 # what the VIM connector is expected to
88 # send to OpenStack based on the input
92 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
93 "egress": "230cdf1b-de37-4891-bc07-f9010cf1f967",
94 "service_function_parameters": {"correlation": correlation
},
98 # call the VIM connector
100 result
= self
.vimconn
.new_sfi(name
, ingress_ports
, egress_ports
)
102 result
= self
.vimconn
.new_sfi(name
, ingress_ports
, egress_ports
, sfc_encap
)
104 # assert that the VIM connector made the expected call to OpenStack
105 create_sfc_port_pair
.assert_called_with(dict_to_neutron
)
106 # assert that the VIM connector had the expected result / return value
107 self
.assertEqual(result
, dict_from_neutron
["port_pair"]["id"])
109 def _test_new_sf(self
, create_sfc_port_pair_group
):
110 # input to VIM connector
113 "bbd01220-cf72-41f2-9e70-0669c2e5c4cd",
114 "12ba215e-3987-4892-bd3a-d0fd91eecf98",
115 "e25a7c79-14c8-469a-9ae1-f601c9371ffd",
118 # what OpenStack is assumed to respond (patch OpenStack"s return value)
119 dict_from_neutron
= {
121 "id": "3d7ddc13-923c-4332-971e-708ed82902ce",
124 "tenant_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
125 "project_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
126 "port_pairs": instances
,
128 "port_pair_group_parameters": {
130 "ppg_n_tuple_mapping": {
131 "ingress_n_tuple": {},
132 "egress_n_tuple": {},
137 create_sfc_port_pair_group
.return_value
= dict_from_neutron
139 # what the VIM connector is expected to
140 # send to OpenStack based on the input
145 "bbd01220-cf72-41f2-9e70-0669c2e5c4cd",
146 "12ba215e-3987-4892-bd3a-d0fd91eecf98",
147 "e25a7c79-14c8-469a-9ae1-f601c9371ffd",
152 # call the VIM connector
153 result
= self
.vimconn
.new_sf(name
, instances
)
155 # assert that the VIM connector made the expected call to OpenStack
156 create_sfc_port_pair_group
.assert_called_with(dict_to_neutron
)
157 # assert that the VIM connector had the expected result / return value
158 self
.assertEqual(result
, dict_from_neutron
["port_pair_group"]["id"])
160 def _test_new_sfp(self
, create_sfc_port_chain
, sfc_encap
, spi
):
161 # input to VIM connector
164 "2bd2a2e5-c5fd-4eac-a297-d5e255c35c19",
165 "00f23389-bdfa-43c2-8b16-5815f2582fa8",
168 "2314daec-c262-414a-86e3-69bb6fa5bc16",
169 "d8bfdb5d-195e-4f34-81aa-6135705317df",
172 # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround)
178 # what OpenStack is assumed to respond (patch OpenStack"s return value)
179 dict_from_neutron
= {
181 "id": "5bc05721-079b-4b6e-a235-47cac331cbb6",
184 "tenant_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
185 "project_id": "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c",
186 "chain_id": chain_id
,
187 "flow_classifiers": classifications
,
188 "port_pair_groups": sfs
,
189 "chain_parameters": {"correlation": correlation
},
192 create_sfc_port_chain
.return_value
= dict_from_neutron
194 # what the VIM connector is expected to
195 # send to OpenStack based on the input
199 "flow_classifiers": [
200 "2bd2a2e5-c5fd-4eac-a297-d5e255c35c19",
201 "00f23389-bdfa-43c2-8b16-5815f2582fa8",
203 "port_pair_groups": [
204 "2314daec-c262-414a-86e3-69bb6fa5bc16",
205 "d8bfdb5d-195e-4f34-81aa-6135705317df",
207 "chain_parameters": {"correlation": correlation
},
211 dict_to_neutron
["port_chain"]["chain_id"] = spi
213 # call the VIM connector
214 if sfc_encap
is None:
216 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
)
218 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
, spi
=spi
)
221 result
= self
.vimconn
.new_sfp(name
, classifications
, sfs
, sfc_encap
)
223 result
= self
.vimconn
.new_sfp(
224 name
, classifications
, sfs
, sfc_encap
, spi
227 # assert that the VIM connector made the expected call to OpenStack
228 create_sfc_port_chain
.assert_called_with(dict_to_neutron
)
229 # assert that the VIM connector had the expected result / return value
230 self
.assertEqual(result
, dict_from_neutron
["port_chain"]["id"])
232 def _test_new_classification(self
, create_sfc_flow_classifier
, ctype
):
233 # input to VIM connector
234 name
= "osm_classification"
237 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
239 "source_ip_prefix": "192.168.2.0/24",
240 "source_port_range_max": 99,
241 "source_port_range_min": 50,
244 # what OpenStack is assumed to respond (patch OpenStack"s return value)
245 dict_from_neutron
= {"flow_classifier": copy
.copy(definition
)}
246 dict_from_neutron
["flow_classifier"][
248 ] = "7735ec2c-fddf-4130-9712-32ed2ab6a372"
249 dict_from_neutron
["flow_classifier"]["name"] = name
250 dict_from_neutron
["flow_classifier"]["description"] = ""
251 dict_from_neutron
["flow_classifier"][
253 ] = "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c"
254 dict_from_neutron
["flow_classifier"][
256 ] = "130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c"
257 create_sfc_flow_classifier
.return_value
= dict_from_neutron
259 # what the VIM connector is expected to
260 # send to OpenStack based on the input
261 dict_to_neutron
= {"flow_classifier": copy
.copy(definition
)}
262 dict_to_neutron
["flow_classifier"]["name"] = "osm_classification"
264 # call the VIM connector
265 result
= self
.vimconn
.new_classification(name
, ctype
, definition
)
267 # assert that the VIM connector made the expected call to OpenStack
268 create_sfc_flow_classifier
.assert_called_with(dict_to_neutron
)
269 # assert that the VIM connector had the expected result / return value
270 self
.assertEqual(result
, dict_from_neutron
["flow_classifier"]["id"])
272 @mock.patch
.object(Client
, "create_sfc_flow_classifier")
273 def test_new_classification(self
, create_sfc_flow_classifier
):
274 self
._test
_new
_classification
(
275 create_sfc_flow_classifier
, "legacy_flow_classifier"
278 @mock.patch
.object(Client
, "create_sfc_flow_classifier")
279 def test_new_classification_unsupported_type(self
, create_sfc_flow_classifier
):
281 vimconn
.VimConnNotSupportedException
,
282 self
._test
_new
_classification
,
283 create_sfc_flow_classifier
,
287 @mock.patch
.object(Client
, "create_sfc_port_pair")
288 def test_new_sfi_with_sfc_encap(self
, create_sfc_port_pair
):
289 self
._test
_new
_sfi
(create_sfc_port_pair
, True)
291 @mock.patch
.object(Client
, "create_sfc_port_pair")
292 def test_new_sfi_without_sfc_encap(self
, create_sfc_port_pair
):
293 self
._test
_new
_sfi
(create_sfc_port_pair
, False)
295 @mock.patch
.object(Client
, "create_sfc_port_pair")
296 def test_new_sfi_default_sfc_encap(self
, create_sfc_port_pair
):
297 self
._test
_new
_sfi
(create_sfc_port_pair
, None)
299 @mock.patch
.object(Client
, "create_sfc_port_pair")
300 def test_new_sfi_bad_ingress_ports(self
, create_sfc_port_pair
):
302 "5311c75d-d718-4369-bbda-cdcc6da60fcc",
303 "a0273f64-82c9-11e7-b08f-6328e53f0fa7",
306 vimconn
.VimConnNotSupportedException
,
308 create_sfc_port_pair
,
310 ingress_ports
=ingress_ports
,
314 vimconn
.VimConnNotSupportedException
,
316 create_sfc_port_pair
,
318 ingress_ports
=ingress_ports
,
321 @mock.patch
.object(Client
, "create_sfc_port_pair")
322 def test_new_sfi_bad_egress_ports(self
, create_sfc_port_pair
):
324 "230cdf1b-de37-4891-bc07-f9010cf1f967",
325 "b41228fe-82c9-11e7-9b44-17504174320b",
328 vimconn
.VimConnNotSupportedException
,
330 create_sfc_port_pair
,
332 egress_ports
=egress_ports
,
336 vimconn
.VimConnNotSupportedException
,
338 create_sfc_port_pair
,
340 egress_ports
=egress_ports
,
343 @mock.patch
.object(vimconnector
, "get_sfi")
344 @mock.patch
.object(Client
, "create_sfc_port_pair_group")
345 def test_new_sf(self
, create_sfc_port_pair_group
, get_sfi
):
346 get_sfi
.return_value
= {"sfc_encap": True}
347 self
._test
_new
_sf
(create_sfc_port_pair_group
)
349 @mock.patch
.object(vimconnector
, "get_sfi")
350 @mock.patch
.object(Client
, "create_sfc_port_pair_group")
351 def test_new_sf_inconsistent_sfc_encap(self
, create_sfc_port_pair_group
, get_sfi
):
352 get_sfi
.return_value
= {"sfc_encap": "nsh"}
354 vimconn
.VimConnNotSupportedException
,
356 create_sfc_port_pair_group
,
359 @mock.patch
.object(Client
, "create_sfc_port_chain")
360 def test_new_sfp_with_sfc_encap(self
, create_sfc_port_chain
):
361 self
._test
_new
_sfp
(create_sfc_port_chain
, True, None)
363 @mock.patch
.object(Client
, "create_sfc_port_chain")
364 def test_new_sfp_without_sfc_encap(self
, create_sfc_port_chain
):
365 self
._test
_new
_sfp
(create_sfc_port_chain
, False, None)
366 self
._test
_new
_sfp
(create_sfc_port_chain
, False, 25)
368 @mock.patch
.object(Client
, "create_sfc_port_chain")
369 def test_new_sfp_default_sfc_encap(self
, create_sfc_port_chain
):
370 self
._test
_new
_sfp
(create_sfc_port_chain
, None, None)
372 @mock.patch
.object(Client
, "create_sfc_port_chain")
373 def test_new_sfp_with_sfc_encap_spi(self
, create_sfc_port_chain
):
374 self
._test
_new
_sfp
(create_sfc_port_chain
, True, 25)
376 @mock.patch
.object(Client
, "create_sfc_port_chain")
377 def test_new_sfp_default_sfc_encap_spi(self
, create_sfc_port_chain
):
378 self
._test
_new
_sfp
(create_sfc_port_chain
, None, 25)
380 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
381 def test_get_classification_list(self
, list_sfc_flow_classifiers
):
382 # what OpenStack is assumed to return to the VIM connector
383 list_sfc_flow_classifiers
.return_value
= {
384 "flow_classifiers": [
386 "source_port_range_min": 2000,
387 "destination_ip_prefix": "192.168.3.0/24",
392 "source_port_range_max": 2000,
393 "destination_port_range_min": 3000,
394 "source_ip_prefix": "192.168.2.0/24",
395 "logical_destination_port": None,
396 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
397 "destination_port_range_max": None,
398 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
399 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
400 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
406 # call the VIM connector
407 filter_dict
= {"protocol": "tcp", "ethertype": "IPv4"}
408 result
= self
.vimconn
.get_classification_list(filter_dict
.copy())
410 # assert that VIM connector called OpenStack with the expected filter
411 list_sfc_flow_classifiers
.assert_called_with(**filter_dict
)
412 # assert that the VIM connector successfully
413 # translated and returned the OpenStack result
418 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
421 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
422 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
423 "ctype": "legacy_flow_classifier",
425 "source_port_range_min": 2000,
426 "destination_ip_prefix": "192.168.3.0/24",
430 "source_port_range_max": 2000,
431 "destination_port_range_min": 3000,
432 "source_ip_prefix": "192.168.2.0/24",
433 "logical_destination_port": None,
434 "destination_port_range_max": None,
435 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
441 def _test_get_sfi_list(self
, list_port_pair
, correlation
, sfc_encap
):
442 # what OpenStack is assumed to return to the VIM connector
443 list_port_pair
.return_value
= {
446 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
448 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
449 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
450 "service_function_parameters": {"correlation": correlation
},
451 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
452 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
458 # call the VIM connector
459 filter_dict
= {"name": "osm_sfi", "description": ""}
460 result
= self
.vimconn
.get_sfi_list(filter_dict
.copy())
462 # assert that VIM connector called OpenStack with the expected filter
463 list_port_pair
.assert_called_with(**filter_dict
)
464 # assert that the VIM connector successfully
465 # translated and returned the OpenStack result
470 "ingress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
472 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
473 "egress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
474 "sfc_encap": sfc_encap
,
475 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
476 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
482 @mock.patch
.object(Client
, "list_sfc_port_pairs")
483 def test_get_sfi_list_with_sfc_encap(self
, list_sfc_port_pairs
):
484 self
._test
_get
_sfi
_list
(list_sfc_port_pairs
, "nsh", True)
486 @mock.patch
.object(Client
, "list_sfc_port_pairs")
487 def test_get_sfi_list_without_sfc_encap(self
, list_sfc_port_pairs
):
488 self
._test
_get
_sfi
_list
(list_sfc_port_pairs
, None, False)
490 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
491 def test_get_sf_list(self
, list_sfc_port_pair_groups
):
492 # what OpenStack is assumed to return to the VIM connector
493 list_sfc_port_pair_groups
.return_value
= {
494 "port_pair_groups": [
497 "08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2",
498 "0d63799c-82d6-11e7-8deb-a746bb3ae9f5",
501 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
502 "port_pair_group_parameters": {},
503 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
504 "id": "f4a0bde8-82d5-11e7-90e1-a72b762fa27f",
510 # call the VIM connector
511 filter_dict
= {"name": "osm_sf", "description": ""}
512 result
= self
.vimconn
.get_sf_list(filter_dict
.copy())
514 # assert that VIM connector called OpenStack with the expected filter
515 list_sfc_port_pair_groups
.assert_called_with(**filter_dict
)
516 # assert that the VIM connector successfully
517 # translated and returned the OpenStack result
523 "08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2",
524 "0d63799c-82d6-11e7-8deb-a746bb3ae9f5",
527 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
528 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
529 "id": "f4a0bde8-82d5-11e7-90e1-a72b762fa27f",
535 def _test_get_sfp_list(self
, list_sfc_port_chains
, correlation
, sfc_encap
):
536 # what OpenStack is assumed to return to the VIM connector
537 list_sfc_port_chains
.return_value
= {
540 "port_pair_groups": [
541 "7d8e3bf8-82d6-11e7-a032-8ff028839d25",
542 "7dc9013e-82d6-11e7-a5a6-a3a8d78a5518",
544 "flow_classifiers": [
545 "1333c2f4-82d7-11e7-a5df-9327f33d104e",
546 "1387ab44-82d7-11e7-9bb0-476337183905",
549 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
550 "chain_parameters": {"correlation": correlation
},
552 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
553 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
559 # call the VIM connector
560 filter_dict
= {"name": "osm_sfp", "description": ""}
561 result
= self
.vimconn
.get_sfp_list(filter_dict
.copy())
563 # assert that VIM connector called OpenStack with the expected filter
564 list_sfc_port_chains
.assert_called_with(**filter_dict
)
565 # assert that the VIM connector successfully
566 # translated and returned the OpenStack result
571 "service_functions": [
572 "7d8e3bf8-82d6-11e7-a032-8ff028839d25",
573 "7dc9013e-82d6-11e7-a5a6-a3a8d78a5518",
576 "1333c2f4-82d7-11e7-a5df-9327f33d104e",
577 "1387ab44-82d7-11e7-9bb0-476337183905",
580 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
581 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
582 "sfc_encap": sfc_encap
,
584 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
590 @mock.patch
.object(Client
, "list_sfc_port_chains")
591 def test_get_sfp_list_with_sfc_encap(self
, list_sfc_port_chains
):
592 self
._test
_get
_sfp
_list
(list_sfc_port_chains
, "nsh", True)
594 @mock.patch
.object(Client
, "list_sfc_port_chains")
595 def test_get_sfp_list_without_sfc_encap(self
, list_sfc_port_chains
):
596 self
._test
_get
_sfp
_list
(list_sfc_port_chains
, None, False)
598 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
599 def test_get_classification(self
, list_sfc_flow_classifiers
):
600 # what OpenStack is assumed to return to the VIM connector
601 list_sfc_flow_classifiers
.return_value
= {
602 "flow_classifiers": [
604 "source_port_range_min": 2000,
605 "destination_ip_prefix": "192.168.3.0/24",
610 "source_port_range_max": 2000,
611 "destination_port_range_min": 3000,
612 "source_ip_prefix": "192.168.2.0/24",
613 "logical_destination_port": None,
614 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
615 "destination_port_range_max": None,
616 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
617 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
618 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
624 # call the VIM connector
625 result
= self
.vimconn
.get_classification("22198366-d4e8-4d6b-b4d2-637d5d6cbb7d")
627 # assert that VIM connector called OpenStack with the expected filter
628 list_sfc_flow_classifiers
.assert_called_with(
629 id="22198366-d4e8-4d6b-b4d2-637d5d6cbb7d"
631 # assert that VIM connector successfully returned the OpenStack result
635 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
638 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
639 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
640 "ctype": "legacy_flow_classifier",
642 "source_port_range_min": 2000,
643 "destination_ip_prefix": "192.168.3.0/24",
647 "source_port_range_max": 2000,
648 "destination_port_range_min": 3000,
649 "source_ip_prefix": "192.168.2.0/24",
650 "logical_destination_port": None,
651 "destination_port_range_max": None,
652 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
657 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
658 def test_get_classification_many_results(self
, list_sfc_flow_classifiers
):
659 # what OpenStack is assumed to return to the VIM connector
660 list_sfc_flow_classifiers
.return_value
= {
661 "flow_classifiers": [
663 "source_port_range_min": 2000,
664 "destination_ip_prefix": "192.168.3.0/24",
669 "source_port_range_max": 2000,
670 "destination_port_range_min": 3000,
671 "source_ip_prefix": "192.168.2.0/24",
672 "logical_destination_port": None,
673 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
674 "destination_port_range_max": None,
675 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
676 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
677 "id": "22198366-d4e8-4d6b-b4d2-637d5d6cbb7d",
681 "source_port_range_min": 1000,
682 "destination_ip_prefix": "192.168.3.0/24",
687 "source_port_range_max": 1000,
688 "destination_port_range_min": 3000,
689 "source_ip_prefix": "192.168.2.0/24",
690 "logical_destination_port": None,
691 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
692 "destination_port_range_max": None,
693 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
694 "logical_source_port": "aaab0ab0-1452-4636-bb3b-11dca833fa2b",
695 "id": "3196bafc-82dd-11e7-a205-9bf6c14b0721",
701 # call the VIM connector
703 vimconn
.VimConnConflictException
,
704 self
.vimconn
.get_classification
,
705 "3196bafc-82dd-11e7-a205-9bf6c14b0721",
708 # assert the VIM connector called OpenStack with the expected filter
709 list_sfc_flow_classifiers
.assert_called_with(
710 id="3196bafc-82dd-11e7-a205-9bf6c14b0721"
713 @mock.patch
.object(Client
, "list_sfc_flow_classifiers")
714 def test_get_classification_no_results(self
, list_sfc_flow_classifiers
):
715 # what OpenStack is assumed to return to the VIM connector
716 list_sfc_flow_classifiers
.return_value
= {"flow_classifiers": []}
718 # call the VIM connector
720 vimconn
.VimConnNotFoundException
,
721 self
.vimconn
.get_classification
,
722 "3196bafc-82dd-11e7-a205-9bf6c14b0721",
725 # assert the VIM connector called OpenStack with the expected filter
726 list_sfc_flow_classifiers
.assert_called_with(
727 id="3196bafc-82dd-11e7-a205-9bf6c14b0721"
730 @mock.patch
.object(Client
, "list_sfc_port_pairs")
731 def test_get_sfi(self
, list_sfc_port_pairs
):
732 # what OpenStack is assumed to return to the VIM connector
733 list_sfc_port_pairs
.return_value
= {
736 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
738 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
739 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
740 "service_function_parameters": {"correlation": "nsh"},
741 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
742 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
748 # call the VIM connector
749 result
= self
.vimconn
.get_sfi("c121ebdd-7f2d-4213-b933-3325298a6966")
751 # assert the VIM connector called OpenStack with the expected filter
752 list_sfc_port_pairs
.assert_called_with(
753 id="c121ebdd-7f2d-4213-b933-3325298a6966"
755 # assert the VIM connector successfully returned the OpenStack result
759 "ingress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
760 "egress_ports": ["5311c75d-d718-4369-bbda-cdcc6da60fcc"],
763 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
764 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
765 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
770 @mock.patch
.object(Client
, "list_sfc_port_pairs")
771 def test_get_sfi_many_results(self
, list_sfc_port_pairs
):
772 # what OpenStack is assumed to return to the VIM connector
773 list_sfc_port_pairs
.return_value
= {
776 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
778 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
779 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
780 "service_function_parameters": {"correlation": "nsh"},
781 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
782 "id": "c121ebdd-7f2d-4213-b933-3325298a6966",
786 "ingress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
788 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
789 "egress": "5311c75d-d718-4369-bbda-cdcc6da60fcc",
790 "service_function_parameters": {"correlation": "nsh"},
791 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
792 "id": "c0436d92-82db-11e7-8f9c-5fa535f1261f",
798 # call the VIM connector
800 vimconn
.VimConnConflictException
,
801 self
.vimconn
.get_sfi
,
802 "c0436d92-82db-11e7-8f9c-5fa535f1261f",
805 # assert that VIM connector called OpenStack with the expected filter
806 list_sfc_port_pairs
.assert_called_with(
807 id="c0436d92-82db-11e7-8f9c-5fa535f1261f"
810 @mock.patch
.object(Client
, "list_sfc_port_pairs")
811 def test_get_sfi_no_results(self
, list_sfc_port_pairs
):
812 # what OpenStack is assumed to return to the VIM connector
813 list_sfc_port_pairs
.return_value
= {"port_pairs": []}
815 # call the VIM connector
817 vimconn
.VimConnNotFoundException
,
818 self
.vimconn
.get_sfi
,
819 "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
822 # assert that VIM connector called OpenStack with the expected filter
823 list_sfc_port_pairs
.assert_called_with(
824 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
827 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
828 def test_get_sf(self
, list_sfc_port_pair_groups
):
829 # what OpenStack is assumed to return to the VIM connector
830 list_sfc_port_pair_groups
.return_value
= {
831 "port_pair_groups": [
833 "port_pairs": ["08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2"],
835 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
836 "port_pair_group_parameters": {},
837 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
838 "id": "aabba8a6-82d9-11e7-a18a-d3c7719b742d",
844 # call the VIM connector
845 result
= self
.vimconn
.get_sf("b22892fc-82d9-11e7-ae85-0fea6a3b3757")
847 # assert that VIM connector called OpenStack with the expected filter
848 list_sfc_port_pair_groups
.assert_called_with(
849 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
851 # assert that VIM connector successfully returned the OpenStack result
856 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
857 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
858 "sfis": ["08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2"],
859 "id": "aabba8a6-82d9-11e7-a18a-d3c7719b742d",
864 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
865 def test_get_sf_many_results(self
, list_sfc_port_pair_groups
):
866 # what OpenStack is assumed to return to the VIM connector
867 list_sfc_port_pair_groups
.return_value
= {
868 "port_pair_groups": [
870 "port_pairs": ["08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2"],
872 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
873 "port_pair_group_parameters": {},
874 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
875 "id": "aabba8a6-82d9-11e7-a18a-d3c7719b742d",
879 "port_pairs": ["0d63799c-82d6-11e7-8deb-a746bb3ae9f5"],
881 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
882 "port_pair_group_parameters": {},
883 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
884 "id": "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
890 # call the VIM connector
892 vimconn
.VimConnConflictException
,
894 "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
897 # assert that VIM connector called OpenStack with the expected filter
898 list_sfc_port_pair_groups
.assert_called_with(
899 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
902 @mock.patch
.object(Client
, "list_sfc_port_pair_groups")
903 def test_get_sf_no_results(self
, list_sfc_port_pair_groups
):
904 # what OpenStack is assumed to return to the VIM connector
905 list_sfc_port_pair_groups
.return_value
= {"port_pair_groups": []}
907 # call the VIM connector
909 vimconn
.VimConnNotFoundException
,
911 "b22892fc-82d9-11e7-ae85-0fea6a3b3757",
914 # assert that VIM connector called OpenStack with the expected filter
915 list_sfc_port_pair_groups
.assert_called_with(
916 id="b22892fc-82d9-11e7-ae85-0fea6a3b3757"
919 @mock.patch
.object(Client
, "list_sfc_port_chains")
920 def test_get_sfp(self
, list_sfc_port_chains
):
921 # what OpenStack is assumed to return to the VIM connector
922 list_sfc_port_chains
.return_value
= {
925 "port_pair_groups": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
926 "flow_classifiers": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
928 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
929 "chain_parameters": {"correlation": "nsh"},
931 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
932 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
938 # call the VIM connector
939 result
= self
.vimconn
.get_sfp("821bc9be-82d7-11e7-8ce3-23a08a27ab47")
941 # assert that VIM connector called OpenStack with the expected filter
942 list_sfc_port_chains
.assert_called_with(
943 id="821bc9be-82d7-11e7-8ce3-23a08a27ab47"
945 # assert that VIM connector successfully returned the OpenStack result
949 "service_functions": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
950 "classifications": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
952 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
953 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
956 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
961 @mock.patch
.object(Client
, "list_sfc_port_chains")
962 def test_get_sfp_many_results(self
, list_sfc_port_chains
):
963 # what OpenStack is assumed to return to the VIM connector
964 list_sfc_port_chains
.return_value
= {
967 "port_pair_groups": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
968 "flow_classifiers": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
970 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
971 "chain_parameters": {"correlation": "nsh"},
973 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
974 "id": "821bc9be-82d7-11e7-8ce3-23a08a27ab47",
978 "port_pair_groups": ["7d8e3bf8-82d6-11e7-a032-8ff028839d25"],
979 "flow_classifiers": ["1333c2f4-82d7-11e7-a5df-9327f33d104e"],
981 "tenant_id": "8f3019ef06374fa880a0144ad4bc1d7b",
982 "chain_parameters": {"correlation": "nsh"},
984 "project_id": "8f3019ef06374fa880a0144ad4bc1d7b",
985 "id": "5d002f38-82de-11e7-a770-f303f11ce66a",
991 # call the VIM connector
993 vimconn
.VimConnConflictException
,
994 self
.vimconn
.get_sfp
,
995 "5d002f38-82de-11e7-a770-f303f11ce66a",
998 # assert that VIM connector called OpenStack with the expected filter
999 list_sfc_port_chains
.assert_called_with(
1000 id="5d002f38-82de-11e7-a770-f303f11ce66a"
1003 @mock.patch
.object(Client
, "list_sfc_port_chains")
1004 def test_get_sfp_no_results(self
, list_sfc_port_chains
):
1005 # what OpenStack is assumed to return to the VIM connector
1006 list_sfc_port_chains
.return_value
= {"port_chains": []}
1008 # call the VIM connector
1010 vimconn
.VimConnNotFoundException
,
1011 self
.vimconn
.get_sfp
,
1012 "5d002f38-82de-11e7-a770-f303f11ce66a",
1015 # assert that VIM connector called OpenStack with the expected filter
1016 list_sfc_port_chains
.assert_called_with(
1017 id="5d002f38-82de-11e7-a770-f303f11ce66a"
1020 @mock.patch
.object(Client
, "delete_sfc_flow_classifier")
1021 def test_delete_classification(self
, delete_sfc_flow_classifier
):
1022 result
= self
.vimconn
.delete_classification(
1023 "638f957c-82df-11e7-b7c8-132706021464"
1025 delete_sfc_flow_classifier
.assert_called_with(
1026 "638f957c-82df-11e7-b7c8-132706021464"
1028 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1030 @mock.patch
.object(Client
, "delete_sfc_port_pair")
1031 def test_delete_sfi(self
, delete_sfc_port_pair
):
1032 result
= self
.vimconn
.delete_sfi("638f957c-82df-11e7-b7c8-132706021464")
1033 delete_sfc_port_pair
.assert_called_with("638f957c-82df-11e7-b7c8-132706021464")
1034 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1036 @mock.patch
.object(Client
, "delete_sfc_port_pair_group")
1037 def test_delete_sf(self
, delete_sfc_port_pair_group
):
1038 result
= self
.vimconn
.delete_sf("638f957c-82df-11e7-b7c8-132706021464")
1039 delete_sfc_port_pair_group
.assert_called_with(
1040 "638f957c-82df-11e7-b7c8-132706021464"
1042 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1044 @mock.patch
.object(Client
, "delete_sfc_port_chain")
1045 def test_delete_sfp(self
, delete_sfc_port_chain
):
1046 result
= self
.vimconn
.delete_sfp("638f957c-82df-11e7-b7c8-132706021464")
1047 delete_sfc_port_chain
.assert_called_with("638f957c-82df-11e7-b7c8-132706021464")
1048 self
.assertEqual(result
, "638f957c-82df-11e7-b7c8-132706021464")
1051 if __name__
== "__main__":