Skip to content

Commit 6dbe7b7

Browse files
andrewbonneysbauza
authored andcommitted
Fix segment-aware scheduling permissions error
Resolves a bug encountered when setting the Nova scheduler to be aware of Neutron routed provider network segments, by using 'query_placement_for_routed_network_aggregates'. Non-admin users attempting to access the 'segment_id' attribute of a subnet caused a traceback, resulting in instance creation failure. This patch ensures the Neutron client is initialised with an administrative context no matter what the requesting user's permissions are. Change-Id: Ic0f25e4d2395560fc2b68f3b469e266ac59abaa2 Closes-Bug: #1970383 (cherry picked from commit ee32934) (cherry picked from commit 60548e8) (cherry picked from commit 28f94eb)
1 parent 4a5158e commit 6dbe7b7

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

nova/network/neutron.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3567,7 +3567,7 @@ def get_segment_ids_for_network(
35673567
if not self._has_segment_extension(context):
35683568
return []
35693569

3570-
client = get_client(context)
3570+
client = get_client(context, admin=True)
35713571
try:
35723572
# NOTE(sbauza): We can't use list_segments() directly because the
35733573
# API is borked and returns both segments but also segmentation IDs
@@ -3597,7 +3597,7 @@ def get_segment_id_for_subnet(
35973597
if not self._has_segment_extension(context):
35983598
return None
35993599

3600-
client = get_client(context)
3600+
client = get_client(context, admin=True)
36013601
try:
36023602
subnet = client.show_subnet(subnet_id)['subnet']
36033603
except neutron_client_exc.NeutronClientException as e:

nova/tests/unit/network/test_neutron.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6323,6 +6323,7 @@ def test_get_segment_ids_for_network_passes(self, mock_client):
63236323
res = self.api.get_segment_ids_for_network(
63246324
self.context, uuids.network_id)
63256325
self.assertEqual([uuids.segment_id], res)
6326+
mock_client.assert_called_once_with(self.context, admin=True)
63266327
mocked_client.list_subnets.assert_called_once_with(
63276328
network_id=uuids.network_id, fields='segment_id')
63286329

@@ -6338,6 +6339,7 @@ def test_get_segment_ids_for_network_with_no_segments(self, mock_client):
63386339
res = self.api.get_segment_ids_for_network(
63396340
self.context, uuids.network_id)
63406341
self.assertEqual([], res)
6342+
mock_client.assert_called_once_with(self.context, admin=True)
63416343
mocked_client.list_subnets.assert_called_once_with(
63426344
network_id=uuids.network_id, fields='segment_id')
63436345

@@ -6353,6 +6355,7 @@ def test_get_segment_ids_for_network_fails(self, mock_client):
63536355
self.assertRaises(exception.InvalidRoutedNetworkConfiguration,
63546356
self.api.get_segment_ids_for_network,
63556357
self.context, uuids.network_id)
6358+
mock_client.assert_called_once_with(self.context, admin=True)
63566359

63576360
def test_get_segment_id_for_subnet_no_segment_ext(self):
63586361
with mock.patch.object(
@@ -6374,6 +6377,7 @@ def test_get_segment_id_for_subnet_passes(self, mock_client):
63746377
res = self.api.get_segment_id_for_subnet(
63756378
self.context, uuids.subnet_id)
63766379
self.assertEqual(uuids.segment_id, res)
6380+
mock_client.assert_called_once_with(self.context, admin=True)
63776381
mocked_client.show_subnet.assert_called_once_with(uuids.subnet_id)
63786382

63796383
@mock.patch.object(neutronapi, 'get_client')
@@ -6388,6 +6392,7 @@ def test_get_segment_id_for_subnet_with_no_segment(self, mock_client):
63886392
self.assertIsNone(
63896393
self.api.get_segment_id_for_subnet(self.context,
63906394
uuids.subnet_id))
6395+
mock_client.assert_called_once_with(self.context, admin=True)
63916396

63926397
@mock.patch.object(neutronapi, 'get_client')
63936398
def test_get_segment_id_for_subnet_fails(self, mock_client):
@@ -6401,6 +6406,7 @@ def test_get_segment_id_for_subnet_fails(self, mock_client):
64016406
self.assertRaises(exception.InvalidRoutedNetworkConfiguration,
64026407
self.api.get_segment_id_for_subnet,
64036408
self.context, uuids.subnet_id)
6409+
mock_client.assert_called_once_with(self.context, admin=True)
64046410

64056411
@mock.patch.object(neutronapi.LOG, 'debug')
64066412
def test_get_port_pci_slot(self, mock_debug):
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
fixes:
3+
- |
4+
`Bug #1970383 <https://bugs.launchpad.net/nova/+bug/1970383>`_: Fixes a
5+
permissions error when using the
6+
'query_placement_for_routed_network_aggregates' scheduler variable, which
7+
caused a traceback on instance creation for non-admin users.

0 commit comments

Comments
 (0)