diff --git a/neutron/agent/l3_agent.py b/neutron/agent/l3_agent.py index 8ddbd75756..aa7f7b782f 100644 --- a/neutron/agent/l3_agent.py +++ b/neutron/agent/l3_agent.py @@ -645,17 +645,11 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager): self.driver.init_l3(interface_name, [ex_gw_port['ip_cidr']], namespace=ri.ns_name, + gateway=ex_gw_port['subnet'].get('gateway_ip'), preserve_ips=preserve_ips) ip_address = ex_gw_port['ip_cidr'].split('/')[0] self._send_gratuitous_arp_packet(ri, interface_name, ip_address) - gw_ip = ex_gw_port['subnet']['gateway_ip'] - if ex_gw_port['subnet']['gateway_ip']: - cmd = ['route', 'add', 'default', 'gw', gw_ip] - ip_wrapper = ip_lib.IPWrapper(self.root_helper, - namespace=ri.ns_name) - ip_wrapper.netns.execute(cmd, check_exit_code=False) - def external_gateway_removed(self, ri, ex_gw_port, interface_name, internal_cidrs): diff --git a/neutron/agent/linux/interface.py b/neutron/agent/linux/interface.py index 946de18fdb..c3a68bbb30 100644 --- a/neutron/agent/linux/interface.py +++ b/neutron/agent/linux/interface.py @@ -72,7 +72,7 @@ class LinuxInterfaceDriver(object): self.root_helper = config.get_root_helper(conf) def init_l3(self, device_name, ip_cidrs, namespace=None, - preserve_ips=[]): + preserve_ips=[], gateway=None): """Set the L3 settings for the interface using data from the port. ip_cidrs: list of 'X.X.X.X/YY' strings @@ -105,6 +105,9 @@ class LinuxInterfaceDriver(object): if ip_cidr not in preserve_ips: device.addr.delete(ip_version, ip_cidr) + if gateway: + device.route.add_gateway(gateway) + def check_bridge_exists(self, bridge): if not ip_lib.device_exists(bridge): raise exceptions.BridgeDoesNotExist(bridge=bridge) diff --git a/neutron/tests/unit/test_l3_agent.py b/neutron/tests/unit/test_l3_agent.py index 8f936d4bcc..20f3e42c79 100644 --- a/neutron/tests/unit/test_l3_agent.py +++ b/neutron/tests/unit/test_l3_agent.py @@ -178,7 +178,8 @@ class TestBasicRouterOperations(base.BaseTestCase): self.send_arp.assert_called_once_with(ri, interface_name, '20.0.0.30') kwargs = {'preserve_ips': ['192.168.1.34/32'], - 'namespace': 'qrouter-' + router_id} + 'namespace': 'qrouter-' + router_id, + 'gateway': '20.0.0.1'} self.mock_driver.init_l3.assert_called_with(interface_name, ['20.0.0.30/24'], **kwargs)