Merge "Fix ip_lib get_gateway for default gateway on an iface"

This commit is contained in:
Jenkins 2015-06-26 22:00:54 +00:00 committed by Gerrit Code Review
commit 7f23d91046
3 changed files with 18 additions and 8 deletions

View File

@ -911,7 +911,7 @@ class DeviceManager(object):
device = ip_lib.IPDevice(device_name, namespace=network.namespace)
gateway = device.route.get_gateway()
if gateway:
gateway = gateway['gateway']
gateway = gateway.get('gateway')
for subnet in network.subnets:
skip_subnet = (

View File

@ -19,6 +19,7 @@ import os
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
import re
from neutron.agent.common import utils
from neutron.common import exceptions
@ -36,6 +37,8 @@ OPTS = [
LOOPBACK_DEVNAME = 'lo'
SYS_NET_PATH = '/sys/class/net'
DEFAULT_GW_PATTERN = re.compile(r"via (\S+)")
METRIC_PATTERN = re.compile(r"metric (\S+)")
class AddressNotReady(exceptions.NeutronException):
@ -531,12 +534,13 @@ class IpRouteCommand(IpDeviceCommandBase):
route_list_lines if
x.strip().startswith('default')), None)
if default_route_line:
gateway_index = 2
parts = default_route_line.split()
retval = dict(gateway=parts[gateway_index])
if 'metric' in parts:
metric_index = parts.index('metric') + 1
retval.update(metric=int(parts[metric_index]))
retval = dict()
gateway = DEFAULT_GW_PATTERN.search(default_route_line)
if gateway:
retval.update(gateway=gateway.group(1))
metric = METRIC_PATTERN.search(default_route_line)
if metric:
retval.update(metric=int(metric.group(1)))
return retval

View File

@ -144,6 +144,10 @@ GATEWAY_SAMPLE6 = ("""
default via 192.168.99.1 proto static metric 100
""")
GATEWAY_SAMPLE7 = ("""
default dev qg-31cd36 metric 1
""")
IPv6_GATEWAY_SAMPLE1 = ("""
default via 2001:470:9:1224:4508:b885:5fb:740b metric 100
2001:db8::/64 proto kernel scope link src 2001:470:9:1224:dfcc:aaff:feb9:76ce
@ -782,7 +786,9 @@ class TestIpRouteCommand(TestIPCmdBase):
'expected': {'gateway': '192.168.99.1'}},
{'sample': GATEWAY_SAMPLE6,
'expected': {'gateway': '192.168.99.1',
'metric': 100}}]
'metric': 100}},
{'sample': GATEWAY_SAMPLE7,
'expected': {'metric': 1}}]
def test_add_gateway(self):
self.route_cmd.add_gateway(self.gateway, self.metric, self.table)