use ml2 driver api from neutron-lib
The ml2 plugin driver API was rehomed into neutron-lib with commit Ifc829953ef4d5859c3475903965dc08aba42fd9c and the API was shimmed in neutron with I86a10091b55d1123e8d16f16155e0312bb10e54c. This patch consumes the ML2 driver api from neutron lib thereby removing the driver_api module from neutron. NeutronLibImpact Change-Id: Ice49572e217eeaf820e48d40f2251d08766490b5
This commit is contained in:
parent
af00cbc3d2
commit
a2c36d7e00
|
@ -1,34 +0,0 @@
|
||||||
# Copyright (c) 2013 OpenStack Foundation
|
|
||||||
# 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_lib.plugins.ml2 import api
|
|
||||||
|
|
||||||
|
|
||||||
# TODO(boden): remove once consumers are moved over to lib's version
|
|
||||||
MechanismDriver = api.MechanismDriver
|
|
||||||
ID = api.ID
|
|
||||||
NETWORK_TYPE = api.NETWORK_TYPE
|
|
||||||
PHYSICAL_NETWORK = api.PHYSICAL_NETWORK
|
|
||||||
SEGMENTATION_ID = api.SEGMENTATION_ID
|
|
||||||
MTU = api.MTU
|
|
||||||
NETWORK_ID = api.NETWORK_ID
|
|
||||||
BOUND_DRIVER = api.BOUND_DRIVER
|
|
||||||
BOUND_SEGMENT = api.BOUND_SEGMENT
|
|
||||||
TypeDriver = api.TypeDriver
|
|
||||||
ML2TypeDriver = api.ML2TypeDriver
|
|
||||||
NetworkContext = api.NetworkContext
|
|
||||||
SubnetContext = api.SubnetContext
|
|
||||||
PortContext = api.PortContext
|
|
||||||
ExtensionDriver = api.ExtensionDriver
|
|
|
@ -15,13 +15,12 @@
|
||||||
|
|
||||||
from neutron_lib.api.definitions import portbindings
|
from neutron_lib.api.definitions import portbindings
|
||||||
from neutron_lib import constants
|
from neutron_lib import constants
|
||||||
from neutron_lib.plugins.ml2 import api as ml2_api
|
from neutron_lib.plugins.ml2 import api
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
|
||||||
from neutron.db import segments_db
|
from neutron.db import segments_db
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -200,16 +199,16 @@ class PortContext(MechanismDriverContext, api.PortContext):
|
||||||
def binding_levels(self):
|
def binding_levels(self):
|
||||||
if self._binding_levels:
|
if self._binding_levels:
|
||||||
return [{
|
return [{
|
||||||
ml2_api.BOUND_DRIVER: level.driver,
|
api.BOUND_DRIVER: level.driver,
|
||||||
ml2_api.BOUND_SEGMENT: self._expand_segment(level.segment_id)
|
api.BOUND_SEGMENT: self._expand_segment(level.segment_id)
|
||||||
} for level in self._binding_levels]
|
} for level in self._binding_levels]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def original_binding_levels(self):
|
def original_binding_levels(self):
|
||||||
if self._original_binding_levels:
|
if self._original_binding_levels:
|
||||||
return [{
|
return [{
|
||||||
ml2_api.BOUND_DRIVER: level.driver,
|
api.BOUND_DRIVER: level.driver,
|
||||||
ml2_api.BOUND_SEGMENT: self._expand_segment(level.segment_id)
|
api.BOUND_SEGMENT: self._expand_segment(level.segment_id)
|
||||||
} for level in self._original_binding_levels]
|
} for level in self._original_binding_levels]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from neutron_lib import context as neutron_ctx
|
from neutron_lib import context as neutron_ctx
|
||||||
|
from neutron_lib.plugins.ml2 import api
|
||||||
from neutron_lib.utils import helpers
|
from neutron_lib.utils import helpers
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_db import exception as db_exc
|
from oslo_db import exception as db_exc
|
||||||
|
@ -25,7 +26,6 @@ from neutron.common import exceptions as exc
|
||||||
from neutron.db import api as db_api
|
from neutron.db import api as db_api
|
||||||
from neutron.objects import base as base_obj
|
from neutron.objects import base as base_obj
|
||||||
from neutron.plugins.common import utils as p_utils
|
from neutron.plugins.common import utils as p_utils
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
|
||||||
|
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
|
@ -19,12 +19,11 @@ from neutron_lib.plugins.ml2 import api
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
from neutron._i18n import _
|
from neutron._i18n import _
|
||||||
from neutron.plugins.ml2 import driver_api
|
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LocalTypeDriver(driver_api.ML2TypeDriver):
|
class LocalTypeDriver(api.ML2TypeDriver):
|
||||||
"""Manage state for local networks with ML2.
|
"""Manage state for local networks with ML2.
|
||||||
|
|
||||||
The LocalTypeDriver implements the 'local' network_type. Local
|
The LocalTypeDriver implements the 'local' network_type. Local
|
||||||
|
|
|
@ -13,10 +13,10 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron_lib.api.definitions import data_plane_status as dps_lib
|
from neutron_lib.api.definitions import data_plane_status as dps_lib
|
||||||
|
from neutron_lib.plugins.ml2 import api
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from neutron.db import data_plane_status_db as dps_db
|
from neutron.db import data_plane_status_db as dps_db
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ from neutron_lib.callbacks import resources
|
||||||
from neutron_lib import constants as lib_const
|
from neutron_lib import constants as lib_const
|
||||||
from neutron_lib.exceptions import dns as dns_exc
|
from neutron_lib.exceptions import dns as dns_exc
|
||||||
from neutron_lib.plugins import directory
|
from neutron_lib.plugins import directory
|
||||||
|
from neutron_lib.plugins.ml2 import api
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
|
@ -28,7 +29,6 @@ from neutron.db import segments_db
|
||||||
from neutron.objects import network as net_obj
|
from neutron.objects import network as net_obj
|
||||||
from neutron.objects import ports as port_obj
|
from neutron.objects import ports as port_obj
|
||||||
from neutron.plugins.common import utils as plugin_utils
|
from neutron.plugins.common import utils as plugin_utils
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
|
||||||
from neutron.services.externaldns import driver
|
from neutron.services.externaldns import driver
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
|
@ -15,12 +15,12 @@
|
||||||
|
|
||||||
from neutron_lib.api.definitions import port_security as psec
|
from neutron_lib.api.definitions import port_security as psec
|
||||||
from neutron_lib.api import validators
|
from neutron_lib.api import validators
|
||||||
|
from neutron_lib.plugins.ml2 import api
|
||||||
from neutron_lib.utils import net
|
from neutron_lib.utils import net
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from neutron.db import common_db_mixin
|
from neutron.db import common_db_mixin
|
||||||
from neutron.db import portsecurity_db_common as ps_db_common
|
from neutron.db import portsecurity_db_common as ps_db_common
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from neutron_lib.plugins.ml2 import api
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from neutron.core_extensions import base as base_core
|
from neutron.core_extensions import base as base_core
|
||||||
from neutron.core_extensions import qos as qos_core
|
from neutron.core_extensions import qos as qos_core
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ from neutron_lib.api.definitions import provider_net as provider
|
||||||
from neutron_lib.api import validators
|
from neutron_lib.api import validators
|
||||||
from neutron_lib import constants
|
from neutron_lib import constants
|
||||||
from neutron_lib import exceptions as exc
|
from neutron_lib import exceptions as exc
|
||||||
from neutron_lib.plugins.ml2 import api as ml2_api
|
from neutron_lib.plugins.ml2 import api
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
|
@ -32,7 +32,6 @@ from neutron.db import segments_db
|
||||||
from neutron.extensions import multiprovidernet as mpnet
|
from neutron.extensions import multiprovidernet as mpnet
|
||||||
from neutron.extensions import vlantransparent
|
from neutron.extensions import vlantransparent
|
||||||
from neutron.plugins.ml2.common import exceptions as ml2_exc
|
from neutron.plugins.ml2.common import exceptions as ml2_exc
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
|
||||||
from neutron.plugins.ml2 import models
|
from neutron.plugins.ml2 import models
|
||||||
|
|
||||||
LOG = log.getLogger(__name__)
|
LOG = log.getLogger(__name__)
|
||||||
|
@ -95,9 +94,9 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
||||||
for attr in provider.ATTRIBUTES)
|
for attr in provider.ATTRIBUTES)
|
||||||
|
|
||||||
if validators.is_attr_set(network_type):
|
if validators.is_attr_set(network_type):
|
||||||
segment = {ml2_api.NETWORK_TYPE: network_type,
|
segment = {api.NETWORK_TYPE: network_type,
|
||||||
ml2_api.PHYSICAL_NETWORK: physical_network,
|
api.PHYSICAL_NETWORK: physical_network,
|
||||||
ml2_api.SEGMENTATION_ID: segmentation_id}
|
api.SEGMENTATION_ID: segmentation_id}
|
||||||
self.validate_provider_segment(segment)
|
self.validate_provider_segment(segment)
|
||||||
return segment
|
return segment
|
||||||
|
|
||||||
|
@ -169,17 +168,17 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
||||||
network[attr] = None
|
network[attr] = None
|
||||||
elif len(segments) > 1:
|
elif len(segments) > 1:
|
||||||
network[mpnet.SEGMENTS] = [
|
network[mpnet.SEGMENTS] = [
|
||||||
{provider.NETWORK_TYPE: segment[ml2_api.NETWORK_TYPE],
|
{provider.NETWORK_TYPE: segment[api.NETWORK_TYPE],
|
||||||
provider.PHYSICAL_NETWORK: segment[ml2_api.PHYSICAL_NETWORK],
|
provider.PHYSICAL_NETWORK: segment[api.PHYSICAL_NETWORK],
|
||||||
provider.SEGMENTATION_ID: segment[ml2_api.SEGMENTATION_ID]}
|
provider.SEGMENTATION_ID: segment[api.SEGMENTATION_ID]}
|
||||||
for segment in segments]
|
for segment in segments]
|
||||||
else:
|
else:
|
||||||
segment = segments[0]
|
segment = segments[0]
|
||||||
network[provider.NETWORK_TYPE] = segment[ml2_api.NETWORK_TYPE]
|
network[provider.NETWORK_TYPE] = segment[api.NETWORK_TYPE]
|
||||||
network[provider.PHYSICAL_NETWORK] = segment[
|
network[provider.PHYSICAL_NETWORK] = segment[
|
||||||
ml2_api.PHYSICAL_NETWORK]
|
api.PHYSICAL_NETWORK]
|
||||||
network[provider.SEGMENTATION_ID] = segment[
|
network[provider.SEGMENTATION_ID] = segment[
|
||||||
ml2_api.SEGMENTATION_ID]
|
api.SEGMENTATION_ID]
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
for network_type, driver in self.drivers.items():
|
for network_type, driver in self.drivers.items():
|
||||||
|
@ -213,16 +212,16 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
||||||
def reserve_network_segment(self, context, segment_data):
|
def reserve_network_segment(self, context, segment_data):
|
||||||
"""Call type drivers to reserve a network segment."""
|
"""Call type drivers to reserve a network segment."""
|
||||||
# Validate the data of segment
|
# Validate the data of segment
|
||||||
if not validators.is_attr_set(segment_data[ml2_api.NETWORK_TYPE]):
|
if not validators.is_attr_set(segment_data[api.NETWORK_TYPE]):
|
||||||
msg = _("network_type required")
|
msg = _("network_type required")
|
||||||
raise exc.InvalidInput(error_message=msg)
|
raise exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
net_type = self._get_attribute(segment_data, ml2_api.NETWORK_TYPE)
|
net_type = self._get_attribute(segment_data, api.NETWORK_TYPE)
|
||||||
phys_net = self._get_attribute(segment_data, ml2_api.PHYSICAL_NETWORK)
|
phys_net = self._get_attribute(segment_data, api.PHYSICAL_NETWORK)
|
||||||
seg_id = self._get_attribute(segment_data, ml2_api.SEGMENTATION_ID)
|
seg_id = self._get_attribute(segment_data, api.SEGMENTATION_ID)
|
||||||
segment = {ml2_api.NETWORK_TYPE: net_type,
|
segment = {api.NETWORK_TYPE: net_type,
|
||||||
ml2_api.PHYSICAL_NETWORK: phys_net,
|
api.PHYSICAL_NETWORK: phys_net,
|
||||||
ml2_api.SEGMENTATION_ID: seg_id}
|
api.SEGMENTATION_ID: seg_id}
|
||||||
|
|
||||||
self.validate_provider_segment(segment)
|
self.validate_provider_segment(segment)
|
||||||
|
|
||||||
|
@ -231,7 +230,7 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
||||||
return self.reserve_provider_segment(context, segment)
|
return self.reserve_provider_segment(context, segment)
|
||||||
|
|
||||||
def is_partial_segment(self, segment):
|
def is_partial_segment(self, segment):
|
||||||
network_type = segment[ml2_api.NETWORK_TYPE]
|
network_type = segment[api.NETWORK_TYPE]
|
||||||
driver = self.drivers.get(network_type)
|
driver = self.drivers.get(network_type)
|
||||||
if driver:
|
if driver:
|
||||||
return driver.obj.is_partial_segment(segment)
|
return driver.obj.is_partial_segment(segment)
|
||||||
|
@ -240,7 +239,7 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
||||||
raise exc.InvalidInput(error_message=msg)
|
raise exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
def validate_provider_segment(self, segment):
|
def validate_provider_segment(self, segment):
|
||||||
network_type = segment[ml2_api.NETWORK_TYPE]
|
network_type = segment[api.NETWORK_TYPE]
|
||||||
driver = self.drivers.get(network_type)
|
driver = self.drivers.get(network_type)
|
||||||
if driver:
|
if driver:
|
||||||
driver.obj.validate_provider_segment(segment)
|
driver.obj.validate_provider_segment(segment)
|
||||||
|
@ -249,7 +248,7 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
||||||
raise exc.InvalidInput(error_message=msg)
|
raise exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
def reserve_provider_segment(self, context, segment):
|
def reserve_provider_segment(self, context, segment):
|
||||||
network_type = segment.get(ml2_api.NETWORK_TYPE)
|
network_type = segment.get(api.NETWORK_TYPE)
|
||||||
driver = self.drivers.get(network_type)
|
driver = self.drivers.get(network_type)
|
||||||
if isinstance(driver.obj, api.TypeDriver):
|
if isinstance(driver.obj, api.TypeDriver):
|
||||||
return driver.obj.reserve_provider_segment(context.session,
|
return driver.obj.reserve_provider_segment(context.session,
|
||||||
|
@ -287,7 +286,7 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
||||||
self.release_network_segment(context, segment)
|
self.release_network_segment(context, segment)
|
||||||
|
|
||||||
def release_network_segment(self, context, segment):
|
def release_network_segment(self, context, segment):
|
||||||
network_type = segment.get(ml2_api.NETWORK_TYPE)
|
network_type = segment.get(api.NETWORK_TYPE)
|
||||||
driver = self.drivers.get(network_type)
|
driver = self.drivers.get(network_type)
|
||||||
if driver:
|
if driver:
|
||||||
if isinstance(driver.obj, api.TypeDriver):
|
if isinstance(driver.obj, api.TypeDriver):
|
||||||
|
@ -301,13 +300,13 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
||||||
def allocate_dynamic_segment(self, context, network_id, segment):
|
def allocate_dynamic_segment(self, context, network_id, segment):
|
||||||
"""Allocate a dynamic segment using a partial or full segment dict."""
|
"""Allocate a dynamic segment using a partial or full segment dict."""
|
||||||
dynamic_segment = segments_db.get_dynamic_segment(
|
dynamic_segment = segments_db.get_dynamic_segment(
|
||||||
context, network_id, segment.get(ml2_api.PHYSICAL_NETWORK),
|
context, network_id, segment.get(api.PHYSICAL_NETWORK),
|
||||||
segment.get(ml2_api.SEGMENTATION_ID))
|
segment.get(api.SEGMENTATION_ID))
|
||||||
|
|
||||||
if dynamic_segment:
|
if dynamic_segment:
|
||||||
return dynamic_segment
|
return dynamic_segment
|
||||||
|
|
||||||
driver = self.drivers.get(segment.get(ml2_api.NETWORK_TYPE))
|
driver = self.drivers.get(segment.get(api.NETWORK_TYPE))
|
||||||
if isinstance(driver.obj, api.TypeDriver):
|
if isinstance(driver.obj, api.TypeDriver):
|
||||||
dynamic_segment = driver.obj.reserve_provider_segment(
|
dynamic_segment = driver.obj.reserve_provider_segment(
|
||||||
context.session, segment)
|
context.session, segment)
|
||||||
|
@ -322,7 +321,7 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
||||||
"""Delete a dynamic segment."""
|
"""Delete a dynamic segment."""
|
||||||
segment = segments_db.get_segment_by_id(context, segment_id)
|
segment = segments_db.get_segment_by_id(context, segment_id)
|
||||||
if segment:
|
if segment:
|
||||||
driver = self.drivers.get(segment.get(ml2_api.NETWORK_TYPE))
|
driver = self.drivers.get(segment.get(api.NETWORK_TYPE))
|
||||||
if driver:
|
if driver:
|
||||||
if isinstance(driver.obj, api.TypeDriver):
|
if isinstance(driver.obj, api.TypeDriver):
|
||||||
driver.obj.release_segment(context.session, segment)
|
driver.obj.release_segment(context.session, segment)
|
||||||
|
@ -852,7 +851,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager):
|
||||||
# level to one of the segments we are currently trying to
|
# level to one of the segments we are currently trying to
|
||||||
# bind. Note that it is OK for the same driver to bind at
|
# bind. Note that it is OK for the same driver to bind at
|
||||||
# multiple levels using different segments.
|
# multiple levels using different segments.
|
||||||
segment_ids_to_bind = {s[ml2_api.SEGMENTATION_ID]
|
segment_ids_to_bind = {s[api.SEGMENTATION_ID]
|
||||||
for s in segments_to_bind}
|
for s in segments_to_bind}
|
||||||
for level in binding_levels:
|
for level in binding_levels:
|
||||||
if (level.driver == driver and
|
if (level.driver == driver and
|
||||||
|
|
|
@ -14,9 +14,8 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from neutron_lib.api.definitions import portbindings
|
from neutron_lib.api.definitions import portbindings
|
||||||
from neutron_lib.plugins.ml2 import api as mech_api
|
from neutron_lib.plugins.ml2 import api
|
||||||
|
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
|
||||||
NETWORK_ID = "fake_network"
|
NETWORK_ID = "fake_network"
|
||||||
|
@ -80,8 +79,8 @@ class FakePortContext(api.PortContext):
|
||||||
def binding_levels(self):
|
def binding_levels(self):
|
||||||
if self._bound_segment:
|
if self._bound_segment:
|
||||||
return [{
|
return [{
|
||||||
mech_api.BOUND_DRIVER: 'fake_driver',
|
api.BOUND_DRIVER: 'fake_driver',
|
||||||
mech_api.BOUND_SEGMENT: self._expand_segment(
|
api.BOUND_SEGMENT: self._expand_segment(
|
||||||
self._bound_segment)
|
self._bound_segment)
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
@ -107,7 +106,7 @@ class FakePortContext(api.PortContext):
|
||||||
|
|
||||||
def _expand_segment(self, segment_id):
|
def _expand_segment(self, segment_id):
|
||||||
for segment in self._network_context.network_segments:
|
for segment in self._network_context.network_segments:
|
||||||
if segment[mech_api.ID] == self._bound_segment_id:
|
if segment[api.ID] == self._bound_segment_id:
|
||||||
return segment
|
return segment
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -176,7 +175,7 @@ class AgentMechanismBaseTestCase(base.BaseTestCase):
|
||||||
self.assertIsNone(context._bound_vif_details)
|
self.assertIsNone(context._bound_vif_details)
|
||||||
|
|
||||||
def _check_bound(self, context, segment):
|
def _check_bound(self, context, segment):
|
||||||
self.assertEqual(context._bound_segment_id, segment[mech_api.ID])
|
self.assertEqual(context._bound_segment_id, segment[api.ID])
|
||||||
self.assertEqual(context._bound_vif_type, self.VIF_TYPE)
|
self.assertEqual(context._bound_vif_type, self.VIF_TYPE)
|
||||||
vif_details = context._bound_vif_details
|
vif_details = context._bound_vif_details
|
||||||
self.assertIsNotNone(vif_details)
|
self.assertIsNotNone(vif_details)
|
||||||
|
@ -194,9 +193,9 @@ class AgentMechanismBaseTestCase(base.BaseTestCase):
|
||||||
|
|
||||||
|
|
||||||
class AgentMechanismGenericTestCase(AgentMechanismBaseTestCase):
|
class AgentMechanismGenericTestCase(AgentMechanismBaseTestCase):
|
||||||
UNKNOWN_TYPE_SEGMENTS = [{mech_api.ID: 'unknown_segment_id',
|
UNKNOWN_TYPE_SEGMENTS = [{api.ID: 'unknown_segment_id',
|
||||||
mech_api.NETWORK_TYPE: 'no_such_type',
|
api.NETWORK_TYPE: 'no_such_type',
|
||||||
mech_api.NETWORK_ID: 'fake_network_id'}]
|
api.NETWORK_ID: 'fake_network_id'}]
|
||||||
|
|
||||||
def test_unknown_type(self):
|
def test_unknown_type(self):
|
||||||
context = FakePortContext(self.AGENT_TYPE,
|
context = FakePortContext(self.AGENT_TYPE,
|
||||||
|
@ -208,12 +207,12 @@ class AgentMechanismGenericTestCase(AgentMechanismBaseTestCase):
|
||||||
|
|
||||||
|
|
||||||
class AgentMechanismLocalTestCase(AgentMechanismBaseTestCase):
|
class AgentMechanismLocalTestCase(AgentMechanismBaseTestCase):
|
||||||
LOCAL_SEGMENTS = [{mech_api.ID: 'unknown_segment_id',
|
LOCAL_SEGMENTS = [{api.ID: 'unknown_segment_id',
|
||||||
mech_api.NETWORK_TYPE: 'no_such_type',
|
api.NETWORK_TYPE: 'no_such_type',
|
||||||
mech_api.NETWORK_ID: 'fake_network_id'},
|
api.NETWORK_ID: 'fake_network_id'},
|
||||||
{mech_api.ID: 'local_segment_id',
|
{api.ID: 'local_segment_id',
|
||||||
mech_api.NETWORK_TYPE: 'local',
|
api.NETWORK_TYPE: 'local',
|
||||||
mech_api.NETWORK_ID: 'fake_network_id'}]
|
api.NETWORK_ID: 'fake_network_id'}]
|
||||||
|
|
||||||
def test_type_local(self):
|
def test_type_local(self):
|
||||||
context = FakePortContext(self.AGENT_TYPE,
|
context = FakePortContext(self.AGENT_TYPE,
|
||||||
|
@ -233,13 +232,13 @@ class AgentMechanismLocalTestCase(AgentMechanismBaseTestCase):
|
||||||
|
|
||||||
|
|
||||||
class AgentMechanismFlatTestCase(AgentMechanismBaseTestCase):
|
class AgentMechanismFlatTestCase(AgentMechanismBaseTestCase):
|
||||||
FLAT_SEGMENTS = [{mech_api.ID: 'unknown_segment_id',
|
FLAT_SEGMENTS = [{api.ID: 'unknown_segment_id',
|
||||||
mech_api.NETWORK_TYPE: 'no_such_type',
|
api.NETWORK_TYPE: 'no_such_type',
|
||||||
mech_api.NETWORK_ID: 'fake_network_id'},
|
api.NETWORK_ID: 'fake_network_id'},
|
||||||
{mech_api.ID: 'flat_segment_id',
|
{api.ID: 'flat_segment_id',
|
||||||
mech_api.NETWORK_TYPE: 'flat',
|
api.NETWORK_TYPE: 'flat',
|
||||||
mech_api.PHYSICAL_NETWORK: 'fake_physical_network',
|
api.PHYSICAL_NETWORK: 'fake_physical_network',
|
||||||
mech_api.NETWORK_ID: 'fake_network_id'}]
|
api.NETWORK_ID: 'fake_network_id'}]
|
||||||
|
|
||||||
def test_type_flat(self):
|
def test_type_flat(self):
|
||||||
context = FakePortContext(self.AGENT_TYPE,
|
context = FakePortContext(self.AGENT_TYPE,
|
||||||
|
@ -259,14 +258,14 @@ class AgentMechanismFlatTestCase(AgentMechanismBaseTestCase):
|
||||||
|
|
||||||
|
|
||||||
class AgentMechanismVlanTestCase(AgentMechanismBaseTestCase):
|
class AgentMechanismVlanTestCase(AgentMechanismBaseTestCase):
|
||||||
VLAN_SEGMENTS = [{mech_api.ID: 'unknown_segment_id',
|
VLAN_SEGMENTS = [{api.ID: 'unknown_segment_id',
|
||||||
mech_api.NETWORK_TYPE: 'no_such_type',
|
api.NETWORK_TYPE: 'no_such_type',
|
||||||
mech_api.NETWORK_ID: 'fake_network_id'},
|
api.NETWORK_ID: 'fake_network_id'},
|
||||||
{mech_api.ID: 'vlan_segment_id',
|
{api.ID: 'vlan_segment_id',
|
||||||
mech_api.NETWORK_TYPE: 'vlan',
|
api.NETWORK_TYPE: 'vlan',
|
||||||
mech_api.PHYSICAL_NETWORK: 'fake_physical_network',
|
api.PHYSICAL_NETWORK: 'fake_physical_network',
|
||||||
mech_api.SEGMENTATION_ID: 1234,
|
api.SEGMENTATION_ID: 1234,
|
||||||
mech_api.NETWORK_ID: 'fake_network_id'}]
|
api.NETWORK_ID: 'fake_network_id'}]
|
||||||
|
|
||||||
def test_type_vlan(self):
|
def test_type_vlan(self):
|
||||||
context = FakePortContext(self.AGENT_TYPE,
|
context = FakePortContext(self.AGENT_TYPE,
|
||||||
|
@ -286,13 +285,13 @@ class AgentMechanismVlanTestCase(AgentMechanismBaseTestCase):
|
||||||
|
|
||||||
|
|
||||||
class AgentMechanismGreTestCase(AgentMechanismBaseTestCase):
|
class AgentMechanismGreTestCase(AgentMechanismBaseTestCase):
|
||||||
GRE_SEGMENTS = [{mech_api.ID: 'unknown_segment_id',
|
GRE_SEGMENTS = [{api.ID: 'unknown_segment_id',
|
||||||
mech_api.NETWORK_TYPE: 'no_such_type',
|
api.NETWORK_TYPE: 'no_such_type',
|
||||||
mech_api.NETWORK_ID: 'fake_network_id'},
|
api.NETWORK_ID: 'fake_network_id'},
|
||||||
{mech_api.ID: 'gre_segment_id',
|
{api.ID: 'gre_segment_id',
|
||||||
mech_api.NETWORK_TYPE: 'gre',
|
api.NETWORK_TYPE: 'gre',
|
||||||
mech_api.SEGMENTATION_ID: 1234,
|
api.SEGMENTATION_ID: 1234,
|
||||||
mech_api.NETWORK_ID: 'fake_network_id'}]
|
api.NETWORK_ID: 'fake_network_id'}]
|
||||||
|
|
||||||
def test_type_gre(self):
|
def test_type_gre(self):
|
||||||
context = FakePortContext(self.AGENT_TYPE,
|
context = FakePortContext(self.AGENT_TYPE,
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
from neutron_lib.api import validators
|
from neutron_lib.api import validators
|
||||||
from neutron_lib import constants
|
from neutron_lib import constants
|
||||||
from neutron_lib.db import model_base
|
from neutron_lib.db import model_base
|
||||||
|
from neutron_lib.plugins.ml2 import api
|
||||||
import oslo_db.sqlalchemy.session
|
import oslo_db.sqlalchemy.session
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
@ -26,11 +27,10 @@ from sqlalchemy import orm
|
||||||
from neutron.api import extensions
|
from neutron.api import extensions
|
||||||
from neutron.db import models_v2
|
from neutron.db import models_v2
|
||||||
from neutron.objects import subnet as subnet_obj
|
from neutron.objects import subnet as subnet_obj
|
||||||
from neutron.plugins.ml2 import driver_api
|
|
||||||
from neutron.tests.unit.plugins.ml2 import extensions as test_extensions
|
from neutron.tests.unit.plugins.ml2 import extensions as test_extensions
|
||||||
|
|
||||||
|
|
||||||
class TestExtensionDriverBase(driver_api.ExtensionDriver):
|
class TestExtensionDriverBase(api.ExtensionDriver):
|
||||||
_supported_extension_aliases = 'fake_extension'
|
_supported_extension_aliases = 'fake_extension'
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
|
|
|
@ -15,12 +15,10 @@
|
||||||
|
|
||||||
from neutron_lib.api.definitions import portbindings
|
from neutron_lib.api.definitions import portbindings
|
||||||
from neutron_lib import constants as const
|
from neutron_lib import constants as const
|
||||||
from neutron_lib.plugins.ml2 import api as mech_api
|
from neutron_lib.plugins.ml2 import api
|
||||||
|
|
||||||
from neutron.plugins.ml2 import driver_api as api
|
|
||||||
|
|
||||||
|
|
||||||
class TestMechanismDriver(mech_api.MechanismDriver):
|
class TestMechanismDriver(api.MechanismDriver):
|
||||||
"""Test mechanism driver for testing mechanism driver api."""
|
"""Test mechanism driver for testing mechanism driver api."""
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
|
@ -94,7 +92,7 @@ class TestMechanismDriver(mech_api.MechanismDriver):
|
||||||
if context.vif_type in (portbindings.VIF_TYPE_UNBOUND,
|
if context.vif_type in (portbindings.VIF_TYPE_UNBOUND,
|
||||||
portbindings.VIF_TYPE_BINDING_FAILED):
|
portbindings.VIF_TYPE_BINDING_FAILED):
|
||||||
if (context.segments_to_bind and
|
if (context.segments_to_bind and
|
||||||
context.segments_to_bind[0][mech_api.NETWORK_TYPE] == 'vlan'):
|
context.segments_to_bind[0][api.NETWORK_TYPE] == 'vlan'):
|
||||||
# Partially bound.
|
# Partially bound.
|
||||||
self._check_bound(context.binding_levels,
|
self._check_bound(context.binding_levels,
|
||||||
context.top_bound_segment,
|
context.top_bound_segment,
|
||||||
|
@ -173,13 +171,13 @@ class TestMechanismDriver(mech_api.MechanismDriver):
|
||||||
top_level = levels[0]
|
top_level = levels[0]
|
||||||
assert(isinstance(top_level, dict))
|
assert(isinstance(top_level, dict))
|
||||||
assert(isinstance(top_segment, dict))
|
assert(isinstance(top_segment, dict))
|
||||||
assert(top_segment == top_level[mech_api.BOUND_SEGMENT])
|
assert(top_segment == top_level[api.BOUND_SEGMENT])
|
||||||
assert('test' == top_level[mech_api.BOUND_DRIVER])
|
assert('test' == top_level[api.BOUND_DRIVER])
|
||||||
bottom_level = levels[-1]
|
bottom_level = levels[-1]
|
||||||
assert(isinstance(bottom_level, dict))
|
assert(isinstance(bottom_level, dict))
|
||||||
assert(isinstance(bottom_segment, dict))
|
assert(isinstance(bottom_segment, dict))
|
||||||
assert(bottom_segment == bottom_level[mech_api.BOUND_SEGMENT])
|
assert(bottom_segment == bottom_level[api.BOUND_SEGMENT])
|
||||||
assert('test' == bottom_level[mech_api.BOUND_DRIVER])
|
assert('test' == bottom_level[api.BOUND_DRIVER])
|
||||||
|
|
||||||
def create_port_precommit(self, context):
|
def create_port_precommit(self, context):
|
||||||
self._check_port_context(context, False)
|
self._check_port_context(context, False)
|
||||||
|
@ -209,7 +207,7 @@ class TestMechanismDriver(mech_api.MechanismDriver):
|
||||||
|
|
||||||
host = context.host
|
host = context.host
|
||||||
segment = context.segments_to_bind[0]
|
segment = context.segments_to_bind[0]
|
||||||
segment_id = segment[mech_api.ID]
|
segment_id = segment[api.ID]
|
||||||
if host == "host-ovs-no_filter":
|
if host == "host-ovs-no_filter":
|
||||||
context.set_binding(segment_id, portbindings.VIF_TYPE_OVS,
|
context.set_binding(segment_id, portbindings.VIF_TYPE_OVS,
|
||||||
{portbindings.CAP_PORT_FILTER: False})
|
{portbindings.CAP_PORT_FILTER: False})
|
||||||
|
@ -224,11 +222,11 @@ class TestMechanismDriver(mech_api.MechanismDriver):
|
||||||
status=const.PORT_STATUS_ACTIVE)
|
status=const.PORT_STATUS_ACTIVE)
|
||||||
self.bound_ports.add((context.current['id'], host))
|
self.bound_ports.add((context.current['id'], host))
|
||||||
elif host == "host-hierarchical":
|
elif host == "host-hierarchical":
|
||||||
segment_type = segment[mech_api.NETWORK_TYPE]
|
segment_type = segment[api.NETWORK_TYPE]
|
||||||
if segment_type == 'local':
|
if segment_type == 'local':
|
||||||
next_segment = context.allocate_dynamic_segment(
|
next_segment = context.allocate_dynamic_segment(
|
||||||
{mech_api.NETWORK_TYPE: 'vlan',
|
{api.NETWORK_TYPE: 'vlan',
|
||||||
mech_api.PHYSICAL_NETWORK: 'physnet1'}
|
api.PHYSICAL_NETWORK: 'physnet1'}
|
||||||
)
|
)
|
||||||
context.continue_binding(segment_id, [next_segment])
|
context.continue_binding(segment_id, [next_segment])
|
||||||
elif segment_type == 'vlan':
|
elif segment_type == 'vlan':
|
||||||
|
|
Loading…
Reference in New Issue