]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Adds macvtap support
authorSamer Deeb <samerd@mellanox.com>
Tue, 21 Oct 2014 07:33:35 +0000 (10:33 +0300)
committerSamer Deeb <samerd@mellanox.com>
Tue, 21 Oct 2014 08:57:44 +0000 (11:57 +0300)
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

neutron/plugins/sriovnicagent/eswitch_manager.py
neutron/tests/unit/sriovnicagent/test_eswitch_manager.py

index 4f5e993f9652cb2f6e00354c6171fef4b6e10df7..8c1c0851a29367a6c64f3e443b4acb62438fd549 100644 (file)
@@ -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<vf_index>\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):
index 9823fb8e01cefdbf9eea6e532c90531798c5435a..f0c19adc0cc174f3c9b767f645fc16dd180aa9cd 100644 (file)
@@ -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)