From 197c57cf23728614cf37c16ed3f6080e19fdacb3 Mon Sep 17 00:00:00 2001 From: LIU Yulong Date: Tue, 17 Sep 2019 00:58:08 +0800 Subject: [PATCH] Stop verifying unique external_net_id This cherry-pick is modified to omit the RPC modification of the original patch. Instead it only drops the code that would generate an exception if there are two different external networks. Tests are amended accordingly. Original patch description: Remove get_external_network_id for router L3 agent supports multiple external networks from a long time ago, so remove this RPC call since it is not used. According to codesearch of [1] and [2], we just remove neutron built-in L3 agent RPC. For neutron server side or RPC callback classes, the function is still remained. [1] http://codesearch.openstack.org/?q=get_external_network_id [2] http://codesearch.openstack.org/?q=L3RpcCallback Conflicts: neutron/agent/l3/agent.py Change-Id: I764423e175d6e82729a647e415a9f267f495916f Closes-Bug: #1844168 (cherry picked from commit f51e5ce9241c9bbd0e2ed786f41dc11ed0146b88) --- neutron/agent/l3/agent.py | 29 ------- .../functional/agent/l3/test_dvr_router.py | 13 ---- .../functional/agent/l3/test_legacy_router.py | 2 - neutron/tests/unit/agent/l3/test_agent.py | 77 +------------------ 4 files changed, 3 insertions(+), 118 deletions(-) diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 56c7bab66ab..28d006c9c4a 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -352,26 +352,6 @@ class L3NATAgent(ha.AgentMixin, LOG.error(msg, self.conf.ipv6_gateway) raise SystemExit(1) - def _fetch_external_net_id(self, force=False): - """Find UUID of single external network for this agent.""" - if self.conf.gateway_external_network_id: - return self.conf.gateway_external_network_id - - if not force and self.target_ex_net_id: - return self.target_ex_net_id - - try: - self.target_ex_net_id = self.plugin_rpc.get_external_network_id( - self.context) - return self.target_ex_net_id - except oslo_messaging.RemoteError as e: - with excutils.save_and_reraise_exception() as ctx: - if e.exc_type == 'TooManyExternalNetworks': - # At this point we know gateway_external_network_id is not - # defined. Since there are more than one external network, - # we will handle all of them - ctx.reraise = False - def _create_router(self, router_id, router): args = [] kwargs = { @@ -554,15 +534,6 @@ class L3NATAgent(ha.AgentMixin, if not ex_net_id and not self.conf.handle_internal_only_routers: raise l3_exc.RouterNotCompatibleWithAgent(router_id=router['id']) - # If target_ex_net_id and ex_net_id are set they must be equal - target_ex_net_id = self._fetch_external_net_id() - if (target_ex_net_id and ex_net_id and ex_net_id != target_ex_net_id): - # Double check that our single external_net_id has not changed - # by forcing a check by RPC. - if ex_net_id != self._fetch_external_net_id(force=True): - raise l3_exc.RouterNotCompatibleWithAgent( - router_id=router['id']) - if router['id'] not in self.router_info: self._process_added_router(router) else: diff --git a/neutron/tests/functional/agent/l3/test_dvr_router.py b/neutron/tests/functional/agent/l3/test_dvr_router.py index 64eeb1a2c16..1d51f76f634 100644 --- a/neutron/tests/functional/agent/l3/test_dvr_router.py +++ b/neutron/tests/functional/agent/l3/test_dvr_router.py @@ -83,8 +83,6 @@ class TestDvrRouter(framework.L3AgentTestFramework): self, agent_mode, **dvr_router_kwargs): self.agent.conf.agent_mode = agent_mode router_info = self.generate_dvr_router_info(**dvr_router_kwargs) - self.mock_plugin_api.get_external_network_id.return_value = ( - router_info['_floatingips'][0]['floating_network_id']) router = self.manage_router(self.agent, router_info) fip_ns = router.fip_ns.get_name() return router, fip_ns @@ -129,8 +127,6 @@ class TestDvrRouter(framework.L3AgentTestFramework): # Create the router with external net router_info = self.generate_dvr_router_info() external_gw_port = router_info['gw_port'] - ext_net_id = router_info['_floatingips'][0]['floating_network_id'] - self.mock_plugin_api.get_external_network_id.return_value = ext_net_id router = self.manage_router(self.agent, router_info) fg_port = router.fip_ns.agent_gateway_port fg_port_name = router.fip_ns.get_ext_device_name(fg_port['id']) @@ -185,8 +181,6 @@ class TestDvrRouter(framework.L3AgentTestFramework): # Create the router with external net router_info = self.generate_dvr_router_info() external_gw_port = router_info['gw_port'] - ext_net_id = router_info['_floatingips'][0]['floating_network_id'] - self.mock_plugin_api.get_external_network_id.return_value = ext_net_id router = self.manage_router(self.agent, router_info) fg_port = router.fip_ns.agent_gateway_port fg_port_name = router.fip_ns.get_ext_device_name(fg_port['id']) @@ -240,7 +234,6 @@ class TestDvrRouter(framework.L3AgentTestFramework): router_info = self.generate_dvr_router_info() external_gw_port = router_info['gw_port'] ext_net_id = router_info['_floatingips'][0]['floating_network_id'] - self.mock_plugin_api.get_external_network_id.return_value = ext_net_id # Create the fip namespace up front fip_ns = dvr_fip_ns.FipNamespace(ext_net_id, @@ -289,7 +282,6 @@ class TestDvrRouter(framework.L3AgentTestFramework): router_info = self.generate_dvr_router_info(**dvr_router_kwargs) external_gw_port = router_info['gw_port'] ext_net_id = router_info['_floatingips'][0]['floating_network_id'] - self.mock_plugin_api.get_external_network_id.return_value(ext_net_id) # Create the fip namespace up front stale_fip_ns = dvr_fip_ns.FipNamespace(ext_net_id, @@ -449,11 +441,6 @@ class TestDvrRouter(framework.L3AgentTestFramework): self.mock_plugin_api.get_agent_gateway_port.return_value = ( fip_agent_gw_port) - # We also need to mock the get_external_network_id method to - # get the correct fip namespace. - self.mock_plugin_api.get_external_network_id.return_value = ( - router_info['_floatingips'][0]['floating_network_id']) - # With all that set we can now ask the l3_agent to # manage the router (create it, create namespaces, # attach interfaces, etc...) diff --git a/neutron/tests/functional/agent/l3/test_legacy_router.py b/neutron/tests/functional/agent/l3/test_legacy_router.py index d1af2c127e7..0eae8d4f450 100644 --- a/neutron/tests/functional/agent/l3/test_legacy_router.py +++ b/neutron/tests/functional/agent/l3/test_legacy_router.py @@ -212,8 +212,6 @@ class L3AgentTestCase(framework.L3AgentTestFramework): # Mock the plugin RPC API so a known external network id is returned # when the router updates are processed by the agent external_network_id = framework._uuid() - self.mock_plugin_api.get_external_network_id.return_value = ( - external_network_id) # Plug external_gateway_info in the routers that are not going to be # deleted by the agent when it processes the updates. Otherwise, diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 2fb1305dbc1..b6058800035 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -26,7 +26,6 @@ import netaddr from neutron_lib.agent import constants as agent_consts from neutron_lib.api.definitions import portbindings from neutron_lib import constants as lib_constants -from neutron_lib.exceptions import l3 as l3_exc from oslo_config import cfg from oslo_log import log import oslo_messaging @@ -2760,27 +2759,6 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.assertEqual(l3_agent.PRIORITY_RELATED_ROUTER, events_queue[0].priority) - def test_process_routers_if_compatible_router_not_compatible(self): - agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) - router = {'id': _uuid()} - agent.router_info = [router['id']] - self.plugin_api.get_routers.return_value = [router] - update = resource_processing_queue.ResourceUpdate( - router['id'], l3_agent.PRIORITY_RPC, resource=router) - - with mock.patch.object( - agent, "_process_router_if_compatible", - side_effect=l3_exc.RouterNotCompatibleWithAgent( - router_id=router['id']) - ) as process_router_if_compatible, mock.patch.object( - agent, "_safe_router_removed" - ) as safe_router_removed: - self.assertTrue( - agent._process_routers_if_compatible([router], update)) - process_router_if_compatible.assert_called_once_with( - router) - safe_router_removed.assert_called_once_with(router['id']) - def test_process_dvr_routers_ha_on_update_when_router_unbound(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent.conf.agent_mode = 'dvr_snat' @@ -2874,50 +2852,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): self.assertIn(router['id'], agent.router_info) self.assertFalse(chsfr.called) - def test_process_router_if_compatible_with_no_ext_net_in_conf(self): - agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) - self.plugin_api.get_external_network_id.return_value = 'aaa' - - router = {'id': _uuid(), - 'routes': [], - 'admin_state_up': True, - 'external_gateway_info': {'network_id': 'aaa'}} - - agent._process_router_if_compatible(router) - self.assertIn(router['id'], agent.router_info) - self.plugin_api.get_external_network_id.assert_called_with( - agent.context) - - def test_process_router_if_compatible_with_cached_ext_net(self): - agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) - self.plugin_api.get_external_network_id.return_value = 'aaa' - agent.target_ex_net_id = 'aaa' - - router = {'id': _uuid(), - 'routes': [], - 'admin_state_up': True, - 'external_gateway_info': {'network_id': 'aaa'}} - - agent._process_router_if_compatible(router) - self.assertIn(router['id'], agent.router_info) - self.assertFalse(self.plugin_api.get_external_network_id.called) - - def test_process_router_if_compatible_with_stale_cached_ext_net(self): - agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) - self.plugin_api.get_external_network_id.return_value = 'aaa' - agent.target_ex_net_id = 'bbb' - - router = {'id': _uuid(), - 'routes': [], - 'admin_state_up': True, - 'external_gateway_info': {'network_id': 'aaa'}} - - agent._process_router_if_compatible(router) - self.assertIn(router['id'], agent.router_info) - self.plugin_api.get_external_network_id.assert_called_with( - agent.context) - - def test_process_router_if_compatible_w_no_ext_net_and_2_net_plugin(self): + def test_process_router_if_compatible(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) router = {'id': _uuid(), @@ -2925,10 +2860,6 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): 'admin_state_up': True, 'external_gateway_info': {'network_id': 'aaa'}} - agent.router_info = {} - e = oslo_messaging.RemoteError() - e.exc_type = 'TooManyExternalNetworks' - agent.plugin_rpc.get_external_network_id.side_effect = e agent._process_router_if_compatible(router) self.assertIn(router['id'], agent.router_info) @@ -2943,10 +2874,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): agent.router_info = {} self.conf.set_override('gateway_external_network_id', 'aaa') - self.assertRaises(l3_exc.RouterNotCompatibleWithAgent, - agent._process_router_if_compatible, - router) - self.assertNotIn(router['id'], agent.router_info) + agent._process_router_if_compatible(router) + self.assertIn(router['id'], agent.router_info) def test_nonexistent_interface_driver(self): self.conf.set_override('interface_driver', None)