Merge "Delete HA network if last HA router is migrated"

This commit is contained in:
Jenkins 2016-08-09 22:58:35 +00:00 committed by Gerrit Code Review
commit 8da4d0d471
2 changed files with 52 additions and 21 deletions

View File

@ -565,6 +565,10 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
self._set_vr_id(context, router_db, ha_network)
else:
self._delete_ha_interfaces(context, router_db.id)
# always attempt to cleanup the network as the router is
# deleted. the core plugin will stop us if its in use
self.safe_delete_ha_network(context, ha_network,
router_db.tenant_id)
self.schedule_router(context, router_id)
router_db = super(L3_HA_NAT_db_mixin, self)._update_router_db(
@ -578,6 +582,26 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
admin_ctx = context.elevated()
self._core_plugin.delete_network(admin_ctx, net.network_id)
def safe_delete_ha_network(self, context, ha_network, tenant_id):
try:
self._delete_ha_network(context, ha_network)
except (n_exc.NetworkNotFound,
orm.exc.ObjectDeletedError):
LOG.debug(
"HA network for tenant %s was already deleted.", tenant_id)
except sa.exc.InvalidRequestError:
LOG.info(_LI("HA network %s can not be deleted."),
ha_network.network_id)
except n_exc.NetworkInUse:
# network is still in use, this is normal so we don't
# log anything
pass
else:
LOG.info(_LI("HA network %(network)s was deleted as "
"no HA routers are present in tenant "
"%(tenant)s."),
{'network': ha_network.network_id, 'tenant': tenant_id})
def delete_router(self, context, id):
router_db = self._get_router(context, id)
super(L3_HA_NAT_db_mixin, self).delete_router(context, id)
@ -598,26 +622,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
# always attempt to cleanup the network as the router is
# deleted. the core plugin will stop us if its in use
try:
self._delete_ha_network(context, ha_network)
except (n_exc.NetworkNotFound,
orm.exc.ObjectDeletedError):
LOG.debug(
"HA network for tenant %s was already deleted.",
router_db.tenant_id)
except sa.exc.InvalidRequestError:
LOG.info(_LI("HA network %s can not be deleted."),
ha_network.network_id)
except n_exc.NetworkInUse:
# network is still in use, this is normal so we don't
# log anything
pass
else:
LOG.info(_LI("HA network %(network)s was deleted as "
"no HA routers are present in tenant "
"%(tenant)s."),
{'network': ha_network.network_id,
'tenant': router_db.tenant_id})
self.safe_delete_ha_network(context, ha_network,
router_db.tenant_id)
def _unbind_ha_router(self, context, router_id):
for agent in self.get_l3_agents_hosting_routers(context, [router_id]):

View File

@ -550,6 +550,27 @@ class L3HATestCase(L3HATestFramework):
network.network_id)
self.assertEqual(allocs_before, allocs_after)
def test_migration_delete_ha_network_if_last_router(self):
router = self._create_router()
self._migrate_router(router['id'], False)
self.assertIsNone(
self.plugin.get_ha_network(self.admin_ctx, router['tenant_id']))
def test_migration_no_delete_ha_network_if_not_last_router(self):
router = self._create_router()
router2 = self._create_router()
network = self.plugin.get_ha_network(self.admin_ctx,
router['tenant_id'])
network2 = self.plugin.get_ha_network(self.admin_ctx,
router2['tenant_id'])
self.assertEqual(network, network2)
self._migrate_router(router['id'], False)
self.assertIsNotNone(
self.plugin.get_ha_network(self.admin_ctx, router2['tenant_id']))
def test_one_ha_router_one_not(self):
self._create_router(ha=False)
self._create_router()
@ -909,9 +930,13 @@ class L3HATestCase(L3HATestFramework):
self.core_plugin.get_networks(self.admin_ctx)]
self.assertIn('HA network tenant %s' % router1['tenant_id'],
nets_before)
ha_network = self.plugin.get_ha_network(self.admin_ctx,
router1['tenant_id'])
with mock.patch.object(self.plugin, '_delete_ha_network',
side_effect=exception):
self.plugin.delete_router(self.admin_ctx, router1['id'])
self.plugin.safe_delete_ha_network(self.admin_ctx,
ha_network,
router1['tenant_id'])
nets_after = [net['name'] for net in
self.core_plugin.get_networks(self.admin_ctx)]
self.assertIn('HA network tenant %s' % router1['tenant_id'],