Fix get_subnet_ids_on_router in dvr scheduler
Added a check to verify if we do have any elements in the list of
fixed_ips, before trying to retrieve the first element of the list, to
get the subnet id. There were no checks in the original code, so it
would crash.
Change-Id: If32db500aa3a0c299a5f19c33c05237e8e407e08
Closes-Bug: 1452458
(cherry picked from commit d198b41def
)
This commit is contained in:
parent
9650a8a691
commit
5469d753f1
@ -138,8 +138,12 @@ class L3_DVRsch_db_mixin(l3agent_sch_db.L3AgentSchedulerDbMixin):
|
|||||||
int_ports = self._core_plugin.get_ports(context, filters=filter_rtr)
|
int_ports = self._core_plugin.get_ports(context, filters=filter_rtr)
|
||||||
for int_port in int_ports:
|
for int_port in int_ports:
|
||||||
int_ips = int_port['fixed_ips']
|
int_ips = int_port['fixed_ips']
|
||||||
|
if int_ips:
|
||||||
int_subnet = int_ips[0]['subnet_id']
|
int_subnet = int_ips[0]['subnet_id']
|
||||||
subnet_ids.add(int_subnet)
|
subnet_ids.add(int_subnet)
|
||||||
|
else:
|
||||||
|
LOG.debug('DVR: Could not find a subnet id'
|
||||||
|
'for router %s', router_id)
|
||||||
return subnet_ids
|
return subnet_ids
|
||||||
|
|
||||||
def check_ports_on_host_and_subnet(self, context, host,
|
def check_ports_on_host_and_subnet(self, context, host,
|
||||||
|
@ -1143,6 +1143,23 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
|
|||||||
self.assertEqual(sub_ids.pop(),
|
self.assertEqual(sub_ids.pop(),
|
||||||
dvr_port.get('fixed_ips').pop(0).get('subnet_id'))
|
dvr_port.get('fixed_ips').pop(0).get('subnet_id'))
|
||||||
|
|
||||||
|
def test_get_subnet_ids_on_router_no_subnet(self):
|
||||||
|
dvr_port = {
|
||||||
|
'id': 'dvr_port1',
|
||||||
|
'device_id': 'r1',
|
||||||
|
'device_owner': 'network:router_interface_distributed',
|
||||||
|
'fixed_ips': []
|
||||||
|
}
|
||||||
|
r1 = {
|
||||||
|
'id': 'r1',
|
||||||
|
'distributed': True,
|
||||||
|
}
|
||||||
|
with mock.patch.object(db_v2.NeutronDbPluginV2, 'get_ports',
|
||||||
|
return_value=[dvr_port]):
|
||||||
|
sub_ids = self.dut.get_subnet_ids_on_router(self.adminContext,
|
||||||
|
r1['id'])
|
||||||
|
self.assertEqual(len(sub_ids), 0)
|
||||||
|
|
||||||
def _test_check_ports_on_host_and_subnet_base(self, port_status):
|
def _test_check_ports_on_host_and_subnet_base(self, port_status):
|
||||||
dvr_port = {
|
dvr_port = {
|
||||||
'id': 'fake_id',
|
'id': 'fake_id',
|
||||||
|
Loading…
Reference in New Issue
Block a user