From 8e29f67920121a6aea3d3e60b6ef84694d3cfc67 Mon Sep 17 00:00:00 2001 From: Boden R Date: Thu, 10 Jan 2019 08:25:26 -0700 Subject: [PATCH] use payloads for all SUBNETPOOL_ADDRESS_SCOPE events This patch switches the code over to the payload style of callbacks [1] for SUBNETPOOL_ADDRESS_SCOPE events. NeutronLibImpact [1] https://docs.openstack.org/neutron-lib/latest/contributor/callbacks.html Change-Id: I9048b2026571694eb39279e3c0fc1d598ee1fd05 --- neutron/db/db_base_plugin_v2.py | 10 +++++----- neutron/db/l3_db.py | 6 +++--- neutron/tests/unit/db/test_l3_db.py | 8 ++++---- neutron/tests/unit/extensions/test_address_scope.py | 12 +++++++----- neutron/tests/unit/extensions/test_l3.py | 3 ++- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 6c4f4f27a54..d20f94b2d63 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -1207,11 +1207,11 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, if address_scope_changed: # Notify about the update of subnetpool's address scope - kwargs = {'context': context, 'subnetpool_id': id} - registry.notify(resources.SUBNETPOOL_ADDRESS_SCOPE, - events.AFTER_UPDATE, - self.update_subnetpool, - **kwargs) + registry.publish(resources.SUBNETPOOL_ADDRESS_SCOPE, + events.AFTER_UPDATE, + self.update_subnetpool, + payload=events.DBEventPayload( + context, resource_id=id)) for key in ['min_prefixlen', 'max_prefixlen', 'default_prefixlen']: updated['key'] = str(updated[key]) diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index d372c72282d..c83078e8eea 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -1965,9 +1965,9 @@ class L3RpcNotifierMixin(object): @registry.receives(resources.SUBNETPOOL_ADDRESS_SCOPE, [events.AFTER_UPDATE]) def _notify_subnetpool_address_scope_update(resource, event, - trigger, **kwargs): - context = kwargs['context'] - subnetpool_id = kwargs['subnetpool_id'] + trigger, payload=None): + context = payload.context + subnetpool_id = payload.resource_id router_ids = l3_obj.RouterPort.get_router_ids_by_subnetpool( context, subnetpool_id) diff --git a/neutron/tests/unit/db/test_l3_db.py b/neutron/tests/unit/db/test_l3_db.py index 6bbf91b0798..fdf212ccb3a 100644 --- a/neutron/tests/unit/db/test_l3_db.py +++ b/neutron/tests/unit/db/test_l3_db.py @@ -241,10 +241,10 @@ class TestL3_NAT_dbonly_mixin(base.BaseTestCase): @mock.patch.object(directory, 'get_plugin') def test_subscribe_address_scope_of_subnetpool(self, gp): l3_db.L3RpcNotifierMixin() - registry.notify(resources.SUBNETPOOL_ADDRESS_SCOPE, - events.AFTER_UPDATE, mock.ANY, - context=mock.MagicMock(), - subnetpool_id='fake_id') + registry.publish(resources.SUBNETPOOL_ADDRESS_SCOPE, + events.AFTER_UPDATE, mock.ANY, + payload=events.DBEventPayload( + mock.MagicMock(), resource_id='fake_id')) self.assertTrue(gp.return_value.notify_routers_updated.called) def test__check_and_get_fip_assoc_with_extra_association_no_change(self): diff --git a/neutron/tests/unit/extensions/test_address_scope.py b/neutron/tests/unit/extensions/test_address_scope.py index 88858ca8db5..a853e1e74f1 100644 --- a/neutron/tests/unit/extensions/test_address_scope.py +++ b/neutron/tests/unit/extensions/test_address_scope.py @@ -388,7 +388,7 @@ class TestSubnetPoolsWithAddressScopes(AddressScopeTestCase): subnet = self.deserialize(self.fmt, req.get_response(self.api)) - with mock.patch.object(registry, 'notify') as notify: + with mock.patch.object(registry, 'publish') as publish: plugin = db_base_plugin_v2.NeutronDbPluginV2() plugin.is_address_scope_owned_by_tenant = mock.Mock( return_value=True) @@ -408,15 +408,17 @@ class TestSubnetPoolsWithAddressScopes(AddressScopeTestCase): if as_change: self.assertEqual(bar_as_id, updated_sp['address_scope_id']) - notify.assert_called_once_with( + publish.assert_called_once_with( resources.SUBNETPOOL_ADDRESS_SCOPE, events.AFTER_UPDATE, - plugin.update_subnetpool, context=ctx, - subnetpool_id=subnetpool_id) + plugin.update_subnetpool, payload=mock.ANY) + payload = publish.mock_calls[0][2]['payload'] + self.assertEqual(ctx, payload.context) + self.assertEqual(subnetpool_id, payload.resource_id) else: self.assertEqual(foo_as_id, updated_sp['address_scope_id']) - self.assertFalse(notify.called) + self.assertFalse(publish.called) def test_update_subnetpool_address_scope_notify(self): self._test_update_subnetpool_address_scope_notify() diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index a149e24f28f..3263e3ba662 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -3623,7 +3623,8 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): router['router']['id'], {'subnet_id': subnet['subnet']['id']}) l3_db.L3RpcNotifierMixin._notify_subnetpool_address_scope_update( mock.ANY, mock.ANY, mock.ANY, - context=admin_ctx, subnetpool_id=subnetpool_id) + payload=events.DBEventPayload( + admin_ctx, resource_id=subnetpool_id)) chk_method.assert_called_with(admin_ctx, [router['router']['id']]) def test_janitor_clears_orphaned_floatingip_port(self):