Merge "network: add command to configure trusted mode for VFs"

This commit is contained in:
Zuul authored and Gerrit Code Review committed 2018-04-04 20:43:57 +00:00
commit 34754743c2
2 files changed
+39

No files matched your search

+17
View File
@@ -1831,3 +1831,20 @@ def set_vf_interface_vlan(pci_addr, mac_addr, vlan=0):
port_state,
run_as_root=True,
check_exit_code=exit_code)
def set_vf_trusted(pci_addr, trusted):
"""Configures the VF to be trusted or not
:param pci_addr: PCI slot of the device
:param trusted: Boolean value to indicate whether to
enable/disable 'trusted' capability
"""
pf_ifname = pci_utils.get_ifname_by_pci_address(pci_addr,
pf_interface=True)
vf_num = pci_utils.get_vf_num_by_pci_address(pci_addr)
utils.execute('ip', 'link', 'set', pf_ifname,
'vf', vf_num,
'trust', bool(trusted) and 'on' or 'off',
run_as_root=True,
check_exit_code=[0, 2, 254])
+22
View File
@@ -1407,3 +1407,25 @@ class LinuxNetworkTestCase(test.NoDBTestCase):
self.assertRaises(processutils.ProcessExecutionError,
linux_net.create_tap_dev,
'tap42', multiqueue=True)
@mock.patch('nova.pci.utils.get_vf_num_by_pci_address')
@mock.patch('nova.pci.utils.get_ifname_by_pci_address')
@mock.patch('nova.utils.execute')
def test_set_vf_trusted_on(self, mexecute, mget_ifname, mget_vfnum):
mget_ifname.return_value = 'eth0'
mget_vfnum.return_value = 2
linux_net.set_vf_trusted('PCI_ADDR', True)
mexecute.assert_called_once_with(
'ip', 'link', 'set', 'eth0', 'vf', 2, 'trust', 'on',
check_exit_code=[0, 2, 254], run_as_root=True)
@mock.patch('nova.pci.utils.get_vf_num_by_pci_address')
@mock.patch('nova.pci.utils.get_ifname_by_pci_address')
@mock.patch('nova.utils.execute')
def test_set_vf_trusted_off(self, mexecute, mget_ifname, mget_vfnum):
mget_ifname.return_value = 'eth0'
mget_vfnum.return_value = 2
linux_net.set_vf_trusted('PCI_ADDR', False)
mexecute.assert_called_once_with(
'ip', 'link', 'set', 'eth0', 'vf', 2, 'trust', 'off',
check_exit_code=[0, 2, 254], run_as_root=True)