Use pick_context_manager throughout DB APIs
The pick_context_manager method will use a connection to a cell database if one is present in the RequestContext, else it falls back on the global main_context_manager in the DB API. Currently, there are several places in our DB API code where pick_context_manager isn't used because in a real scenario, each cell is in a separate process where main_context_manager points to its local database. This causes problems for testing though, because we are unable to patch the DB API to simulate switching between multiple 'main' databases in our functional tests because of the global nature of main_context_manager. This replaces all uses of main_context_manager with pick_context_manager to: 1. Make switching between multiple databases able to work in functional tests 2. Fix any possible cases where pick_context_manager is not used for a DB API method that could be called from the API using target_cell Change-Id: I31e3170e0953cefbf49bfc84b29edab514c90cb5
This commit is contained in:
parent
215dc29bd9
commit
9ffa622b6f
File diff suppressed because it is too large
Load Diff
|
@ -328,7 +328,7 @@ class Aggregate(base.NovaPersistentObject, base.NovaObject):
|
|||
return cls._from_db_object(context, cls(), db_aggregate)
|
||||
|
||||
@staticmethod
|
||||
@db_api.main_context_manager.reader
|
||||
@db_api.pick_context_manager_reader
|
||||
def _ensure_migrated(context):
|
||||
result = context.session.query(main_models.Aggregate).\
|
||||
filter_by(deleted=0).count()
|
||||
|
@ -561,7 +561,7 @@ class AggregateList(base.ObjectListBase, base.NovaObject):
|
|||
all_aggregates)
|
||||
|
||||
|
||||
@db_api.main_context_manager.reader
|
||||
@db_api.pick_context_manager_reader
|
||||
def _get_main_db_aggregate_ids(context, limit):
|
||||
from nova.db.sqlalchemy import models
|
||||
return [x[0] for x in context.session.query(models.Aggregate.id).
|
||||
|
|
|
@ -187,7 +187,7 @@ def _flavor_destroy(context, flavor_id=None, flavorid=None):
|
|||
context.session.delete(result)
|
||||
|
||||
|
||||
@db_api.main_context_manager.reader
|
||||
@db_api.pick_context_manager_reader
|
||||
def _ensure_migrated(context):
|
||||
result = context.session.query(main_models.InstanceTypes).\
|
||||
filter_by(deleted=0).count()
|
||||
|
@ -682,7 +682,7 @@ class FlavorList(base.ObjectListBase, base.NovaObject):
|
|||
expected_attrs=['extra_specs'])
|
||||
|
||||
|
||||
@db_api.main_context_manager.reader
|
||||
@db_api.pick_context_manager_reader
|
||||
def _get_main_db_flavor_ids(context, limit):
|
||||
# NOTE(danms): We don't need this imported at runtime, so
|
||||
# keep it separate here
|
||||
|
@ -692,7 +692,7 @@ def _get_main_db_flavor_ids(context, limit):
|
|||
limit(limit)]
|
||||
|
||||
|
||||
@db_api.main_context_manager.writer
|
||||
@db_api.pick_context_manager_writer
|
||||
def _destroy_flavor_hard(context, name):
|
||||
# NOTE(danms): We don't need this imported at runtime, so
|
||||
# keep it separate here
|
||||
|
|
|
@ -1354,7 +1354,7 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
|
|||
return [inst['uuid'] for inst in db_instances]
|
||||
|
||||
|
||||
@db_api.main_context_manager.writer
|
||||
@db_api.pick_context_manager_writer
|
||||
def _migrate_instance_keypairs(ctxt, count):
|
||||
db_extras = ctxt.session.query(models.InstanceExtra).\
|
||||
options(joinedload('instance')).\
|
||||
|
|
|
@ -512,7 +512,7 @@ class InstanceGroupList(base.ObjectListBase, base.NovaObject):
|
|||
api_db_groups + main_db_groups)
|
||||
|
||||
|
||||
@db_api.main_context_manager.reader
|
||||
@db_api.pick_context_manager_reader
|
||||
def _get_main_instance_groups(context, limit):
|
||||
return context.session.query(main_models.InstanceGroup).\
|
||||
options(joinedload('_policies')).\
|
||||
|
|
|
@ -239,7 +239,7 @@ class KeyPairList(base.ObjectListBase, base.NovaObject):
|
|||
db.key_pair_count_by_user(context, user_id))
|
||||
|
||||
|
||||
@db_api.main_context_manager.reader
|
||||
@db_api.pick_context_manager_reader
|
||||
def _count_unmigrated_instances(context):
|
||||
return context.session.query(main_models.InstanceExtra).\
|
||||
filter_by(keypairs=None).\
|
||||
|
@ -247,7 +247,7 @@ def _count_unmigrated_instances(context):
|
|||
count()
|
||||
|
||||
|
||||
@db_api.main_context_manager.reader
|
||||
@db_api.pick_context_manager_reader
|
||||
def _get_main_keypairs(context, limit):
|
||||
return context.session.query(main_models.KeyPair).\
|
||||
filter_by(deleted=0).\
|
||||
|
|
Loading…
Reference in New Issue