Use set_gateway from ip_lib

Change-Id: I7df0f2b09a0d312902fc4745e0a245b5756074d9
Closes-Bug: #1312402
This commit is contained in:
Carl Baldwin 2014-04-24 19:50:43 +00:00
parent 968193808c
commit d7652fd38a
3 changed files with 7 additions and 9 deletions

View File

@ -645,17 +645,11 @@ class L3NATAgent(firewall_l3_agent.FWaaSL3AgentRpcCallback, manager.Manager):
self.driver.init_l3(interface_name, [ex_gw_port['ip_cidr']], self.driver.init_l3(interface_name, [ex_gw_port['ip_cidr']],
namespace=ri.ns_name, namespace=ri.ns_name,
gateway=ex_gw_port['subnet'].get('gateway_ip'),
preserve_ips=preserve_ips) preserve_ips=preserve_ips)
ip_address = ex_gw_port['ip_cidr'].split('/')[0] ip_address = ex_gw_port['ip_cidr'].split('/')[0]
self._send_gratuitous_arp_packet(ri, interface_name, ip_address) 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, def external_gateway_removed(self, ri, ex_gw_port,
interface_name, internal_cidrs): interface_name, internal_cidrs):

View File

@ -72,7 +72,7 @@ class LinuxInterfaceDriver(object):
self.root_helper = config.get_root_helper(conf) self.root_helper = config.get_root_helper(conf)
def init_l3(self, device_name, ip_cidrs, namespace=None, 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. """Set the L3 settings for the interface using data from the port.
ip_cidrs: list of 'X.X.X.X/YY' strings ip_cidrs: list of 'X.X.X.X/YY' strings
@ -105,6 +105,9 @@ class LinuxInterfaceDriver(object):
if ip_cidr not in preserve_ips: if ip_cidr not in preserve_ips:
device.addr.delete(ip_version, ip_cidr) device.addr.delete(ip_version, ip_cidr)
if gateway:
device.route.add_gateway(gateway)
def check_bridge_exists(self, bridge): def check_bridge_exists(self, bridge):
if not ip_lib.device_exists(bridge): if not ip_lib.device_exists(bridge):
raise exceptions.BridgeDoesNotExist(bridge=bridge) raise exceptions.BridgeDoesNotExist(bridge=bridge)

View File

@ -178,7 +178,8 @@ class TestBasicRouterOperations(base.BaseTestCase):
self.send_arp.assert_called_once_with(ri, interface_name, self.send_arp.assert_called_once_with(ri, interface_name,
'20.0.0.30') '20.0.0.30')
kwargs = {'preserve_ips': ['192.168.1.34/32'], 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, self.mock_driver.init_l3.assert_called_with(interface_name,
['20.0.0.30/24'], ['20.0.0.30/24'],
**kwargs) **kwargs)