Stash the cell uuid on the context when targeting

This has been something we've needed for a while in order to do
some optimization in places like multi_cell_list where we need to
know which cell we are looking at during a scatter_gather operation.

Change-Id: Ib47d4ed1072c9ee6b2d9d084e678c80a05604963
This commit is contained in:
Dan Smith 2018-08-21 15:08:38 -07:00
parent b7c3dd8682
commit d4411a1876
2 changed files with 11 additions and 0 deletions

View File

@ -147,6 +147,7 @@ class RequestContext(context.RequestContext):
# provided by this module
self.db_connection = None
self.mq_connection = None
self.cell_uuid = None
self.user_auth_plugin = user_auth_plugin
if self.is_admin is None:
@ -373,16 +374,19 @@ def set_target_cell(context, cell_mapping):
if not cell_mapping.transport_url.startswith('none'):
context.mq_connection = rpc.create_transport(
cell_mapping.transport_url)
context.cell_uuid = cell_mapping.uuid
CELL_CACHE[cell_mapping.uuid] = (context.db_connection,
context.mq_connection)
else:
context.db_connection = cell_tuple[0]
context.mq_connection = cell_tuple[1]
context.cell_uuid = cell_mapping.uuid
get_or_set_cached_cell_and_set_connections()
else:
context.db_connection = None
context.mq_connection = None
context.cell_uuid = None
@contextmanager

View File

@ -256,8 +256,15 @@ class ContextTestCase(test.NoDBTestCase):
with context.target_cell(ctxt, mapping) as cctxt:
self.assertEqual(cctxt.db_connection, mock.sentinel.cdb)
self.assertEqual(cctxt.mq_connection, mock.sentinel.cmq)
self.assertEqual(cctxt.cell_uuid, mapping.uuid)
self.assertEqual(mock.sentinel.db_conn, ctxt.db_connection)
self.assertEqual(mock.sentinel.mq_conn, ctxt.mq_connection)
self.assertIsNone(ctxt.cell_uuid)
# Test again now that we have populated the cache
with context.target_cell(ctxt, mapping) as cctxt:
self.assertEqual(cctxt.db_connection, mock.sentinel.cdb)
self.assertEqual(cctxt.mq_connection, mock.sentinel.cmq)
self.assertEqual(cctxt.cell_uuid, mapping.uuid)
@mock.patch('nova.rpc.create_transport')
@mock.patch('nova.db.api.create_context_manager')