summaryrefslogtreecommitdiff
path: root/nova/context.py
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem.os@gmail.com>2017-03-11 17:59:43 -0500
committerMatt Riedemann <mriedem.os@gmail.com>2017-03-13 13:45:03 -0400
commitedf51119fa59ff8a3337abb9107a06fa33d3c68f (patch)
tree3c834318162b4ef2ad9282677c81ea8173b777a7 /nova/context.py
parent018068c4caac324643c7c6a4360fad855dd096eb (diff)
downloadnova-edf51119fa59ff8a3337abb9107a06fa33d3c68f.tar.gz
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
Diffstat (limited to 'nova/context.py')
-rw-r--r--nova/context.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/nova/context.py b/nova/context.py
index 4dfd025722..be49d2945c 100644
--- a/nova/context.py
+++ b/nova/context.py
@@ -365,17 +365,23 @@ def set_target_cell(context, cell_mapping):
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
+ :param cell_mapping: An objects.CellMapping object or 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)
+ 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
@contextmanager
@@ -386,8 +392,10 @@ def target_cell(context, cell_mapping):
This context manager makes a temporary change to the context
and restores it when complete.
+ Passing None for cell_mapping will untarget the context temporarily.
+
:param context: The RequestContext to add connection information
- :param cell_mapping: A objects.CellMapping object
+ :param cell_mapping: An objects.CellMapping object or None
"""
original_db_connection = context.db_connection
original_mq_connection = context.mq_connection