Correctly call is_distributed_router()
A recent change to _notify_l3_agent_port_update() was making a call to is_distributed_router() via the l3plugin, but since that method lives in l3_dvr_db.py it was failing. This was not caught by the unit test since it was mocking the return value. Had to modify things to get the router first since the object is required for the check. Change-Id: I2289f882b692b375d1b40d7a50d206d72da66155 Closes-bug: #1785848
This commit is contained in:
@@ -19,6 +19,7 @@ from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
from neutron_lib import constants as n_const
|
||||
from neutron_lib.exceptions import l3 as l3_exc
|
||||
from neutron_lib.plugins import constants as plugin_constants
|
||||
from neutron_lib.plugins import directory
|
||||
from oslo_log import log as logging
|
||||
@@ -28,6 +29,7 @@ from neutron.common import utils as n_utils
|
||||
|
||||
from neutron.db import agentschedulers_db
|
||||
from neutron.db import l3_agentschedulers_db as l3agent_sch_db
|
||||
from neutron.db import l3_dvr_db
|
||||
from neutron.db import models_v2
|
||||
from neutron.objects import l3agent as rb_obj
|
||||
from neutron.plugins.ml2 import db as ml2_db
|
||||
@@ -453,13 +455,20 @@ def _notify_l3_agent_port_update(resource, event, trigger, **kwargs):
|
||||
fips = l3plugin._get_floatingips_by_port_id(
|
||||
context, port_id=original_port['id'])
|
||||
fip = fips[0] if fips else None
|
||||
removed_router_ids = [
|
||||
info['router_id'] for info in removed_routers
|
||||
]
|
||||
if (fip and
|
||||
l3plugin.is_distributed_router(fip['router_id']) and
|
||||
not (removed_routers and
|
||||
fip['router_id'] in removed_router_ids)):
|
||||
|
||||
def _should_notify_on_fip_update():
|
||||
if not fip:
|
||||
return False
|
||||
for info in removed_routers:
|
||||
if info['router_id'] == fip['router_id']:
|
||||
return False
|
||||
try:
|
||||
router = l3plugin._get_router(context, fip['router_id'])
|
||||
except l3_exc.RouterNotFound:
|
||||
return False
|
||||
return l3_dvr_db.is_distributed_router(router)
|
||||
|
||||
if _should_notify_on_fip_update():
|
||||
l3plugin.l3_rpc_notifier.routers_updated_on_host(
|
||||
context, [fip['router_id']],
|
||||
original_port[portbindings.HOST_ID])
|
||||
|
@@ -34,6 +34,7 @@ import testtools
|
||||
|
||||
from neutron.db import db_base_plugin_v2 as db_v2
|
||||
from neutron.db import l3_db
|
||||
from neutron.db import l3_dvr_db
|
||||
from neutron.db import l3_dvr_ha_scheduler_db
|
||||
from neutron.db import l3_dvrscheduler_db
|
||||
from neutron.db import l3_hamode_db
|
||||
@@ -1084,7 +1085,7 @@ class L3DvrSchedulerTestCase(L3SchedulerBaseMixin,
|
||||
if routers_to_remove else []),\
|
||||
mock.patch.object(l3plugin, '_get_floatingips_by_port_id',
|
||||
return_value=[fip] if fip else []),\
|
||||
mock.patch.object(l3plugin, 'is_distributed_router',
|
||||
mock.patch.object(l3_dvr_db, 'is_distributed_router',
|
||||
return_value=is_distributed):
|
||||
l3_dvrscheduler_db._notify_l3_agent_port_update(
|
||||
'port', 'after_update', mock.ANY, **kwargs)
|
||||
|
Reference in New Issue
Block a user