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():
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
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)