Merge "DVR: Move _get_floatingip_by_port to l3_db"
This commit is contained in:
commit
7ba2c108dd
|
@ -1477,15 +1477,19 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
|||
router_ids = set()
|
||||
|
||||
with context.session.begin(subtransactions=True):
|
||||
fip_qry = context.session.query(l3_models.FloatingIP)
|
||||
floating_ips = fip_qry.filter_by(fixed_port_id=port_id)
|
||||
for floating_ip in floating_ips:
|
||||
for floating_ip in self._get_floatingips_by_port_id(
|
||||
context, port_id):
|
||||
router_ids.add(floating_ip['router_id'])
|
||||
floating_ip.update({'fixed_port_id': None,
|
||||
'fixed_ip_address': None,
|
||||
'router_id': None})
|
||||
return router_ids
|
||||
|
||||
def _get_floatingips_by_port_id(self, context, port_id):
|
||||
"""Helper function to retrieve the fips associated with a port_id."""
|
||||
fip_qry = context.session.query(l3_models.FloatingIP)
|
||||
return fip_qry.filter_by(fixed_port_id=port_id).all()
|
||||
|
||||
def _build_routers_list(self, context, routers, gw_ports):
|
||||
"""Subclasses can override this to add extra gateway info"""
|
||||
return routers
|
||||
|
|
|
@ -286,12 +286,6 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
|||
self.update_arp_entry_for_dvr_service_port(context,
|
||||
service_port_dict)
|
||||
|
||||
def _get_floatingip_on_port(self, context, port_id=None):
|
||||
"""Helper function to retrieve the fip associated with port."""
|
||||
fip_qry = context.session.query(l3_models.FloatingIP)
|
||||
floating_ip = fip_qry.filter_by(fixed_port_id=port_id)
|
||||
return floating_ip.first()
|
||||
|
||||
@registry.receives(resources.ROUTER_INTERFACE, [events.BEFORE_CREATE])
|
||||
@db_api.retry_if_session_inactive()
|
||||
def _add_csnat_on_interface_create(self, resource, event, trigger,
|
||||
|
@ -642,9 +636,10 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
|||
def check_for_fip_and_create_agent_gw_port_on_host_if_not_exists(
|
||||
self, context, port, host):
|
||||
"""Create fip agent_gw_port on host if not exists"""
|
||||
fip = self._get_floatingip_on_port(context, port_id=port['id'])
|
||||
if not fip:
|
||||
fips = self._get_floatingips_by_port_id(context, port['id'])
|
||||
if not fips:
|
||||
return
|
||||
fip = fips[0]
|
||||
network_id = fip.get('floating_network_id')
|
||||
agent_gw_port = self.create_fip_agent_gw_port_if_not_exists(
|
||||
context.elevated(), network_id, host)
|
||||
|
|
|
@ -428,8 +428,9 @@ def _notify_l3_agent_port_update(resource, event, trigger, **kwargs):
|
|||
}
|
||||
_notify_port_delete(
|
||||
event, resource, trigger, **removed_router_args)
|
||||
fip = l3plugin._get_floatingip_on_port(context,
|
||||
port_id=original_port['id'])
|
||||
fips = l3plugin._get_floatingips_by_port_id(
|
||||
context, port_id=original_port['id'])
|
||||
fip = fips[0] if fips else None
|
||||
if fip and not (removed_routers and
|
||||
fip['router_id'] in removed_routers):
|
||||
l3plugin.l3_rpc_notifier.routers_updated_on_host(
|
||||
|
|
|
@ -1059,8 +1059,8 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
|
|||
directory.add_plugin(constants.L3, l3plugin)
|
||||
with mock.patch.object(l3plugin, 'get_dvr_routers_to_remove',
|
||||
return_value=routers_to_remove),\
|
||||
mock.patch.object(l3plugin, '_get_floatingip_on_port',
|
||||
return_value=fip):
|
||||
mock.patch.object(l3plugin, '_get_floatingips_by_port_id',
|
||||
return_value=[fip] if fip else []):
|
||||
l3_dvrscheduler_db._notify_l3_agent_port_update(
|
||||
'port', 'after_update', mock.ANY, **kwargs)
|
||||
if routers_to_remove:
|
||||
|
@ -1108,8 +1108,8 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase):
|
|||
return_value=[{'agent_id': 'foo_agent',
|
||||
'router_id': 'foo_id',
|
||||
'host': source_host}]),\
|
||||
mock.patch.object(l3plugin, '_get_floatingip_on_port',
|
||||
return_value=None):
|
||||
mock.patch.object(l3plugin, '_get_floatingips_by_port_id',
|
||||
return_value=[]):
|
||||
l3_dvrscheduler_db._notify_l3_agent_port_update(
|
||||
'port', 'after_update', plugin, **kwargs)
|
||||
|
||||
|
|
Loading…
Reference in New Issue