From: Samer Deeb Date: Tue, 21 Oct 2014 07:33:35 +0000 (+0300) Subject: Adds macvtap support X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6f41074e113719ba0330f286809a4ccf986fa56d;p=openstack-build%2Fneutron-build.git Adds macvtap support The current logic handles only VFs with direct vnic-type. This fix will add support for VFs with macvtap vnic-type, By checking the relevant upper_macvtap directory. Change-Id: Id69b7e64858020682fd0f68b0e162e5e8022eea3 Closes-Bug: 1383098 --- diff --git a/neutron/plugins/sriovnicagent/eswitch_manager.py b/neutron/plugins/sriovnicagent/eswitch_manager.py index 4f5e993f9..8c1c0851a 100644 --- a/neutron/plugins/sriovnicagent/eswitch_manager.py +++ b/neutron/plugins/sriovnicagent/eswitch_manager.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import glob import os import re @@ -30,6 +31,7 @@ class PciOsWrapper(object): PCI_PATH = "/sys/class/net/%s/device/virtfn%s/net" VIRTFN_FORMAT = "^virtfn(?P\d+)" VIRTFN_REG_EX = re.compile(VIRTFN_FORMAT) + MAC_VTAP_PREFIX = "upper_macvtap*" @classmethod def scan_vf_devices(cls, dev_name): @@ -65,12 +67,18 @@ class PciOsWrapper(object): """Check if VF is assigned. Checks if a given vf index of a given device name is assigned - by checking the relevant path in the system + by checking the relevant path in the system: + VF is assigned if: + Direct VF: PCI_PATH does not exist. + Macvtap VF: upper_macvtap path exists. @param dev_name: pf network device name @param vf_index: vf index """ path = cls.PCI_PATH % (dev_name, vf_index) - return not (os.path.isdir(path)) + if not os.path.isdir(path): + return True + upper_macvtap_path = os.path.join(path, "*", cls.MAC_VTAP_PREFIX) + return bool(glob.glob(upper_macvtap_path)) class EmbSwitch(object): diff --git a/neutron/tests/unit/sriovnicagent/test_eswitch_manager.py b/neutron/tests/unit/sriovnicagent/test_eswitch_manager.py index 9823fb8e0..f0c19adc0 100644 --- a/neutron/tests/unit/sriovnicagent/test_eswitch_manager.py +++ b/neutron/tests/unit/sriovnicagent/test_eswitch_manager.py @@ -363,3 +363,22 @@ class TestPciOsWrapper(base.BaseTestCase): def test_is_assigned_vf_false(self): self._mock_assign_vf(False) + + def _mock_assign_vf_macvtap(self, macvtap_exists): + def _glob(file_path): + return ["upper_macvtap0"] if macvtap_exists else [] + + with contextlib.nested( + mock.patch("os.path.isdir", + return_value=True), + mock.patch("glob.glob", + side_effect=_glob)): + result = esm.PciOsWrapper.is_assigned_vf(self.DEV_NAME, + self.VF_INDEX) + self.assertEqual(macvtap_exists, result) + + def test_is_assigned_vf_macvtap_true(self): + self._mock_assign_vf_macvtap(True) + + def test_is_assigned_vf_macvtap_false(self): + self._mock_assign_vf_macvtap(False)