From e7c2e55c6685ccda23ad5c020db5b204f82d296e Mon Sep 17 00:00:00 2001 From: Sean Mooney Date: Fri, 18 Nov 2022 12:08:55 +0000 Subject: 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 8d2776fb34339b311c713992a39507452c4ae42f) (cherry picked from commit 683cbd06336bba37d033c292c4c0ea83e06d9c07) --- nova/network/neutron.py | 17 +++++++++-------- nova/tests/unit/network/test_neutron.py | 9 +++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/nova/network/neutron.py b/nova/network/neutron.py index 3ec9d03c26..ba814d40b2 100644 --- a/nova/network/neutron.py +++ b/nova/network/neutron.py @@ -3512,15 +3512,15 @@ class API: migration.get('status') == 'reverted') return instance.migration_context.get_pci_mapping_for_migration(revert) - def _get_port_pci_slot(self, context, instance, port): - """Find the PCI address of the device corresponding to the port. + def _get_port_pci_dev(self, context, instance, port): + """Find the PCI device corresponding to the port. Assumes the port is an SRIOV one. :param context: The request context. :param instance: The instance to which the port is attached. :param port: The Neutron port, as obtained from the Neutron API JSON form. - :return: The PCI address as a string, or None if unable to find. + :return: The PciDevice object, or None if unable to find. """ # Find the port's PCIRequest, or return None for r in instance.pci_requests.requests: @@ -3540,8 +3540,7 @@ class API: LOG.debug('No PCI device found for request %s', request.request_id, instance=instance) return None - # Return the device's PCI address - return device.address + return device def _update_port_binding_for_instance( self, context, instance, host, migration=None, @@ -3609,9 +3608,11 @@ class API: # need to figure out the pci_slot from the InstancePCIRequest # and PciDevice objects. else: - pci_slot = self._get_port_pci_slot(context, instance, p) - if pci_slot: - binding_profile.update({'pci_slot': pci_slot}) + pci_dev = self._get_port_pci_dev(context, instance, p) + if pci_dev: + binding_profile.update( + self._get_pci_device_profile(pci_dev) + ) updates[constants.BINDING_PROFILE] = binding_profile # NOTE(gibi): during live migration the conductor already sets the diff --git a/nova/tests/unit/network/test_neutron.py b/nova/tests/unit/network/test_neutron.py index 0d6e84c505..75a2e5ad78 100644 --- a/nova/tests/unit/network/test_neutron.py +++ b/nova/tests/unit/network/test_neutron.py @@ -7085,7 +7085,7 @@ class TestAPI(TestAPIBase): self.context, uuids.subnet_id) @mock.patch.object(neutronapi.LOG, 'debug') - def test_get_port_pci_slot(self, mock_debug): + def test_get_port_pci_dev(self, mock_debug): fake_port = {'id': uuids.fake_port_id} request = objects.InstancePCIRequest(requester_id=uuids.fake_port_id, request_id=uuids.pci_request_id) @@ -7100,13 +7100,14 @@ class TestAPI(TestAPIBase): pci_devices=objects.PciDeviceList(objects=[device])) self.assertEqual( 'fake-pci-address', - self.api._get_port_pci_slot(self.context, instance, fake_port)) + self.api._get_port_pci_dev( + self.context, instance, fake_port).address) # Test not finding the request instance = objects.Instance( pci_requests=objects.InstancePCIRequests( requests=[objects.InstancePCIRequest(bad_request)])) self.assertIsNone( - self.api._get_port_pci_slot(self.context, instance, fake_port)) + self.api._get_port_pci_dev(self.context, instance, fake_port)) mock_debug.assert_called_with('No PCI request found for port %s', uuids.fake_port_id, instance=instance) mock_debug.reset_mock() @@ -7115,7 +7116,7 @@ class TestAPI(TestAPIBase): pci_requests=objects.InstancePCIRequests(requests=[request]), pci_devices=objects.PciDeviceList(objects=[bad_device])) self.assertIsNone( - self.api._get_port_pci_slot(self.context, instance, fake_port)) + self.api._get_port_pci_dev(self.context, instance, fake_port)) mock_debug.assert_called_with('No PCI device found for request %s', uuids.pci_request_id, instance=instance) -- cgit v1.2.1