Call _allocate_vr_id outside of transaction

_allocate_vr_id is called from _set_vr_id, which was starting a
transaction before calling it. This caused an error when the retry
logic was triggered inside of _allocate_vr_id since it would
encounter a DB exception and put the transaction into a bad state
that couldn't be used on the retry.

This patch just stops _set_vr_id from starting a transaction because
it didn't serve a purpose. It also stops _allocate_vr_id from allowing
subtransactions when it starts a transaction, since it's retry logic
isn't compatible with them.

Co-Authored-By: Ann Kamyshnikova <akamyshnikova@mirantis.com>
Closes-Bug: #1528201
Change-Id: If7bcae39098f40f5ee9db78d3190bf9fdaf6438b
(cherry picked from commit 18e2117e3d)
This commit is contained in:
Kevin Benton 2015-12-24 00:54:06 -08:00 committed by Assaf Muller
parent 827a4444e9
commit 608b54137f
1 changed files with 5 additions and 4 deletions

View File

@ -181,7 +181,9 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin):
def _allocate_vr_id(self, context, network_id, router_id):
for count in range(MAX_ALLOCATION_TRIES):
try:
with context.session.begin(subtransactions=True):
# NOTE(kevinbenton): we disallow subtransactions because the
# retry logic will bust any parent transactions
with context.session.begin():
allocated_vr_ids = self._get_allocated_vr_id(context,
network_id)
available_vr_ids = VR_ID_RANGE - allocated_vr_ids
@ -214,9 +216,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin):
vr_id=vr_id).delete()
def _set_vr_id(self, context, router, ha_network):
with context.session.begin(subtransactions=True):
router.extra_attributes.ha_vr_id = self._allocate_vr_id(
context, ha_network.network_id, router.id)
router.extra_attributes.ha_vr_id = self._allocate_vr_id(
context, ha_network.network_id, router.id)
def _create_ha_subnet(self, context, network_id, tenant_id):
args = {'subnet':