Skip to content

Commit dd5c2dd

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Refactor vf profile for PCI device" into stable/2023.1
2 parents f53824f + 5b41710 commit dd5c2dd

File tree

3 files changed

+80
-6
lines changed

3 files changed

+80
-6
lines changed

nova/network/neutron.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,12 +1595,13 @@ def _get_vf_pci_device_profile(self, pci_dev):
15951595
pf_mac = pci_dev.sriov_cap.get('pf_mac_address')
15961596
vf_num = pci_dev.sriov_cap.get('vf_num')
15971597
card_serial_number = pci_dev.card_serial_number
1598-
if all((pf_mac, vf_num, card_serial_number)):
1599-
vf_profile.update({
1600-
'card_serial_number': card_serial_number,
1601-
'pf_mac_address': pf_mac,
1602-
'vf_num': vf_num,
1603-
})
1598+
1599+
if card_serial_number is not None:
1600+
vf_profile['card_serial_number'] = card_serial_number
1601+
if pf_mac is not None:
1602+
vf_profile['pf_mac_address'] = pf_mac
1603+
if vf_num is not None:
1604+
vf_profile['vf_num'] = vf_num
16041605

16051606
# Update port binding capabilities using PCI device's network
16061607
# capabilities if they exist.

nova/tests/functional/libvirt/test_pci_sriov_servers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,8 @@ def fake_create(cls, xml, host):
521521
'pci_vendor_info': '8086:1515',
522522
'pci_slot': '0000:81:00.2',
523523
'physical_network': 'physnet4',
524+
'pf_mac_address': '52:54:00:1e:59:c6',
525+
'vf_num': 1
524526
},
525527
port['binding:profile'],
526528
)
@@ -1017,6 +1019,8 @@ def test_live_migrate_server_with_neutron(self):
10171019
# matching one)
10181020
'pci_slot': '0000:81:00.4',
10191021
'physical_network': 'physnet4',
1022+
'pf_mac_address': '52:54:00:1e:59:c6',
1023+
'vf_num': 1
10201024
},
10211025
port['binding:profile'],
10221026
)
@@ -1062,6 +1066,8 @@ def test_live_migrate_server_with_neutron(self):
10621066
'pci_vendor_info': '8086:1515',
10631067
'pci_slot': '0000:81:00.2',
10641068
'physical_network': 'physnet4',
1069+
'pf_mac_address': '52:54:00:1e:59:c6',
1070+
'vf_num': 1,
10651071
},
10661072
port['binding:profile'],
10671073
)

nova/tests/unit/network/test_neutron.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8627,6 +8627,73 @@ def test_unbind_ports_clean_arq(self, mock_neutron, mock_show,
86278627
self.assertEqual(call_args['port']['binding:profile'],
86288628
{'key': 'val'})
86298629

8630+
def test__get_vf_pci_device_profile_without_serial_num(self):
8631+
mydev = objects.PciDevice(
8632+
address='foo',
8633+
compute_node_id='123',
8634+
extra_info={
8635+
'capabilities': jsonutils.dumps({
8636+
'sriov': {
8637+
'pf_mac_address': '52:54:00:1e:59:c6',
8638+
'vf_num': 1,
8639+
},
8640+
'network': ['gso', 'sg', 'tso', 'tx'],
8641+
}),
8642+
},
8643+
)
8644+
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
8645+
{'pf_mac_address': '52:54:00:1e:59:c6',
8646+
'vf_num': 1,
8647+
'capabilities': ['gso', 'sg', 'tso', 'tx']})
8648+
8649+
def test__get_vf_pci_device_profile_without_pf_mac_addr(self):
8650+
mydev = objects.PciDevice(
8651+
address='foo',
8652+
compute_node_id='123',
8653+
extra_info={
8654+
'capabilities': jsonutils.dumps({
8655+
'vpd': {'card_serial_number': 'MT2113X00000'},
8656+
'sriov': {'vf_num': 1},
8657+
'network': ['gso', 'sg', 'tso', 'tx'],
8658+
}),
8659+
},
8660+
)
8661+
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
8662+
{'card_serial_number': 'MT2113X00000',
8663+
'vf_num': 1,
8664+
'capabilities': ['gso', 'sg', 'tso', 'tx']})
8665+
8666+
def test__get_vf_pci_device_profile_without_vf_num(self):
8667+
mydev = objects.PciDevice(
8668+
address='foo',
8669+
compute_node_id='123',
8670+
extra_info={
8671+
'capabilities': jsonutils.dumps({
8672+
'vpd': {'card_serial_number': 'MT2113X00000'},
8673+
'sriov': {'pf_mac_address': '52:54:00:1e:59:c6'},
8674+
'network': ['gso', 'sg', 'tso', 'tx'],
8675+
}),
8676+
},
8677+
)
8678+
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
8679+
{'card_serial_number': 'MT2113X00000',
8680+
'pf_mac_address': '52:54:00:1e:59:c6',
8681+
'capabilities': ['gso', 'sg', 'tso', 'tx']})
8682+
8683+
def test__get_vf_pci_device_profile_with_dev_capabilities(self):
8684+
mydev = objects.PciDevice(
8685+
address='foo',
8686+
compute_node_id='123',
8687+
extra_info={
8688+
'capabilities': jsonutils.dumps({
8689+
'sriov': {},
8690+
'network': ['gso', 'sg', 'tso', 'tx'],
8691+
}),
8692+
},
8693+
)
8694+
self.assertEqual(self.api._get_vf_pci_device_profile(mydev),
8695+
{'capabilities': ['gso', 'sg', 'tso', 'tx']})
8696+
86308697

86318698
class TestAllocateForInstance(test.NoDBTestCase):
86328699
def setUp(self):

0 commit comments

Comments
 (0)