From 4979a23b8b2c0094ced98cf05eebb692d6609937 Mon Sep 17 00:00:00 2001 From: Wojciech Dec Date: Wed, 17 Aug 2016 13:14:23 +0200 Subject: Correcting networking-odl to mitaka/stable + app topology patch Change-Id: Iddcd8dda2d49fcdd8e0f37a1d052a6fa8a24b035 Signed-off-by: Wojciech Dec --- .../networking_odl/ml2/mech_driver_v2.py | 117 ++++++++++++--------- 1 file changed, 66 insertions(+), 51 deletions(-) (limited to 'networking-odl/networking_odl/ml2/mech_driver_v2.py') diff --git a/networking-odl/networking_odl/ml2/mech_driver_v2.py b/networking-odl/networking_odl/ml2/mech_driver_v2.py index dfc8df1..6fc199b 100644 --- a/networking-odl/networking_odl/ml2/mech_driver_v2.py +++ b/networking-odl/networking_odl/ml2/mech_driver_v2.py @@ -12,6 +12,7 @@ # 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 copy from oslo_config import cfg from oslo_log import log as logging @@ -21,11 +22,8 @@ from neutron.plugins.ml2 import driver_api as api from networking_odl.common import callback from networking_odl.common import config as odl_conf -from networking_odl.common import constants as odl_const -from networking_odl.journal import cleanup -from networking_odl.journal import full_sync +from networking_odl.db import db from networking_odl.journal import journal -from networking_odl.journal import maintenance from networking_odl.ml2 import port_binding LOG = logging.getLogger(__name__) @@ -44,66 +42,83 @@ class OpenDaylightMechanismDriver(api.MechanismDriver): self.sg_handler = callback.OdlSecurityGroupsHandler(self) self.journal = journal.OpendaylightJournalThread() self.port_binding_controller = port_binding.PortBindingManager.create() - self._start_maintenance_thread() - - def _start_maintenance_thread(self): - # start the maintenance thread and register all the maintenance - # operations : - # (1) JournalCleanup - Delete completed rows from journal - # (2) CleanupProcessing - Mark orphaned processing rows to pending - # (3) Full sync - Re-sync when detecting an ODL "cold reboot" - cleanup_obj = cleanup.JournalCleanup() - self._maintenance_thread = maintenance.MaintenanceThread() - self._maintenance_thread.register_operation( - cleanup_obj.delete_completed_rows) - self._maintenance_thread.register_operation( - cleanup_obj.cleanup_processing_rows) - self._maintenance_thread.register_operation(full_sync.full_sync) - self._maintenance_thread.start() - - @staticmethod - def _record_in_journal(context, object_type, operation, data=None): - if data is None: - data = context.current - journal.record(context._plugin_context.session, object_type, - context.current['id'], operation, data) def create_network_precommit(self, context): - OpenDaylightMechanismDriver._record_in_journal( - context, odl_const.ODL_NETWORK, odl_const.ODL_CREATE) + db.create_pending_row(context._plugin_context.session, 'network', + context.current['id'], 'create', context.current) def create_subnet_precommit(self, context): - OpenDaylightMechanismDriver._record_in_journal( - context, odl_const.ODL_SUBNET, odl_const.ODL_CREATE) + db.create_pending_row(context._plugin_context.session, 'subnet', + context.current['id'], 'create', context.current) def create_port_precommit(self, context): - OpenDaylightMechanismDriver._record_in_journal( - context, odl_const.ODL_PORT, odl_const.ODL_CREATE) + dbcontext = context._plugin_context + groups = [context._plugin.get_security_group(dbcontext, sg) + for sg in context.current['security_groups']] + new_context = copy.deepcopy(context.current) + new_context['security_groups'] = groups + # NOTE(yamahata): work around for port creation for router + # tenant_id=''(empty string) is passed when port is created + # by l3 plugin internally for router. + # On the other hand, ODL doesn't accept empty string for tenant_id. + # In that case, deduce tenant_id from network_id for now. + # Right fix: modify Neutron so that don't allow empty string + # for tenant_id even for port for internal use. + # TODO(yamahata): eliminate this work around when neutron side + # is fixed + # assert port['tenant_id'] != '' + if ('tenant_id' not in context.current or + context.current['tenant_id'] == ''): + tenant_id = context._network_context._network['tenant_id'] + new_context['tenant_id'] = tenant_id + db.create_pending_row(context._plugin_context.session, 'port', + context.current['id'], 'create', new_context) def update_network_precommit(self, context): - OpenDaylightMechanismDriver._record_in_journal( - context, odl_const.ODL_NETWORK, odl_const.ODL_UPDATE) + db.create_pending_row(context._plugin_context.session, 'network', + context.current['id'], 'update', context.current) def update_subnet_precommit(self, context): - OpenDaylightMechanismDriver._record_in_journal( - context, odl_const.ODL_SUBNET, odl_const.ODL_UPDATE) + db.create_pending_row(context._plugin_context.session, 'subnet', + context.current['id'], 'update', context.current) def update_port_precommit(self, context): - OpenDaylightMechanismDriver._record_in_journal( - context, odl_const.ODL_PORT, odl_const.ODL_UPDATE) + port = context._plugin.get_port(context._plugin_context, + context.current['id']) + dbcontext = context._plugin_context + new_context = copy.deepcopy(context.current) + groups = [context._plugin.get_security_group(dbcontext, sg) + for sg in port['security_groups']] + new_context['security_groups'] = groups + # Add the network_id in for validation + new_context['network_id'] = port['network_id'] + # NOTE(yamahata): work around for port creation for router + # tenant_id=''(empty string) is passed when port is created + # by l3 plugin internally for router. + # On the other hand, ODL doesn't accept empty string for tenant_id. + # In that case, deduce tenant_id from network_id for now. + # Right fix: modify Neutron so that don't allow empty string + # for tenant_id even for port for internal use. + # TODO(yamahata): eliminate this work around when neutron side + # is fixed + # assert port['tenant_id'] != '' + if ('tenant_id' not in context.current or + context.current['tenant_id'] == ''): + port['tenant_id'] = context._network_context._network['tenant_id'] + db.create_pending_row(context._plugin_context.session, 'port', + context.current['id'], 'update', new_context) def delete_network_precommit(self, context): - OpenDaylightMechanismDriver._record_in_journal( - context, odl_const.ODL_NETWORK, odl_const.ODL_DELETE, data=[]) + db.create_pending_row(context._plugin_context.session, 'network', + context.current['id'], 'delete', None) def delete_subnet_precommit(self, context): # Use the journal row's data field to store parent object # uuids. This information is required for validation checking # when deleting parent objects. new_context = [context.current['network_id']] - OpenDaylightMechanismDriver._record_in_journal( - context, odl_const.ODL_SUBNET, odl_const.ODL_DELETE, - data=new_context) + db.create_pending_row(context._plugin_context.session, 'subnet', + context.current['id'], 'delete', new_context) def delete_port_precommit(self, context): # Use the journal row's data field to store parent object @@ -112,19 +127,19 @@ class OpenDaylightMechanismDriver(api.MechanismDriver): new_context = [context.current['network_id']] for subnet in context.current['fixed_ips']: new_context.append(subnet['subnet_id']) - OpenDaylightMechanismDriver._record_in_journal( - context, odl_const.ODL_PORT, odl_const.ODL_DELETE, - data=new_context) + db.create_pending_row(context._plugin_context.session, 'port', + context.current['id'], 'delete', new_context) @journal.call_thread_on_end - def sync_from_callback(self, operation, res_type, res_id, resource_dict): - object_type = res_type.singular + def sync_from_callback(self, operation, res_type_uri, res_id, + resource_dict): + object_type = res_type_uri.replace('-', '_')[:-1] object_uuid = (resource_dict[object_type]['id'] if operation == 'create' else res_id) if resource_dict is not None: resource_dict = resource_dict[object_type] - journal.record(db_api.get_session(), object_type, object_uuid, - operation, resource_dict) + db.create_pending_row(db_api.get_session(), object_type, object_uuid, + operation, resource_dict) def _postcommit(self, context): self.journal.set_sync_event() -- cgit 1.2.3-korg