def target_cell(context, cell_mapping): """Adds database and message queue connection information to the context for communicating with the given target cell. :param context: The RequestContext to add connection information :param cell_mapping: A objects.CellMapping object """ original_db_connection = context.db_connection original_mq_connection = context.mq_connection # avoid circular imports from nova import db from nova import rpc db_connection_string = cell_mapping.database_connection context.db_connection = db.create_context_manager(db_connection_string) # NOTE(melwitt): none:// url is a special value meaning do not switch if not cell_mapping.transport_url.startswith("none"): transport_url = cell_mapping.transport_url context.mq_connection = rpc.create_transport(transport_url) try: yield context finally: context.db_connection = original_db_connection context.mq_connection = original_mq_connection
def test_create_transport(self, mock_transport, mock_exmods): exmods = mock_exmods.return_value transport = rpc.create_transport(mock.sentinel.url) self.assertEqual(mock_transport.return_value, transport) mock_exmods.assert_called_once_with() mock_transport.assert_called_once_with(rpc.CONF, url=mock.sentinel.url, allowed_remote_exmods=exmods)
def get_or_set_cached_cell_and_set_connections(): try: cell_tuple = CELL_CACHE[cell_mapping.uuid] except KeyError: db_connection_string = cell_mapping.database_connection context.db_connection = db.create_context_manager( db_connection_string) if not cell_mapping.transport_url.startswith('none'): context.mq_connection = rpc.create_transport( cell_mapping.transport_url) CELL_CACHE[cell_mapping.uuid] = (context.db_connection, context.mq_connection) else: context.db_connection = cell_tuple[0] context.mq_connection = cell_tuple[1]
def set_target_cell(context, cell_mapping): """Adds database connection information to the context for communicating with the given target_cell. This is used for permanently targeting a cell in a context. Use this when you want all subsequent code to target a cell. :param context: The RequestContext to add connection information :param cell_mapping: An objects.CellMapping object """ # avoid circular import from nova import db from nova import rpc db_connection_string = cell_mapping.database_connection context.db_connection = db.create_context_manager(db_connection_string) if not cell_mapping.transport_url.startswith('none'): context.mq_connection = rpc.create_transport( cell_mapping.transport_url)
def target_cell(context, cell_mapping): """Adds database and message queue connection information to the context for communicating with the given target cell. :param context: The RequestContext to add connection information :param cell_mapping: A objects.CellMapping object """ original_db_connection = context.db_connection original_mq_connection = context.mq_connection # avoid circular imports from nova import db from nova import rpc db_connection_string = cell_mapping.database_connection context.db_connection = db.create_context_manager(db_connection_string) # NOTE(melwitt): none:// url is a special value meaning do not switch if not cell_mapping.transport_url.startswith('none'): transport_url = cell_mapping.transport_url context.mq_connection = rpc.create_transport(transport_url) try: yield context finally: context.db_connection = original_db_connection context.mq_connection = original_mq_connection
def set_target_cell(context, cell_mapping): """Adds database connection information to the context for communicating with the given target_cell. This is used for permanently targeting a cell in a context. Use this when you want all subsequent code to target a cell. Passing None for cell_mapping will untarget the context. :param context: The RequestContext to add connection information :param cell_mapping: An objects.CellMapping object or None """ if cell_mapping is not None: # avoid circular import from nova import db from nova import rpc db_connection_string = cell_mapping.database_connection context.db_connection = db.create_context_manager(db_connection_string) if not cell_mapping.transport_url.startswith('none'): context.mq_connection = rpc.create_transport( cell_mapping.transport_url) else: context.db_connection = None context.mq_connection = None