Debian Codegraph @

neutron_lib/tests/unit/api/definitions/test_multiprovidernet.py

raw
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 multiprovidernet
14 from neutron_lib.api.definitions import provider_net
15 from neutron_lib.exceptions import multiprovidernet as mp_exc
16 from neutron_lib.tests.unit.api.definitions import base
17 from neutron_lib.tests.unit.api.validators import test_multiprovidernet \
18 as test_mpnet
19
20
21 class MultiProviderNetworkDefinitionTestCase(base.DefinitionBaseTestCase):
22 extension_module = multiprovidernet
23 extension_attributes = (multiprovidernet.SEGMENTS,)
24
25 def test_check_duplicate_segments_with_dups(self):
26 self.assertRaises(mp_exc.SegmentsContainDuplicateEntry,
27 multiprovidernet.check_duplicate_segments,
28 [test_mpnet._build_segment('nt0', 'pn0', 2),
29 test_mpnet._build_segment('nt0', 'pn0', 2)])
30
31 def test_check_duplicate_segments_with_dups_and_partial(self):
32
33 def _seg_partial(seg):
34 return seg[provider_net.PHYSICAL_NETWORK] == 'pn0'
35
36 self.assertIsNone(
37 multiprovidernet.check_duplicate_segments(
38 [test_mpnet._build_segment('nt0', 'pn0', 2),
39 test_mpnet._build_segment('nt1', 'pn1', 2)],
40 is_partial_func=_seg_partial))
41
42 def test_check_duplicate_segments_no_dups(self):
43 self.assertIsNone(
44 multiprovidernet.check_duplicate_segments(
45 [test_mpnet._build_segment('nt0', 'pn0', 2),
46 test_mpnet._build_segment('nt0', 'pn0', 3)]))