From d4411a1876a498fa2f0e8811f8d5d608b8a17c95 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Tue, 21 Aug 2018 15:08:38 -0700 Subject: [PATCH] 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 --- nova/context.py | 4 ++++ nova/tests/unit/test_context.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/nova/context.py b/nova/context.py index 399ecf02e014..0b345ab829f1 100644 --- a/nova/context.py +++ b/nova/context.py @@ -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 diff --git a/nova/tests/unit/test_context.py b/nova/tests/unit/test_context.py index 076dd2e2f472..016081583055 100644 --- a/nova/tests/unit/test_context.py +++ b/nova/tests/unit/test_context.py @@ -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')