| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
from neutron_lib.api.definitions import bgpvpn |
| 14 |
from neutron_lib.api import validators |
| 15 |
from neutron_lib.tests.unit.api.definitions import base |
| 16 |
|
| 17 |
|
| 18 |
class BgpvpnDefinitionTestCase(base.DefinitionBaseTestCase): |
| 19 |
extension_module = bgpvpn |
| 20 |
extension_resources = (bgpvpn.COLLECTION_NAME,) |
| 21 |
extension_attributes = ('type', 'route_targets', 'import_targets', |
| 22 |
'export_targets', 'route_distinguishers', |
| 23 |
'networks', 'routers', 'router_id', 'network_id') |
| 24 |
extension_subresources = ('network_associations', 'router_associations') |
| 25 |
|
| 26 |
def _data_for_invalid_rtdt(self): |
| 27 |
values = [[':1'], |
| 28 |
['1:'], |
| 29 |
['42'], |
| 30 |
['65536:123456'], |
| 31 |
['123.456.789.123:65535'], |
| 32 |
['4294967296:65535'], |
| 33 |
['1.1.1.1:655351'], |
| 34 |
['4294967295:65536'], |
| 35 |
[''], |
| 36 |
] |
| 37 |
yield from values |
| 38 |
|
| 39 |
def _data_for_valid_rtdt(self): |
| 40 |
values = [['1:1'], |
| 41 |
['1:4294967295'], |
| 42 |
['65535:0'], |
| 43 |
['65535:4294967295'], |
| 44 |
['1.1.1.1:1'], |
| 45 |
['1.1.1.1:65535'], |
| 46 |
['4294967295:0'], |
| 47 |
['65536:65535'], |
| 48 |
['4294967295:65535'], |
| 49 |
] |
| 50 |
yield from values |
| 51 |
|
| 52 |
def test_valid_rtrd(self): |
| 53 |
for rtrd in self._data_for_valid_rtdt(): |
| 54 |
msg = validators.validate_list_of_regex_or_none( |
| 55 |
rtrd, |
| 56 |
bgpvpn.RTRD_REGEX) |
| 57 |
self.assertIsNone(msg) |
| 58 |
|
| 59 |
def test_invalid_rtrd(self): |
| 60 |
for rtrd in self._data_for_invalid_rtdt(): |
| 61 |
msg = validators.validate_list_of_regex_or_none( |
| 62 |
rtrd, |
| 63 |
bgpvpn.RTRD_REGEX) |
| 64 |
self.assertIsNotNone(msg) |