Skip to content

Commit f766db2

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Query ports with admin client to get resource_request" into stable/xena
2 parents 82ceb6b + d960c24 commit f766db2

File tree

5 files changed

+55
-72
lines changed

5 files changed

+55
-72
lines changed

nova/compute/api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5141,7 +5141,11 @@ def attach_interface(self, context, instance, network_id, port_id,
51415141
context, instance, instance_actions.ATTACH_INTERFACE)
51425142

51435143
if port_id:
5144-
port = self.network_api.show_port(context, port_id)['port']
5144+
# We need to query the port with admin context as
5145+
# ensure_compute_version_for_resource_request depends on the
5146+
# port.resource_request field which only returned for admins
5147+
port = self.network_api.show_port(
5148+
context.elevated(), port_id)['port']
51455149
if port.get('binding:vnic_type', "normal") == "vdpa":
51465150
# FIXME(sean-k-mooney): Attach works but detach results in a
51475151
# QEMU error; blocked until this is resolved

nova/network/neutron.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,11 @@ def get_binding_profile_allocation(
10461046
of request group id: resource provider UUID mapping if the port has
10471047
an extended resource request.
10481048
"""
1049+
# We need to use an admin client as the port.resource_request is admin
1050+
# only
1051+
neutron_admin = get_client(context, admin=True)
10491052
neutron = get_client(context)
1050-
port = self._show_port(context, port_id, neutron_client=neutron)
1053+
port = self._show_port(context, port_id, neutron_client=neutron_admin)
10511054
if self._has_resource_request(context, port, neutron):
10521055
return self._get_binding_profile_allocation(
10531056
context, port, neutron, resource_provider_mapping)
@@ -1724,12 +1727,15 @@ def deallocate_port_for_instance(self, context, instance, port_id):
17241727
Note that right now this dict only contains a single key as a
17251728
neutron port only allocates from a single resource provider.
17261729
"""
1730+
# We need to use an admin client as the port.resource_request is admin
1731+
# only
1732+
neutron_admin = get_client(context, admin=True)
17271733
neutron = get_client(context)
17281734
port_allocation: ty.Dict = {}
17291735
try:
17301736
# NOTE(gibi): we need to read the port resource information from
17311737
# neutron here as we might delete the port below
1732-
port = neutron.show_port(port_id)['port']
1738+
port = neutron_admin.show_port(port_id)['port']
17331739
except exception.PortNotFound:
17341740
LOG.debug('Unable to determine port %s resource allocation '
17351741
'information as the port no longer exists.', port_id)

nova/tests/functional/test_servers_resource_request.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import copy
1616
import logging
17-
import unittest
1817

1918
from keystoneauth1 import adapter
2019
import mock
@@ -821,11 +820,6 @@ def setUp(self):
821820
'os_compute_api:os-evacuate': '@',
822821
})
823822

824-
# this is bug 1945310
825-
@unittest.expectedFailure
826-
def test_interface_attach_with_resource_request_old_compute(self):
827-
super().test_interface_attach_with_resource_request_old_compute()
828-
829823

830824
class PortResourceRequestBasedSchedulingTest(
831825
PortResourceRequestBasedSchedulingTestBase):
@@ -1529,11 +1523,6 @@ def setUp(self):
15291523
'os_compute_api:os-services:list': '@',
15301524
})
15311525

1532-
# this is bug 1945310
1533-
@unittest.expectedFailure
1534-
def test_interface_detach_with_port_with_bandwidth_request(self):
1535-
super().test_interface_detach_with_port_with_bandwidth_request()
1536-
15371526

15381527
class ExtendedPortResourceRequestBasedSchedulingTestBase(
15391528
PortResourceRequestBasedSchedulingTestBase):
@@ -1680,11 +1669,6 @@ def setUp(self):
16801669
'os_compute_api:os-services:list': '@',
16811670
})
16821671

1683-
# this is bug 1945310
1684-
@unittest.expectedFailure
1685-
def test_interface_detach_with_port_with_bandwidth_request(self):
1686-
super().test_interface_detach_with_port_with_bandwidth_request()
1687-
16881672

16891673
class ServerMoveWithPortResourceRequestTest(
16901674
PortResourceRequestBasedSchedulingTestBase):
@@ -2650,23 +2634,6 @@ def setUp(self):
26502634
'os_compute_api:os-instance-actions:list': '@',
26512635
})
26522636

2653-
# this is bug 1945310
2654-
@unittest.expectedFailure
2655-
def test_live_migrate_with_qos_port(self, host=None):
2656-
super().test_live_migrate_with_qos_port()
2657-
2658-
# this is bug 1945310
2659-
@unittest.expectedFailure
2660-
def test_live_migrate_with_qos_port_with_target_host(self):
2661-
super(
2662-
).test_live_migrate_with_qos_port_with_target_host()
2663-
2664-
# this is bug 1945310
2665-
@unittest.expectedFailure
2666-
def test_live_migrate_with_qos_port_reschedule_success(self):
2667-
super(
2668-
).test_live_migrate_with_qos_port_reschedule_success()
2669-
26702637

26712638
class ServerMoveWithMultiGroupResourceRequestBasedSchedulingTest(
26722639
ExtendedPortResourceRequestBasedSchedulingTestBase,
@@ -2717,23 +2684,6 @@ def setUp(self):
27172684
'os_compute_api:os-instance-actions:list': '@',
27182685
})
27192686

2720-
# this is bug 1945310
2721-
@unittest.expectedFailure
2722-
def test_live_migrate_with_qos_port(self, host=None):
2723-
super().test_live_migrate_with_qos_port()
2724-
2725-
# this is bug 1945310
2726-
@unittest.expectedFailure
2727-
def test_live_migrate_with_qos_port_with_target_host(self):
2728-
super(
2729-
).test_live_migrate_with_qos_port_with_target_host()
2730-
2731-
# this is bug 1945310
2732-
@unittest.expectedFailure
2733-
def test_live_migrate_with_qos_port_reschedule_success(self):
2734-
super(
2735-
).test_live_migrate_with_qos_port_reschedule_success()
2736-
27372687

27382688
class LiveMigrateAbortWithPortResourceRequestTest(
27392689
PortResourceRequestBasedSchedulingTestBase):
@@ -3153,8 +3103,3 @@ def setUp(self):
31533103
'os_compute_api:servers:resize': '@',
31543104
'os_compute_api:os-evacuate': '@',
31553105
})
3156-
3157-
# this is bug 1945310
3158-
@unittest.expectedFailure
3159-
def test_interface_attach(self, mock_get_service):
3160-
super().test_interface_attach()

nova/tests/unit/compute/test_api.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7267,6 +7267,10 @@ def test_tagged_interface_attach(self, mock_attach, mock_record):
72677267
mock_record.assert_called_once_with(
72687268
self.context, instance, instance_actions.ATTACH_INTERFACE)
72697269

