hooks: fix initial sriov configurations

To configure SRIOV devices it was expected that the 'sriov-numvfs'
config option to be changed but during an initial setup this not
happens.

In this commit we remove the condition but add a logic in
PCINetDevice to avoid reconfiguring PF devices if not necessary.

Change-Id: Ib8232b29f76ca7e25e1cd835d5e31a276000f1d4
Closes-Bug: #1817079
Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@canonical.com>
This commit is contained in:
Sahid Orentino Ferdjaoui 2019-02-25 14:54:48 +00:00 committed by sahid
parent 450cf845be
commit 381a3b1a33
4 changed files with 88 additions and 78 deletions

View File

@ -610,69 +610,68 @@ def configure_sriov():
os.chmod(NEUTRON_SRIOV_INIT_SCRIPT, 0o755) os.chmod(NEUTRON_SRIOV_INIT_SCRIPT, 0o755)
service('enable', 'neutron-openvswitch-networking-sriov') service('enable', 'neutron-openvswitch-networking-sriov')
if charm_config.changed('sriov-numvfs'): devices = PCINetDevices()
devices = PCINetDevices() sriov_numvfs = charm_config.get('sriov-numvfs')
sriov_numvfs = charm_config.get('sriov-numvfs')
# automatic configuration of all SR-IOV devices # automatic configuration of all SR-IOV devices
if sriov_numvfs == 'auto': if sriov_numvfs == 'auto':
log('Configuring SR-IOV device VF functions in auto mode') 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)
else:
# Single int blanket configuration
try:
log('Configuring SR-IOV device VF functions'
' with blanket setting')
for device in devices.pci_devices: for device in devices.pci_devices:
if device and device.sriov: if device and device.sriov:
log("Configuring SR-IOV device" numvfs = min(int(sriov_numvfs), device.sriov_totalvfs)
" {} with {} VF's".format(device.interface_name, if int(sriov_numvfs) > device.sriov_totalvfs:
device.sriov_totalvfs)) log('Requested value for sriov-numvfs ({}) too '
device.set_sriov_numvfs(device.sriov_totalvfs) 'high for interface {}. Falling back to '
else: 'interface totalvfs '
# Single int blanket configuration 'value: {}'.format(sriov_numvfs,
try: device.interface_name,
log('Configuring SR-IOV device VF functions' device.sriov_totalvfs))
' with blanket setting') log("Configuring SR-IOV device {} with {} "
for device in devices.pci_devices: "VFs".format(device.interface_name, numvfs))
if device and device.sriov: device.set_sriov_numvfs(numvfs)
numvfs = min(int(sriov_numvfs), device.sriov_totalvfs) except ValueError:
if int(sriov_numvfs) > device.sriov_totalvfs: # <device>:<numvfs>[ <device>:numvfs] configuration
log('Requested value for sriov-numvfs ({}) too ' sriov_numvfs = sriov_numvfs.split()
'high for interface {}. Falling back to ' for device_config in sriov_numvfs:
'interface totalvfs ' log('Configuring SR-IOV device VF functions per interface')
'value: {}'.format(sriov_numvfs, interface_name, numvfs = device_config.split(':')
device.interface_name, device = devices.get_device_from_interface_name(
device.sriov_totalvfs)) interface_name)
log("Configuring SR-IOV device {} with {} " if device and device.sriov:
"VFs".format(device.interface_name, numvfs)) if int(numvfs) > device.sriov_totalvfs:
device.set_sriov_numvfs(numvfs) log('Requested value for sriov-numfs ({}) too '
except ValueError: 'high for interface {}. Falling back to '
# <device>:<numvfs>[ <device>:numvfs] configuration 'interface totalvfs '
sriov_numvfs = sriov_numvfs.split() 'value: {}'.format(numvfs,
for device_config in sriov_numvfs: device.interface_name,
log('Configuring SR-IOV device VF functions per interface') device.sriov_totalvfs))
interface_name, numvfs = device_config.split(':') numvfs = device.sriov_totalvfs
device = devices.get_device_from_interface_name( log("Configuring SR-IOV device {} with {} "
interface_name) "VF's".format(device.interface_name, numvfs))
if device and device.sriov: device.set_sriov_numvfs(int(numvfs))
if int(numvfs) > device.sriov_totalvfs:
log('Requested value for sriov-numfs ({}) too '
'high for interface {}. Falling back to '
'interface totalvfs '
'value: {}'.format(numvfs,
device.interface_name,
device.sriov_totalvfs))
numvfs = device.sriov_totalvfs
log("Configuring SR-IOV device {} with {} "
"VF's".format(device.interface_name, numvfs))
device.set_sriov_numvfs(int(numvfs))
# Trigger remote restart in parent application # Trigger remote restart in parent application
remote_restart('neutron-plugin', 'nova-compute') remote_restart('neutron-plugin', 'nova-compute')
# Restart of SRIOV agent is required after changes to system runtime # Restart of SRIOV agent is required after changes to system runtime
# VF configuration # VF configuration
cmp_release = CompareOpenStackReleases( cmp_release = CompareOpenStackReleases(
os_release('neutron-common', base='icehouse')) os_release('neutron-common', base='icehouse'))
if cmp_release >= 'mitaka': if cmp_release >= 'mitaka':
service_restart('neutron-sriov-agent') service_restart('neutron-sriov-agent')
else: else:
service_restart('neutron-plugin-sriov-agent') service_restart('neutron-plugin-sriov-agent')
def get_shared_secret(): def get_shared_secret():

