rehome availability zone API def
This patch rehomes neutron's availability zone extension into neutron-libs API definition layout/structure. UTs and a reno are also included. Change-Id: Id8513a7a82609808829e3e66827f69f3fd0c3e4d
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
from neutron_lib.api.definitions import address_scope
|
||||
from neutron_lib.api.definitions import agent
|
||||
from neutron_lib.api.definitions import auto_allocated_topology
|
||||
from neutron_lib.api.definitions import availability_zone
|
||||
from neutron_lib.api.definitions import bgpvpn
|
||||
from neutron_lib.api.definitions import bgpvpn_routes_control
|
||||
from neutron_lib.api.definitions import data_plane_status
|
||||
@@ -43,6 +44,7 @@ _ALL_API_DEFINITIONS = {
|
||||
address_scope,
|
||||
agent,
|
||||
auto_allocated_topology,
|
||||
availability_zone,
|
||||
bgpvpn,
|
||||
bgpvpn_routes_control,
|
||||
data_plane_status,
|
||||
|
49
neutron_lib/api/definitions/availability_zone.py
Normal file
49
neutron_lib/api/definitions/availability_zone.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from neutron_lib.api.definitions import agent
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib.api.validators import availability_zone as az_validator
|
||||
|
||||
|
||||
validators.add_validator('availability_zone_hint_list',
|
||||
az_validator._validate_availability_zone_hints)
|
||||
|
||||
AZ_HINTS = 'availability_zone_hints'
|
||||
|
||||
ALIAS = 'availability_zone'
|
||||
IS_SHIM_EXTENSION = False
|
||||
IS_STANDARD_ATTR_EXTENSION = False
|
||||
NAME = 'Availability Zone'
|
||||
API_PREFIX = ''
|
||||
DESCRIPTION = 'The availability zone extension.'
|
||||
UPDATED_TIMESTAMP = '2015-01-01T10:00:00-00:00'
|
||||
RESOURCE_NAME = 'availability_zone'
|
||||
COLLECTION_NAME = RESOURCE_NAME + 's'
|
||||
RESOURCE_ATTRIBUTE_MAP = {
|
||||
COLLECTION_NAME: {
|
||||
'name': {'is_visible': True},
|
||||
'resource': {'is_visible': True},
|
||||
'state': {'is_visible': True}
|
||||
},
|
||||
agent.COLLECTION_NAME: {
|
||||
RESOURCE_NAME: {
|
||||
'allow_post': False, 'allow_put': False,
|
||||
'is_visible': True}
|
||||
}
|
||||
}
|
||||
SUB_RESOURCE_ATTRIBUTE_MAP = {}
|
||||
ACTION_MAP = {}
|
||||
REQUIRED_EXTENSIONS = [agent.ALIAS]
|
||||
OPTIONAL_EXTENSIONS = []
|
||||
ACTION_STATUS = {}
|
47
neutron_lib/api/validators/availability_zone.py
Normal file
47
neutron_lib/api/validators/availability_zone.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
from neutron_lib.api import validators
|
||||
from neutron_lib.db import constants as db_const
|
||||
from neutron_lib import exceptions
|
||||
|
||||
|
||||
def convert_az_list_to_string(az_list):
|
||||
"""Convert a list of availability zones into a string.
|
||||
|
||||
:param az_list: A list of AZs.
|
||||
:returns: The az_list in string format.
|
||||
"""
|
||||
return jsonutils.dumps(az_list)
|
||||
|
||||
|
||||
def convert_az_string_to_list(az_string):
|
||||
"""Convert an AZ list in string format into a python list.
|
||||
|
||||
:param az_string: The AZ list in string format.
|
||||
:returns: The python list of AZs build from az_string.
|
||||
"""
|
||||
return jsonutils.loads(az_string) if az_string else []
|
||||
|
||||
|
||||
def _validate_availability_zone_hints(data, valid_value=None):
|
||||
msg = validators.validate_list_of_unique_strings(data)
|
||||
if msg:
|
||||
return msg
|
||||
az_string = convert_az_list_to_string(data)
|
||||
if len(az_string) > db_const.AZ_HINTS_DB_LEN:
|
||||
msg = _("Too many availability_zone_hints specified")
|
||||
raise exceptions.InvalidInput(error_message=msg)
|
@@ -23,6 +23,7 @@ IP_ADDR_FIELD_SIZE = 64 # large enough to hold a v4 or v6 address
|
||||
MAC_ADDR_FIELD_SIZE = 32
|
||||
RESOURCE_TYPE_FIELD_SIZE = 255
|
||||
FQDN_FIELD_SIZE = 255
|
||||
AZ_HINTS_DB_LEN = 255
|
||||
|
||||
# Alembic branches
|
||||
EXPAND_BRANCH = 'expand'
|
||||
|
19
neutron_lib/exceptions/availability_zone.py
Normal file
19
neutron_lib/exceptions/availability_zone.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from neutron_lib._i18n import _
|
||||
from neutron_lib import exceptions
|
||||
|
||||
|
||||
class AvailabilityZoneNotFound(exceptions.NotFound):
|
||||
message = _("AvailabilityZone %(availability_zone)s could not be found.")
|
@@ -0,0 +1,23 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib.api.definitions import agent
|
||||
from neutron_lib.api.definitions import availability_zone
|
||||
from neutron_lib.tests.unit.api.definitions import base
|
||||
|
||||
|
||||
class AvailabilityZoneDefinitionTestCase(base.DefinitionBaseTestCase):
|
||||
extension_module = availability_zone
|
||||
extension_resources = (availability_zone.COLLECTION_NAME,
|
||||
agent.COLLECTION_NAME,)
|
||||
extension_attributes = (availability_zone.AZ_HINTS, 'resource',
|
||||
availability_zone.RESOURCE_NAME, 'state',)
|
@@ -0,0 +1,39 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from neutron_lib.api.validators import availability_zone as az_validator
|
||||
from neutron_lib.db import constants as db_const
|
||||
from neutron_lib import exceptions
|
||||
from neutron_lib.tests import _base as base
|
||||
|
||||
|
||||
class TestAvailabilityZoneValidator(base.BaseTestCase):
|
||||
|
||||
@mock.patch.object(az_validator.validators,
|
||||
'validate_list_of_unique_strings',
|
||||
return_value='bad')
|
||||
def test__validate_availability_zone_hints_unique_strings(
|
||||
self, mock_unique_strs):
|
||||
self.assertEqual(
|
||||
'bad', az_validator._validate_availability_zone_hints(['a', 'a']))
|
||||
|
||||
def test__validate_availability_zone_hints_excessive_len(self):
|
||||
self.assertRaisesRegex(
|
||||
exceptions.InvalidInput, 'Too many availability_zone_hints',
|
||||
az_validator._validate_availability_zone_hints,
|
||||
['a' * (db_const.AZ_HINTS_DB_LEN + 1)])
|
||||
|
||||
def test__validate_availability_zone_hints_valid_input(self):
|
||||
self.assertIsNone(
|
||||
az_validator._validate_availability_zone_hints(['a', 'b', 'c']))
|
10
releasenotes/notes/rehome-az-apidef-1e63cbd2359994fa.yaml
Normal file
10
releasenotes/notes/rehome-az-apidef-1e63cbd2359994fa.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
features:
|
||||
- The ``availability_zone`` extension's API definition is now available
|
||||
in ``neutron_lib.api.definitions.availability_zone``.
|
||||
- A new API validation type ``type:availability_zone_hint_list`` has been
|
||||
added and validates a list of availability zone hints.
|
||||
- Exceptions for the ``availability_zone`` are now available in
|
||||
``neutron_lib.exceptions.availability_zone``.
|
||||
- The constant ``AZ_HINTS_DB_LEN`` has been added to
|
||||
``neutron_lib.db.constants``.
|
@@ -15,5 +15,6 @@ oslo.i18n!=3.15.2,>=2.1.0 # Apache-2.0
|
||||
oslo.log>=3.22.0 # Apache-2.0
|
||||
oslo.messaging!=5.25.0,>=5.24.2 # Apache-2.0
|
||||
oslo.policy>=1.23.0 # Apache-2.0
|
||||
oslo.serialization!=2.19.1,>=1.10.0 # Apache-2.0
|
||||
oslo.service>=1.10.0 # Apache-2.0
|
||||
oslo.utils>=3.20.0 # Apache-2.0
|
||||
|
Reference in New Issue
Block a user