pci: fix missing update attributes
We should update state of PCIDevDevice after to have updated its numvfs. Related-to: #1817079 Change-Id: I2c07c4376cca5afe9fe8e636a1be051c5f63367a Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@canonical.com>
This commit is contained in:
parent
2b4fdffc52
commit
3957a46959
@ -155,6 +155,8 @@ class PCINetDevice(object):
|
||||
self.mac_address = None
|
||||
self.state = None
|
||||
self.sriov = False
|
||||
self.sriov_totalvfs = None
|
||||
self.sriov_numvfs = None
|
||||
self.update_attributes()
|
||||
|
||||
def update_attributes(self):
|
||||
@ -186,6 +188,7 @@ class PCINetDevice(object):
|
||||
'device', 'sriov_numvfs')
|
||||
with open(sdevice, 'w') as sh:
|
||||
sh.write(str(numvfs))
|
||||
self.update_attributes()
|
||||
|
||||
|
||||
class PCINetDevices(object):
|
||||
|
@ -178,6 +178,40 @@ class PCINetDeviceTest(CharmTestCase):
|
||||
self.assertEqual(
|
||||
pci.get_sysnet_interface('/sys/class/net/eth3'), 'eth3')
|
||||
|
||||
@patch('pci.get_sysnet_interfaces_and_macs')
|
||||
def test_set_sriov_numvfs(self, mock_sysnet_ints):
|
||||
mock_sysnet_ints.side_effect = [{
|
||||
'interface': 'eth2',
|
||||
'mac_address': 'a8:9d:21:cf:93:fc',
|
||||
'pci_address': '0000:10:00.0',
|
||||
'state': 'up',
|
||||
'sriov': True,
|
||||
'sriov_totalvfs': 7,
|
||||
'sriov_numvfs': 0
|
||||
}], [{
|
||||
'interface': 'eth2',
|
||||
'mac_address': 'a8:9d:21:cf:93:fc',
|
||||
'pci_address': '0000:10:00.0',
|
||||
'state': 'up',
|
||||
'sriov': True,
|
||||
'sriov_totalvfs': 7,
|
||||
'sriov_numvfs': 4
|
||||
}]
|
||||
dev = pci.PCINetDevice('0000:10:00.0')
|
||||
self.assertEqual('eth2', dev.interface_name)
|
||||
self.assertTrue(dev.sriov)
|
||||
self.assertEqual(7, dev.sriov_totalvfs)
|
||||
self.assertEqual(0, dev.sriov_numvfs)
|
||||
|
||||
with patch_open() as (mock_open, mock_file):
|
||||
dev.set_sriov_numvfs(4)
|
||||
mock_open.assert_called_with(
|
||||
'/sys/class/net/eth2/device/sriov_numvfs', 'w')
|
||||
mock_file.write.assert_called_with("4")
|
||||
self.assertTrue(dev.sriov)
|
||||
self.assertEqual(7, dev.sriov_totalvfs)
|
||||
self.assertEqual(4, dev.sriov_numvfs)
|
||||
|
||||
|
||||
class PCINetDevicesTest(CharmTestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user