Temporarily untarget context when deleting from cell0

When deleting an instance we look it up in the _get_instance
method and if it's in cell0 then the context is permanently
targeted to that cell via the set_target_cell method.

When we delete the instance in _delete we need to temporarily
untarget the context when we decrement the quota usage otherwise
the quota usage gets decremented in the cell0 database rather than
the cell database. Once the instance is deleted then we
re-apply the target cell on the context.

Change-Id: I7de87dce216835729283bca69f0eff59a679b624
Closes-Bug: #1670627
This commit is contained in:
Matt Riedemann
2017-03-11 17:59:43 -05:00
parent c651feb43e
commit a08a4ef3dc

View File

@ -399,6 +399,16 @@ class CellDatabases(fixtures.Fixture):
@contextmanager
def _wrap_target_cell(self, context, cell_mapping):
with self._cell_lock.write_lock():
if cell_mapping is None:
# NOTE(danms): The real target_cell untargets with a
# cell_mapping of None. Since we're controlling our
# own targeting in this fixture, we need to call this out
# specifically and avoid switching global database state
try:
with self._real_target_cell(context, cell_mapping) as c:
yield c
finally:
return
ctxt_mgr = self._ctxt_mgrs[cell_mapping.database_connection]
# This assumes the next local DB access is the same cell that
# was targeted last time.