From: Moshe Levi Date: Wed, 15 Jul 2015 05:25:38 +0000 (+0300) Subject: SR-IOV: update pci lib to support rate limit X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3a9c08b80b7f86fa2cd0cbc08de6d1845249ac13;p=openstack-build%2Fneutron-build.git SR-IOV: update pci lib to support rate limit Partially-Implements: blueprint ml2-qos Change-Id: I3095f0e8249941f24cbf478cba142135272ebfd3 --- diff --git a/neutron/cmd/sanity/checks.py b/neutron/cmd/sanity/checks.py index 5d90ad9c3..c3ef8a3c9 100644 --- a/neutron/cmd/sanity/checks.py +++ b/neutron/cmd/sanity/checks.py @@ -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(): diff --git a/neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py b/neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py index 05fc0d2f8..723e4b43d 100644 --- a/neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py +++ b/neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py @@ -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 diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py index 62a10f0fb..38e0eac06 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py @@ -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)