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 8 months 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):
81 81
     @registry.receives(resources.ROUTER_CONTROLLER,
82 82
                        [events.PRECOMMIT_ADD_ASSOCIATION])
83 83
     @log_helpers.log_method_call
84
-    def _router_add_association(self, resource, event, trigger, **kwargs):
85
-        context = kwargs['context']
86
-        router_dict = kwargs['router']
87
-        router_dict['gw_port_id'] = kwargs['router_db'].gw_port_id
88
-        router_id = kwargs['router_id']
84
+    def _router_add_association(self, resource, event, trigger, payload=None):
85
+        context = payload.context
86
+        router_dict = payload.request_body
87
+        router_dict['gw_port_id'] = payload.latest_state.gw_port_id
88
+        router_id = payload.resource_id
89 89
         if not self._validate_l3_flavor(context, router_id):
90 90
             return
91 91
         journal.record(context, odl_const.ODL_ROUTER, router_dict['id'],
@@ -120,13 +120,13 @@ class ODLL3ServiceProvider(base.L3ServiceProvider):
120 120
     @registry.receives(resources.ROUTER_CONTROLLER,
121 121
                        [events.PRECOMMIT_DELETE_ASSOCIATIONS])
122 122
     @log_helpers.log_method_call
123
-    def _router_del_association(self, resource, event, trigger, **kwargs):
124
-        router_id = kwargs['router_db'].id
125
-        context = kwargs['context']
123
+    def _router_del_association(self, resource, event, trigger, payload=None):
124
+        router_id = payload.latest_state.id
125
+        context = payload.context
126 126
         if not self._validate_l3_flavor(context, router_id):
127 127
             return
128 128
         # TODO(yamahata): process floating ip etc. or just raise error?
129
-        dependency_list = [kwargs['router_db'].gw_port_id]
129
+        dependency_list = [payload.latest_state.gw_port_id]
130 130
         journal.record(context, odl_const.ODL_ROUTER, router_id,
131 131
                        odl_const.ODL_DELETE, dependency_list)
132 132
 

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

@@ -15,6 +15,8 @@
15 15
 import mock
16 16
 
17 17
 from neutron.objects import router as l3_obj
18
+from neutron_lib.callbacks import events
19
+from neutron_lib.callbacks import resources
18 20
 from oslo_config import fixture as config_fixture
19 21
 from oslo_utils import uuidutils
20 22
 
@@ -88,7 +90,15 @@ class OpenDaylightL3FlavorTestCase(base_v2.OpenDaylightConfigBase):
88 90
     def _test_router_operation(self, event, operation, router, ops=True):
89 91
         method = getattr(self.flavor_driver,
90 92
                          '_router_%s_%s' % (operation, event))
91
-        method(odl_const.ODL_ROUTER, mock.ANY, mock.ANY, **router)
93
+        if event == 'precommit':
94
+            method(odl_const.ODL_ROUTER, mock.ANY, mock.ANY, **router)
95
+        else:
96
+            payload = events.DBEventPayload(
97
+                router.get('context'), states=(router.get('router_db'),),
98
+                request_body=router.get(resources.ROUTER),
99
+                resource_id=router.get(resources.ROUTER).get('id'))
100
+
101
+            method(odl_const.ODL_ROUTER, mock.ANY, mock.ANY, payload=payload)
92 102
         row = db.get_oldest_pending_db_row_with_lock(self.db_context)
93 103
         if ops:
94 104
             if operation in ['del', odl_const.ODL_DELETE]:

Loading…
Cancel
Save