From a2c36d7e00ca0b3f9b2914b1039fbda50f3219d0 Mon Sep 17 00:00:00 2001 From: Boden R Date: Wed, 25 Oct 2017 14:18:21 -0600 Subject: [PATCH] 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 --- neutron/plugins/ml2/driver_api.py | 34 --------- neutron/plugins/ml2/driver_context.py | 11 ++- neutron/plugins/ml2/drivers/helpers.py | 2 +- neutron/plugins/ml2/drivers/type_local.py | 3 +- .../ml2/extensions/data_plane_status.py | 2 +- .../plugins/ml2/extensions/dns_integration.py | 2 +- .../plugins/ml2/extensions/port_security.py | 2 +- neutron/plugins/ml2/extensions/qos.py | 2 +- neutron/plugins/ml2/managers.py | 53 +++++++------- .../unit/plugins/ml2/_test_mech_agent.py | 73 +++++++++---------- .../unit/plugins/ml2/drivers/ext_test.py | 4 +- .../plugins/ml2/drivers/mechanism_test.py | 24 +++--- 12 files changed, 86 insertions(+), 126 deletions(-) delete mode 100644 neutron/plugins/ml2/driver_api.py diff --git a/neutron/plugins/ml2/driver_api.py b/neutron/plugins/ml2/driver_api.py deleted file mode 100644 index f03b72a83bb..00000000000 --- a/neutron/plugins/ml2/driver_api.py +++ /dev/null @@ -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 diff --git a/neutron/plugins/ml2/driver_context.py b/neutron/plugins/ml2/driver_context.py index 34df36d092c..68da335ad5e 100644 --- a/neutron/plugins/ml2/driver_context.py +++ b/neutron/plugins/ml2/driver_context.py @@ -15,13 +15,12 @@ from neutron_lib.api.definitions import portbindings 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_serialization import jsonutils import sqlalchemy from neutron.db import segments_db -from neutron.plugins.ml2 import driver_api as api LOG = log.getLogger(__name__) @@ -200,16 +199,16 @@ class PortContext(MechanismDriverContext, api.PortContext): def binding_levels(self): if self._binding_levels: return [{ - ml2_api.BOUND_DRIVER: level.driver, - ml2_api.BOUND_SEGMENT: self._expand_segment(level.segment_id) + api.BOUND_DRIVER: level.driver, + api.BOUND_SEGMENT: self._expand_segment(level.segment_id) } for level in self._binding_levels] @property def original_binding_levels(self): if self._original_binding_levels: return [{ - ml2_api.BOUND_DRIVER: level.driver, - ml2_api.BOUND_SEGMENT: self._expand_segment(level.segment_id) + api.BOUND_DRIVER: level.driver, + api.BOUND_SEGMENT: self._expand_segment(level.segment_id) } for level in self._original_binding_levels] @property diff --git a/neutron/plugins/ml2/drivers/helpers.py b/neutron/plugins/ml2/drivers/helpers.py index c3f5f1e586c..6561844bc08 100644 --- a/neutron/plugins/ml2/drivers/helpers.py +++ b/neutron/plugins/ml2/drivers/helpers.py @@ -16,6 +16,7 @@ import random from neutron_lib import context as neutron_ctx +from neutron_lib.plugins.ml2 import api from neutron_lib.utils import helpers from oslo_config import cfg 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.objects import base as base_obj from neutron.plugins.common import utils as p_utils -from neutron.plugins.ml2 import driver_api as api LOG = log.getLogger(__name__) diff --git a/neutron/plugins/ml2/drivers/type_local.py b/neutron/plugins/ml2/drivers/type_local.py index f152f1ed27c..61a005282cb 100644 --- a/neutron/plugins/ml2/drivers/type_local.py +++ b/neutron/plugins/ml2/drivers/type_local.py @@ -19,12 +19,11 @@ from neutron_lib.plugins.ml2 import api from oslo_log import log from neutron._i18n import _ -from neutron.plugins.ml2 import driver_api LOG = log.getLogger(__name__) -class LocalTypeDriver(driver_api.ML2TypeDriver): +class LocalTypeDriver(api.ML2TypeDriver): """Manage state for local networks with ML2. The LocalTypeDriver implements the 'local' network_type. Local diff --git a/neutron/plugins/ml2/extensions/data_plane_status.py b/neutron/plugins/ml2/extensions/data_plane_status.py index 850dafab615..40b63f27aaa 100644 --- a/neutron/plugins/ml2/extensions/data_plane_status.py +++ b/neutron/plugins/ml2/extensions/data_plane_status.py @@ -13,10 +13,10 @@ # under the License. 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 neutron.db import data_plane_status_db as dps_db -from neutron.plugins.ml2 import driver_api as api LOG = logging.getLogger(__name__) diff --git a/neutron/plugins/ml2/extensions/dns_integration.py b/neutron/plugins/ml2/extensions/dns_integration.py index f03804a977f..4c7ccedb0c8 100644 --- a/neutron/plugins/ml2/extensions/dns_integration.py +++ b/neutron/plugins/ml2/extensions/dns_integration.py @@ -21,6 +21,7 @@ from neutron_lib.callbacks import resources from neutron_lib import constants as lib_const from neutron_lib.exceptions import dns as dns_exc from neutron_lib.plugins import directory +from neutron_lib.plugins.ml2 import api from oslo_config import cfg 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 ports as port_obj from neutron.plugins.common import utils as plugin_utils -from neutron.plugins.ml2 import driver_api as api from neutron.services.externaldns import driver LOG = logging.getLogger(__name__) diff --git a/neutron/plugins/ml2/extensions/port_security.py b/neutron/plugins/ml2/extensions/port_security.py index 6b3f0da63a9..d43142ff8e0 100644 --- a/neutron/plugins/ml2/extensions/port_security.py +++ b/neutron/plugins/ml2/extensions/port_security.py @@ -15,12 +15,12 @@ from neutron_lib.api.definitions import port_security as psec from neutron_lib.api import validators +from neutron_lib.plugins.ml2 import api from neutron_lib.utils import net from oslo_log import log as logging from neutron.db import common_db_mixin from neutron.db import portsecurity_db_common as ps_db_common -from neutron.plugins.ml2 import driver_api as api LOG = logging.getLogger(__name__) diff --git a/neutron/plugins/ml2/extensions/qos.py b/neutron/plugins/ml2/extensions/qos.py index 46f11b0e9e3..9feac080203 100644 --- a/neutron/plugins/ml2/extensions/qos.py +++ b/neutron/plugins/ml2/extensions/qos.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.plugins.ml2 import api from oslo_log import log as logging from neutron.core_extensions import base as base_core from neutron.core_extensions import qos as qos_core -from neutron.plugins.ml2 import driver_api as api LOG = logging.getLogger(__name__) diff --git a/neutron/plugins/ml2/managers.py b/neutron/plugins/ml2/managers.py index fbe3f530d5b..b0727fd2e8b 100644 --- a/neutron/plugins/ml2/managers.py +++ b/neutron/plugins/ml2/managers.py @@ -19,7 +19,7 @@ from neutron_lib.api.definitions import provider_net as provider from neutron_lib.api import validators from neutron_lib import constants 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_log import log 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 vlantransparent 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 LOG = log.getLogger(__name__) @@ -95,9 +94,9 @@ class TypeManager(stevedore.named.NamedExtensionManager): for attr in provider.ATTRIBUTES) if validators.is_attr_set(network_type): - segment = {ml2_api.NETWORK_TYPE: network_type, - ml2_api.PHYSICAL_NETWORK: physical_network, - ml2_api.SEGMENTATION_ID: segmentation_id} + segment = {api.NETWORK_TYPE: network_type, + api.PHYSICAL_NETWORK: physical_network, + api.SEGMENTATION_ID: segmentation_id} self.validate_provider_segment(segment) return segment @@ -169,17 +168,17 @@ class TypeManager(stevedore.named.NamedExtensionManager): network[attr] = None elif len(segments) > 1: network[mpnet.SEGMENTS] = [ - {provider.NETWORK_TYPE: segment[ml2_api.NETWORK_TYPE], - provider.PHYSICAL_NETWORK: segment[ml2_api.PHYSICAL_NETWORK], - provider.SEGMENTATION_ID: segment[ml2_api.SEGMENTATION_ID]} + {provider.NETWORK_TYPE: segment[api.NETWORK_TYPE], + provider.PHYSICAL_NETWORK: segment[api.PHYSICAL_NETWORK], + provider.SEGMENTATION_ID: segment[api.SEGMENTATION_ID]} for segment in segments] else: 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[ - ml2_api.PHYSICAL_NETWORK] + api.PHYSICAL_NETWORK] network[provider.SEGMENTATION_ID] = segment[ - ml2_api.SEGMENTATION_ID] + api.SEGMENTATION_ID] def initialize(self): 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): """Call type drivers to reserve a network 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") raise exc.InvalidInput(error_message=msg) - net_type = self._get_attribute(segment_data, ml2_api.NETWORK_TYPE) - phys_net = self._get_attribute(segment_data, ml2_api.PHYSICAL_NETWORK) - seg_id = self._get_attribute(segment_data, ml2_api.SEGMENTATION_ID) - segment = {ml2_api.NETWORK_TYPE: net_type, - ml2_api.PHYSICAL_NETWORK: phys_net, - ml2_api.SEGMENTATION_ID: seg_id} + net_type = self._get_attribute(segment_data, api.NETWORK_TYPE) + phys_net = self._get_attribute(segment_data, api.PHYSICAL_NETWORK) + seg_id = self._get_attribute(segment_data, api.SEGMENTATION_ID) + segment = {api.NETWORK_TYPE: net_type, + api.PHYSICAL_NETWORK: phys_net, + api.SEGMENTATION_ID: seg_id} self.validate_provider_segment(segment) @@ -231,7 +230,7 @@ class TypeManager(stevedore.named.NamedExtensionManager): return self.reserve_provider_segment(context, 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) if driver: return driver.obj.is_partial_segment(segment) @@ -240,7 +239,7 @@ class TypeManager(stevedore.named.NamedExtensionManager): raise exc.InvalidInput(error_message=msg) 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) if driver: driver.obj.validate_provider_segment(segment) @@ -249,7 +248,7 @@ class TypeManager(stevedore.named.NamedExtensionManager): raise exc.InvalidInput(error_message=msg) 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) if isinstance(driver.obj, api.TypeDriver): return driver.obj.reserve_provider_segment(context.session, @@ -287,7 +286,7 @@ class TypeManager(stevedore.named.NamedExtensionManager): self.release_network_segment(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) if driver: if isinstance(driver.obj, api.TypeDriver): @@ -301,13 +300,13 @@ class TypeManager(stevedore.named.NamedExtensionManager): def allocate_dynamic_segment(self, context, network_id, segment): """Allocate a dynamic segment using a partial or full segment dict.""" dynamic_segment = segments_db.get_dynamic_segment( - context, network_id, segment.get(ml2_api.PHYSICAL_NETWORK), - segment.get(ml2_api.SEGMENTATION_ID)) + context, network_id, segment.get(api.PHYSICAL_NETWORK), + segment.get(api.SEGMENTATION_ID)) if 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): dynamic_segment = driver.obj.reserve_provider_segment( context.session, segment) @@ -322,7 +321,7 @@ class TypeManager(stevedore.named.NamedExtensionManager): """Delete a dynamic segment.""" segment = segments_db.get_segment_by_id(context, segment_id) if segment: - driver = self.drivers.get(segment.get(ml2_api.NETWORK_TYPE)) + driver = self.drivers.get(segment.get(api.NETWORK_TYPE)) if driver: if isinstance(driver.obj, api.TypeDriver): 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 # bind. Note that it is OK for the same driver to bind at # 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 level in binding_levels: if (level.driver == driver and diff --git a/neutron/tests/unit/plugins/ml2/_test_mech_agent.py b/neutron/tests/unit/plugins/ml2/_test_mech_agent.py index 011892365bc..4a8fadd59ce 100644 --- a/neutron/tests/unit/plugins/ml2/_test_mech_agent.py +++ b/neutron/tests/unit/plugins/ml2/_test_mech_agent.py @@ -14,9 +14,8 @@ # under the License. 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 NETWORK_ID = "fake_network" @@ -80,8 +79,8 @@ class FakePortContext(api.PortContext): def binding_levels(self): if self._bound_segment: return [{ - mech_api.BOUND_DRIVER: 'fake_driver', - mech_api.BOUND_SEGMENT: self._expand_segment( + api.BOUND_DRIVER: 'fake_driver', + api.BOUND_SEGMENT: self._expand_segment( self._bound_segment) }] @@ -107,7 +106,7 @@ class FakePortContext(api.PortContext): def _expand_segment(self, segment_id): 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 @property @@ -176,7 +175,7 @@ class AgentMechanismBaseTestCase(base.BaseTestCase): self.assertIsNone(context._bound_vif_details) 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) vif_details = context._bound_vif_details self.assertIsNotNone(vif_details) @@ -194,9 +193,9 @@ class AgentMechanismBaseTestCase(base.BaseTestCase): class AgentMechanismGenericTestCase(AgentMechanismBaseTestCase): - UNKNOWN_TYPE_SEGMENTS = [{mech_api.ID: 'unknown_segment_id', - mech_api.NETWORK_TYPE: 'no_such_type', - mech_api.NETWORK_ID: 'fake_network_id'}] + UNKNOWN_TYPE_SEGMENTS = [{api.ID: 'unknown_segment_id', + api.NETWORK_TYPE: 'no_such_type', + api.NETWORK_ID: 'fake_network_id'}] def test_unknown_type(self): context = FakePortContext(self.AGENT_TYPE, @@ -208,12 +207,12 @@ class AgentMechanismGenericTestCase(AgentMechanismBaseTestCase): class AgentMechanismLocalTestCase(AgentMechanismBaseTestCase): - LOCAL_SEGMENTS = [{mech_api.ID: 'unknown_segment_id', - mech_api.NETWORK_TYPE: 'no_such_type', - mech_api.NETWORK_ID: 'fake_network_id'}, - {mech_api.ID: 'local_segment_id', - mech_api.NETWORK_TYPE: 'local', - mech_api.NETWORK_ID: 'fake_network_id'}] + LOCAL_SEGMENTS = [{api.ID: 'unknown_segment_id', + api.NETWORK_TYPE: 'no_such_type', + api.NETWORK_ID: 'fake_network_id'}, + {api.ID: 'local_segment_id', + api.NETWORK_TYPE: 'local', + api.NETWORK_ID: 'fake_network_id'}] def test_type_local(self): context = FakePortContext(self.AGENT_TYPE, @@ -233,13 +232,13 @@ class AgentMechanismLocalTestCase(AgentMechanismBaseTestCase): class AgentMechanismFlatTestCase(AgentMechanismBaseTestCase): - FLAT_SEGMENTS = [{mech_api.ID: 'unknown_segment_id', - mech_api.NETWORK_TYPE: 'no_such_type', - mech_api.NETWORK_ID: 'fake_network_id'}, - {mech_api.ID: 'flat_segment_id', - mech_api.NETWORK_TYPE: 'flat', - mech_api.PHYSICAL_NETWORK: 'fake_physical_network', - mech_api.NETWORK_ID: 'fake_network_id'}] + FLAT_SEGMENTS = [{api.ID: 'unknown_segment_id', + api.NETWORK_TYPE: 'no_such_type', + api.NETWORK_ID: 'fake_network_id'}, + {api.ID: 'flat_segment_id', + api.NETWORK_TYPE: 'flat', + api.PHYSICAL_NETWORK: 'fake_physical_network', + api.NETWORK_ID: 'fake_network_id'}] def test_type_flat(self): context = FakePortContext(self.AGENT_TYPE, @@ -259,14 +258,14 @@ class AgentMechanismFlatTestCase(AgentMechanismBaseTestCase): class AgentMechanismVlanTestCase(AgentMechanismBaseTestCase): - VLAN_SEGMENTS = [{mech_api.ID: 'unknown_segment_id', - mech_api.NETWORK_TYPE: 'no_such_type', - mech_api.NETWORK_ID: 'fake_network_id'}, - {mech_api.ID: 'vlan_segment_id', - mech_api.NETWORK_TYPE: 'vlan', - mech_api.PHYSICAL_NETWORK: 'fake_physical_network', - mech_api.SEGMENTATION_ID: 1234, - mech_api.NETWORK_ID: 'fake_network_id'}] + VLAN_SEGMENTS = [{api.ID: 'unknown_segment_id', + api.NETWORK_TYPE: 'no_such_type', + api.NETWORK_ID: 'fake_network_id'}, + {api.ID: 'vlan_segment_id', + api.NETWORK_TYPE: 'vlan', + api.PHYSICAL_NETWORK: 'fake_physical_network', + api.SEGMENTATION_ID: 1234, + api.NETWORK_ID: 'fake_network_id'}] def test_type_vlan(self): context = FakePortContext(self.AGENT_TYPE, @@ -286,13 +285,13 @@ class AgentMechanismVlanTestCase(AgentMechanismBaseTestCase): class AgentMechanismGreTestCase(AgentMechanismBaseTestCase): - GRE_SEGMENTS = [{mech_api.ID: 'unknown_segment_id', - mech_api.NETWORK_TYPE: 'no_such_type', - mech_api.NETWORK_ID: 'fake_network_id'}, - {mech_api.ID: 'gre_segment_id', - mech_api.NETWORK_TYPE: 'gre', - mech_api.SEGMENTATION_ID: 1234, - mech_api.NETWORK_ID: 'fake_network_id'}] + GRE_SEGMENTS = [{api.ID: 'unknown_segment_id', + api.NETWORK_TYPE: 'no_such_type', + api.NETWORK_ID: 'fake_network_id'}, + {api.ID: 'gre_segment_id', + api.NETWORK_TYPE: 'gre', + api.SEGMENTATION_ID: 1234, + api.NETWORK_ID: 'fake_network_id'}] def test_type_gre(self): context = FakePortContext(self.AGENT_TYPE, diff --git a/neutron/tests/unit/plugins/ml2/drivers/ext_test.py b/neutron/tests/unit/plugins/ml2/drivers/ext_test.py index e001dee0e19..3f6c2fb1ff0 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/ext_test.py +++ b/neutron/tests/unit/plugins/ml2/drivers/ext_test.py @@ -19,6 +19,7 @@ from neutron_lib.api import validators from neutron_lib import constants from neutron_lib.db import model_base +from neutron_lib.plugins.ml2 import api import oslo_db.sqlalchemy.session import sqlalchemy as sa from sqlalchemy import orm @@ -26,11 +27,10 @@ from sqlalchemy import orm from neutron.api import extensions from neutron.db import models_v2 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 -class TestExtensionDriverBase(driver_api.ExtensionDriver): +class TestExtensionDriverBase(api.ExtensionDriver): _supported_extension_aliases = 'fake_extension' def initialize(self): diff --git a/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py b/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py index 6bb6762ac1d..eece0f68159 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mechanism_test.py @@ -15,12 +15,10 @@ from neutron_lib.api.definitions import portbindings from neutron_lib import constants as const -from neutron_lib.plugins.ml2 import api as mech_api - -from neutron.plugins.ml2 import driver_api as api +from neutron_lib.plugins.ml2 import api -class TestMechanismDriver(mech_api.MechanismDriver): +class TestMechanismDriver(api.MechanismDriver): """Test mechanism driver for testing mechanism driver api.""" def initialize(self): @@ -94,7 +92,7 @@ class TestMechanismDriver(mech_api.MechanismDriver): if context.vif_type in (portbindings.VIF_TYPE_UNBOUND, portbindings.VIF_TYPE_BINDING_FAILED): 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. self._check_bound(context.binding_levels, context.top_bound_segment, @@ -173,13 +171,13 @@ class TestMechanismDriver(mech_api.MechanismDriver): top_level = levels[0] assert(isinstance(top_level, dict)) assert(isinstance(top_segment, dict)) - assert(top_segment == top_level[mech_api.BOUND_SEGMENT]) - assert('test' == top_level[mech_api.BOUND_DRIVER]) + assert(top_segment == top_level[api.BOUND_SEGMENT]) + assert('test' == top_level[api.BOUND_DRIVER]) bottom_level = levels[-1] assert(isinstance(bottom_level, dict)) assert(isinstance(bottom_segment, dict)) - assert(bottom_segment == bottom_level[mech_api.BOUND_SEGMENT]) - assert('test' == bottom_level[mech_api.BOUND_DRIVER]) + assert(bottom_segment == bottom_level[api.BOUND_SEGMENT]) + assert('test' == bottom_level[api.BOUND_DRIVER]) def create_port_precommit(self, context): self._check_port_context(context, False) @@ -209,7 +207,7 @@ class TestMechanismDriver(mech_api.MechanismDriver): host = context.host segment = context.segments_to_bind[0] - segment_id = segment[mech_api.ID] + segment_id = segment[api.ID] if host == "host-ovs-no_filter": context.set_binding(segment_id, portbindings.VIF_TYPE_OVS, {portbindings.CAP_PORT_FILTER: False}) @@ -224,11 +222,11 @@ class TestMechanismDriver(mech_api.MechanismDriver): status=const.PORT_STATUS_ACTIVE) self.bound_ports.add((context.current['id'], host)) elif host == "host-hierarchical": - segment_type = segment[mech_api.NETWORK_TYPE] + segment_type = segment[api.NETWORK_TYPE] if segment_type == 'local': next_segment = context.allocate_dynamic_segment( - {mech_api.NETWORK_TYPE: 'vlan', - mech_api.PHYSICAL_NETWORK: 'physnet1'} + {api.NETWORK_TYPE: 'vlan', + api.PHYSICAL_NETWORK: 'physnet1'} ) context.continue_binding(segment_id, [next_segment]) elif segment_type == 'vlan':