sriov: Fix macvtap vf interface regex pattern

The check if macvtap is assigend we parse
the output of ip link show and check if
macvtap[0-9]+@<vf interface>.

This patch update the <vf_interface> regex to include
underscore as interfce can contain underscore
e.g. p2p1_0.

Change-Id: I2d41972bb8a92bcaad9cd2250be1a7cb30326180
This commit is contained in:
Moshe Levi 2016-06-29 12:46:30 +03:00
parent e8c97686d9
commit b8cadc7623
2 changed files with 13 additions and 1 deletions

View File

@ -34,7 +34,7 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
MAC_PATTERN = r"MAC\s+(?P<mac>[a-fA-F0-9:]+),"
STATE_PATTERN = r"\s+link-state\s+(?P<state>\w+)"
ANY_PATTERN = ".*,"
MACVTAP_PATTERN = r".*macvtap[0-9]+@(?P<vf_interface>[a-zA-Z0-9]+):"
MACVTAP_PATTERN = r".*macvtap[0-9]+@(?P<vf_interface>[a-zA-Z0-9_]+):"
VF_LINE_FORMAT = VF_PATTERN + MAC_PATTERN + ANY_PATTERN + STATE_PATTERN
VF_DETAILS_REG_EX = re.compile(VF_LINE_FORMAT)

View File

@ -41,8 +41,13 @@ class TestPciLib(base.BaseTestCase):
'1500 qdisc noop state DOWN mode DEFAULT group '
'default qlen 500 link/ether 4a:9b:6d:de:65:b5 brd '
'ff:ff:ff:ff:ff:ff')
MACVTAP_LINK_SHOW2 = ('64: macvtap2@p1p2_1: <BROADCAST,MULTICAST> mtu '
'1500 qdisc noop state DOWN mode DEFAULT group '
'default qlen 500 link/ether 4a:9b:6d:de:65:b5 brd '
'ff:ff:ff:ff:ff:ff')
IP_LINK_SHOW_WITH_MACVTAP = '\n'.join((VF_LINK_SHOW, MACVTAP_LINK_SHOW))
IP_LINK_SHOW_WITH_MACVTAP2 = '\n'.join((VF_LINK_SHOW, MACVTAP_LINK_SHOW2))
MAC_MAPPING = {
0: "fa:16:3e:b4:81:ac",
@ -156,6 +161,13 @@ class TestPciLib(base.BaseTestCase):
self.assertTrue(
pci_lib.PciDeviceIPWrapper.is_macvtap_assigned('enp129s0f1'))
def test_is_macvtap_assigned_interface_with_underscore(self):
with mock.patch.object(pci_lib.PciDeviceIPWrapper,
"_execute") as mock_exec:
mock_exec.return_value = self.IP_LINK_SHOW_WITH_MACVTAP2
self.assertTrue(
pci_lib.PciDeviceIPWrapper.is_macvtap_assigned('p1p2_1'))
def test_is_macvtap_assigned_not_assigned(self):
with mock.patch.object(pci_lib.PciDeviceIPWrapper,
"_execute") as mock_exec: