Merge "Fix get_segments_id with subnets without segment_id"

This commit is contained in:
Zuul 2023-05-04 10:31:26 +00:00 committed by Gerrit Code Review
commit 8e4a7290f8
2 changed files with 18 additions and 2 deletions

View File

@ -3907,7 +3907,7 @@ class API:
'Failed to get segment IDs for network %s' % network_id) from e
# The segment field of an unconfigured subnet could be None
return [subnet['segment_id'] for subnet in subnets
if subnet['segment_id'] is not None]
if subnet.get('segment_id') is not None]
def get_segment_id_for_subnet(
self,

View File

@ -7415,7 +7415,7 @@ class TestAPI(TestAPIBase):
network_id=uuids.network_id, fields='segment_id')
@mock.patch.object(neutronapi, 'get_client')
def test_get_segment_ids_for_network_with_no_segments(self, mock_client):
def test_get_segment_ids_for_network_with_segments_none(self, mock_client):
subnets = {'subnets': [{'segment_id': None}]}
mocked_client = mock.create_autospec(client.Client)
mock_client.return_value = mocked_client
@ -7430,6 +7430,22 @@ class TestAPI(TestAPIBase):
mocked_client.list_subnets.assert_called_once_with(
network_id=uuids.network_id, fields='segment_id')
@mock.patch.object(neutronapi, 'get_client')
def test_get_segment_ids_for_network_with_no_segments(self, mock_client):
subnets = {'subnets': [{}]}
mocked_client = mock.create_autospec(client.Client)
mock_client.return_value = mocked_client
mocked_client.list_subnets.return_value = subnets
with mock.patch.object(
self.api, 'has_segment_extension', return_value=True,
):
res = self.api.get_segment_ids_for_network(
self.context, uuids.network_id)
self.assertEqual([], res)
mock_client.assert_called_once_with(self.context, admin=True)
mocked_client.list_subnets.assert_called_once_with(
network_id=uuids.network_id, fields='segment_id')
@mock.patch.object(neutronapi, 'get_client')
def test_get_segment_ids_for_network_fails(self, mock_client):
mocked_client = mock.create_autospec(client.Client)