use payloads for ROUTER_GATEWAY events
This patch switches the code over to the payload style of callbacks [1] for PORT ROUTER_GATEWAY events for those that are not using them yet. The unit tests are also updated where needed to account for the payload style callbacks and publish() method. Finally the patch normalizes the passing of gateway IPs which are currently referred to as 'gw_ips' and 'gateway_ips' depending on the event; now all events use 'gateway_ips'. [1] https://docs.openstack.org/neutron-lib/latest/contributor/callbacks.html Change-Id: Ibc255de79443e908cc3615a8e1cb108757f80011
This commit is contained in:
parent
8de7e8e53b
commit
eedbcdd03b
@ -449,9 +449,9 @@ class NsxPluginBase(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
|
||||
|
||||
# Register the callback
|
||||
def _validate_network_has_subnet(resource, event, trigger, **kwargs):
|
||||
network_id = kwargs.get('network_id')
|
||||
subnets = kwargs.get('subnets')
|
||||
def _validate_network_has_subnet(resource, event, trigger, payload=None):
|
||||
network_id = payload.metadata.get('network_id')
|
||||
subnets = payload.metadata.get('subnets')
|
||||
if not subnets:
|
||||
msg = _('No subnet defined on network %s') % network_id
|
||||
raise n_exc.InvalidInput(error_message=msg)
|
||||
|
@ -3760,14 +3760,15 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
context, router.gw_port['id'], {'port': port_data})
|
||||
self._extension_manager.process_update_port(
|
||||
context, port_data, updated_port)
|
||||
registry.notify(resources.ROUTER_GATEWAY,
|
||||
registry.publish(resources.ROUTER_GATEWAY,
|
||||
events.AFTER_UPDATE,
|
||||
self._update_current_gw_port,
|
||||
context=context,
|
||||
router_id=router_id,
|
||||
router=router,
|
||||
network_id=router.gw_port.network_id,
|
||||
updated_port=updated_port)
|
||||
payload=events.DBEventPayload(
|
||||
context, resource_id=router_id,
|
||||
states=(router,), metadata={
|
||||
'network_id': router.gw_port.network_id,
|
||||
'updated_port': updated_port
|
||||
}))
|
||||
context.session.expire(router.gw_port)
|
||||
|
||||
def _update_router_gw_info(self, context, router_id, info,
|
||||
|
@ -300,11 +300,11 @@ class NSXBgpPlugin(service_base.ServicePluginBase, bgp_db.BgpDbMixin):
|
||||
driver.withdraw_subnet(context, speaker_id,
|
||||
router_id, subnet_id)
|
||||
|
||||
def router_gateway_callback(self, resource, event, trigger, **kwargs):
|
||||
context = kwargs.get('context') or n_context.get_admin_context()
|
||||
def router_gateway_callback(self, resource, event, trigger, payload=None):
|
||||
context = payload.context or n_context.get_admin_context()
|
||||
context = context.elevated()
|
||||
router_id = kwargs['router_id']
|
||||
network_id = kwargs['network_id']
|
||||
router_id = payload.resource_id
|
||||
network_id = payload.metadata['network_id']
|
||||
speakers = self._bgp_speakers_for_gateway_network(context, network_id)
|
||||
|
||||
for speaker in speakers:
|
||||
@ -316,14 +316,14 @@ class NSXBgpPlugin(service_base.ServicePluginBase, bgp_db.BgpDbMixin):
|
||||
if network_id not in speaker['networks']:
|
||||
continue
|
||||
if event == events.AFTER_DELETE:
|
||||
gw_ips = kwargs['gateway_ips']
|
||||
gw_ips = payload.metadata['gateway_ips']
|
||||
driver.disable_bgp_on_router(context,
|
||||
speaker,
|
||||
router_id,
|
||||
gw_ips[0])
|
||||
if event == events.AFTER_UPDATE:
|
||||
updated_port = kwargs['updated_port']
|
||||
router = kwargs['router']
|
||||
updated_port = payload.metadata['updated_port']
|
||||
router = payload.latest_state
|
||||
driver.process_router_gw_port_update(
|
||||
context, speaker, router, updated_port)
|
||||
|
||||
|
@ -339,9 +339,9 @@ class NSXv3IPsecVpnDriver(common_driver.NSXcommonIPsecVpnDriver):
|
||||
self.l3_plugin.delete_port(context, port['id'],
|
||||
force_delete_vpn=True)
|
||||
|
||||
def _delete_local_endpoint(self, resource, event, trigger, **kwargs):
|
||||
def _delete_local_endpoint(self, resource, event, trigger, payload=None):
|
||||
"""Upon router deletion / gw removal delete the matching endpoint"""
|
||||
router_id = kwargs.get('router_id')
|
||||
router_id = payload.resource_id
|
||||
ctx = n_context.get_admin_context()
|
||||
self._delete_local_endpoint_by_router(ctx, router_id)
|
||||
|
||||
|
@ -1965,15 +1965,14 @@ class NsxPTestL3NatTestCase(NsxPTestL3NatTest,
|
||||
with self.router() as r,\
|
||||
self._create_l3_ext_network() as ext_net,\
|
||||
self.subnet(network=ext_net, enable_dhcp=False):
|
||||
with mock.patch.object(registry, 'notify') as notify:
|
||||
with mock.patch.object(registry, 'publish') as publish:
|
||||
self._add_external_gateway_to_router(
|
||||
r['router']['id'], ext_net['network']['id'])
|
||||
expected = [mock.call(
|
||||
resources.ROUTER_GATEWAY,
|
||||
events.AFTER_CREATE, mock.ANY,
|
||||
context=mock.ANY, gw_ips=mock.ANY,
|
||||
network_id=mock.ANY, router_id=mock.ANY)]
|
||||
notify.assert_has_calls(expected)
|
||||
payload=mock.ANY)]
|
||||
publish.assert_has_calls(expected)
|
||||
|
||||
def test_router_add_gateway_no_subnet_forbidden(self):
|
||||
with self.router() as r:
|
||||
|
@ -2779,15 +2779,14 @@ class L3NatTestCaseBase(test_l3_plugin.L3NatTestCaseMixin):
|
||||
with self.router() as r,\
|
||||
self._create_l3_ext_network() as ext_net,\
|
||||
self.subnet(network=ext_net):
|
||||
with mock.patch.object(registry, 'notify') as notify:
|
||||
with mock.patch.object(registry, 'publish') as publish:
|
||||
self._add_external_gateway_to_router(
|
||||
r['router']['id'], ext_net['network']['id'])
|
||||
expected = [mock.call(
|
||||
resources.ROUTER_GATEWAY,
|
||||
events.AFTER_CREATE, mock.ANY,
|
||||
context=mock.ANY, gw_ips=mock.ANY,
|
||||
network_id=mock.ANY, router_id=mock.ANY)]
|
||||
notify.assert_has_calls(expected)
|
||||
payload=mock.ANY)]
|
||||
publish.assert_has_calls(expected)
|
||||
|
||||
def test_router_delete_ipv6_slaac_subnet_inuse_returns_409(self):
|
||||
self.skipTest('No DHCP v6 Support yet')
|
||||
|
@ -2288,15 +2288,14 @@ class TestL3NatTestCase(L3NatTest,
|
||||
with self.router() as r,\
|
||||
self._create_l3_ext_network() as ext_net,\
|
||||
self.subnet(network=ext_net):
|
||||
with mock.patch.object(registry, 'notify') as notify:
|
||||
with mock.patch.object(registry, 'publish') as publish:
|
||||
self._add_external_gateway_to_router(
|
||||
r['router']['id'], ext_net['network']['id'])
|
||||
expected = [mock.call(
|
||||
resources.ROUTER_GATEWAY,
|
||||
events.AFTER_CREATE, mock.ANY,
|
||||
context=mock.ANY, gw_ips=mock.ANY,
|
||||
network_id=mock.ANY, router_id=mock.ANY)]
|
||||
notify.assert_has_calls(expected)
|
||||
payload=mock.ANY)]
|
||||
publish.assert_has_calls(expected)
|
||||
|
||||
def test_create_l3_ext_network_with_default_tier0(self):
|
||||
self._test_create_l3_ext_network()
|
||||
|
Loading…
Reference in New Issue
Block a user