Merge "Refactor vf profile for PCI device"

This commit is contained in:
Zuul 2024-04-11 14:38:11 +00:00 committed by Gerrit Code Review
commit c199becf52
3 changed files with 80 additions and 6 deletions

View File

@ -1595,12 +1595,13 @@ class API:
pf_mac = pci_dev.sriov_cap.get('pf_mac_address')
vf_num = pci_dev.sriov_cap.get('vf_num')
card_serial_number = pci_dev.card_serial_number
if all((pf_mac, vf_num, card_serial_number)):
vf_profile.update({
'card_serial_number': card_serial_number,
'pf_mac_address': pf_mac,
'vf_num': vf_num,
})
if card_serial_number is not None:
vf_profile['card_serial_number'] = card_serial_number
if pf_mac is not None:
vf_profile['pf_mac_address'] = pf_mac
if vf_num is not None:
vf_profile['vf_num'] = vf_num
# Update port binding capabilities using PCI device's network
# capabilities if they exist.

View File

@ -521,6 +521,8 @@ class SRIOVServersTest(_PCIServersWithMigrationTestBase):
'pci_vendor_info': '8086:1515',
'pci_slot': '0000:81:00.2',
'physical_network': 'physnet4',
'pf_mac_address': '52:54:00:1e:59:c6',
'vf_num': 1
},
port['binding:profile'],
)
@ -1017,6 +1019,8 @@ class SRIOVServersTest(_PCIServersWithMigrationTestBase):
# matching one)
'pci_slot': '0000:81:00.4',
'physical_network': 'physnet4',
'pf_mac_address': '52:54:00:1e:59:c6',
'vf_num': 1
},
port['binding:profile'],
)
@ -1062,6 +1066,8 @@ class SRIOVServersTest(_PCIServersWithMigrationTestBase):
'pci_vendor_info': '8086:1515',
'pci_slot': '0000:81:00.2',
'physical_network': 'physnet4',
'pf_mac_address': '52:54:00:1e:59:c6',
'vf_num': 1,
},
port['binding:profile'],
)

View File

@ -8627,6 +8627,73 @@ class TestAPIPortbinding(TestAPIBase):
self.assertEqual(call_args['port']['binding:profile'],
{'key': 'val'})
def test__get_vf_pci_device_profile_without_serial_num(self):
mydev = objects.PciDevice(
address='foo',
compute_node_id='123',
extra_info={
'capabilities': jsonutils.dumps({
'sriov': {
'pf_mac_address': '52:54:00:1e:59:c6',
'vf_num': 1,
},
'network': ['gso', 'sg', 'tso', 'tx'],
}),
},
)
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
{'pf_mac_address': '52:54:00:1e:59:c6',
'vf_num': 1,
'capabilities': ['gso', 'sg', 'tso', 'tx']})
def test__get_vf_pci_device_profile_without_pf_mac_addr(self):
mydev = objects.PciDevice(
address='foo',
compute_node_id='123',
extra_info={
'capabilities': jsonutils.dumps({
'vpd': {'card_serial_number': 'MT2113X00000'},
'sriov': {'vf_num': 1},
'network': ['gso', 'sg', 'tso', 'tx'],
}),
},
)
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
{'card_serial_number': 'MT2113X00000',
'vf_num': 1,
'capabilities': ['gso', 'sg', 'tso', 'tx']})
def test__get_vf_pci_device_profile_without_vf_num(self):
mydev = objects.PciDevice(
address='foo',
compute_node_id='123',
extra_info={
'capabilities': jsonutils.dumps({
'vpd': {'card_serial_number': 'MT2113X00000'},
'sriov': {'pf_mac_address': '52:54:00:1e:59:c6'},
'network': ['gso', 'sg', 'tso', 'tx'],
}),
},
)
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
{'card_serial_number': 'MT2113X00000',
'pf_mac_address': '52:54:00:1e:59:c6',
'capabilities': ['gso', 'sg', 'tso', 'tx']})
def test__get_vf_pci_device_profile_with_dev_capabilities(self):
mydev = objects.PciDevice(
address='foo',
compute_node_id='123',
extra_info={
'capabilities': jsonutils.dumps({
'sriov': {},
'network': ['gso', 'sg', 'tso', 'tx'],
}),
},
)
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
{'capabilities': ['gso', 'sg', 'tso', 'tx']})
class TestAllocateForInstance(test.NoDBTestCase):
def setUp(self):