Fix get_segments_id with subnets without segment_id
Unfortunatly when we merged Ie166f3b51fddeaf916cda7c5ac34bbcdda0fd17a we forgot that subnets can have no segment_id field. Change-Id: Idb35b7e3c69fe8efe498abe4ebcc6cad8918c4ed Closes-Bug: #2018375 (cherry picked from commit 6d7bd6a03446d5227d515b2b4c0da632ef4aa4a1) (cherry picked from commit 6b8d9d419170fb0ec2c6df561a0874e6362382c1) (cherry picked from commit 77db64237b23050d94df113a38412c5333d23357)
This commit is contained in:
parent
7b4098c963
commit
9a6a421c04
@ -3924,7 +3924,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,
|
||||
|
@ -7432,7 +7432,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
|
||||
@ -7447,6 +7447,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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user