Ensure changes to api.QUOTA_SYNC_FUNCTIONS are restored.

Add a local callable restore_sync_functions() that is
established as an addCleanup() fixture callable,
making use of a copy of the QUOTA_SYNC_FUNCTIONS
dictionary to restore its previous contents in-place.

Change-Id: I7fa69ea91e517121aba0ee22a71b0594591ae308
Closes-Bug: #1329482
This commit is contained in:
Mike Bayer 2014-06-12 17:28:36 -04:00
parent 389816f759
commit 7168fcfe2d
1 changed files with 8 additions and 0 deletions

View File

@ -2108,6 +2108,14 @@ class QuotaReserveSqlAlchemyTestCase(test.TestCase):
return sync
self.resources = {}
_existing_quota_sync_func_dict = dict(sqa_api.QUOTA_SYNC_FUNCTIONS)
def restore_sync_functions():
sqa_api.QUOTA_SYNC_FUNCTIONS.clear()
sqa_api.QUOTA_SYNC_FUNCTIONS.update(_existing_quota_sync_func_dict)
self.addCleanup(restore_sync_functions)
for res_name in ('instances', 'cores', 'ram', 'fixed_ips'):
method_name = '_sync_%s' % res_name
sqa_api.QUOTA_SYNC_FUNCTIONS[method_name] = make_sync(res_name)