Skip to content

Commit 8882902

Browse files
authored
Merge pull request #52 from stackhpc/upstream/wallaby-2023-08-07
Synchronise wallaby with upstream
2 parents d70c81d + 4aaeae3 commit 8882902

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

nova/network/neutron.py

Lines changed: 3 additions & 3 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
@@ -3579,7 +3579,7 @@ def get_segment_ids_for_network(
35793579
'Failed to get segment IDs for network %s' % network_id) from e
35803580
# The segment field of an unconfigured subnet could be None
35813581
return [subnet['segment_id'] for subnet in subnets
3582-
if subnet['segment_id'] is not None]
3582+
if subnet.get('segment_id') is not None]
35833583

35843584
def get_segment_id_for_subnet(
35853585
self,
@@ -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: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6323,11 +6323,12 @@ 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

63296330
@mock.patch.object(neutronapi, 'get_client')
6330-
def test_get_segment_ids_for_network_with_no_segments(self, mock_client):
6331+
def test_get_segment_ids_for_network_with_segments_none(self, mock_client):
63316332
subnets = {'subnets': [{'segment_id': None}]}
63326333
mocked_client = mock.create_autospec(client.Client)
63336334
mock_client.return_value = mocked_client
@@ -6338,6 +6339,23 @@ 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)
6343+
mocked_client.list_subnets.assert_called_once_with(
6344+
network_id=uuids.network_id, fields='segment_id')
6345+
6346+
@mock.patch.object(neutronapi, 'get_client')
6347+
def test_get_segment_ids_for_network_with_no_segments(self, mock_client):
6348+
subnets = {'subnets': [{}]}
6349+
mocked_client = mock.create_autospec(client.Client)
6350+
mock_client.return_value = mocked_client
6351+
mocked_client.list_subnets.return_value = subnets
6352+
with mock.patch.object(
6353+
self.api, '_has_segment_extension', return_value=True,
6354+
):
6355+
res = self.api.get_segment_ids_for_network(
6356+
self.context, uuids.network_id)
6357+
self.assertEqual([], res)
6358+
mock_client.assert_called_once_with(self.context, admin=True)
63416359
mocked_client.list_subnets.assert_called_once_with(
63426360
network_id=uuids.network_id, fields='segment_id')
63436361

@@ -6353,6 +6371,7 @@ def test_get_segment_ids_for_network_fails(self, mock_client):
63536371
self.assertRaises(exception.InvalidRoutedNetworkConfiguration,
63546372
self.api.get_segment_ids_for_network,
63556373
self.context, uuids.network_id)
6374+
mock_client.assert_called_once_with(self.context, admin=True)
63566375

63576376
def test_get_segment_id_for_subnet_no_segment_ext(self):
63586377
with mock.patch.object(
@@ -6374,6 +6393,7 @@ def test_get_segment_id_for_subnet_passes(self, mock_client):
63746393
res = self.api.get_segment_id_for_subnet(
63756394
self.context, uuids.subnet_id)
63766395
self.assertEqual(uuids.segment_id, res)
6396+
mock_client.assert_called_once_with(self.context, admin=True)
63776397
mocked_client.show_subnet.assert_called_once_with(uuids.subnet_id)
63786398

63796399
@mock.patch.object(neutronapi, 'get_client')
@@ -6388,6 +6408,7 @@ def test_get_segment_id_for_subnet_with_no_segment(self, mock_client):
63886408
self.assertIsNone(
63896409
self.api.get_segment_id_for_subnet(self.context,
63906410
uuids.subnet_id))
6411+
mock_client.assert_called_once_with(self.context, admin=True)
63916412

63926413
@mock.patch.object(neutronapi, 'get_client')
63936414
def test_get_segment_id_for_subnet_fails(self, mock_client):
@@ -6401,6 +6422,7 @@ def test_get_segment_id_for_subnet_fails(self, mock_client):
64016422
self.assertRaises(exception.InvalidRoutedNetworkConfiguration,
64026423
self.api.get_segment_id_for_subnet,
64036424
self.context, uuids.subnet_id)
6425+
mock_client.assert_called_once_with(self.context, admin=True)
64046426

64056427
@mock.patch.object(neutronapi.LOG, 'debug')
64066428
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)