diff --git a/networking_odl/common/constants.py b/networking_odl/common/constants.py index 2b422c3cb..b02400e07 100644 --- a/networking_odl/common/constants.py +++ b/networking_odl/common/constants.py @@ -13,8 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron_lib.plugins import constants - ODL_NETWORK = 'network' ODL_NETWORKS = 'networks' ODL_SUBNET = 'subnet' @@ -77,18 +75,6 @@ ODL_CREATE = 'create' ODL_UPDATE = 'update' ODL_DELETE = 'delete' -L2_RESOURCES = {ODL_SG: ODL_SGS, - ODL_SG_RULE: ODL_SG_RULES, - ODL_NETWORK: ODL_NETWORKS, - ODL_SUBNET: ODL_SUBNETS, - ODL_PORT: ODL_PORTS} -L3_RESOURCES = {ODL_ROUTER: ODL_ROUTERS, - ODL_FLOATINGIP: ODL_FLOATINGIPS} -# TODO(yamahata): add more resources -# as networking-odl supports more services like qos, ... -ALL_RESOURCES = {constants.CORE: L2_RESOURCES, - constants.L3: L3_RESOURCES} - # Constants for journal operation states PENDING = 'pending' PROCESSING = 'processing' diff --git a/networking_odl/journal/recovery.py b/networking_odl/journal/recovery.py index df8ce0745..b058a1a85 100644 --- a/networking_odl/journal/recovery.py +++ b/networking_odl/journal/recovery.py @@ -16,7 +16,6 @@ from neutron_lib import context as neutron_context from neutron_lib import exceptions as nexc -from neutron_lib.plugins import constants from neutron_lib.plugins import directory from oslo_log import log as logging @@ -24,6 +23,7 @@ from networking_odl._i18n import _ from networking_odl.common import client from networking_odl.common import constants as odl_const from networking_odl.db import db +from networking_odl.journal import full_sync from networking_odl.journal import journal _CLIENT = client.OpenDaylightRestClientGlobal() @@ -54,10 +54,10 @@ def journal_recovery(session): def _get_latest_resource(row): object_type = row.object_type - if object_type in odl_const.L2_RESOURCES: - plugin = directory.get_plugin() - elif object_type in odl_const.L3_RESOURCES: - plugin = directory.get_plugin(constants.L3) + for plugin_alias, resources in full_sync.ALL_RESOURCES.items(): + if object_type in resources: + plugin = directory.get_plugin(plugin_alias) + break else: raise UnsupportedResourceType( _("unsupported resource type: {}").format(object_type)) diff --git a/networking_odl/tests/unit/journal/test_recovery.py b/networking_odl/tests/unit/journal/test_recovery.py index 773169311..8bc86600a 100644 --- a/networking_odl/tests/unit/journal/test_recovery.py +++ b/networking_odl/tests/unit/journal/test_recovery.py @@ -19,11 +19,13 @@ import mock from neutron.db import api as neutron_db_api from neutron.tests.unit.testlib_api import SqlTestCaseLight from neutron_lib import exceptions as nexc +from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import directory from networking_odl.common import constants as odl_const from networking_odl.db import db from networking_odl.db import models +from networking_odl.journal import full_sync from networking_odl.journal import recovery from networking_odl.l3 import l3_odl_v2 from networking_odl.ml2 import mech_driver_v2 @@ -40,10 +42,15 @@ class RecoveryTestCase(SqlTestCaseLight): self._CLIENT = recovery._CLIENT.get_client() self.addCleanup(self._db_cleanup) + self.addCleanup(self.clean_registered_resources) def _db_cleanup(self): self.db_session.query(models.OpenDaylightJournal).delete() + @staticmethod + def clean_registered_resources(): + full_sync.ALL_RESOURCES = {} + def _mock_resource(self, plugin, resource_type): mock_resource = mock.MagicMock() get_func = getattr(plugin, 'get_{}'.format(resource_type)) @@ -54,6 +61,8 @@ class RecoveryTestCase(SqlTestCaseLight): return mock.MagicMock(object_type=resource_type) def _test__get_latest_resource(self, plugin, resource_type): + l2 = mech_driver_v2.L2_RESOURCES + full_sync.ALL_RESOURCES[plugin_constants.CORE] = l2 mock_resource = self._mock_resource(plugin, resource_type) mock_row = self._mock_row(resource_type) @@ -68,6 +77,7 @@ class RecoveryTestCase(SqlTestCaseLight): @mock.patch.object(directory, 'get_plugin') def test__get_latest_resource_l3(self, plugin_mock): + full_sync.ALL_RESOURCES[plugin_constants.L3] = l3_odl_v2.L3_RESOURCES for resource_type in l3_odl_v2.L3_RESOURCES: plugin = plugin_mock.return_value self._test__get_latest_resource(plugin, resource_type) @@ -81,6 +91,8 @@ class RecoveryTestCase(SqlTestCaseLight): @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 + full_sync.ALL_RESOURCES[plugin_constants.CORE] = l2 mock_row = self._mock_row(odl_const.ODL_NETWORK) self.assertRaises(