This patch improves how the trunk plugin supports future segmentation types and how it can handle multi-driver deployments where each driver may have its own set of supported segmentation types. It does so by: a) removing the existing segmentation type registration mechanism; this has become superseded by how drivers advertise their capabilities and register themselves with the plugin. b) introducing a new compatibility check that makes the plugin fails to load in case of conflicts: for multi-drivers environments a common set of segmentation types must be found for the plugin to load successfully. In case of single driver deployments, a driver can bring its own segmentation type. Partially-implement: blueprint vlan-aware-vms Change-Id: I0bd8b479c07945c65e14d4b59dfbcc1bc9a85a88changes/27/356127/5
parent
ab324cf161
commit
fb5c043d0d
@ -1,15 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 neutron.services.trunk.validators # noqa
|
@ -0,0 +1,41 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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._i18n import _
|
||||
|
||||
from neutron.plugins.common import utils
|
||||
from neutron.services.trunk import constants as trunk_consts
|
||||
|
||||
# Base map of segmentation types supported with their respective validator
|
||||
# functions. In multi-driver deployments all drivers must support the same
|
||||
# set of segmentation types consistently. Drivers can add their own type
|
||||
# and respective validator, however this is a configuration that may be
|
||||
# supported only in single-driver deployments.
|
||||
_supported = {
|
||||
trunk_consts.VLAN: utils.is_valid_vlan_tag,
|
||||
}
|
||||
|
||||
|
||||
def get_validator(segmentation_type):
|
||||
"""Get validator for the segmentation type or KeyError if not found."""
|
||||
return _supported[segmentation_type]
|
||||
|
||||
|
||||
def add_validator(segmentation_type, validator_function):
|
||||
"""Introduce new entry to the map of supported segmentation types."""
|
||||
if segmentation_type in _supported:
|
||||
msg = _("Cannot redefine existing %s "
|
||||
"segmentation type") % segmentation_type
|
||||
raise KeyError(msg)
|
||||
_supported[segmentation_type] = validator_function
|
@ -1,18 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.services.trunk.validators import vlan
|
||||
|
||||
# Register segmentation_type validation drivers
|
||||
vlan.register()
|
@ -1,34 +0,0 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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_log import log as logging
|
||||
|
||||
from neutron.callbacks import events
|
||||
from neutron.callbacks import registry
|
||||
from neutron.plugins.common import utils
|
||||
from neutron.services.trunk import constants as trunk_consts
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def register():
|
||||
registry.subscribe(handler, trunk_consts.TRUNK_PLUGIN,
|
||||
events.AFTER_INIT)
|
||||
LOG.debug('Registering for trunk support')
|
||||
|
||||
|
||||
def handler(resource, event, trigger, **kwargs):
|
||||
trigger.add_segmentation_type(
|
||||
trunk_consts.VLAN, utils.is_valid_vlan_tag)
|
||||
LOG.debug('Registration complete')
|
@ -0,0 +1,37 @@
|
||||
# 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.services.trunk import constants
|
||||
from neutron.services.trunk.seg_types import validators
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
class ValidatorsTestCase(base.BaseTestCase):
|
||||
|
||||
def test_add_validator_raises_keyerror_on_redefinition(self):
|
||||
self.assertRaises(KeyError,
|
||||
validators.add_validator,
|
||||
constants.VLAN, mock.ANY)
|
||||
|
||||
def test_add_validator_add_new_type(self):
|
||||
validators.add_validator('foo', lambda: None)
|
||||
self.assertIn('foo', validators._supported)
|
||||
|
||||
def test_get_validator(self):
|
||||
self.assertIsNotNone(validators.get_validator(constants.VLAN))
|
||||
|
||||
def test_get_validator_raises_keyerror_on_missing_validator(self):
|
||||
self.assertRaises(KeyError,
|
||||
validators.get_validator, 'my_random_seg_type')
|
Loading…
Reference in new issue