| 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 webob import exc |
| 14 |
|
| 15 |
from neutron_lib.api.definitions import provider_net |
| 16 |
from neutron_lib.api.validators import multiprovidernet as mp_validator |
| 17 |
from neutron_lib import constants |
| 18 |
from neutron_lib.tests import _base as base |
| 19 |
|
| 20 |
|
| 21 |
def _build_segment(net_type=constants.ATTR_NOT_SPECIFIED, |
| 22 |
phy_net=constants.ATTR_NOT_SPECIFIED, |
| 23 |
seg_id=constants.ATTR_NOT_SPECIFIED): |
| 24 |
return { |
| 25 |
provider_net.NETWORK_TYPE: net_type, |
| 26 |
provider_net.PHYSICAL_NETWORK: phy_net, |
| 27 |
provider_net.SEGMENTATION_ID: seg_id |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
class TestMultiprovidernetValidators(base.BaseTestCase): |
| 32 |
|
| 33 |
def test_convert_and_validate_segments_default_values(self): |
| 34 |
segs = [{}] |
| 35 |
mp_validator.convert_and_validate_segments(segs) |
| 36 |
self.assertEqual( |
| 37 |
[_build_segment()], segs) |
| 38 |
|
| 39 |
def test_convert_and_validate_segments_seg_id_to_int(self): |
| 40 |
segs = [_build_segment(seg_id="9")] |
| 41 |
mp_validator.convert_and_validate_segments(segs) |
| 42 |
self.assertEqual(_build_segment(seg_id=9), segs[0]) |
| 43 |
|
| 44 |
def test_convert_and_validate_segments_invalid_key(self): |
| 45 |
segs = [_build_segment(seg_id=2)] |
| 46 |
segs[0]['some_key'] = 'some_value' |
| 47 |
self.assertRaises(exc.HTTPBadRequest, |
| 48 |
mp_validator.convert_and_validate_segments, |
| 49 |
segs) |