Browse Source

Remove redundant exception

Remove UnsupportedResourceType exception defined in
networking_odl/journal/journal.py and use exception defined in
neworking_odl/common/exceptions.py.

Change-Id: Icaaae5f62f58be9f57ab71f1d4b9f946f0840867
Partial-Bug: #1713697
tags/12.0.0.0rc1
Rajiv Kumar 2 years ago
parent
commit
1196e9de28
2 changed files with 5 additions and 9 deletions
  1. +3
    -8
      networking_odl/journal/recovery.py
  2. +2
    -1
      networking_odl/tests/unit/journal/test_recovery.py

+ 3
- 8
networking_odl/journal/recovery.py View File

@@ -20,9 +20,9 @@ from oslo_log import log as logging

from neutron.db import api as db_api

from networking_odl._i18n import _
from networking_odl.common import client
from networking_odl.common import constants as odl_const
from networking_odl.common import exceptions
from networking_odl.db import db
from networking_odl.journal import full_sync
from networking_odl.journal import journal
@@ -32,10 +32,6 @@ _CLIENT = client.OpenDaylightRestClientGlobal()
LOG = logging.getLogger(__name__)


class UnsupportedResourceType(Exception):
pass


@db_api.retry_if_session_inactive()
def journal_recovery(context):
for row in db.get_all_db_rows_by_state(context.session,
@@ -45,7 +41,7 @@ def journal_recovery(context):
odl_resource = _CLIENT.get_client().get_resource(
row.object_type,
row.object_uuid)
except UnsupportedResourceType:
except exceptions.UnsupportedResourceType:
LOG.warning('Unsupported resource %s', row.object_type)
except Exception:
LOG.exception("Failure while recovering journal entry %s.", row)
@@ -65,8 +61,7 @@ def _get_latest_resource(context, row):
plugin = directory.get_plugin(plugin_alias)
break
else:
raise UnsupportedResourceType(
_("unsupported resource type: {}").format(object_type))
raise exceptions.UnsupportedResourceType(resource=object_type)

obj_getter = getattr(plugin, 'get_{}'.format(object_type))
return obj_getter(context, row.object_uuid)


+ 2
- 1
networking_odl/tests/unit/journal/test_recovery.py View File

@@ -21,6 +21,7 @@ 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.common import exceptions
from networking_odl.db import db
from networking_odl.journal import full_sync
from networking_odl.journal import recovery
@@ -77,7 +78,7 @@ class RecoveryTestCase(test_base_db.ODLBaseDbTestCase):
def test__get_latest_resource_unsupported(self):
mock_row = self._mock_row('aaa')
self.assertRaises(
recovery.UnsupportedResourceType, recovery._get_latest_resource,
exceptions.UnsupportedResourceType, recovery._get_latest_resource,
self.db_context.session, mock_row)

@mock.patch.object(directory, 'get_plugin')


Loading…
Cancel
Save