From 62e0bee8206491690bd6b6b72fc38d9694d5083f Mon Sep 17 00:00:00 2001 From: Miguel Lavalle Date: Sun, 26 May 2019 19:15:25 -0500 Subject: [PATCH] Support multiple external networks in L3 agent Change [1] removed the deprecated option external_network_bridge. Per commit message in change [2], "l3 agent can handle any networks by setting the neutron parameter external_network_bridge and gateway_external_network_id to empty". So the consequence of [1] was to introduce a regression whereby multiple external networks are not supported by the L3 agent anymore. This change proposes a new simplified rule. If gateway_external_network_id is defined, that is the network that the L3 agent will use. If not and multiple external networks exist, the L3 agent will handle any of them. [1] https://review.opendev.org/#/c/567369/ [2] https://review.opendev.org/#/c/59359 Change-Id: Idd766bd069eda85ab6876a78b8b050ee5ab66cf6 Closes-Bug: #1824571 (cherry picked from commit 0b3f5f429d2e495eb78d78d46186092ac735e0d5) --- neutron/agent/l3/agent.py | 9 +++----- neutron/tests/unit/agent/l3/test_agent.py | 25 +++++------------------ 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 92621d58524..ba057a0adea 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -36,7 +36,6 @@ from oslo_utils import excutils from oslo_utils import timeutils from osprofiler import profiler -from neutron._i18n import _ from neutron.agent.common import resource_processing_queue as queue from neutron.agent.common import utils as common_utils from neutron.agent.l3 import dvr @@ -368,12 +367,10 @@ class L3NATAgent(ha.AgentMixin, 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 - msg = _( - "The 'gateway_external_network_id' option must be " - "configured for this agent as Neutron has more than " - "one external network.") - raise Exception(msg) def _create_router(self, router_id, router): args = [] diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 2ecf102f21e..e458c161507 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -24,7 +24,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 import exceptions as exc from neutron_lib.exceptions import l3 as l3_exc from oslo_config import cfg from oslo_log import log @@ -2889,12 +2888,11 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): 'external_gateway_info': {'network_id': 'aaa'}} agent.router_info = {} - self.plugin_api.get_external_network_id.side_effect = ( - exc.TooManyExternalNetworks()) - self.assertRaises(exc.TooManyExternalNetworks, - agent._process_router_if_compatible, - router) - self.assertNotIn(router['id'], 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) def test_process_router_if_compatible_with_ext_net_in_conf(self): agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) @@ -2912,19 +2910,6 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): router) self.assertNotIn(router['id'], agent.router_info) - def test_process_router_if_compatible_with_no_bridge_no_ext_net(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.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) self.assertRaises(SystemExit, l3_agent.L3NATAgent,