Merge "Query ports with admin client to get resource_request"
This commit is contained in:
commit
4bed410ce6
|
@ -5141,7 +5141,11 @@ class API:
|
|||
context, instance, instance_actions.ATTACH_INTERFACE)
|
||||
|
||||
if port_id:
|
||||
port = self.network_api.show_port(context, port_id)['port']
|
||||
# We need to query the port with admin context as
|
||||
# ensure_compute_version_for_resource_request depends on the
|
||||
# port.resource_request field which only returned for admins
|
||||
port = self.network_api.show_port(
|
||||
context.elevated(), port_id)['port']
|
||||
if port.get('binding:vnic_type', "normal") == "vdpa":
|
||||
# FIXME(sean-k-mooney): Attach works but detach results in a
|
||||
# QEMU error; blocked until this is resolved
|
||||
|
|
|
@ -1046,8 +1046,11 @@ class API:
|
|||
of request group id: resource provider UUID mapping if the port has
|
||||
an extended resource request.
|
||||
"""
|
||||
# We need to use an admin client as the port.resource_request is admin
|
||||
# only
|
||||
neutron_admin = get_client(context, admin=True)
|
||||
neutron = get_client(context)
|
||||
port = self._show_port(context, port_id, neutron_client=neutron)
|
||||
port = self._show_port(context, port_id, neutron_client=neutron_admin)
|
||||
if self._has_resource_request(context, port, neutron):
|
||||
return self._get_binding_profile_allocation(
|
||||
context, port, neutron, resource_provider_mapping)
|
||||
|
@ -1724,12 +1727,15 @@ class API:
|
|||
Note that right now this dict only contains a single key as a
|
||||
neutron port only allocates from a single resource provider.
|
||||
"""
|
||||
# We need to use an admin client as the port.resource_request is admin
|
||||
# only
|
||||
neutron_admin = get_client(context, admin=True)
|
||||
neutron = get_client(context)
|
||||
port_allocation: ty.Dict = {}
|
||||
try:
|
||||
# NOTE(gibi): we need to read the port resource information from
|
||||
# neutron here as we might delete the port below
|
||||
port = neutron.show_port(port_id)['port']
|
||||
port = neutron_admin.show_port(port_id)['port']
|
||||
except exception.PortNotFound:
|
||||
LOG.debug('Unable to determine port %s resource allocation '
|
||||
'information as the port no longer exists.', port_id)
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
import copy
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
from keystoneauth1 import adapter
|
||||
import mock
|
||||
|
@ -821,11 +820,6 @@ class NonAdminUnsupportedPortResourceRequestBasedSchedulingTest(
|
|||
'os_compute_api:os-evacuate': '@',
|
||||
})
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_interface_attach_with_resource_request_old_compute(self):
|
||||
super().test_interface_attach_with_resource_request_old_compute()
|
||||
|
||||
|
||||
class PortResourceRequestBasedSchedulingTest(
|
||||
PortResourceRequestBasedSchedulingTestBase):
|
||||
|
@ -1529,11 +1523,6 @@ class NonAdminPortResourceRequestTests(
|
|||
'os_compute_api:os-services:list': '@',
|
||||
})
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_interface_detach_with_port_with_bandwidth_request(self):
|
||||
super().test_interface_detach_with_port_with_bandwidth_request()
|
||||
|
||||
|
||||
class ExtendedPortResourceRequestBasedSchedulingTestBase(
|
||||
PortResourceRequestBasedSchedulingTestBase):
|
||||
|
@ -1680,11 +1669,6 @@ class NonAdminMultiGroupResReqTests(
|
|||
'os_compute_api:os-services:list': '@',
|
||||
})
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_interface_detach_with_port_with_bandwidth_request(self):
|
||||
super().test_interface_detach_with_port_with_bandwidth_request()
|
||||
|
||||
|
||||
class ServerMoveWithPortResourceRequestTest(
|
||||
PortResourceRequestBasedSchedulingTestBase):
|
||||
|
@ -2650,23 +2634,6 @@ class NonAdminServerMoveWithPortResourceRequestTests(
|
|||
'os_compute_api:os-instance-actions:list': '@',
|
||||
})
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_live_migrate_with_qos_port(self, host=None):
|
||||
super().test_live_migrate_with_qos_port()
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_live_migrate_with_qos_port_with_target_host(self):
|
||||
super(
|
||||
).test_live_migrate_with_qos_port_with_target_host()
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_live_migrate_with_qos_port_reschedule_success(self):
|
||||
super(
|
||||
).test_live_migrate_with_qos_port_reschedule_success()
|
||||
|
||||
|
||||
class ServerMoveWithMultiGroupResourceRequestBasedSchedulingTest(
|
||||
ExtendedPortResourceRequestBasedSchedulingTestBase,
|
||||
|
@ -2717,23 +2684,6 @@ class NonAdminServerMoveWithMultiGroupResReqTests(
|
|||
'os_compute_api:os-instance-actions:list': '@',
|
||||
})
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_live_migrate_with_qos_port(self, host=None):
|
||||
super().test_live_migrate_with_qos_port()
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_live_migrate_with_qos_port_with_target_host(self):
|
||||
super(
|
||||
).test_live_migrate_with_qos_port_with_target_host()
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_live_migrate_with_qos_port_reschedule_success(self):
|
||||
super(
|
||||
).test_live_migrate_with_qos_port_reschedule_success()
|
||||
|
||||
|
||||
class LiveMigrateAbortWithPortResourceRequestTest(
|
||||
PortResourceRequestBasedSchedulingTestBase):
|
||||
|
@ -3153,8 +3103,3 @@ class NonAdminExtendedResourceRequestOldCompute(
|
|||
'os_compute_api:servers:resize': '@',
|
||||
'os_compute_api:os-evacuate': '@',
|
||||
})
|
||||
|
||||
# this is bug 1945310
|
||||
@unittest.expectedFailure
|
||||
def test_interface_attach(self, mock_get_service):
|
||||
super().test_interface_attach()
|
||||
|
|
|
@ -7267,6 +7267,10 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase):
|
|||
mock_record.assert_called_once_with(
|
||||
self.context, instance, instance_actions.ATTACH_INTERFACE)
|
||||
|
||||
@mock.patch(
|
||||
'nova.context.RequestContext.elevated',
|
||||
new=mock.Mock(return_value=mock.sentinel.admin_context)
|
||||
)
|
||||
@mock.patch(
|
||||
'nova.network.neutron.API.has_extended_resource_request_extension',
|
||||
new=mock.Mock(return_value=False),
|
||||
|
@ -7292,10 +7296,15 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase):
|
|||
self.context, instance,
|
||||
'foo_net_id', 'foo_port_id', None
|
||||
)
|
||||
mock_show_port.assert_called_once_with(self.context, 'foo_port_id')
|
||||
mock_show_port.assert_called_once_with(
|
||||
mock.sentinel.admin_context, 'foo_port_id')
|
||||
mock_get_service.assert_called_once_with(
|
||||
self.context, instance.host, 'nova-compute')
|
||||
|
||||
@mock.patch(
|
||||
'nova.context.RequestContext.elevated',
|
||||
new=mock.Mock(return_value=mock.sentinel.admin_context)
|
||||
)
|
||||
@mock.patch(
|
||||
'nova.network.neutron.API.has_extended_resource_request_extension',
|
||||
new=mock.Mock(return_value=False)
|
||||
|
@ -7326,7 +7335,7 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase):
|
|||
mock.sentinel.port_id, mock.sentinel.ip, mock.sentinel.tag)
|
||||
|
||||
mock_show_port.assert_called_once_with(
|
||||
self.context, mock.sentinel.port_id)
|
||||
mock.sentinel.admin_context, mock.sentinel.port_id)
|
||||
mock_get_service.assert_called_once_with(
|
||||
self.context, instance.host, 'nova-compute')
|
||||
mock_attach.assert_called_once_with(
|
||||
|
@ -7334,6 +7343,10 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase):
|
|||
port_id=mock.sentinel.port_id, requested_ip=mock.sentinel.ip,
|
||||
tag=mock.sentinel.tag)
|
||||
|
||||
@mock.patch(
|
||||
'nova.context.RequestContext.elevated',
|
||||
new=mock.Mock(return_value=mock.sentinel.admin_context)
|
||||
)
|
||||
@mock.patch(
|
||||
'nova.network.neutron.API.has_extended_resource_request_extension',
|
||||
new=mock.Mock(return_value=True),
|
||||
|
@ -7367,10 +7380,15 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase):
|
|||
self.context, instance,
|
||||
'foo_net_id', 'foo_port_id', None
|
||||
)
|
||||
mock_show_port.assert_called_once_with(self.context, 'foo_port_id')
|
||||
mock_show_port.assert_called_once_with(
|
||||
mock.sentinel.admin_context, 'foo_port_id')
|
||||
mock_get_service.assert_called_once_with(
|
||||
self.context, instance.host, 'nova-compute')
|
||||
|
||||
@mock.patch(
|
||||
'nova.context.RequestContext.elevated',
|
||||
new=mock.Mock(return_value=mock.sentinel.admin_context)
|
||||
)
|
||||
@mock.patch(
|
||||
'nova.network.neutron.API.has_extended_resource_request_extension',
|
||||
new=mock.Mock(return_value=True)
|
||||
|
@ -7404,7 +7422,7 @@ class ComputeAPIUnitTestCase(_ComputeAPIUnitTestMixIn, test.NoDBTestCase):
|
|||
mock.sentinel.port_id, mock.sentinel.ip, mock.sentinel.tag)
|
||||
|
||||
mock_show_port.assert_called_once_with(
|
||||
self.context, mock.sentinel.port_id)
|
||||
mock.sentinel.admin_context, mock.sentinel.port_id)
|
||||
mock_get_service.assert_called_once_with(
|
||||
self.context, instance.host, 'nova-compute')
|
||||
mock_attach.assert_called_once_with(
|
||||
|
|
|
@ -1750,7 +1750,9 @@ class TestAPI(TestAPIBase):
|
|||
mocked_client.delete_port.assert_called_once_with(port_data[0]['id'])
|
||||
mocked_client.show_port.assert_called_once_with(port_data[0]['id'])
|
||||
expected_get_client_calls = [
|
||||
mock.call(self.context), mock.call(self.context, admin=True)]
|
||||
mock.call(self.context, admin=True),
|
||||
mock.call(self.context, admin=True),
|
||||
]
|
||||
if number == 2:
|
||||
expected_get_client_calls.append(mock.call(self.context,
|
||||
admin=True))
|
||||
|
@ -7146,25 +7148,33 @@ class TestAPI(TestAPIBase):
|
|||
"nova.network.neutron.API.has_extended_resource_request_extension",
|
||||
new=mock.Mock(return_value=False),
|
||||
)
|
||||
@mock.patch("neutronclient.v2_0.client.Client.show_port")
|
||||
def test_get_binding_profile_allocation_no_request(self, mock_show_port):
|
||||
mock_show_port.return_value = {
|
||||
@mock.patch("nova.network.neutron.get_client")
|
||||
def test_get_binding_profile_allocation_no_request(
|
||||
self, mock_get_client
|
||||
):
|
||||
mock_get_client.return_value.show_port.return_value = {
|
||||
"port": {
|
||||
}
|
||||
}
|
||||
self.assertIsNone(
|
||||
self.api.get_binding_profile_allocation(
|
||||
self.context, uuids.port_uuid, {}))
|
||||
mock_get_client.assert_has_calls(
|
||||
[
|
||||
mock.call(self.context, admin=True),
|
||||
mock.call(self.context),
|
||||
]
|
||||
)
|
||||
|
||||
@mock.patch(
|
||||
"nova.network.neutron.API.has_extended_resource_request_extension",
|
||||
new=mock.Mock(return_value=False),
|
||||
)
|
||||
@mock.patch("neutronclient.v2_0.client.Client.show_port")
|
||||
@mock.patch("nova.network.neutron.get_client")
|
||||
def test_get_binding_profile_allocation_legacy_request(
|
||||
self, mock_show_port
|
||||
self, mock_get_client
|
||||
):
|
||||
mock_show_port.return_value = {
|
||||
mock_get_client.return_value.show_port.return_value = {
|
||||
"port": {
|
||||
"id": uuids.port_uuid,
|
||||
"resource_request": {
|
||||
|
@ -7188,11 +7198,11 @@ class TestAPI(TestAPIBase):
|
|||
"nova.network.neutron.API.has_extended_resource_request_extension",
|
||||
new=mock.Mock(return_value=True),
|
||||
)
|
||||
@mock.patch("neutronclient.v2_0.client.Client.show_port")
|
||||
@mock.patch("nova.network.neutron.get_client")
|
||||
def test_get_binding_profile_allocation_extended_request(
|
||||
self, mock_show_port
|
||||
self, mock_get_client
|
||||
):
|
||||
mock_show_port.return_value = {
|
||||
mock_get_client.return_value.show_port.return_value = {
|
||||
"port": {
|
||||
"id": uuids.port_uuid,
|
||||
"resource_request": {
|
||||
|
|
Loading…
Reference in New Issue