Merge "Ignore possible suffix in iproute commands."
This commit is contained in:
commit
06242d6dbf
@ -46,6 +46,17 @@ METRIC_PATTERN = re.compile(r"metric (\S+)")
|
||||
DEVICE_NAME_PATTERN = re.compile(r"(\d+?): (\S+?):.*")
|
||||
|
||||
|
||||
def remove_interface_suffix(interface):
|
||||
"""Remove a possible "<if>@<endpoint>" suffix from an interface' name.
|
||||
|
||||
This suffix can appear in some kernel versions, and intends on specifying,
|
||||
for example, a veth's pair. However, this interface name is useless to us
|
||||
as further 'ip' commands require that the suffix be removed.
|
||||
"""
|
||||
# If '@' is not present, this will do nothing.
|
||||
return interface.partition("@")[0]
|
||||
|
||||
|
||||
class AddressNotReady(exceptions.NeutronException):
|
||||
message = _("Failure waiting for address %(address)s to "
|
||||
"become ready: %(reason)s")
|
||||
@ -556,7 +567,7 @@ class IpAddrCommand(IpDeviceCommandBase):
|
||||
if match:
|
||||
# Found a match for a device name, but its' addresses will
|
||||
# only appear in following lines, so we may as well continue.
|
||||
device_name = match.group(2)
|
||||
device_name = remove_interface_suffix(match.group(2))
|
||||
continue
|
||||
elif not line.startswith('inet'):
|
||||
continue
|
||||
|
@ -18,6 +18,7 @@ from oslo_utils import excutils
|
||||
|
||||
from neutron._i18n import _LE
|
||||
from neutron.agent.linux import async_process
|
||||
from neutron.agent.linux import ip_lib
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -47,7 +48,7 @@ class IPMonitorEvent(object):
|
||||
route = route[1:]
|
||||
|
||||
try:
|
||||
interface = route[1]
|
||||
interface = ip_lib.remove_interface_suffix(route[1])
|
||||
cidr = route[3]
|
||||
except IndexError:
|
||||
with excutils.save_and_reraise_exception():
|
||||
|
@ -125,6 +125,13 @@ ADDR_SAMPLE2 = ("""
|
||||
valid_lft forever preferred_lft forever
|
||||
""")
|
||||
|
||||
|
||||
ADDR_SAMPLE3 = ("""
|
||||
2: eth0@NONE: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP
|
||||
link/ether dd:cc:aa:b9:76:ce brd ff:ff:ff:ff:ff:ff
|
||||
inet 172.16.77.240/24 brd 172.16.77.255 scope global eth0
|
||||
""")
|
||||
|
||||
GATEWAY_SAMPLE1 = ("""
|
||||
default via 10.35.19.254 metric 100
|
||||
10.35.16.0/22 proto kernel scope link src 10.35.17.97
|
||||
@ -852,6 +859,12 @@ class TestIpAddrCommand(TestIPCmdBase):
|
||||
self._assert_call([], ('show', 'tap0', 'permanent', 'scope',
|
||||
'global'))
|
||||
|
||||
def test_get_devices_with_ip(self):
|
||||
self.parent._run.return_value = ADDR_SAMPLE3
|
||||
devices = self.addr_cmd.get_devices_with_ip('172.16.77.240/24')
|
||||
self.assertEqual(1, len(devices))
|
||||
self.assertEqual('eth0', devices[0]['name'])
|
||||
|
||||
|
||||
class TestIpRouteCommand(TestIPCmdBase):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user