From 1825b0fdf9b383566c5f509108b88de39ca0bc31 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Mon, 17 Nov 2014 23:12:03 -0800 Subject: [PATCH] BSN: Add network to ext_gw_info sent to backend Include the full network info in the external gateway info sent to the backend controller. This alleviates a very expensive query across all tenants on the backend controller. Closes-Bug: #1393991 Change-Id: If3601ccbce21e683924a7056cdfe4e3c2d4d4a93 --- neutron/plugins/bigswitch/l3_router_plugin.py | 7 ++++++- neutron/tests/unit/bigswitch/test_router_db.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/bigswitch/l3_router_plugin.py b/neutron/plugins/bigswitch/l3_router_plugin.py index 2b2529e44..12805f564 100644 --- a/neutron/plugins/bigswitch/l3_router_plugin.py +++ b/neutron/plugins/bigswitch/l3_router_plugin.py @@ -95,7 +95,12 @@ class L3RestProxy(cplugin.NeutronRestProxyV2Base, new_router = super(L3RestProxy, self).update_router(context, router_id, router) router = self._map_state_and_status(new_router) - + # look up the network on this side to save an expensive query on + # the backend controller. + if router and router.get('external_gateway_info'): + router['external_gateway_info']['network'] = self.get_network( + context.elevated(), + router['external_gateway_info']['network_id']) # update router on network controller self.servers.rest_update_router(tenant_id, router, router_id) diff --git a/neutron/tests/unit/bigswitch/test_router_db.py b/neutron/tests/unit/bigswitch/test_router_db.py index bb2452a7e..8261982f0 100644 --- a/neutron/tests/unit/bigswitch/test_router_db.py +++ b/neutron/tests/unit/bigswitch/test_router_db.py @@ -135,6 +135,23 @@ class RouterDBTestCase(RouterDBTestBase, # remove extra port created self._delete('ports', p2['port']['id']) + def test_add_network_to_ext_gw_backend_body(self): + plugin_obj = manager.NeutronManager.get_plugin() + with contextlib.nested( + self.network(), self.router() + ) as (n1, r1): + with self.subnet(network=n1, cidr='10.10.10.10/24') as s1: + self._set_net_external(s1['subnet']['network_id']) + with mock.patch.object(plugin_obj.servers, + 'rest_update_router') as upmock: + self._add_external_gateway_to_router(r1['router']['id'], + n1['network']['id']) + router_body = upmock.mock_calls[0][1][1] + self.assertEqual( + plugin_obj.get_network(context.get_admin_context(), + n1['network']['id']), + router_body['external_gateway_info']['network']) + def test_multi_tenant_flip_alllocation(self): tenant1_id = _uuid() tenant2_id = _uuid() -- 2.45.2