Browse Source

use callback payloads for ROUTER_CONTROLLER events

This patch switches the code over to the payload style of callbacks [1]
for ROUTER_CONTROLLER events. In addition it updates the unit tests to
also use payloads for ROUTER_CONTROLLER based events.

[1] https://docs.openstack.org/neutron-lib/latest/contributor/callbacks.html

Depends-On: https://review.opendev.org/#/c/636394/
Change-Id: I2bbff0ea8a745fde2e3ddb7ce869cb394519cff3
tags/15.0.0.0b1
Boden R Lajos Katona 1 year ago
parent
commit
4414f47272
2 changed files with 20 additions and 10 deletions
  1. +9
    -9
      networking_odl/l3/l3_flavor.py
  2. +11
    -1
      networking_odl/tests/unit/l3/test_l3_flavor.py

+ 9
- 9
networking_odl/l3/l3_flavor.py View File

@@ -81,11 +81,11 @@ class ODLL3ServiceProvider(base.L3ServiceProvider):
@registry.receives(resources.ROUTER_CONTROLLER,
[events.PRECOMMIT_ADD_ASSOCIATION])
@log_helpers.log_method_call
def _router_add_association(self, resource, event, trigger, **kwargs):
context = kwargs['context']
router_dict = kwargs['router']
router_dict['gw_port_id'] = kwargs['router_db'].gw_port_id
router_id = kwargs['router_id']
def _router_add_association(self, resource, event, trigger, payload=None):
context = payload.context
router_dict = payload.request_body
router_dict['gw_port_id'] = payload.latest_state.gw_port_id
router_id = payload.resource_id
if not self._validate_l3_flavor(context, router_id):
return
journal.record(context, odl_const.ODL_ROUTER, router_dict['id'],
@@ -120,13 +120,13 @@ class ODLL3ServiceProvider(base.L3ServiceProvider):
@registry.receives(resources.ROUTER_CONTROLLER,
[events.PRECOMMIT_DELETE_ASSOCIATIONS])
@log_helpers.log_method_call
def _router_del_association(self, resource, event, trigger, **kwargs):
router_id = kwargs['router_db'].id
context = kwargs['context']
def _router_del_association(self, resource, event, trigger, payload=None):
router_id = payload.latest_state.id
context = payload.context
if not self._validate_l3_flavor(context, router_id):
return
# TODO(yamahata): process floating ip etc. or just raise error?
dependency_list = [kwargs['router_db'].gw_port_id]
dependency_list = [payload.latest_state.gw_port_id]
journal.record(context, odl_const.ODL_ROUTER, router_id,
odl_const.ODL_DELETE, dependency_list)



+ 11
- 1
networking_odl/tests/unit/l3/test_l3_flavor.py View File

@@ -15,6 +15,8 @@
import mock

from neutron.objects import router as l3_obj
from neutron_lib.callbacks import events
from neutron_lib.callbacks import resources
from oslo_config import fixture as config_fixture
from oslo_utils import uuidutils

@@ -88,7 +90,15 @@ class OpenDaylightL3FlavorTestCase(base_v2.OpenDaylightConfigBase):
def _test_router_operation(self, event, operation, router, ops=True):
method = getattr(self.flavor_driver,
'_router_%s_%s' % (operation, event))
method(odl_const.ODL_ROUTER, mock.ANY, mock.ANY, **router)
if event == 'precommit':
method(odl_const.ODL_ROUTER, mock.ANY, mock.ANY, **router)
else:
payload = events.DBEventPayload(
router.get('context'), states=(router.get('router_db'),),
request_body=router.get(resources.ROUTER),
resource_id=router.get(resources.ROUTER).get('id'))

method(odl_const.ODL_ROUTER, mock.ANY, mock.ANY, payload=payload)
row = db.get_oldest_pending_db_row_with_lock(self.db_context)
if ops:
if operation in ['del', odl_const.ODL_DELETE]:


Loading…
Cancel
Save