From c7a43d342735c93ef33208af9de06ce2d743e477 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Thu, 24 Oct 2019 17:31:45 +0200 Subject: [PATCH] Use admin neutron client to gather port resource requests The network_api get_requested_resource_for_instance() creates a neutron client with the current request context and uses the client to query neutron ports. Neutron does not return the resource_request of the neutron port if it is queried by a non-admin. So if the request context was a non admin context nova thought that none of the ports have resource requests. This patch ensures that an admin client is used to query the ports. Change-Id: I1178fb77a74010c3b9f51eea22c7e7576b600015 Closes-Bug: #1849695 (cherry picked from commit 38a214466fa2cccc3808ca6d7d7140cf56f733ba) --- nova/network/neutronv2/api.py | 6 +++++- nova/tests/unit/network/test_neutronv2.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nova/network/neutronv2/api.py b/nova/network/neutronv2/api.py index c548e6bbf3b4..e26da18a0d16 100644 --- a/nova/network/neutronv2/api.py +++ b/nova/network/neutronv2/api.py @@ -2231,7 +2231,11 @@ class API(base_api.NetworkAPI): :return: A list of RequestGroup objects """ - neutron = get_client(context) + # NOTE(gibi): We need to use an admin client as otherwise a non admin + # initiated resize causes that neutron does not fill the + # resource_request field of the port and this will lead to resource + # allocation issues. See bug 1849695 + neutron = get_client(context, admin=True) # get the ports associated to this instance data = neutron.list_ports( device_id=instance_uuid, fields=['id', 'resource_request']) diff --git a/nova/tests/unit/network/test_neutronv2.py b/nova/tests/unit/network/test_neutronv2.py index 2174746beb37..6a33e9ff042f 100644 --- a/nova/tests/unit/network/test_neutronv2.py +++ b/nova/tests/unit/network/test_neutronv2.py @@ -6151,6 +6151,8 @@ class TestNeutronv2WithMock(TestNeutronv2Base): uuids.port1, request_groups[0].requester_id) + mock_get_client.assert_called_once_with(self.context, admin=True) + class TestNeutronv2ModuleMethods(test.NoDBTestCase):