Merge "Move DVR fip agent gw port create out of transaction"
This commit is contained in:
commit
f2235b7994
@ -201,8 +201,12 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
router_db, _unused = common_db_mixin.safe_creation(context, create,
|
||||
delete, update_gw,
|
||||
transaction=False)
|
||||
|
||||
return self._make_router_dict(router_db)
|
||||
new_router = self._make_router_dict(router_db)
|
||||
registry.notify(resources.ROUTER, events.AFTER_CREATE, self,
|
||||
context=context, router_id=router_db.id,
|
||||
router=new_router, request_attrs=r,
|
||||
router_db=router_db)
|
||||
return new_router
|
||||
|
||||
def _update_router_db(self, context, router_id, data):
|
||||
"""Update the DB object."""
|
||||
@ -221,6 +225,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
def update_router(self, context, id, router):
|
||||
r = router['router']
|
||||
gw_info = r.pop(EXTERNAL_GW_INFO, lib_constants.ATTR_NOT_SPECIFIED)
|
||||
original = self.get_router(context, id)
|
||||
# check whether router needs and can be rescheduled to the proper
|
||||
# l3 agent (associated with given external network);
|
||||
# do check before update in DB as an exception will be raised
|
||||
@ -239,7 +244,11 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
|
||||
l3_plugin = manager.NeutronManager.get_service_plugins().get(
|
||||
constants.L3_ROUTER_NAT)
|
||||
l3_plugin.reschedule_router(context, id, candidates)
|
||||
return self._make_router_dict(router_db)
|
||||
updated = self._make_router_dict(router_db)
|
||||
registry.notify(resources.ROUTER, events.AFTER_UPDATE, self,
|
||||
context=context, router_id=id, old_router=original,
|
||||
router=updated, request_attrs=r, router_db=router_db)
|
||||
return updated
|
||||
|
||||
def _check_router_needs_rescheduling(self, context, router_id, gw_info):
|
||||
"""Checks whether router's l3 agent can handle the given network
|
||||
|
@ -74,6 +74,10 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
||||
n = super(L3_NAT_with_dvr_db_mixin, cls).__new__(cls, *args, **kwargs)
|
||||
registry.subscribe(n._create_dvr_floating_gw_port,
|
||||
resources.FLOATING_IP, events.AFTER_UPDATE)
|
||||
registry.subscribe(n._create_snat_interfaces_after_change,
|
||||
resources.ROUTER, events.AFTER_UPDATE)
|
||||
registry.subscribe(n._create_snat_interfaces_after_change,
|
||||
resources.ROUTER, events.AFTER_CREATE)
|
||||
return n
|
||||
|
||||
def _create_router_db(self, context, router, tenant_id):
|
||||
@ -141,17 +145,6 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
||||
self._update_distributed_attr(
|
||||
context, router_id, router_db, data)
|
||||
if migrating_to_distributed:
|
||||
if router_db['gw_port_id']:
|
||||
# If the Legacy router is getting migrated to a DVR
|
||||
# router, make sure to create corresponding
|
||||
# snat interface ports that are to be consumed by
|
||||
# the Service Node.
|
||||
# TODO(haleyb): move this out of transaction
|
||||
setattr(context, 'GUARD_TRANSACTION', False)
|
||||
if not self._create_snat_intf_ports_if_not_exists(
|
||||
context.elevated(), router_db):
|
||||
LOG.debug("SNAT interface ports not created: %s",
|
||||
router_db['id'])
|
||||
cur_agents = self.list_l3_agents_hosting_router(
|
||||
context, router_db['id'])['agents']
|
||||
for agent in cur_agents:
|
||||
@ -159,6 +152,28 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
||||
agent['id'])
|
||||
return router_db
|
||||
|
||||
def _create_snat_interfaces_after_change(self, resource, event, trigger,
|
||||
context, router_id, router,
|
||||
request_attrs, router_db,
|
||||
**kwargs):
|
||||
if not router.get(l3.EXTERNAL_GW_INFO) or not router['distributed']:
|
||||
# we don't care if it's not distributed or not attached to an
|
||||
# external network
|
||||
return
|
||||
if event == events.AFTER_UPDATE:
|
||||
# after an update, we check to see if it was a migration or a
|
||||
# gateway attachment
|
||||
old_router = kwargs['old_router']
|
||||
do_create = (not old_router['distributed'] or
|
||||
not old_router.get(l3.EXTERNAL_GW_INFO))
|
||||
if not do_create:
|
||||
return
|
||||
if not self._create_snat_intf_ports_if_not_exists(
|
||||
context.elevated(), router_db):
|
||||
LOG.debug("SNAT interface ports not created: %s",
|
||||
router_db['id'])
|
||||
return router_db
|
||||
|
||||
def _delete_current_gw_port(self, context, router_id, router, new_network):
|
||||
"""
|
||||
Overridden here to handle deletion of dvr internal ports.
|
||||
@ -193,19 +208,6 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
||||
self.l3_rpc_notifier.delete_fipnamespace_for_ext_net(
|
||||
context, gw_ext_net_id)
|
||||
|
||||
def _create_gw_port(self, context, router_id, router, new_network,
|
||||
ext_ips):
|
||||
super(L3_NAT_with_dvr_db_mixin,
|
||||
self)._create_gw_port(context, router_id, router, new_network,
|
||||
ext_ips)
|
||||
# Make sure that the gateway port exists before creating the
|
||||
# snat interface ports for distributed router.
|
||||
if router.extra_attributes.distributed and router.gw_port:
|
||||
snat_p_list = self._create_snat_intf_ports_if_not_exists(
|
||||
context.elevated(), router)
|
||||
if not snat_p_list:
|
||||
LOG.debug("SNAT interface ports not created: %s", snat_p_list)
|
||||
|
||||
def _get_device_owner(self, context, router=None):
|
||||
"""Get device_owner for the specified router."""
|
||||
router_is_uuid = isinstance(router, six.string_types)
|
||||
|
@ -17,6 +17,7 @@ from neutron_lib import constants
|
||||
|
||||
from neutron.common import topics
|
||||
from neutron.extensions import external_net
|
||||
from neutron.extensions import l3
|
||||
from neutron.extensions import l3_ext_ha_mode
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.tests.common import helpers
|
||||
@ -243,9 +244,10 @@ class L3DvrHATestCase(test_l3_dvr_router_plugin.L3DvrTestCase):
|
||||
with self.subnet() as subnet, \
|
||||
self.network(**kwargs) as ext_net, \
|
||||
self.subnet(network=ext_net, cidr='20.0.0.0/24'):
|
||||
self.l3_plugin._update_router_gw_info(
|
||||
gw_info = {'network_id': ext_net['network']['id']}
|
||||
self.l3_plugin.update_router(
|
||||
self.context, router['id'],
|
||||
{'network_id': ext_net['network']['id']})
|
||||
{'router': {l3.EXTERNAL_GW_INFO: gw_info}})
|
||||
self.l3_plugin.add_router_interface(
|
||||
self.context, router['id'],
|
||||
{'subnet_id': subnet['subnet']['id']})
|
||||
@ -273,9 +275,10 @@ class L3DvrHATestCase(test_l3_dvr_router_plugin.L3DvrTestCase):
|
||||
self.core_plugin.update_port(
|
||||
self.context, port['port']['id'],
|
||||
{'port': {'binding:host_id': self.l3_agent['host']}})
|
||||
self.l3_plugin._update_router_gw_info(
|
||||
gw_info = {'network_id': ext_net['network']['id']}
|
||||
self.l3_plugin.update_router(
|
||||
self.context, router['id'],
|
||||
{'network_id': ext_net['network']['id']})
|
||||
{'router': {l3.EXTERNAL_GW_INFO: gw_info}})
|
||||
self.l3_plugin.add_router_interface(
|
||||
self.context, router['id'],
|
||||
{'subnet_id': subnet['subnet']['id']})
|
||||
@ -318,13 +321,15 @@ class L3DvrHATestCase(test_l3_dvr_router_plugin.L3DvrTestCase):
|
||||
return ext_net
|
||||
|
||||
def _set_external_gateway(self, router, ext_net):
|
||||
self.l3_plugin._update_router_gw_info(
|
||||
gw_info = {'network_id': ext_net['network']['id']}
|
||||
self.l3_plugin.update_router(
|
||||
self.context, router['id'],
|
||||
{'network_id': ext_net['network']['id']})
|
||||
{'router': {l3.EXTERNAL_GW_INFO: gw_info}})
|
||||
|
||||
def _clear_external_gateway(self, router):
|
||||
self.l3_plugin._update_router_gw_info(
|
||||
self.context, router['id'], {})
|
||||
self.l3_plugin.update_router(
|
||||
self.context, router['id'],
|
||||
{'router': {l3.EXTERNAL_GW_INFO: {}}})
|
||||
|
||||
def _remove_interface_from_router(self, router, subnet):
|
||||
self.l3_plugin.remove_router_interface(
|
||||
|
@ -22,6 +22,7 @@ from neutron.callbacks import resources
|
||||
from neutron.common import topics
|
||||
from neutron import context
|
||||
from neutron.extensions import external_net
|
||||
from neutron.extensions import l3
|
||||
from neutron.extensions import portbindings
|
||||
from neutron.tests.common import helpers
|
||||
from neutron.tests.unit.plugins.ml2 import base as ml2_test_base
|
||||
@ -91,9 +92,10 @@ class L3DvrTestCase(L3DvrTestCaseBase):
|
||||
self.l3_plugin.add_router_interface(
|
||||
self.context, router['id'],
|
||||
{'subnet_id': subnet2['subnet']['id']})
|
||||
self.l3_plugin._update_router_gw_info(
|
||||
gw_info = {'network_id': ext_net['network']['id']}
|
||||
self.l3_plugin.update_router(
|
||||
self.context, router['id'],
|
||||
{'network_id': ext_net['network']['id']})
|
||||
{'router': {l3.EXTERNAL_GW_INFO: gw_info}})
|
||||
|
||||
snat_router_intfs = self.l3_plugin._get_snat_sync_interfaces(
|
||||
self.context, [router['id']])
|
||||
|
Loading…
x
Reference in New Issue
Block a user