summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-12-05 17:03:52 +0000
committerGerrit Code Review <review@openstack.org>2022-12-05 17:03:52 +0000
commit2561237c9f295daf988307d5361a7e1075e7cf0a (patch)
tree64e0ef18e1187d7216dce081710817255ac0866f
parent2d65da72e14cfd3a11dc134e7a0269d230a7427c (diff)
parente7c2e55c6685ccda23ad5c020db5b204f82d296e (diff)
downloadnova-2561237c9f295daf988307d5361a7e1075e7cf0a.tar.gz
Merge "refactor: remove duplicated logic" into stable/xena
-rw-r--r--nova/network/neutron.py17
-rw-r--r--nova/tests/unit/network/test_neutron.py9
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)