Browse Source

Enabling ML2 for new full sync and recovery mechanism

This patch provide basic code for enabling full sync and recovery
for ML2. It keeps existing mechanism as it is, but implements
other protocols expected by new full sync mechanism.

This patch adds resources to driver classes, which will be used
by base driver to register for full sync and recovery.

Change-Id: I00b5a5f927ef3b2cce1bfa203a1402dd3cd1c61e
Partial-Bug: #1713697
tags/13.0.0.0b2
Rajiv Kumar 3 years ago
committed by Rajiv Kumar
parent
commit
6e9cb606ec
4 changed files with 28 additions and 13 deletions
  1. +12
    -10
      networking_odl/ml2/mech_driver_v2.py
  2. +2
    -0
      networking_odl/tests/unit/base_v2.py
  3. +5
    -3
      networking_odl/tests/unit/journal/test_recovery.py
  4. +9
    -0
      networking_odl/tests/unit/ml2/test_mechanism_odl_v2.py

+ 12
- 10
networking_odl/ml2/mech_driver_v2.py View File

@@ -28,6 +28,7 @@ from networking_odl.common import constants as odl_const
from networking_odl.common import odl_features
from networking_odl.common import postcommit
from networking_odl.dhcp import odl_dhcp_driver as dhcp_driver
from networking_odl.journal import base_driver
from networking_odl.journal import full_sync
from networking_odl.journal import journal
from networking_odl.journal import worker
@@ -38,22 +39,23 @@ from networking_odl.trunk import trunk_driver_v2 as trunk_driver

LOG = logging.getLogger(__name__)

L2_RESOURCES = {
odl_const.ODL_SG: odl_const.ODL_SGS,
odl_const.ODL_SG_RULE: odl_const.ODL_SG_RULES,
odl_const.ODL_NETWORK: odl_const.ODL_NETWORKS,
odl_const.ODL_SUBNET: odl_const.ODL_SUBNETS,
odl_const.ODL_PORT: odl_const.ODL_PORTS
}


@postcommit.add_postcommit('network', 'subnet', 'port')
class OpenDaylightMechanismDriver(api.MechanismDriver):
class OpenDaylightMechanismDriver(api.MechanismDriver,
base_driver.ResourceBaseDriver):
"""OpenDaylight Python Driver for Neutron.

This code is the backend implementation for the OpenDaylight ML2
MechanismDriver for OpenStack Neutron.
"""
RESOURCES = {
odl_const.ODL_SG: odl_const.ODL_SGS,
odl_const.ODL_SG_RULE: odl_const.ODL_SG_RULES,
odl_const.ODL_NETWORK: odl_const.ODL_NETWORKS,
odl_const.ODL_SUBNET: odl_const.ODL_SUBNETS,
odl_const.ODL_PORT: odl_const.ODL_PORTS
}
plugin_type = nlib_const.CORE

def initialize(self):
LOG.debug("Initializing OpenDaylight ML2 driver")
@@ -69,7 +71,7 @@ class OpenDaylightMechanismDriver(api.MechanismDriver):
if cfg.CONF.ml2_odl.enable_dhcp_service:
self.dhcp_driver = dhcp_driver.OdlDhcpDriver()

full_sync.register(nlib_const.CORE, L2_RESOURCES)
full_sync.register(nlib_const.CORE, self.RESOURCES)
odl_features.init()

def get_workers(self):


+ 2
- 0
networking_odl/tests/unit/base_v2.py View File

@@ -18,6 +18,7 @@ import mock
from neutron.tests.unit.plugins.ml2 import test_plugin

from networking_odl.common import client
from networking_odl.journal import base_driver
from networking_odl.journal import journal
from networking_odl.ml2 import mech_driver_v2
from networking_odl.tests import base
@@ -33,6 +34,7 @@ class OpenDaylightConfigBase(test_plugin.Ml2PluginV2TestCase,
self.useFixture(base.OpenDaylightFullSyncFixture())
super(OpenDaylightConfigBase, self).setUp()
self.thread = journal.OpenDaylightJournalThread()
self.addCleanup(base_driver.ALL_RESOURCES.clear)

def run_journal_processing(self):
"""Cause the journal to process the first pending entry"""


+ 5
- 3
networking_odl/tests/unit/journal/test_recovery.py View File

@@ -54,7 +54,7 @@ class RecoveryTestCase(test_base_db.ODLBaseDbTestCase):
return mock.MagicMock(object_type=resource_type)

def _test__get_latest_resource(self, plugin, resource_type):
l2 = mech_driver_v2.L2_RESOURCES
l2 = mech_driver_v2.OpenDaylightMechanismDriver.RESOURCES
full_sync.ALL_RESOURCES[plugin_constants.CORE] = l2
mock_resource = self._mock_resource(plugin, resource_type)
mock_row = self._mock_row(resource_type)
@@ -65,7 +65,9 @@ class RecoveryTestCase(test_base_db.ODLBaseDbTestCase):

@mock.patch.object(directory, 'get_plugin')
def test__get_latest_resource_l2(self, plugin_mock):
for resource_type in mech_driver_v2.L2_RESOURCES:
for resource_type in(
mech_driver_v2.OpenDaylightMechanismDriver.RESOURCES):

plugin = plugin_mock.return_value
self._test__get_latest_resource(plugin, resource_type)

@@ -85,7 +87,7 @@ class RecoveryTestCase(test_base_db.ODLBaseDbTestCase):
@mock.patch.object(directory, 'get_plugin')
def test__get_latest_resource_none(self, plugin_mock):
plugin_mock.return_value.get_network.side_effect = nexc.NotFound()
l2 = mech_driver_v2.L2_RESOURCES
l2 = mech_driver_v2.OpenDaylightMechanismDriver.RESOURCES
full_sync.ALL_RESOURCES[plugin_constants.CORE] = l2

mock_row = self._mock_row(odl_const.ODL_NETWORK)


+ 9
- 0
networking_odl/tests/unit/ml2/test_mechanism_odl_v2.py View File

@@ -38,6 +38,7 @@ from networking_odl.common import constants as odl_const
from networking_odl.common import filters
from networking_odl.common import utils
from networking_odl.db import db
from networking_odl.journal import base_driver
from networking_odl.journal import cleanup
from networking_odl.journal import journal
from networking_odl.ml2 import mech_driver_v2
@@ -176,6 +177,14 @@ class OpenDaylightMechanismDriverTestCase(base_v2.OpenDaylightConfigBase):
self.mech = mech_driver_v2.OpenDaylightMechanismDriver()
self.mech.initialize()

def test_registered_plugin_type(self):
self.assertEqual(self.mech.plugin_type, n_constants.CORE)

def test_registered_resources(self):
for resource in self.mech.RESOURCES:
self.assertIn(resource, base_driver.ALL_RESOURCES)
self.assertEqual(base_driver.ALL_RESOURCES[resource], self.mech)

def _get_mock_network_operation_context(self):
current = {'status': 'ACTIVE',
'subnets': [],


Loading…
Cancel
Save