Browse Source

Merge "Don't use wrap_db_retry on subtransaction in resource_create_replacement()" into stable/train

changes/04/700704/1
Zuul 2 years ago
committed by Gerrit Code Review
parent
commit
759bfae5b8
  1. 16
      heat/db/sqlalchemy/api.py
  2. 8
      heat/tests/db/test_sqlalchemy_api.py

16
heat/db/sqlalchemy/api.py

@ -260,6 +260,12 @@ def _add_atomic_key_to_values(values, atomic_key):
retry_interval=0.5, inc_retry_interval=True)
def resource_update(context, resource_id, values, atomic_key,
expected_engine_id=None):
return _try_resource_update(context, resource_id, values, atomic_key,
expected_engine_id)
def _try_resource_update(context, resource_id, values, atomic_key,
expected_engine_id=None):
session = context.session
with session.begin(subtransactions=True):
_add_atomic_key_to_values(values, atomic_key)
@ -448,6 +454,8 @@ def resource_create(context, values):
return resource_ref
@oslo_db_api.wrap_db_retry(max_retries=3, retry_on_deadlock=True,
retry_interval=0.5, inc_retry_interval=True)
def resource_create_replacement(context,
existing_res_id, existing_res_values,
new_res_values,
@ -458,10 +466,10 @@ def resource_create_replacement(context,
new_res = resource_create(context, new_res_values)
update_data = {'replaced_by': new_res.id}
update_data.update(existing_res_values)
if not resource_update(context,
existing_res_id, update_data,
atomic_key,
expected_engine_id=expected_engine_id):
if not _try_resource_update(context,
existing_res_id, update_data,
atomic_key,
expected_engine_id=expected_engine_id):
data = {}
if 'name' in new_res_values:
data['resource_name'] = new_res_values['name']

8
heat/tests/db/test_sqlalchemy_api.py

@ -2685,8 +2685,8 @@ class DBAPIResourceReplacementTest(common.HeatTestCase):
db_api.resource_update_and_save(other_ctx, orig.id,
{'atomic_key': 2})
self.patchobject(db_api, 'resource_update',
new=mock.Mock(wraps=db_api.resource_update,
self.patchobject(db_api, '_try_resource_update',
new=mock.Mock(wraps=db_api._try_resource_update,
side_effect=update_atomic_key))
self.assertRaises(exception.UpdateInProgress,
@ -2728,8 +2728,8 @@ class DBAPIResourceReplacementTest(common.HeatTestCase):
{'engine_id': 'a',
'atomic_key': 2})
self.patchobject(db_api, 'resource_update',
new=mock.Mock(wraps=db_api.resource_update,
self.patchobject(db_api, '_try_resource_update',
new=mock.Mock(wraps=db_api._try_resource_update,
side_effect=lock_resource))
self.assertRaises(exception.UpdateInProgress,

Loading…
Cancel
Save