Merge "[SR-IOV] The port status=DOWN has precedence in the VF link status"

This commit is contained in:
Zuul 2024-09-03 13:56:08 +00:00 committed by Gerrit Code Review
commit 091725432f
3 changed files with 23 additions and 3 deletions

View File

@ -73,10 +73,14 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
@param auto: set link_state to auto (0)
"""
ip = self.device(self.dev_name)
if auto:
# NOTE(ralonsoh): the state=False --> "disable" (2) has precedence over
# "auto" (0) and "enable" (1).
if state is False:
link_state = 2
elif auto:
link_state = 0
else:
link_state = 1 if state else 2
link_state = 1
vf_config = {'vf': vf_index, 'link_state': link_state}
ip.link.set_vf_feature(vf_config)

View File

@ -67,18 +67,27 @@ class TestPciLib(base.BaseTestCase):
self.assertEqual(pci_lib.LinkState.disable.name, result)
def test_set_vf_state(self):
# state=True, auto=False --> link_state=enable
self.pci_wrapper.set_vf_state(self.VF_INDEX, True)
vf = {'vf': self.VF_INDEX, 'link_state': 1}
self.mock_ip_device.link.set_vf_feature.assert_called_once_with(vf)
# state=False, auto=False --> link_state=disable
self.mock_ip_device.link.set_vf_feature.reset_mock()
self.pci_wrapper.set_vf_state(self.VF_INDEX, False)
vf = {'vf': self.VF_INDEX, 'link_state': 2}
self.mock_ip_device.link.set_vf_feature.assert_called_once_with(vf)
# state=True, auto=True --> link_state=auto
self.mock_ip_device.link.set_vf_feature.reset_mock()
self.pci_wrapper.set_vf_state(self.VF_INDEX, True, auto=True)
vf = {'vf': self.VF_INDEX, 'link_state': 0}
self.mock_ip_device.link.set_vf_feature.assert_called_once_with(vf)
# state=False, auto=True --> link_state=disable
self.mock_ip_device.link.set_vf_feature.reset_mock()
self.pci_wrapper.set_vf_state(self.VF_INDEX, False, auto=True)
vf = {'vf': self.VF_INDEX, 'link_state': 0}
vf = {'vf': self.VF_INDEX, 'link_state': 2}
self.mock_ip_device.link.set_vf_feature.assert_called_once_with(vf)
def test_set_vf_spoofcheck(self):

View File

@ -0,0 +1,7 @@
---
security:
- |
A ML2/SR-IOV port with status=DOWN will always set the VF link state to
"disable", regardless of the ``propagate_uplink_status`` port field value.
The port disabling, to stop any transmission, has precedence over the
link state "auto" value.