diff options
author | Zuul <zuul@review.opendev.org> | 2023-05-17 23:28:09 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-05-17 23:28:09 +0000 |
commit | eebb5db030830af8526e27f1acd271e619c1af39 (patch) | |
tree | 775a7134010d52dab78fc7fc69f297a4ea3e342b | |
parent | 2c8772ab51352555726227b99ae3b84b586627c6 (diff) | |
parent | b6c7ee07ad2a6503b8aad0921cca70e61e60259d (diff) | |
download | nova-eebb5db030830af8526e27f1acd271e619c1af39.tar.gz |
Merge "Update RequestSpec.pci_request for resize" into stable/yoga
-rw-r--r-- | nova/compute/api.py | 13 | ||||
-rw-r--r-- | nova/tests/functional/libvirt/test_pci_sriov_servers.py | 15 | ||||
-rw-r--r-- | nova/tests/functional/regressions/test_bug_1983753.py | 26 | ||||
-rw-r--r-- | nova/tests/unit/compute/test_api.py | 3 |
4 files changed, 29 insertions, 28 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 24dd40bc3c..76c11658c2 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -4217,6 +4217,19 @@ class API: if not same_flavor: request_spec.numa_topology = hardware.numa_get_constraints( new_flavor, instance.image_meta) + # if the flavor is changed then we need to recalculate the + # pci_requests as well because the new flavor might request + # different pci_aliases + new_pci_requests = pci_request.get_pci_requests_from_flavor( + new_flavor) + new_pci_requests.instance_uuid = instance.uuid + # The neutron based InstancePCIRequest cannot change during resize, + # so we just need to copy them from the old request + for request in request_spec.pci_requests.requests or []: + if request.source == objects.InstancePCIRequest.NEUTRON_PORT: + new_pci_requests.requests.append(request) + request_spec.pci_requests = new_pci_requests + # TODO(huaqiang): Remove in Wallaby # check nova-compute nodes have been updated to Victoria to resize # instance to a new mixed instance from a dedicated or shared diff --git a/nova/tests/functional/libvirt/test_pci_sriov_servers.py b/nova/tests/functional/libvirt/test_pci_sriov_servers.py index c8add15480..6e5165134b 100644 --- a/nova/tests/functional/libvirt/test_pci_sriov_servers.py +++ b/nova/tests/functional/libvirt/test_pci_sriov_servers.py @@ -1733,13 +1733,16 @@ class PCIServersTest(_PCIServersTestBase): # Resize it to a flavor without PCI devices. We expect this to work, as # test_compute1 is available. - # FIXME(artom) This is bug 1941005. flavor_id = self._create_flavor() - ex = self.assertRaises(client.OpenStackApiException, - self._resize_server, server, flavor_id) - self.assertEqual(500, ex.response.status_code) - self.assertIn('NoValidHost', str(ex)) - # self._confirm_resize(server) + with mock.patch( + 'nova.virt.libvirt.driver.LibvirtDriver' + '.migrate_disk_and_power_off', + return_value='{}', + ): + self._resize_server(server, flavor_id) + self._confirm_resize(server) + self.assertPCIDeviceCounts('test_compute0', total=1, free=1) + self.assertPCIDeviceCounts('test_compute1', total=0, free=0) def _confirm_resize(self, server, host='host1'): # NOTE(sbauza): Unfortunately, _cleanup_resize() in libvirt checks the diff --git a/nova/tests/functional/regressions/test_bug_1983753.py b/nova/tests/functional/regressions/test_bug_1983753.py index a11ea8dc63..78499335ec 100644 --- a/nova/tests/functional/regressions/test_bug_1983753.py +++ b/nova/tests/functional/regressions/test_bug_1983753.py @@ -16,7 +16,6 @@ import fixtures from oslo_serialization import jsonutils from nova.tests.fixtures import libvirt as fakelibvirt -from nova.tests.functional.api import client from nova.tests.functional.libvirt import test_pci_sriov_servers @@ -119,19 +118,10 @@ class TestPciResize(test_pci_sriov_servers._PCIServersTestBase): "compute2", total=num_pci_on_dest, free=num_pci_on_dest - 1) def test_resize_from_two_devs_to_one_dev_dest_has_two_devs(self): - # this works self._test_resize_from_two_devs_to_one_dev(num_pci_on_dest=2) def test_resize_from_two_devs_to_one_dev_dest_has_one_dev(self): - # This is bug 1983753 as nova uses the old InstancePciRequest during - # the scheduling and therefore tries to find a compute with two PCI - # devs even though the flavor only requests one. - ex = self.assertRaises( - client.OpenStackApiException, - self._test_resize_from_two_devs_to_one_dev, - num_pci_on_dest=1 - ) - self.assertIn('nova.exception.NoValidHost', str(ex)) + self._test_resize_from_two_devs_to_one_dev(num_pci_on_dest=1) def test_resize_from_vf_to_pf(self): # The fake libvirt will emulate on the host: @@ -181,13 +171,7 @@ class TestPciResize(test_pci_sriov_servers._PCIServersTestBase): # dev. This should fit to compute2 having exactly one PF dev. extra_spec = {"pci_passthrough:alias": "a-pf:1"} flavor_id = self._create_flavor(extra_spec=extra_spec) - # This is bug 1983753 as nova uses the old InstancePciRequest during - # the scheduling and therefore tries to find a compute with a VF dev - # even though the flavor only requests a PF dev. - ex = self.assertRaises( - client.OpenStackApiException, - self._resize_server, - server, - flavor_id=flavor_id, - ) - self.assertIn('nova.exception.NoValidHost', str(ex)) + self._resize_server(server, flavor_id=flavor_id) + self._confirm_resize(server) + self.assertPCIDeviceCounts("compute1", total=1, free=1) + self.assertPCIDeviceCounts("compute2", total=1, free=0) diff --git a/nova/tests/unit/compute/test_api.py b/nova/tests/unit/compute/test_api.py index 135b9442c0..390dece66d 100644 --- a/nova/tests/unit/compute/test_api.py +++ b/nova/tests/unit/compute/test_api.py @@ -2088,7 +2088,8 @@ class _ComputeAPIUnitTestMixIn(object): filter_properties = {'ignore_hosts': [fake_inst['host']]} if request_spec: - fake_spec = objects.RequestSpec() + fake_spec = objects.RequestSpec( + pci_requests=objects.InstancePCIRequests(requests=[])) if requested_destination: cell1 = objects.CellMapping(uuid=uuids.cell1, name='cell1') fake_spec.requested_destination = objects.Destination( |