Allow the service plugin to import the extension
I hit this circular import which made it so that I couldn't import the extension from db.py within the service plugin because the extension imports the plugin. This seems backwards to me. The extension is the interface and should pretty much stand alone shouldn't it? The service plugin is the implementation and should be free to import it at will. This patch fixes the circular import issue. Change-Id: I3b84496bf65578b02b43bbffb227db9bb9879288 Partially-implements: bp/routed-networks
This commit is contained in:
parent
1ce8ce9546
commit
c937b571c8
|
@ -22,7 +22,7 @@ from neutron.api import extensions
|
|||
from neutron.api.v2 import attributes
|
||||
from neutron.api.v2 import base
|
||||
from neutron.extensions import providernet
|
||||
from neutron.services.segments import plugin
|
||||
from neutron import manager
|
||||
|
||||
SEGMENT = 'segment'
|
||||
SEGMENTS = '%ss' % SEGMENT
|
||||
|
@ -103,7 +103,7 @@ class Segment(extensions.ExtensionDescriptor):
|
|||
controller = base.create_resource(
|
||||
SEGMENTS,
|
||||
SEGMENT,
|
||||
plugin.Plugin.get_instance(),
|
||||
manager.NeutronManager.get_service_plugins()[SEGMENTS],
|
||||
resource_attributes)
|
||||
return [extensions.ResourceExtension(SEGMENTS,
|
||||
controller,
|
||||
|
@ -210,3 +210,9 @@ class SegmentPluginBase(object):
|
|||
value. Each result returned by this function will have
|
||||
matched one of the values for each key in filters.
|
||||
"""
|
||||
|
||||
def get_plugin_description(self):
|
||||
return "Network Segments"
|
||||
|
||||
def get_plugin_type(self):
|
||||
return SEGMENTS
|
||||
|
|
|
@ -30,6 +30,7 @@ from neutron.api.v2 import attributes
|
|||
from neutron.db import common_db_mixin
|
||||
from neutron.db import model_base
|
||||
from neutron.db import segments_db as db
|
||||
from neutron.extensions import segment as extension
|
||||
from neutron.services.segments import exceptions
|
||||
|
||||
|
||||
|
@ -91,12 +92,11 @@ class SegmentDbMixin(common_db_mixin.CommonDbMixin):
|
|||
segment_id = segment.get('id') or uuidutils.generate_uuid()
|
||||
with context.session.begin(subtransactions=True):
|
||||
network_id = segment['network_id']
|
||||
# FIXME couldn't use constants because of a circular import problem
|
||||
physical_network = segment['physical_network']
|
||||
physical_network = segment[extension.PHYSICAL_NETWORK]
|
||||
if physical_network == constants.ATTR_NOT_SPECIFIED:
|
||||
physical_network = None
|
||||
network_type = segment['network_type']
|
||||
segmentation_id = segment['segmentation_id']
|
||||
network_type = segment[extension.NETWORK_TYPE]
|
||||
segmentation_id = segment[extension.SEGMENTATION_ID]
|
||||
if segmentation_id == constants.ATTR_NOT_SPECIFIED:
|
||||
segmentation_id = None
|
||||
args = {'id': segment_id,
|
||||
|
|
|
@ -15,10 +15,11 @@
|
|||
# under the License.
|
||||
|
||||
|
||||
from neutron.extensions import segment
|
||||
from neutron.services.segments import db
|
||||
|
||||
|
||||
class Plugin(db.SegmentDbMixin):
|
||||
class Plugin(db.SegmentDbMixin, segment.SegmentPluginBase):
|
||||
|
||||
_instance = None
|
||||
|
||||
|
@ -29,9 +30,3 @@ class Plugin(db.SegmentDbMixin):
|
|||
if cls._instance is None:
|
||||
cls._instance = cls()
|
||||
return cls._instance
|
||||
|
||||
def get_plugin_description(self):
|
||||
return "Network Segments"
|
||||
|
||||
def get_plugin_type(self):
|
||||
return "segments"
|
||||
|
|
|
@ -29,8 +29,9 @@ from neutron.services.segments import db
|
|||
from neutron.tests.common import helpers
|
||||
from neutron.tests.unit.db import test_db_base_plugin_v2
|
||||
|
||||
DB_PLUGIN_KLASS = ('neutron.tests.unit.extensions.test_segment.'
|
||||
'SegmentTestPlugin')
|
||||
SERVICE_PLUGIN_KLASS = 'neutron.services.segments.plugin.Plugin'
|
||||
TEST_PLUGIN_KLASS = (
|
||||
'neutron.tests.unit.extensions.test_segment.SegmentTestPlugin')
|
||||
|
||||
|
||||
class SegmentTestExtensionManager(object):
|
||||
|
@ -53,9 +54,10 @@ class SegmentTestExtensionManager(object):
|
|||
|
||||
class SegmentTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase):
|
||||
|
||||
def setUp(self, plugin=None, service_plugins=None):
|
||||
def setUp(self, plugin=None):
|
||||
if not plugin:
|
||||
plugin = DB_PLUGIN_KLASS
|
||||
plugin = TEST_PLUGIN_KLASS
|
||||
service_plugins = {'segments_plugin_name': SERVICE_PLUGIN_KLASS}
|
||||
ext_mgr = SegmentTestExtensionManager()
|
||||
super(SegmentTestCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr,
|
||||
service_plugins=service_plugins)
|
||||
|
@ -285,11 +287,7 @@ class HostSegmentMappingTestCase(SegmentTestCase):
|
|||
group='ml2')
|
||||
if not plugin:
|
||||
plugin = 'neutron.plugins.ml2.plugin.Ml2Plugin'
|
||||
segments_plugin = ('neutron.tests.unit.extensions.test_segment.'
|
||||
'SegmentTestPlugin')
|
||||
service_plugins = {'segments_plugin_name': segments_plugin}
|
||||
super(HostSegmentMappingTestCase, self).setUp(
|
||||
plugin=plugin, service_plugins=service_plugins)
|
||||
super(HostSegmentMappingTestCase, self).setUp(plugin=plugin)
|
||||
|
||||
def _get_segments_for_host(self, host):
|
||||
ctx = context.get_admin_context()
|
||||
|
|
Loading…
Reference in New Issue