View File

@ -190,7 +190,7 @@ class PCINetDevice(object):
@param numvfs: integer to set the current number of VF's to @param numvfs: integer to set the current number of VF's to
""" """
if self.sriov: if self.sriov and numvfs != self.sriov_numvfs:
# NOTE(fnordahl): run-time change of numvfs is disallowed # NOTE(fnordahl): run-time change of numvfs is disallowed
# without resetting to 0 first. # without resetting to 0 first.
self._set_sriov_numvfs(0) self._set_sriov_numvfs(0)

View File

@ -795,13 +795,11 @@ class TestNeutronOVSUtils(CharmTestCase):
# ports=None whilst port checks are disabled. # ports=None whilst port checks are disabled.
f.assert_called_once_with('assessor', services='s1', ports=None) f.assert_called_once_with('assessor', services='s1', ports=None)
def _configure_sriov_base(self, config, def _configure_sriov_base(self, config):
changed=False):
self.mock_config = MagicMock() self.mock_config = MagicMock()
self.config.side_effect = None self.config.side_effect = None
self.config.return_value = self.mock_config self.config.return_value = self.mock_config
self.mock_config.get.side_effect = lambda x: config.get(x) self.mock_config.get.side_effect = lambda x: config.get(x)
self.mock_config.changed.return_value = changed
self.mock_eth_device = MagicMock() self.mock_eth_device = MagicMock()
self.mock_eth_device.sriov = False self.mock_eth_device.sriov = False
@ -835,19 +833,6 @@ class TestNeutronOVSUtils(CharmTestCase):
mock_pci_devices.get_device_from_interface_name.side_effect = \ mock_pci_devices.get_device_from_interface_name.side_effect = \
lambda x: self.pci_devices.get(x) lambda x: self.pci_devices.get(x)
@patch('os.chmod')
def test_configure_sriov_no_changes(self, _os_chmod):
self.os_release.return_value = 'kilo'
_config = {
'enable-sriov': True,
'sriov-numvfs': 'auto'
}
self._configure_sriov_base(_config, False)
nutils.configure_sriov()
self.assertFalse(self.remote_restart.called)
@patch('os.chmod') @patch('os.chmod')
def test_configure_sriov_auto(self, _os_chmod): def test_configure_sriov_auto(self, _os_chmod):
self.os_release.return_value = 'mitaka' self.os_release.return_value = 'mitaka'
@ -855,7 +840,7 @@ class TestNeutronOVSUtils(CharmTestCase):
'enable-sriov': True, 'enable-sriov': True,
'sriov-numvfs': 'auto' 'sriov-numvfs': 'auto'
} }
self._configure_sriov_base(_config, True) self._configure_sriov_base(_config)
nutils.configure_sriov() nutils.configure_sriov()
@ -874,7 +859,7 @@ class TestNeutronOVSUtils(CharmTestCase):
'enable-sriov': True, 'enable-sriov': True,
'sriov-numvfs': '32', 'sriov-numvfs': '32',
} }
self._configure_sriov_base(_config, True) self._configure_sriov_base(_config)
nutils.configure_sriov() nutils.configure_sriov()
@ -890,7 +875,7 @@ class TestNeutronOVSUtils(CharmTestCase):
'enable-sriov': True, 'enable-sriov': True,
'sriov-numvfs': 'ens0:32 sriov23:64' 'sriov-numvfs': 'ens0:32 sriov23:64'
} }
self._configure_sriov_base(_config, True) self._configure_sriov_base(_config)
nutils.configure_sriov() nutils.configure_sriov()
@ -899,6 +884,24 @@ class TestNeutronOVSUtils(CharmTestCase):
self.assertTrue(self.remote_restart.called) self.assertTrue(self.remote_restart.called)
@patch('os.chmod')
def test_configure_sriov_auto_avoid_recall(self, _os_chmod):
self.os_release.return_value = 'mitaka'
_config = {
'enable-sriov': True,
'sriov-numvfs': 'auto'
}
self._configure_sriov_base(_config)
nutils.configure_sriov()
self.mock_sriov_device2.sriov_numvfs = 64
self.mock_sriov_device2.set_sriov_numvfs.assert_called_with(
self.mock_sriov_device2.sriov_totalvfs)
self.mock_sriov_device2._set_sriov_numvfs.assert_not_called()
self.assertTrue(self.remote_restart.called)
@patch.object(nutils, 'subprocess') @patch.object(nutils, 'subprocess')
@patch.object(nutils, 'shutil') @patch.object(nutils, 'shutil')
def test_install_tmpfilesd_lxd(self, mock_shutil, mock_subprocess): def test_install_tmpfilesd_lxd(self, mock_shutil, mock_subprocess):

View File

@ -220,6 +220,14 @@ class PCINetDeviceTest(CharmTestCase):
mock__set_sriov_numvfs.assert_has_calls([ mock__set_sriov_numvfs.assert_has_calls([
call(0), call(4)]) call(0), call(4)])
@patch('pci.PCINetDevice._set_sriov_numvfs')
def test_set_sriov_numvfs_avoid_call(self, mock__set_sriov_numvfs):
dev = pci.PCINetDevice('0000:10:00.0')
dev.sriov = True
dev.sriov_numvfs = 4
dev.set_sriov_numvfs(4)
self.assertFalse(mock__set_sriov_numvfs.called)
class PCINetDevicesTest(CharmTestCase): class PCINetDevicesTest(CharmTestCase):