From 380adb7271c8de67d343f43b9226efa77eb5adc2 Mon Sep 17 00:00:00 2001 From: Sahid Orentino Ferdjaoui Date: Tue, 21 May 2019 15:21:30 +0200 Subject: [PATCH] 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 --- config.yaml | 8 +++++--- hooks/neutron_ovs_utils.py | 25 +++++++++++++++++++++---- unit_tests/test_neutron_ovs_utils.py | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/config.yaml b/config.yaml index c89ead3e..169d7cef 100644 --- a/config.yaml +++ b/config.yaml @@ -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 . : . diff --git a/hooks/neutron_ovs_utils.py b/hooks/neutron_ovs_utils.py index 9d0b75b5..8993b1e0 100644 --- a/hooks/neutron_ovs_utils.py +++ b/hooks/neutron_ovs_utils.py @@ -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: + # :[ :] 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: diff --git a/unit_tests/test_neutron_ovs_utils.py b/unit_tests/test_neutron_ovs_utils.py index 3041a1f8..1ecf6038 100644 --- a/unit_tests/test_neutron_ovs_utils.py +++ b/unit_tests/test_neutron_ovs_utils.py @@ -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'