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 38a214466f)
This commit is contained in:
Balazs Gibizer 2019-10-24 17:31:45 +02:00
parent b6989836dd
commit c7a43d3427
2 changed files with 7 additions and 1 deletions

View File

@ -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'])

View File

@ -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):