7270+
@mock.patch(
7271+
'nova.context.RequestContext.elevated',
7272+
new=mock.Mock(return_value=mock.sentinel.admin_context)
7273+
)
72707274
@mock.patch(
72717275
'nova.network.neutron.API.has_extended_resource_request_extension',
72727276
new=mock.Mock(return_value=False),
@@ -7292,10 +7296,15 @@ def test_attach_interface_qos_aware_port_old_compute(
72927296
self.context, instance,
72937297
'foo_net_id', 'foo_port_id', None
72947298
)
7295-
mock_show_port.assert_called_once_with(self.context, 'foo_port_id')
7299+
mock_show_port.assert_called_once_with(
7300+
mock.sentinel.admin_context, 'foo_port_id')
72967301
mock_get_service.assert_called_once_with(
72977302
self.context, instance.host, 'nova-compute')
72987303

7304+
@mock.patch(
7305+
'nova.context.RequestContext.elevated',
7306+
new=mock.Mock(return_value=mock.sentinel.admin_context)
7307+
)
72997308
@mock.patch(
73007309
'nova.network.neutron.API.has_extended_resource_request_extension',
73017310
new=mock.Mock(return_value=False)
@@ -7326,14 +7335,18 @@ def test_attach_interface_qos_aware_port(
73267335
mock.sentinel.port_id, mock.sentinel.ip, mock.sentinel.tag)
73277336

73287337
mock_show_port.assert_called_once_with(
7329-
self.context, mock.sentinel.port_id)
7338+
mock.sentinel.admin_context, mock.sentinel.port_id)
73307339
mock_get_service.assert_called_once_with(
73317340
self.context, instance.host, 'nova-compute')
73327341
mock_attach.assert_called_once_with(
73337342
self.context, instance=instance, network_id=mock.sentinel.net_id,
73347343
port_id=mock.sentinel.port_id, requested_ip=mock.sentinel.ip,
73357344
tag=mock.sentinel.tag)
73367345

7346+
@mock.patch(
7347+
'nova.context.RequestContext.elevated',
7348+
new=mock.Mock(return_value=mock.sentinel.admin_context)
7349+
)
73377350
@mock.patch(
73387351
'nova.network.neutron.API.has_extended_resource_request_extension',
73397352
new=mock.Mock(return_value=True),
@@ -7367,10 +7380,15 @@ def test_attach_interface_extended_qos_port_old_compute(
73677380
self.context, instance,
73687381
'foo_net_id', 'foo_port_id', None
73697382
)
7370-
mock_show_port.assert_called_once_with(self.context, 'foo_port_id')
7383+
mock_show_port.assert_called_once_with(
7384+
mock.sentinel.admin_context, 'foo_port_id')
73717385
mock_get_service.assert_called_once_with(
73727386
self.context, instance.host, 'nova-compute')
73737387

7388+
@mock.patch(
7389+
'nova.context.RequestContext.elevated',
7390+
new=mock.Mock(return_value=mock.sentinel.admin_context)
7391+
)
73747392
@mock.patch(
73757393
'nova.network.neutron.API.has_extended_resource_request_extension',
73767394
new=mock.Mock(return_value=True)
@@ -7404,7 +7422,7 @@ def test_attach_interface_extended_qos_port(
74047422
mock.sentinel.port_id, mock.sentinel.ip, mock.sentinel.tag)
74057423

74067424
mock_show_port.assert_called_once_with(
7407-
self.context, mock.sentinel.port_id)
7425+
mock.sentinel.admin_context, mock.sentinel.port_id)
74087426
mock_get_service.assert_called_once_with(
74097427
self.context, instance.host, 'nova-compute')
74107428
mock_attach.assert_called_once_with(

nova/tests/unit/network/test_neutron.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,9 @@ def _test_deallocate_port_for_instance(self, number, mock_get_client,
17501750
mocked_client.delete_port.assert_called_once_with(port_data[0]['id'])
17511751
mocked_client.show_port.assert_called_once_with(port_data[0]['id'])
17521752
expected_get_client_calls = [
1753-
mock.call(self.context), mock.call(self.context, admin=True)]
1753+
mock.call(self.context, admin=True),
1754+
mock.call(self.context, admin=True),
1755+
]
17541756
if number == 2:
17551757
expected_get_client_calls.append(mock.call(self.context,
17561758
admin=True))
@@ -7146,25 +7148,33 @@ def test__has_resource_request(self, mock_has_extended_res_req):
71467148
"nova.network.neutron.API.has_extended_resource_request_extension",
71477149
new=mock.Mock(return_value=False),
71487150
)
7149-
@mock.patch("neutronclient.v2_0.client.Client.show_port")
7150-
def test_get_binding_profile_allocation_no_request(self, mock_show_port):
7151-
mock_show_port.return_value = {
7151+
@mock.patch("nova.network.neutron.get_client")
7152+
def test_get_binding_profile_allocation_no_request(
7153+
self, mock_get_client
7154+
):
7155+
mock_get_client.return_value.show_port.return_value = {
71527156
"port": {
71537157
}
71547158
}
71557159
self.assertIsNone(
71567160
self.api.get_binding_profile_allocation(
71577161
self.context, uuids.port_uuid, {}))
7162+
mock_get_client.assert_has_calls(
7163+
[
7164+
mock.call(self.context, admin=True),
7165+
mock.call(self.context),
7166+
]
7167+
)
71587168

71597169
@mock.patch(
71607170
"nova.network.neutron.API.has_extended_resource_request_extension",
71617171
new=mock.Mock(return_value=False),
71627172
)
7163-
@mock.patch("neutronclient.v2_0.client.Client.show_port")
7173+
@mock.patch("nova.network.neutron.get_client")
71647174
def test_get_binding_profile_allocation_legacy_request(
7165-
self, mock_show_port
7175+
self, mock_get_client
71667176
):
7167-
mock_show_port.return_value = {
7177+
mock_get_client.return_value.show_port.return_value = {
71687178
"port": {
71697179
"id": uuids.port_uuid,
71707180
"resource_request": {
@@ -7188,11 +7198,11 @@ def test_get_binding_profile_allocation_legacy_request(
71887198
"nova.network.neutron.API.has_extended_resource_request_extension",
71897199
new=mock.Mock(return_value=True),
71907200
)
7191-
@mock.patch("neutronclient.v2_0.client.Client.show_port")
7201+
@mock.patch("nova.network.neutron.get_client")
71927202
def test_get_binding_profile_allocation_extended_request(
7193-
self, mock_show_port
7203+
self, mock_get_client
71947204
):
7195-
mock_show_port.return_value = {
7205+
mock_get_client.return_value.show_port.return_value = {
71967206
"port": {
71977207
"id": uuids.port_uuid,
71987208
"resource_request": {

0 commit comments

Comments
 (0)