Skip to content

Commit e7c2e55

Browse files
committed
refactor: remove duplicated logic
Remove _update_port_pci_binding_profile and replace its usage with _get_pci_device_profile. changes from yoga are due to a partial backport of are due to a partial backport of I9a1532e9a98f89db69b9ae3b41b06318a43519b3 which is required to resolve conflict due to the lack of the remote managed ports feature in xena specificaly _get_port_pci_slot was refactored to _get_port_pci_dev Change-Id: I34dae6fdb746205f0baa4997e69eec55634bec4d (cherry picked from commit 8d2776f) (cherry picked from commit 683cbd0)
1 parent 8538721 commit e7c2e55

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

nova/network/neutron.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3512,15 +3512,15 @@ def _get_pci_mapping_for_migration(self, instance, migration):
35123512
migration.get('status') == 'reverted')
35133513
return instance.migration_context.get_pci_mapping_for_migration(revert)
35143514

3515-
def _get_port_pci_slot(self, context, instance, port):
3516-
"""Find the PCI address of the device corresponding to the port.
3515+
def _get_port_pci_dev(self, context, instance, port):
3516+
"""Find the PCI device corresponding to the port.
35173517
Assumes the port is an SRIOV one.
35183518
35193519
:param context: The request context.
35203520
:param instance: The instance to which the port is attached.
35213521
:param port: The Neutron port, as obtained from the Neutron API
35223522
JSON form.
3523-
:return: The PCI address as a string, or None if unable to find.
3523+
:return: The PciDevice object, or None if unable to find.
35243524
"""
35253525
# Find the port's PCIRequest, or return None
35263526
for r in instance.pci_requests.requests:
@@ -3540,8 +3540,7 @@ def _get_port_pci_slot(self, context, instance, port):
35403540
LOG.debug('No PCI device found for request %s',
35413541
request.request_id, instance=instance)
35423542
return None
3543-
# Return the device's PCI address
3544-
return device.address
3543+
return device
35453544

35463545
def _update_port_binding_for_instance(
35473546
self, context, instance, host, migration=None,
@@ -3609,9 +3608,11 @@ def _update_port_binding_for_instance(
36093608
# need to figure out the pci_slot from the InstancePCIRequest
36103609
# and PciDevice objects.
36113610
else:
3612-
pci_slot = self._get_port_pci_slot(context, instance, p)
3613-
if pci_slot:
3614-
binding_profile.update({'pci_slot': pci_slot})
3611+
pci_dev = self._get_port_pci_dev(context, instance, p)
3612+
if pci_dev:
3613+
binding_profile.update(
3614+
self._get_pci_device_profile(pci_dev)
3615+
)
36153616
updates[constants.BINDING_PROFILE] = binding_profile
36163617

36173618
# NOTE(gibi): during live migration the conductor already sets the

nova/tests/unit/network/test_neutron.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7085,7 +7085,7 @@ def test_get_segment_id_for_subnet_fails(self, mock_client):
70857085
self.context, uuids.subnet_id)
70867086

70877087
@mock.patch.object(neutronapi.LOG, 'debug')
7088-
def test_get_port_pci_slot(self, mock_debug):
7088+
def test_get_port_pci_dev(self, mock_debug):
70897089
fake_port = {'id': uuids.fake_port_id}
70907090
request = objects.InstancePCIRequest(requester_id=uuids.fake_port_id,
70917091
request_id=uuids.pci_request_id)
@@ -7100,13 +7100,14 @@ def test_get_port_pci_slot(self, mock_debug):
71007100
pci_devices=objects.PciDeviceList(objects=[device]))
71017101
self.assertEqual(
71027102
'fake-pci-address',
7103-
self.api._get_port_pci_slot(self.context, instance, fake_port))
7103+
self.api._get_port_pci_dev(
7104+
self.context, instance, fake_port).address)
71047105
# Test not finding the request
71057106
instance = objects.Instance(
71067107
pci_requests=objects.InstancePCIRequests(
71077108
requests=[objects.InstancePCIRequest(bad_request)]))
71087109
self.assertIsNone(
7109-
self.api._get_port_pci_slot(self.context, instance, fake_port))
7110+
self.api._get_port_pci_dev(self.context, instance, fake_port))
71107111
mock_debug.assert_called_with('No PCI request found for port %s',
71117112
uuids.fake_port_id, instance=instance)
71127113
mock_debug.reset_mock()
@@ -7115,7 +7116,7 @@ def test_get_port_pci_slot(self, mock_debug):
71157116
pci_requests=objects.InstancePCIRequests(requests=[request]),
71167117
pci_devices=objects.PciDeviceList(objects=[bad_device]))
71177118
self.assertIsNone(
7118-
self.api._get_port_pci_slot(self.context, instance, fake_port))
7119+
self.api._get_port_pci_dev(self.context, instance, fake_port))
71197120
mock_debug.assert_called_with('No PCI device found for request %s',
71207121
uuids.pci_request_id, instance=instance)
71217122

0 commit comments

Comments
 (0)