From: John Schwarz Date: Tue, 8 Dec 2015 14:17:46 +0000 (+0200) Subject: Ignore possible suffix in iproute commands. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8ddeb4be9e32e5cefab8324d0cbf9cecead1f808;p=openstack-build%2Fneutron-build.git Ignore possible suffix in iproute commands. Closes-Bug: #1522199 Change-Id: I14815abd9345edb079e3331cbe2465ad22a0d4c3 --- diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index 89bc5776f..db538ecd1 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -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 "@" 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 diff --git a/neutron/agent/linux/ip_monitor.py b/neutron/agent/linux/ip_monitor.py index 97bd7ffa7..4e36c813b 100644 --- a/neutron/agent/linux/ip_monitor.py +++ b/neutron/agent/linux/ip_monitor.py @@ -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(): diff --git a/neutron/tests/unit/agent/linux/test_ip_lib.py b/neutron/tests/unit/agent/linux/test_ip_lib.py index b7f0d1b29..d8584995b 100644 --- a/neutron/tests/unit/agent/linux/test_ip_lib.py +++ b/neutron/tests/unit/agent/linux/test_ip_lib.py @@ -125,6 +125,13 @@ ADDR_SAMPLE2 = (""" valid_lft forever preferred_lft forever """) + +ADDR_SAMPLE3 = (""" +2: eth0@NONE: 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):