pci: use sriov-device-mappings when configure sriov devices
When 'sriov-numvfs' is configured in 'auto', only the devies set in 'sriov-device-mappings' are discovered and automatically configured. Change-Id: I1be61a19639d366d787fb92815c3a8a5c302fbda Closes-Bug: #1818975 Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@canonical.com>
This commit is contained in:
parent
0610e920a7
commit
380adb7271
@ -212,9 +212,11 @@ options:
|
||||
default: auto
|
||||
description: |
|
||||
Number of VF's to configure each PF with; by default, each SR-IOV PF will
|
||||
be configured with the maximum number of VF's it can support. Either use
|
||||
a single integer to apply the same VF configuration to all detected
|
||||
SR-IOV devices or use a per-device configuration in the following format
|
||||
be configured with the maximum number of VF's it can support. In the case
|
||||
sriov-device-mappings is set, only the devices in the mapping are configured.
|
||||
Either use a single integer to apply the same VF configuration to all
|
||||
detected SR-IOV devices or use a per-device configuration in the following
|
||||
format
|
||||
.
|
||||
<device>:<numvfs>
|
||||
.
|
||||
|
@ -599,6 +599,17 @@ def configure_ovs():
|
||||
service_restart('os-charm-phy-nic-mtu')
|
||||
|
||||
|
||||
def _get_interfaces_from_mappings(sriov_mappings):
|
||||
"""Returns list of interfaces based on sriov-device-mappings"""
|
||||
interfaces = []
|
||||
if sriov_mappings:
|
||||
# <net>:<interface>[ <net>:<interface>] configuration
|
||||
for token in sriov_mappings.split():
|
||||
_, interface = token.split(':')
|
||||
interfaces.append(interface)
|
||||
return interfaces
|
||||
|
||||
|
||||
def configure_sriov():
|
||||
'''Configure SR-IOV devices based on provided configuration options
|
||||
|
||||
@ -621,13 +632,19 @@ def configure_sriov():
|
||||
|
||||
# automatic configuration of all SR-IOV devices
|
||||
if sriov_numvfs == 'auto':
|
||||
interfaces = _get_interfaces_from_mappings(
|
||||
charm_config.get('sriov-device-mappings'))
|
||||
log('Configuring SR-IOV device VF functions in auto mode')
|
||||
for device in devices.pci_devices:
|
||||
if device and device.sriov:
|
||||
log("Configuring SR-IOV device"
|
||||
" {} with {} VF's".format(device.interface_name,
|
||||
device.sriov_totalvfs))
|
||||
device.set_sriov_numvfs(device.sriov_totalvfs)
|
||||
if interfaces and device.interface_name not in interfaces:
|
||||
log("Excluding configuration of SR-IOV device {}.".format(
|
||||
device.interface_name))
|
||||
else:
|
||||
log("Configuring SR-IOV device"
|
||||
" {} with {} VF's".format(device.interface_name,
|
||||
device.sriov_totalvfs))
|
||||
device.set_sriov_numvfs(device.sriov_totalvfs)
|
||||
else:
|
||||
# Single int blanket configuration
|
||||
try:
|
||||
|
@ -880,6 +880,24 @@ class TestNeutronOVSUtils(CharmTestCase):
|
||||
)
|
||||
self.assertTrue(self.remote_restart.called)
|
||||
|
||||
@patch('os.chmod')
|
||||
def test_configure_sriov_auto_mapping(self, _os_chmod):
|
||||
self.os_release.return_value = 'mitaka'
|
||||
_config = {
|
||||
'enable-sriov': True,
|
||||
'sriov-numvfs': 'auto',
|
||||
'sriov-device-mappings': 'net1:ens49'
|
||||
}
|
||||
self._configure_sriov_base(_config)
|
||||
|
||||
nutils.configure_sriov()
|
||||
|
||||
self.assertFalse(self.mock_sriov_device.set_sriov_numvfs.called)
|
||||
self.mock_sriov_device2.set_sriov_numvfs.assert_called_with(
|
||||
self.mock_sriov_device2.sriov_totalvfs
|
||||
)
|
||||
self.assertTrue(self.remote_restart.called)
|
||||
|
||||
@patch('os.chmod')
|
||||
def test_configure_sriov_numvfs(self, _os_chmod):
|
||||
self.os_release.return_value = 'mitaka'
|
||||
|
Loading…
Reference in New Issue
Block a user