]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
SR-IOV: update pci lib to support rate limit
authorMoshe Levi <moshele@mellanox.com>
Wed, 15 Jul 2015 05:25:38 +0000 (08:25 +0300)
committerMoshe Levi <moshele@mellanox.com>
Thu, 30 Jul 2015 12:38:22 +0000 (15:38 +0300)
Partially-Implements: blueprint ml2-qos
Change-Id: I3095f0e8249941f24cbf478cba142135272ebfd3

neutron/cmd/sanity/checks.py
neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py
neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py

index 5d90ad9c306e0d83b1f69b925bcb7ffd5125e94a..c3ef8a3c98640009879074738a00c74093305dda 100644 (file)
@@ -127,18 +127,23 @@ def arp_header_match_supported():
 
 
 def vf_management_supported():
+    is_supported = True
+    required_caps = (
+        ip_link_support.IpLinkConstants.IP_LINK_CAPABILITY_STATE,
+        ip_link_support.IpLinkConstants.IP_LINK_CAPABILITY_RATE)
     try:
         vf_section = ip_link_support.IpLinkSupport.get_vf_mgmt_section()
-        if not ip_link_support.IpLinkSupport.vf_mgmt_capability_supported(
-                vf_section,
-                ip_link_support.IpLinkConstants.IP_LINK_CAPABILITY_STATE):
-            LOG.debug("ip link command does not support vf capability")
-            return False
+        for cap in required_caps:
+            if not ip_link_support.IpLinkSupport.vf_mgmt_capability_supported(
+                   vf_section, cap):
+                is_supported = False
+                LOG.debug("ip link command does not support "
+                          "vf capability '%(cap)s'", cap)
     except ip_link_support.UnsupportedIpLinkCommand:
         LOG.exception(_LE("Unexpected exception while checking supported "
                           "ip link command"))
         return False
-    return True
+    return is_supported
 
 
 def netns_read_requires_helper():
index 05fc0d2f85987eea354fe1c42cc80d8d8f558c9c..723e4b43d69a95788ff62a682cafcfc08d81241d 100644 (file)
@@ -106,6 +106,21 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
             raise exc.IpCommandError(dev_name=self.dev_name,
                                      reason=e)
 
+    def set_vf_max_rate(self, vf_index, max_tx_rate):
+        """sets vf max rate.
+
+        @param vf_index: vf index
+        @param max_tx_rate: vf max tx rate
+        """
+        try:
+            self._as_root([], "link", ("set", self.dev_name, "vf",
+                                       str(vf_index), "rate",
+                                       str(max_tx_rate)))
+        except Exception as e:
+            LOG.exception(_LE("Failed executing ip command"))
+            raise exc.IpCommandError(dev_name=self.dev_name,
+                                     reason=e)
+
     def _get_vf_link_show(self, vf_list, link_show_out):
         """Get link show output for VFs
 
index 62a10f0fba09ba5a97b3c2e809c8156d9c3e89d4..38e0eac060d8a81bb86a70936ee236576f1261a3 100644 (file)
@@ -99,3 +99,20 @@ class TestPciLib(base.BaseTestCase):
                               self.pci_wrapper.set_vf_state,
                               self.VF_INDEX,
                               True)
+
+    def test_set_vf_max_rate(self):
+        with mock.patch.object(self.pci_wrapper, "_as_root") \
+                as mock_as_root:
+            result = self.pci_wrapper.set_vf_max_rate(self.VF_INDEX, 1000)
+            self.assertIsNone(result)
+        mock_as_root.assert_called_once_with([], "link",
+            ("set", self.DEV_NAME, "vf", str(self.VF_INDEX), "rate", '1000'))
+
+    def test_set_vf_max_rate_fail(self):
+        with mock.patch.object(self.pci_wrapper,
+                               "_execute") as mock_exec:
+            mock_exec.side_effect = Exception()
+            self.assertRaises(exc.IpCommandError,
+                              self.pci_wrapper.set_vf_max_rate,
+                              self.VF_INDEX,
+                              1000)