| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | ## |
| 4 | # Copyright 2017 Intel Corporation. |
| 5 | # |
| 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 |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 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 |
| 16 | # under the License. |
| 17 | # |
| 18 | # For those usages not covered by the Apache License, Version 2.0 please |
| 19 | # contact with: nfvlabs@tid.es |
| 20 | ## |
| 21 | |
| 22 | """ |
| 23 | This module contains unit tests for the OpenStack VIM connector |
| 24 | Run this directly with python2 or python3. |
| 25 | """ |
| 26 | |
| 27 | import copy |
| 28 | import unittest |
| 29 | |
| 30 | import mock |
| 31 | from neutronclient.v2_0.client import Client |
| 32 | |
| 33 | from osm_ro import vimconn |
| 34 | from osm_ro.vimconn_openstack import vimconnector |
| 35 | |
| 36 | |
| 37 | __author__ = "Igor D.C." |
| 38 | __date__ = "$23-aug-2017 23:59:59$" |
| 39 | |
| 40 | |
| 41 | class TestSfcOperations(unittest.TestCase): |
| 42 | def setUp(self): |
| 43 | # instantiate dummy VIM connector so we can test it |
| 44 | self.vimconn = vimconnector( |
| 45 | '123', 'openstackvim', '456', '789', 'http://dummy.url', None, |
| 46 | 'user', 'pass') |
| 47 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 48 | def _test_new_sfi(self, create_sfc_port_pair, sfc_encap, |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 49 | ingress_ports=['5311c75d-d718-4369-bbda-cdcc6da60fcc'], |
| 50 | egress_ports=['230cdf1b-de37-4891-bc07-f9010cf1f967']): |
| 51 | # input to VIM connector |
| 52 | name = 'osm_sfi' |
| 53 | # + ingress_ports |
| 54 | # + egress_ports |
| 55 | # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround) |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 56 | correlation = 'nsh' |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 57 | if sfc_encap is not None: |
| 58 | if not sfc_encap: |
| 59 | correlation = None |
| 60 | |
| 61 | # what OpenStack is assumed to respond (patch OpenStack's return value) |
| 62 | dict_from_neutron = {'port_pair': { |
| 63 | 'id': '3d7ddc13-923c-4332-971e-708ed82902ce', |
| 64 | 'name': name, |
| 65 | 'description': '', |
| 66 | 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c', |
| 67 | 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c', |
| 68 | 'ingress': ingress_ports[0] if len(ingress_ports) else None, |
| 69 | 'egress': egress_ports[0] if len(egress_ports) else None, |
| 70 | 'service_function_parameters': {'correlation': correlation} |
| 71 | }} |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 72 | create_sfc_port_pair.return_value = dict_from_neutron |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 73 | |
| 74 | # what the VIM connector is expected to |
| 75 | # send to OpenStack based on the input |
| 76 | dict_to_neutron = {'port_pair': { |
| 77 | 'name': name, |
| 78 | 'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 79 | 'egress': '230cdf1b-de37-4891-bc07-f9010cf1f967', |
| 80 | 'service_function_parameters': {'correlation': correlation} |
| 81 | }} |
| 82 | |
| 83 | # call the VIM connector |
| 84 | if sfc_encap is None: |
| 85 | result = self.vimconn.new_sfi(name, ingress_ports, egress_ports) |
| 86 | else: |
| 87 | result = self.vimconn.new_sfi(name, ingress_ports, egress_ports, |
| 88 | sfc_encap) |
| 89 | |
| 90 | # assert that the VIM connector made the expected call to OpenStack |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 91 | create_sfc_port_pair.assert_called_with(dict_to_neutron) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 92 | # assert that the VIM connector had the expected result / return value |
| 93 | self.assertEqual(result, dict_from_neutron['port_pair']['id']) |
| 94 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 95 | def _test_new_sf(self, create_sfc_port_pair_group): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 96 | # input to VIM connector |
| 97 | name = 'osm_sf' |
| 98 | instances = ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd', |
| 99 | '12ba215e-3987-4892-bd3a-d0fd91eecf98', |
| 100 | 'e25a7c79-14c8-469a-9ae1-f601c9371ffd'] |
| 101 | |
| 102 | # what OpenStack is assumed to respond (patch OpenStack's return value) |
| 103 | dict_from_neutron = {'port_pair_group': { |
| 104 | 'id': '3d7ddc13-923c-4332-971e-708ed82902ce', |
| 105 | 'name': name, |
| 106 | 'description': '', |
| 107 | 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c', |
| 108 | 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c', |
| 109 | 'port_pairs': instances, |
| 110 | 'group_id': 1, |
| 111 | 'port_pair_group_parameters': { |
| 112 | "lb_fields": [], |
| 113 | "ppg_n_tuple_mapping": { |
| 114 | "ingress_n_tuple": {}, |
| 115 | "egress_n_tuple": {} |
| 116 | }} |
| 117 | }} |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 118 | create_sfc_port_pair_group.return_value = dict_from_neutron |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 119 | |
| 120 | # what the VIM connector is expected to |
| 121 | # send to OpenStack based on the input |
| 122 | dict_to_neutron = {'port_pair_group': { |
| 123 | 'name': name, |
| 124 | 'port_pairs': ['bbd01220-cf72-41f2-9e70-0669c2e5c4cd', |
| 125 | '12ba215e-3987-4892-bd3a-d0fd91eecf98', |
| 126 | 'e25a7c79-14c8-469a-9ae1-f601c9371ffd'] |
| 127 | }} |
| 128 | |
| 129 | # call the VIM connector |
| 130 | result = self.vimconn.new_sf(name, instances) |
| 131 | |
| 132 | # assert that the VIM connector made the expected call to OpenStack |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 133 | create_sfc_port_pair_group.assert_called_with(dict_to_neutron) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 134 | # assert that the VIM connector had the expected result / return value |
| 135 | self.assertEqual(result, dict_from_neutron['port_pair_group']['id']) |
| 136 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 137 | def _test_new_sfp(self, create_sfc_port_chain, sfc_encap, spi): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 138 | # input to VIM connector |
| 139 | name = 'osm_sfp' |
| 140 | classifications = ['2bd2a2e5-c5fd-4eac-a297-d5e255c35c19', |
| 141 | '00f23389-bdfa-43c2-8b16-5815f2582fa8'] |
| 142 | sfs = ['2314daec-c262-414a-86e3-69bb6fa5bc16', |
| 143 | 'd8bfdb5d-195e-4f34-81aa-6135705317df'] |
| 144 | |
| 145 | # TODO(igordc): must be changed to NSH in Queens (MPLS is a workaround) |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 146 | correlation = 'nsh' |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 147 | chain_id = 33 |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 148 | if spi: |
| 149 | chain_id = spi |
| 150 | |
| 151 | # what OpenStack is assumed to respond (patch OpenStack's return value) |
| 152 | dict_from_neutron = {'port_chain': { |
| 153 | 'id': '5bc05721-079b-4b6e-a235-47cac331cbb6', |
| 154 | 'name': name, |
| 155 | 'description': '', |
| 156 | 'tenant_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c', |
| 157 | 'project_id': '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c', |
| 158 | 'chain_id': chain_id, |
| 159 | 'flow_classifiers': classifications, |
| 160 | 'port_pair_groups': sfs, |
| 161 | 'chain_parameters': {'correlation': correlation} |
| 162 | }} |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 163 | create_sfc_port_chain.return_value = dict_from_neutron |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 164 | |
| 165 | # what the VIM connector is expected to |
| 166 | # send to OpenStack based on the input |
| 167 | dict_to_neutron = {'port_chain': { |
| 168 | 'name': name, |
| 169 | 'flow_classifiers': ['2bd2a2e5-c5fd-4eac-a297-d5e255c35c19', |
| 170 | '00f23389-bdfa-43c2-8b16-5815f2582fa8'], |
| 171 | 'port_pair_groups': ['2314daec-c262-414a-86e3-69bb6fa5bc16', |
| 172 | 'd8bfdb5d-195e-4f34-81aa-6135705317df'], |
| 173 | 'chain_parameters': {'correlation': correlation} |
| 174 | }} |
| 175 | if spi: |
| 176 | dict_to_neutron['port_chain']['chain_id'] = spi |
| 177 | |
| 178 | # call the VIM connector |
| 179 | if sfc_encap is None: |
| 180 | if spi is None: |
| 181 | result = self.vimconn.new_sfp(name, classifications, sfs) |
| 182 | else: |
| 183 | result = self.vimconn.new_sfp(name, classifications, sfs, |
| 184 | spi=spi) |
| 185 | else: |
| 186 | if spi is None: |
| 187 | result = self.vimconn.new_sfp(name, classifications, sfs, |
| 188 | sfc_encap) |
| 189 | else: |
| 190 | result = self.vimconn.new_sfp(name, classifications, sfs, |
| 191 | sfc_encap, spi) |
| 192 | |
| 193 | # assert that the VIM connector made the expected call to OpenStack |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 194 | create_sfc_port_chain.assert_called_with(dict_to_neutron) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 195 | # assert that the VIM connector had the expected result / return value |
| 196 | self.assertEqual(result, dict_from_neutron['port_chain']['id']) |
| 197 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 198 | def _test_new_classification(self, create_sfc_flow_classifier, ctype): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 199 | # input to VIM connector |
| 200 | name = 'osm_classification' |
| 201 | definition = {'ethertype': 'IPv4', |
| 202 | 'logical_source_port': |
| 203 | 'aaab0ab0-1452-4636-bb3b-11dca833fa2b', |
| 204 | 'protocol': 'tcp', |
| 205 | 'source_ip_prefix': '192.168.2.0/24', |
| 206 | 'source_port_range_max': 99, |
| 207 | 'source_port_range_min': 50} |
| 208 | |
| 209 | # what OpenStack is assumed to respond (patch OpenStack's return value) |
| 210 | dict_from_neutron = {'flow_classifier': copy.copy(definition)} |
| 211 | dict_from_neutron['flow_classifier'][ |
| 212 | 'id'] = '7735ec2c-fddf-4130-9712-32ed2ab6a372' |
| 213 | dict_from_neutron['flow_classifier']['name'] = name |
| 214 | dict_from_neutron['flow_classifier']['description'] = '' |
| 215 | dict_from_neutron['flow_classifier'][ |
| 216 | 'tenant_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c' |
| 217 | dict_from_neutron['flow_classifier'][ |
| 218 | 'project_id'] = '130b1e97-b0f1-40a8-8804-b6ad9b8c3e0c' |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 219 | create_sfc_flow_classifier.return_value = dict_from_neutron |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 220 | |
| 221 | # what the VIM connector is expected to |
| 222 | # send to OpenStack based on the input |
| 223 | dict_to_neutron = {'flow_classifier': copy.copy(definition)} |
| 224 | dict_to_neutron['flow_classifier']['name'] = 'osm_classification' |
| 225 | |
| 226 | # call the VIM connector |
| 227 | result = self.vimconn.new_classification(name, ctype, definition) |
| 228 | |
| 229 | # assert that the VIM connector made the expected call to OpenStack |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 230 | create_sfc_flow_classifier.assert_called_with(dict_to_neutron) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 231 | # assert that the VIM connector had the expected result / return value |
| 232 | self.assertEqual(result, dict_from_neutron['flow_classifier']['id']) |
| 233 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 234 | @mock.patch.object(Client, 'create_sfc_flow_classifier') |
| 235 | def test_new_classification(self, create_sfc_flow_classifier): |
| 236 | self._test_new_classification(create_sfc_flow_classifier, |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 237 | 'legacy_flow_classifier') |
| 238 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 239 | @mock.patch.object(Client, 'create_sfc_flow_classifier') |
| 240 | def test_new_classification_unsupported_type(self, create_sfc_flow_classifier): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 241 | self.assertRaises(vimconn.vimconnNotSupportedException, |
| 242 | self._test_new_classification, |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 243 | create_sfc_flow_classifier, 'h265') |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 244 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 245 | @mock.patch.object(Client, 'create_sfc_port_pair') |
| 246 | def test_new_sfi_with_sfc_encap(self, create_sfc_port_pair): |
| 247 | self._test_new_sfi(create_sfc_port_pair, True) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 248 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 249 | @mock.patch.object(Client, 'create_sfc_port_pair') |
| 250 | def test_new_sfi_without_sfc_encap(self, create_sfc_port_pair): |
| 251 | self._test_new_sfi(create_sfc_port_pair, False) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 252 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 253 | @mock.patch.object(Client, 'create_sfc_port_pair') |
| 254 | def test_new_sfi_default_sfc_encap(self, create_sfc_port_pair): |
| 255 | self._test_new_sfi(create_sfc_port_pair, None) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 256 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 257 | @mock.patch.object(Client, 'create_sfc_port_pair') |
| 258 | def test_new_sfi_bad_ingress_ports(self, create_sfc_port_pair): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 259 | ingress_ports = ['5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 260 | 'a0273f64-82c9-11e7-b08f-6328e53f0fa7'] |
| 261 | self.assertRaises(vimconn.vimconnNotSupportedException, |
| 262 | self._test_new_sfi, |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 263 | create_sfc_port_pair, True, ingress_ports=ingress_ports) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 264 | ingress_ports = [] |
| 265 | self.assertRaises(vimconn.vimconnNotSupportedException, |
| 266 | self._test_new_sfi, |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 267 | create_sfc_port_pair, True, ingress_ports=ingress_ports) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 268 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 269 | @mock.patch.object(Client, 'create_sfc_port_pair') |
| 270 | def test_new_sfi_bad_egress_ports(self, create_sfc_port_pair): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 271 | egress_ports = ['230cdf1b-de37-4891-bc07-f9010cf1f967', |
| 272 | 'b41228fe-82c9-11e7-9b44-17504174320b'] |
| 273 | self.assertRaises(vimconn.vimconnNotSupportedException, |
| 274 | self._test_new_sfi, |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 275 | create_sfc_port_pair, True, egress_ports=egress_ports) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 276 | egress_ports = [] |
| 277 | self.assertRaises(vimconn.vimconnNotSupportedException, |
| 278 | self._test_new_sfi, |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 279 | create_sfc_port_pair, True, egress_ports=egress_ports) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 280 | |
| 281 | @mock.patch.object(vimconnector, 'get_sfi') |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 282 | @mock.patch.object(Client, 'create_sfc_port_pair_group') |
| 283 | def test_new_sf(self, create_sfc_port_pair_group, get_sfi): |
| 284 | get_sfi.return_value = {'sfc_encap': True} |
| 285 | self._test_new_sf(create_sfc_port_pair_group) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 286 | |
| 287 | @mock.patch.object(vimconnector, 'get_sfi') |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 288 | @mock.patch.object(Client, 'create_sfc_port_pair_group') |
| 289 | def test_new_sf_inconsistent_sfc_encap(self, create_sfc_port_pair_group, |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 290 | get_sfi): |
| 291 | get_sfi.return_value = {'sfc_encap': 'nsh'} |
| 292 | self.assertRaises(vimconn.vimconnNotSupportedException, |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 293 | self._test_new_sf, create_sfc_port_pair_group) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 294 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 295 | @mock.patch.object(Client, 'create_sfc_port_chain') |
| 296 | def test_new_sfp_with_sfc_encap(self, create_sfc_port_chain): |
| 297 | self._test_new_sfp(create_sfc_port_chain, True, None) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 298 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 299 | @mock.patch.object(Client, 'create_sfc_port_chain') |
| 300 | def test_new_sfp_without_sfc_encap(self, create_sfc_port_chain): |
| 301 | self._test_new_sfp(create_sfc_port_chain, False, None) |
| 302 | self._test_new_sfp(create_sfc_port_chain, False, 25) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 303 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 304 | @mock.patch.object(Client, 'create_sfc_port_chain') |
| 305 | def test_new_sfp_default_sfc_encap(self, create_sfc_port_chain): |
| 306 | self._test_new_sfp(create_sfc_port_chain, None, None) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 307 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 308 | @mock.patch.object(Client, 'create_sfc_port_chain') |
| 309 | def test_new_sfp_with_sfc_encap_spi(self, create_sfc_port_chain): |
| 310 | self._test_new_sfp(create_sfc_port_chain, True, 25) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 311 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 312 | @mock.patch.object(Client, 'create_sfc_port_chain') |
| 313 | def test_new_sfp_default_sfc_encap_spi(self, create_sfc_port_chain): |
| 314 | self._test_new_sfp(create_sfc_port_chain, None, 25) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 315 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 316 | @mock.patch.object(Client, 'list_sfc_flow_classifiers') |
| 317 | def test_get_classification_list(self, list_sfc_flow_classifiers): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 318 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 319 | list_sfc_flow_classifiers.return_value = {'flow_classifiers': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 320 | {'source_port_range_min': 2000, |
| 321 | 'destination_ip_prefix': '192.168.3.0/24', |
| 322 | 'protocol': 'udp', |
| 323 | 'description': '', |
| 324 | 'ethertype': 'IPv4', |
| 325 | 'l7_parameters': {}, |
| 326 | 'source_port_range_max': 2000, |
| 327 | 'destination_port_range_min': 3000, |
| 328 | 'source_ip_prefix': '192.168.2.0/24', |
| 329 | 'logical_destination_port': None, |
| 330 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 331 | 'destination_port_range_max': None, |
| 332 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 333 | 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b', |
| 334 | 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d', |
| 335 | 'name': 'fc1'}]} |
| 336 | |
| 337 | # call the VIM connector |
| 338 | filter_dict = {'protocol': 'tcp', 'ethertype': 'IPv4'} |
| 339 | result = self.vimconn.get_classification_list(filter_dict.copy()) |
| 340 | |
| 341 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 342 | list_sfc_flow_classifiers.assert_called_with(**filter_dict) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 343 | # assert that the VIM connector successfully |
| 344 | # translated and returned the OpenStack result |
| 345 | self.assertEqual(result, [ |
| 346 | {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d', |
| 347 | 'name': 'fc1', |
| 348 | 'description': '', |
| 349 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 350 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 351 | 'ctype': 'legacy_flow_classifier', |
| 352 | 'definition': { |
| 353 | 'source_port_range_min': 2000, |
| 354 | 'destination_ip_prefix': '192.168.3.0/24', |
| 355 | 'protocol': 'udp', |
| 356 | 'ethertype': 'IPv4', |
| 357 | 'l7_parameters': {}, |
| 358 | 'source_port_range_max': 2000, |
| 359 | 'destination_port_range_min': 3000, |
| 360 | 'source_ip_prefix': '192.168.2.0/24', |
| 361 | 'logical_destination_port': None, |
| 362 | 'destination_port_range_max': None, |
| 363 | 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'} |
| 364 | }]) |
| 365 | |
| 366 | def _test_get_sfi_list(self, list_port_pair, correlation, sfc_encap): |
| 367 | # what OpenStack is assumed to return to the VIM connector |
| 368 | list_port_pair.return_value = {'port_pairs': [ |
| 369 | {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 370 | 'description': '', |
| 371 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 372 | 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 373 | 'service_function_parameters': {'correlation': correlation}, |
| 374 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 375 | 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966', |
| 376 | 'name': 'osm_sfi'}]} |
| 377 | |
| 378 | # call the VIM connector |
| 379 | filter_dict = {'name': 'osm_sfi', 'description': ''} |
| 380 | result = self.vimconn.get_sfi_list(filter_dict.copy()) |
| 381 | |
| 382 | # assert that VIM connector called OpenStack with the expected filter |
| 383 | list_port_pair.assert_called_with(**filter_dict) |
| 384 | # assert that the VIM connector successfully |
| 385 | # translated and returned the OpenStack result |
| 386 | self.assertEqual(result, [ |
| 387 | {'ingress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'], |
| 388 | 'description': '', |
| 389 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 390 | 'egress_ports': ['5311c75d-d718-4369-bbda-cdcc6da60fcc'], |
| 391 | 'sfc_encap': sfc_encap, |
| 392 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 393 | 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966', |
| 394 | 'name': 'osm_sfi'}]) |
| 395 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 396 | @mock.patch.object(Client, 'list_sfc_port_pairs') |
| 397 | def test_get_sfi_list_with_sfc_encap(self, list_sfc_port_pairs): |
| 398 | self._test_get_sfi_list(list_sfc_port_pairs, 'nsh', True) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 399 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 400 | @mock.patch.object(Client, 'list_sfc_port_pairs') |
| 401 | def test_get_sfi_list_without_sfc_encap(self, list_sfc_port_pairs): |
| 402 | self._test_get_sfi_list(list_sfc_port_pairs, None, False) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 403 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 404 | @mock.patch.object(Client, 'list_sfc_port_pair_groups') |
| 405 | def test_get_sf_list(self, list_sfc_port_pair_groups): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 406 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 407 | list_sfc_port_pair_groups.return_value = {'port_pair_groups': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 408 | {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2', |
| 409 | '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'], |
| 410 | 'description': '', |
| 411 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 412 | 'port_pair_group_parameters': {}, |
| 413 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 414 | 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f', |
| 415 | 'name': 'osm_sf'}]} |
| 416 | |
| 417 | # call the VIM connector |
| 418 | filter_dict = {'name': 'osm_sf', 'description': ''} |
| 419 | result = self.vimconn.get_sf_list(filter_dict.copy()) |
| 420 | |
| 421 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 422 | list_sfc_port_pair_groups.assert_called_with(**filter_dict) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 423 | # assert that the VIM connector successfully |
| 424 | # translated and returned the OpenStack result |
| 425 | self.assertEqual(result, [ |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 426 | {'sfis': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2', |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 427 | '0d63799c-82d6-11e7-8deb-a746bb3ae9f5'], |
| 428 | 'description': '', |
| 429 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 430 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 431 | 'id': 'f4a0bde8-82d5-11e7-90e1-a72b762fa27f', |
| 432 | 'name': 'osm_sf'}]) |
| 433 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 434 | def _test_get_sfp_list(self, list_sfc_port_chains, correlation, sfc_encap): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 435 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 436 | list_sfc_port_chains.return_value = {'port_chains': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 437 | {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25', |
| 438 | '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'], |
| 439 | 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e', |
| 440 | '1387ab44-82d7-11e7-9bb0-476337183905'], |
| 441 | 'description': '', |
| 442 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 443 | 'chain_parameters': {'correlation': correlation}, |
| 444 | 'chain_id': 40, |
| 445 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 446 | 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47', |
| 447 | 'name': 'osm_sfp'}]} |
| 448 | |
| 449 | # call the VIM connector |
| 450 | filter_dict = {'name': 'osm_sfp', 'description': ''} |
| 451 | result = self.vimconn.get_sfp_list(filter_dict.copy()) |
| 452 | |
| 453 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 454 | list_sfc_port_chains.assert_called_with(**filter_dict) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 455 | # assert that the VIM connector successfully |
| 456 | # translated and returned the OpenStack result |
| 457 | self.assertEqual(result, [ |
| 458 | {'service_functions': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25', |
| 459 | '7dc9013e-82d6-11e7-a5a6-a3a8d78a5518'], |
| 460 | 'classifications': ['1333c2f4-82d7-11e7-a5df-9327f33d104e', |
| 461 | '1387ab44-82d7-11e7-9bb0-476337183905'], |
| 462 | 'description': '', |
| 463 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 464 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 465 | 'sfc_encap': sfc_encap, |
| 466 | 'spi': 40, |
| 467 | 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47', |
| 468 | 'name': 'osm_sfp'}]) |
| 469 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 470 | @mock.patch.object(Client, 'list_sfc_port_chains') |
| 471 | def test_get_sfp_list_with_sfc_encap(self, list_sfc_port_chains): |
| 472 | self._test_get_sfp_list(list_sfc_port_chains, 'nsh', True) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 473 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 474 | @mock.patch.object(Client, 'list_sfc_port_chains') |
| 475 | def test_get_sfp_list_without_sfc_encap(self, list_sfc_port_chains): |
| 476 | self._test_get_sfp_list(list_sfc_port_chains, None, False) |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 477 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 478 | @mock.patch.object(Client, 'list_sfc_flow_classifiers') |
| 479 | def test_get_classification(self, list_sfc_flow_classifiers): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 480 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 481 | list_sfc_flow_classifiers.return_value = {'flow_classifiers': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 482 | {'source_port_range_min': 2000, |
| 483 | 'destination_ip_prefix': '192.168.3.0/24', |
| 484 | 'protocol': 'udp', |
| 485 | 'description': '', |
| 486 | 'ethertype': 'IPv4', |
| 487 | 'l7_parameters': {}, |
| 488 | 'source_port_range_max': 2000, |
| 489 | 'destination_port_range_min': 3000, |
| 490 | 'source_ip_prefix': '192.168.2.0/24', |
| 491 | 'logical_destination_port': None, |
| 492 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 493 | 'destination_port_range_max': None, |
| 494 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 495 | 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b', |
| 496 | 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d', |
| 497 | 'name': 'fc1'} |
| 498 | ]} |
| 499 | |
| 500 | # call the VIM connector |
| 501 | result = self.vimconn.get_classification( |
| 502 | '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d') |
| 503 | |
| 504 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 505 | list_sfc_flow_classifiers.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 506 | id='22198366-d4e8-4d6b-b4d2-637d5d6cbb7d') |
| 507 | # assert that VIM connector successfully returned the OpenStack result |
| 508 | self.assertEqual(result, |
| 509 | {'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d', |
| 510 | 'name': 'fc1', |
| 511 | 'description': '', |
| 512 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 513 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 514 | 'ctype': 'legacy_flow_classifier', |
| 515 | 'definition': { |
| 516 | 'source_port_range_min': 2000, |
| 517 | 'destination_ip_prefix': '192.168.3.0/24', |
| 518 | 'protocol': 'udp', |
| 519 | 'ethertype': 'IPv4', |
| 520 | 'l7_parameters': {}, |
| 521 | 'source_port_range_max': 2000, |
| 522 | 'destination_port_range_min': 3000, |
| 523 | 'source_ip_prefix': '192.168.2.0/24', |
| 524 | 'logical_destination_port': None, |
| 525 | 'destination_port_range_max': None, |
| 526 | 'logical_source_port': |
| 527 | 'aaab0ab0-1452-4636-bb3b-11dca833fa2b'} |
| 528 | }) |
| 529 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 530 | @mock.patch.object(Client, 'list_sfc_flow_classifiers') |
| 531 | def test_get_classification_many_results(self, list_sfc_flow_classifiers): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 532 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 533 | list_sfc_flow_classifiers.return_value = {'flow_classifiers': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 534 | {'source_port_range_min': 2000, |
| 535 | 'destination_ip_prefix': '192.168.3.0/24', |
| 536 | 'protocol': 'udp', |
| 537 | 'description': '', |
| 538 | 'ethertype': 'IPv4', |
| 539 | 'l7_parameters': {}, |
| 540 | 'source_port_range_max': 2000, |
| 541 | 'destination_port_range_min': 3000, |
| 542 | 'source_ip_prefix': '192.168.2.0/24', |
| 543 | 'logical_destination_port': None, |
| 544 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 545 | 'destination_port_range_max': None, |
| 546 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 547 | 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b', |
| 548 | 'id': '22198366-d4e8-4d6b-b4d2-637d5d6cbb7d', |
| 549 | 'name': 'fc1'}, |
| 550 | {'source_port_range_min': 1000, |
| 551 | 'destination_ip_prefix': '192.168.3.0/24', |
| 552 | 'protocol': 'udp', |
| 553 | 'description': '', |
| 554 | 'ethertype': 'IPv4', |
| 555 | 'l7_parameters': {}, |
| 556 | 'source_port_range_max': 1000, |
| 557 | 'destination_port_range_min': 3000, |
| 558 | 'source_ip_prefix': '192.168.2.0/24', |
| 559 | 'logical_destination_port': None, |
| 560 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 561 | 'destination_port_range_max': None, |
| 562 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 563 | 'logical_source_port': 'aaab0ab0-1452-4636-bb3b-11dca833fa2b', |
| 564 | 'id': '3196bafc-82dd-11e7-a205-9bf6c14b0721', |
| 565 | 'name': 'fc2'} |
| 566 | ]} |
| 567 | |
| 568 | # call the VIM connector |
| 569 | self.assertRaises(vimconn.vimconnConflictException, |
| 570 | self.vimconn.get_classification, |
| 571 | '3196bafc-82dd-11e7-a205-9bf6c14b0721') |
| 572 | |
| 573 | # assert the VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 574 | list_sfc_flow_classifiers.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 575 | id='3196bafc-82dd-11e7-a205-9bf6c14b0721') |
| 576 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 577 | @mock.patch.object(Client, 'list_sfc_flow_classifiers') |
| 578 | def test_get_classification_no_results(self, list_sfc_flow_classifiers): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 579 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 580 | list_sfc_flow_classifiers.return_value = {'flow_classifiers': []} |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 581 | |
| 582 | # call the VIM connector |
| 583 | self.assertRaises(vimconn.vimconnNotFoundException, |
| 584 | self.vimconn.get_classification, |
| 585 | '3196bafc-82dd-11e7-a205-9bf6c14b0721') |
| 586 | |
| 587 | # assert the VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 588 | list_sfc_flow_classifiers.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 589 | id='3196bafc-82dd-11e7-a205-9bf6c14b0721') |
| 590 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 591 | @mock.patch.object(Client, 'list_sfc_port_pairs') |
| 592 | def test_get_sfi(self, list_sfc_port_pairs): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 593 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 594 | list_sfc_port_pairs.return_value = {'port_pairs': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 595 | {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 596 | 'description': '', |
| 597 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 598 | 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 599 | 'service_function_parameters': {'correlation': 'nsh'}, |
| 600 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 601 | 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966', |
| 602 | 'name': 'osm_sfi1'}, |
| 603 | ]} |
| 604 | |
| 605 | # call the VIM connector |
| 606 | result = self.vimconn.get_sfi('c121ebdd-7f2d-4213-b933-3325298a6966') |
| 607 | |
| 608 | # assert the VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 609 | list_sfc_port_pairs.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 610 | id='c121ebdd-7f2d-4213-b933-3325298a6966') |
| 611 | # assert the VIM connector successfully returned the OpenStack result |
| 612 | self.assertEqual(result, |
| 613 | {'ingress_ports': [ |
| 614 | '5311c75d-d718-4369-bbda-cdcc6da60fcc'], |
| 615 | 'egress_ports': [ |
| 616 | '5311c75d-d718-4369-bbda-cdcc6da60fcc'], |
| 617 | 'sfc_encap': True, |
| 618 | 'description': '', |
| 619 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 620 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 621 | 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966', |
| 622 | 'name': 'osm_sfi1'}) |
| 623 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 624 | @mock.patch.object(Client, 'list_sfc_port_pairs') |
| 625 | def test_get_sfi_many_results(self, list_sfc_port_pairs): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 626 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 627 | list_sfc_port_pairs.return_value = {'port_pairs': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 628 | {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 629 | 'description': '', |
| 630 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 631 | 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 632 | 'service_function_parameters': {'correlation': 'nsh'}, |
| 633 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 634 | 'id': 'c121ebdd-7f2d-4213-b933-3325298a6966', |
| 635 | 'name': 'osm_sfi1'}, |
| 636 | {'ingress': '5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 637 | 'description': '', |
| 638 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 639 | 'egress': '5311c75d-d718-4369-bbda-cdcc6da60fcc', |
| 640 | 'service_function_parameters': {'correlation': 'nsh'}, |
| 641 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 642 | 'id': 'c0436d92-82db-11e7-8f9c-5fa535f1261f', |
| 643 | 'name': 'osm_sfi2'} |
| 644 | ]} |
| 645 | |
| 646 | # call the VIM connector |
| 647 | self.assertRaises(vimconn.vimconnConflictException, |
| 648 | self.vimconn.get_sfi, |
| 649 | 'c0436d92-82db-11e7-8f9c-5fa535f1261f') |
| 650 | |
| 651 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 652 | list_sfc_port_pairs.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 653 | id='c0436d92-82db-11e7-8f9c-5fa535f1261f') |
| 654 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 655 | @mock.patch.object(Client, 'list_sfc_port_pairs') |
| 656 | def test_get_sfi_no_results(self, list_sfc_port_pairs): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 657 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 658 | list_sfc_port_pairs.return_value = {'port_pairs': []} |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 659 | |
| 660 | # call the VIM connector |
| 661 | self.assertRaises(vimconn.vimconnNotFoundException, |
| 662 | self.vimconn.get_sfi, |
| 663 | 'b22892fc-82d9-11e7-ae85-0fea6a3b3757') |
| 664 | |
| 665 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 666 | list_sfc_port_pairs.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 667 | id='b22892fc-82d9-11e7-ae85-0fea6a3b3757') |
| 668 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 669 | @mock.patch.object(Client, 'list_sfc_port_pair_groups') |
| 670 | def test_get_sf(self, list_sfc_port_pair_groups): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 671 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 672 | list_sfc_port_pair_groups.return_value = {'port_pair_groups': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 673 | {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'], |
| 674 | 'description': '', |
| 675 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 676 | 'port_pair_group_parameters': {}, |
| 677 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 678 | 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d', |
| 679 | 'name': 'osm_sf1'} |
| 680 | ]} |
| 681 | |
| 682 | # call the VIM connector |
| 683 | result = self.vimconn.get_sf('b22892fc-82d9-11e7-ae85-0fea6a3b3757') |
| 684 | |
| 685 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 686 | list_sfc_port_pair_groups.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 687 | id='b22892fc-82d9-11e7-ae85-0fea6a3b3757') |
| 688 | # assert that VIM connector successfully returned the OpenStack result |
| 689 | self.assertEqual(result, |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 690 | {'description': '', |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 691 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 692 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 693 | 'sfis': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'], |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 694 | 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d', |
| 695 | 'name': 'osm_sf1'}) |
| 696 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 697 | @mock.patch.object(Client, 'list_sfc_port_pair_groups') |
| 698 | def test_get_sf_many_results(self, list_sfc_port_pair_groups): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 699 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 700 | list_sfc_port_pair_groups.return_value = {'port_pair_groups': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 701 | {'port_pairs': ['08fbdbb0-82d6-11e7-ad95-9bb52fbec2f2'], |
| 702 | 'description': '', |
| 703 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 704 | 'port_pair_group_parameters': {}, |
| 705 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 706 | 'id': 'aabba8a6-82d9-11e7-a18a-d3c7719b742d', |
| 707 | 'name': 'osm_sf1'}, |
| 708 | {'port_pairs': ['0d63799c-82d6-11e7-8deb-a746bb3ae9f5'], |
| 709 | 'description': '', |
| 710 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 711 | 'port_pair_group_parameters': {}, |
| 712 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 713 | 'id': 'b22892fc-82d9-11e7-ae85-0fea6a3b3757', |
| 714 | 'name': 'osm_sf2'} |
| 715 | ]} |
| 716 | |
| 717 | # call the VIM connector |
| 718 | self.assertRaises(vimconn.vimconnConflictException, |
| 719 | self.vimconn.get_sf, |
| 720 | 'b22892fc-82d9-11e7-ae85-0fea6a3b3757') |
| 721 | |
| 722 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 723 | list_sfc_port_pair_groups.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 724 | id='b22892fc-82d9-11e7-ae85-0fea6a3b3757') |
| 725 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 726 | @mock.patch.object(Client, 'list_sfc_port_pair_groups') |
| 727 | def test_get_sf_no_results(self, list_sfc_port_pair_groups): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 728 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 729 | list_sfc_port_pair_groups.return_value = {'port_pair_groups': []} |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 730 | |
| 731 | # call the VIM connector |
| 732 | self.assertRaises(vimconn.vimconnNotFoundException, |
| 733 | self.vimconn.get_sf, |
| 734 | 'b22892fc-82d9-11e7-ae85-0fea6a3b3757') |
| 735 | |
| 736 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 737 | list_sfc_port_pair_groups.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 738 | id='b22892fc-82d9-11e7-ae85-0fea6a3b3757') |
| 739 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 740 | @mock.patch.object(Client, 'list_sfc_port_chains') |
| 741 | def test_get_sfp(self, list_sfc_port_chains): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 742 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 743 | list_sfc_port_chains.return_value = {'port_chains': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 744 | {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'], |
| 745 | 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'], |
| 746 | 'description': '', |
| 747 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 748 | 'chain_parameters': {'correlation': 'nsh'}, |
| 749 | 'chain_id': 40, |
| 750 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 751 | 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47', |
| 752 | 'name': 'osm_sfp1'}]} |
| 753 | |
| 754 | # call the VIM connector |
| 755 | result = self.vimconn.get_sfp('821bc9be-82d7-11e7-8ce3-23a08a27ab47') |
| 756 | |
| 757 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 758 | list_sfc_port_chains.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 759 | id='821bc9be-82d7-11e7-8ce3-23a08a27ab47') |
| 760 | # assert that VIM connector successfully returned the OpenStack result |
| 761 | self.assertEqual(result, |
| 762 | {'service_functions': [ |
| 763 | '7d8e3bf8-82d6-11e7-a032-8ff028839d25'], |
| 764 | 'classifications': [ |
| 765 | '1333c2f4-82d7-11e7-a5df-9327f33d104e'], |
| 766 | 'description': '', |
| 767 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 768 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 769 | 'sfc_encap': True, |
| 770 | 'spi': 40, |
| 771 | 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47', |
| 772 | 'name': 'osm_sfp1'}) |
| 773 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 774 | @mock.patch.object(Client, 'list_sfc_port_chains') |
| 775 | def test_get_sfp_many_results(self, list_sfc_port_chains): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 776 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 777 | list_sfc_port_chains.return_value = {'port_chains': [ |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 778 | {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'], |
| 779 | 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'], |
| 780 | 'description': '', |
| 781 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 782 | 'chain_parameters': {'correlation': 'nsh'}, |
| 783 | 'chain_id': 40, |
| 784 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 785 | 'id': '821bc9be-82d7-11e7-8ce3-23a08a27ab47', |
| 786 | 'name': 'osm_sfp1'}, |
| 787 | {'port_pair_groups': ['7d8e3bf8-82d6-11e7-a032-8ff028839d25'], |
| 788 | 'flow_classifiers': ['1333c2f4-82d7-11e7-a5df-9327f33d104e'], |
| 789 | 'description': '', |
| 790 | 'tenant_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 791 | 'chain_parameters': {'correlation': 'nsh'}, |
| 792 | 'chain_id': 50, |
| 793 | 'project_id': '8f3019ef06374fa880a0144ad4bc1d7b', |
| 794 | 'id': '5d002f38-82de-11e7-a770-f303f11ce66a', |
| 795 | 'name': 'osm_sfp2'} |
| 796 | ]} |
| 797 | |
| 798 | # call the VIM connector |
| 799 | self.assertRaises(vimconn.vimconnConflictException, |
| 800 | self.vimconn.get_sfp, |
| 801 | '5d002f38-82de-11e7-a770-f303f11ce66a') |
| 802 | |
| 803 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 804 | list_sfc_port_chains.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 805 | id='5d002f38-82de-11e7-a770-f303f11ce66a') |
| 806 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 807 | @mock.patch.object(Client, 'list_sfc_port_chains') |
| 808 | def test_get_sfp_no_results(self, list_sfc_port_chains): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 809 | # what OpenStack is assumed to return to the VIM connector |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 810 | list_sfc_port_chains.return_value = {'port_chains': []} |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 811 | |
| 812 | # call the VIM connector |
| 813 | self.assertRaises(vimconn.vimconnNotFoundException, |
| 814 | self.vimconn.get_sfp, |
| 815 | '5d002f38-82de-11e7-a770-f303f11ce66a') |
| 816 | |
| 817 | # assert that VIM connector called OpenStack with the expected filter |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 818 | list_sfc_port_chains.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 819 | id='5d002f38-82de-11e7-a770-f303f11ce66a') |
| 820 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 821 | @mock.patch.object(Client, 'delete_sfc_flow_classifier') |
| 822 | def test_delete_classification(self, delete_sfc_flow_classifier): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 823 | result = self.vimconn.delete_classification( |
| 824 | '638f957c-82df-11e7-b7c8-132706021464') |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 825 | delete_sfc_flow_classifier.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 826 | '638f957c-82df-11e7-b7c8-132706021464') |
| 827 | self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464') |
| 828 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 829 | @mock.patch.object(Client, 'delete_sfc_port_pair') |
| 830 | def test_delete_sfi(self, delete_sfc_port_pair): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 831 | result = self.vimconn.delete_sfi( |
| 832 | '638f957c-82df-11e7-b7c8-132706021464') |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 833 | delete_sfc_port_pair.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 834 | '638f957c-82df-11e7-b7c8-132706021464') |
| 835 | self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464') |
| 836 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 837 | @mock.patch.object(Client, 'delete_sfc_port_pair_group') |
| 838 | def test_delete_sf(self, delete_sfc_port_pair_group): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 839 | result = self.vimconn.delete_sf('638f957c-82df-11e7-b7c8-132706021464') |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 840 | delete_sfc_port_pair_group.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 841 | '638f957c-82df-11e7-b7c8-132706021464') |
| 842 | self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464') |
| 843 | |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 844 | @mock.patch.object(Client, 'delete_sfc_port_chain') |
| 845 | def test_delete_sfp(self, delete_sfc_port_chain): |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 846 | result = self.vimconn.delete_sfp( |
| 847 | '638f957c-82df-11e7-b7c8-132706021464') |
| anwars | 50e4304 | 2018-09-28 16:00:13 +0530 | [diff] [blame] | 848 | delete_sfc_port_chain.assert_called_with( |
| Igor Duarte Cardoso | 3cf9bcd | 2017-08-14 16:39:34 +0000 | [diff] [blame] | 849 | '638f957c-82df-11e7-b7c8-132706021464') |
| 850 | self.assertEqual(result, '638f957c-82df-11e7-b7c8-132706021464') |
| 851 | |
| 852 | |
| 853 | if __name__ == '__main__': |
| 854 | unittest.main() |