db: Unify 'nova.db.api', 'nova.db.sqlalchemy.api'

Merge these, removing an unnecessary layer of abstraction, and place
them in the new 'nova.db.main' directory. The resulting change is huge,
but it's mainly the result of 's/sqlalchemy import api/main import api/'
and 's/nova.db.api/nova.db.main.api/' with some necessary cleanup. We
also need to rework how we do the blocking of API calls since we no
longer have a 'DBAPI' object that we can monkey patch as we were doing
before. This is now done via a global variable that is set by the 'main'
function of 'nova.cmd.compute'.

The main impact of this change is that it's no longer possible to set
'[database] use_db_reconnect' and have all APIs automatically wrapped in
a DB retry. Seeing as this behavior is experimental, isn't applied to
any of the API DB methods (which don't use oslo.db's 'DBAPI' helper),
and is used explicitly in what would appear to be the critical cases
(via the explicit 'oslo_db.api.wrap_db_retry' decorator), this doesn't
seem like a huge loss.

Change-Id: Iad2e4da4546b80a016e477577d23accb2606a6e4
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2021-04-01 17:49:02 +01:00
parent 84b6179076
commit 100b9dc62c
164 changed files with 801 additions and 2240 deletions

View File

@ -9,7 +9,6 @@ namespace = oslo.policy
namespace = oslo.privsep
namespace = oslo.service.periodic_task
namespace = oslo.service.service
namespace = oslo.db
namespace = oslo.middleware
namespace = oslo.concurrency
namespace = keystonemiddleware.auth_token

View File

@ -19,12 +19,11 @@
import argparse
import inspect
import traceback
from oslo_log import log as logging
import nova.conf
import nova.db.api
import nova.db.main.api
from nova import exception
from nova.i18n import _
@ -32,23 +31,6 @@ CONF = nova.conf.CONF
LOG = logging.getLogger(__name__)
def block_db_access(service_name):
"""Blocks Nova DB access."""
class NoDB(object):
def __getattr__(self, attr):
return self
def __call__(self, *args, **kwargs):
stacktrace = "".join(traceback.format_stack())
LOG.error('No db access allowed in %(service_name)s: '
'%(stacktrace)s',
dict(service_name=service_name, stacktrace=stacktrace))
raise exception.DBNotAllowed(binary=service_name)
nova.db.api.IMPL = NoDB()
def validate_args(fn, *args, **kwargs):
"""Check that the supplied args are sufficient for calling a function.

View File

@ -25,12 +25,12 @@ from oslo_privsep import priv_context
from oslo_reports import guru_meditation_report as gmr
from oslo_reports import opts as gmr_opts
from nova.cmd import common as cmd_common
from nova.compute import rpcapi as compute_rpcapi
from nova.conductor import rpcapi as conductor_rpcapi
import nova.conf
from nova.conf import remote_debug
from nova import config
import nova.db.main.api
from nova import objects
from nova.objects import base as objects_base
from nova import service
@ -52,7 +52,8 @@ def main():
gmr.TextGuruMeditation.setup_autorun(version, conf=CONF)
cmd_common.block_db_access('nova-compute')
# disable database access for this service
nova.db.main.api.DISABLE_DB_ACCESS = True
objects_base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI()
objects.Service.enable_min_version_cache()
server = service.Service.create(binary='nova-compute',

View File

@ -47,10 +47,9 @@ from nova.compute import api as compute_api
import nova.conf
from nova import config
from nova import context
from nova.db import api as db
from nova.db import constants as db_const
from nova.db.main import api as db
from nova.db import migration
from nova.db.sqlalchemy import api as sa_db
from nova import exception
from nova.i18n import _
from nova.network import constants
@ -121,7 +120,7 @@ class DbCommands(object):
# Added in Pike
quotas_obj.migrate_quota_classes_to_api_db,
# Added in Queens
sa_db.migration_migrate_to_uuid,
db.migration_migrate_to_uuid,
# Added in Queens
block_device_obj.BlockDeviceMapping.populate_uuids,
# Added in Rocky
@ -461,13 +460,12 @@ Error: %s""") % str(e))
for cell in cells:
identity = _('Cell %s') % cell.identity
with context.target_cell(admin_ctxt, cell) as cctxt:
deleted += sa_db.purge_shadow_tables(cctxt,
before_date,
status_fn=status)
deleted += db.purge_shadow_tables(
cctxt, before_date, status_fn=status)
else:
identity = _('DB')
deleted = sa_db.purge_shadow_tables(admin_ctxt,
before_date, status_fn=status)
deleted = db.purge_shadow_tables(
admin_ctxt, before_date, status_fn=status)
if deleted:
return 0
else:

View File

@ -27,7 +27,7 @@ from nova.cmd import common as cmd_common
import nova.conf
from nova import config
from nova import context as nova_context
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova.i18n import _
from nova import policies

View File

@ -32,7 +32,7 @@ from nova.cmd import common as cmd_common
import nova.conf
from nova import config
from nova import context as nova_context
from nova.db.sqlalchemy import api as db_session
from nova.db.main import api as db_session
from nova import exception
from nova.i18n import _
from nova.objects import cell_mapping as cell_mapping_obj

View File

@ -53,8 +53,7 @@ from nova import conductor
import nova.conf
from nova import context as nova_context
from nova import crypto
from nova.db import api as db
from nova.db.sqlalchemy import api as db_api
from nova.db.main import api as db_api
from nova import exception
from nova import exception_wrapper
from nova.i18n import _
@ -5083,7 +5082,7 @@ class API:
def get_instance_metadata(self, context, instance):
"""Get all metadata associated with an instance."""
return db.instance_metadata_get(context, instance.uuid)
return db_api.instance_metadata_get(context, instance.uuid)
@check_instance_lock
@check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.PAUSED,
@ -5963,7 +5962,7 @@ class HostAPI:
"""Return the task logs within a given range, optionally
filtering by host and/or state.
"""
return db.task_log_get_all(
return db_api.task_log_get_all(
context, task_name, period_beginning, period_ending, host=host,
state=state)
@ -6056,7 +6055,7 @@ class HostAPI:
if cell.uuid == objects.CellMapping.CELL0_UUID:
continue
with nova_context.target_cell(context, cell) as cctxt:
cell_stats.append(db.compute_node_statistics(cctxt))
cell_stats.append(db_api.compute_node_statistics(cctxt))
if cell_stats:
keys = cell_stats[0].keys()

View File

@ -97,7 +97,8 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
for key, value in flavor_attributes.items():
kwargs[key] = utils.validate_integer(
kwargs[key], value[0], value[1], db_const.MAX_INT)
kwargs[key], value[0], value[1], db_const.MAX_INT,
)
# rxtx_factor should be a positive float
try:

View File

@ -15,7 +15,7 @@ import copy
from nova.compute import multi_cell_list
import nova.conf
from nova import context
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova import objects
from nova.objects import instance as instance_obj

View File

@ -14,7 +14,7 @@ import copy
from nova.compute import multi_cell_list
from nova import context
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova import objects
from nova.objects import base

View File

@ -49,16 +49,12 @@ api_db_opts = copy.deepcopy(oslo_db_opts.database_opts)
def register_opts(conf):
# TODO(stephenfin): Enable this once we drop use of
# 'oslo_db.api.DBAPI.from_config'
# conf.register_opts(copy.deepcopy(main_db_opts), group=main_db_group)
conf.register_opts(copy.deepcopy(main_db_opts), group=main_db_group)
conf.register_opts(copy.deepcopy(api_db_opts), group=api_db_group)
def list_opts():
return {
# TODO(stephenfin): Enable this once we drop use of
# 'oslo_db.api.DBAPI.from_config'
# main_db_group: main_db_opts,
main_db_group: main_db_opts,
api_db_group: api_db_opts,
}

View File

@ -22,7 +22,7 @@ from oslo_policy import opts as policy_opts
from oslo_utils import importutils
import nova.conf
from nova.db.sqlalchemy import api as sqlalchemy_api
from nova.db.main import api as db_api
from nova import middleware
from nova import policy
from nova import rpc
@ -100,4 +100,4 @@ def parse_args(argv, default_config_files=None, configure_db=True,
rpc.init(CONF)
if configure_db:
sqlalchemy_api.configure(CONF)
db_api.configure(CONF)

View File

@ -339,7 +339,7 @@ def set_target_cell(context, cell_mapping):
global CELL_CACHE
if cell_mapping is not None:
# avoid circular import
from nova.db import api as db
from nova.db.main import api as db
from nova import rpc
# Synchronize access to the cache by multiple API workers.

View File

@ -1,13 +0,0 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Use nova.db.api instead. In the past this file imported * from there,
which led to unwanted imports."""

File diff suppressed because it is too large Load Diff

0
nova/db/main/__init__.py Normal file
View File

View File

@ -23,6 +23,7 @@ import datetime
import functools
import inspect
import sys
import traceback
from oslo_db import api as oslo_db_api
from oslo_db import exception as db_exc
@ -47,7 +48,7 @@ from nova.compute import task_states
from nova.compute import vm_states
import nova.conf
import nova.context
from nova.db.sqlalchemy import models
from nova.db.main import models
from nova import exception
from nova.i18n import _
from nova import safe_utils
@ -55,10 +56,10 @@ from nova import safe_utils
profiler_sqlalchemy = importutils.try_import('osprofiler.sqlalchemy')
CONF = nova.conf.CONF
LOG = logging.getLogger(__name__)
DISABLE_DB_ACCESS = False
main_context_manager = enginefacade.transaction_context()
api_context_manager = enginefacade.transaction_context()
@ -193,6 +194,17 @@ def select_db_reader_mode(f):
return wrapper
def _check_db_access():
# disable all database access if required
if DISABLE_DB_ACCESS:
service_name = 'nova-compute'
stacktrace = ''.join(traceback.format_stack())
LOG.error(
'No DB access allowed in %(service_name)s: %(stacktrace)s',
{'service_name': service_name, 'stacktrace': stacktrace})
raise exception.DBNotAllowed(binary=service_name)
def pick_context_manager_writer(f):
"""Decorator to use a writer db context manager.
@ -202,6 +214,7 @@ def pick_context_manager_writer(f):
"""
@functools.wraps(f)
def wrapper(context, *args, **kwargs):
_check_db_access()
ctxt_mgr = get_context_manager(context)
with ctxt_mgr.writer.using(context):
return f(context, *args, **kwargs)
@ -218,6 +231,7 @@ def pick_context_manager_reader(f):
"""
@functools.wraps(f)
def wrapper(context, *args, **kwargs):
_check_db_access()
ctxt_mgr = get_context_manager(context)
with ctxt_mgr.reader.using(context):
return f(context, *args, **kwargs)
@ -234,6 +248,7 @@ def pick_context_manager_reader_allow_async(f):
"""
@functools.wraps(f)
def wrapper(context, *args, **kwargs):
_check_db_access()
ctxt_mgr = get_context_manager(context)
with ctxt_mgr.reader.allow_async.using(context):
return f(context, *args, **kwargs)

View File

@ -22,7 +22,7 @@ from migrate.versioning.repository import Repository
from oslo_log import log as logging
import sqlalchemy
from nova.db.sqlalchemy import api as db_session
from nova.db.main import api as db_session
from nova import exception
from nova.i18n import _

View File

@ -184,8 +184,8 @@ def import_no_db_in_virt(logical_line, filename):
N307
"""
if "nova/virt" in filename and not filename.endswith("fake.py"):
if logical_line.startswith("from nova.db import api"):
yield (0, "N307: nova.db.api import not allowed in nova/virt/*")
if logical_line.startswith("from nova.db.main import api"):
yield (0, "N307: nova.db.* import not allowed in nova/virt/*")
@core.flake8ext

View File

@ -54,7 +54,7 @@ This module provides Manager, a base class for managers.
from oslo_service import periodic_task
import nova.conf
import nova.db.api
import nova.db.main.api
from nova import profiler
from nova import rpc

View File

@ -19,7 +19,7 @@ from oslo_utils import uuidutils
from sqlalchemy import orm
from nova.compute import utils as compute_utils
from nova.db.sqlalchemy import api as db_api
from nova.db.main import api as db_api
from nova.db.sqlalchemy import api_models
from nova import exception
from nova.i18n import _

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.db import api as db
from nova.db.main import api as db
from nova.objects import base
from nova.objects import fields

View File

@ -19,9 +19,8 @@ from oslo_utils import uuidutils
from oslo_utils import versionutils
from nova import block_device
from nova.db import api as db
from nova.db.sqlalchemy import api as db_api
from nova.db.sqlalchemy import models as db_models
from nova.db.main import api as db
from nova.db.main import models as db_models
from nova import exception
from nova.i18n import _
from nova import objects
@ -109,7 +108,7 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
@classmethod
def populate_uuids(cls, context, count):
@db_api.pick_context_manager_reader
@db.pick_context_manager_reader
def get_bdms_no_uuid(context):
return context.session.query(db_models.BlockDeviceMapping).\
filter_by(uuid=None).limit(count).all()
@ -145,7 +144,7 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
# normally a read operation. Forcing everything (transitively)
# which reads a BDM to be in a write transaction for a narrow
# temporary edge case is undesirable.
tctxt = db_api.get_context_manager(context).writer.independent
tctxt = db.get_context_manager(context).writer.independent
with tctxt.using(context):
query = context.session.query(db_models.BlockDeviceMapping).\
filter_by(id=bdm_id)

View File

@ -18,7 +18,7 @@ from oslo_serialization import jsonutils
from oslo_utils import versionutils
from oslo_versionedobjects import exception as ovoo_exc
from nova.db.sqlalchemy import api as db
from nova.db.main import api as db
from nova.db.sqlalchemy import api_models
from nova import exception
from nova import objects

View File

@ -18,7 +18,7 @@ from sqlalchemy import sql
from sqlalchemy.sql import expression
import nova.conf
from nova.db.sqlalchemy import api as db_api
from nova.db.main import api as db_api
from nova.db.sqlalchemy import api_models
from nova import exception
from nova.objects import base

View File

@ -19,9 +19,8 @@ import sqlalchemy as sa
from sqlalchemy import sql
import nova.conf
from nova.db import api as db
from nova.db.sqlalchemy import api as sa_api
from nova.db.sqlalchemy import models
from nova.db.main import api as db
from nova.db.main import models
from nova import exception
from nova import objects
from nova.objects import base
@ -469,7 +468,7 @@ class ComputeNodeList(base.ObjectListBase, base.NovaObject):
@staticmethod
@db.select_db_reader_mode
def _db_compute_node_get_all_by_uuids(context, compute_uuids):
db_computes = sa_api.model_query(context, models.ComputeNode).filter(
db_computes = db.model_query(context, models.ComputeNode).filter(
models.ComputeNode.uuid.in_(compute_uuids)).all()
return db_computes
@ -509,7 +508,7 @@ def _get_node_empty_ratio(context, max_count):
)).filter(models.ComputeNode.deleted == 0).limit(max_count).all()
@sa_api.pick_context_manager_writer
@db.pick_context_manager_writer
def migrate_empty_ratio(context, max_count):
cns = _get_node_empty_ratio(context, max_count)

View File

@ -21,7 +21,7 @@ from oslo_utils import strutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova.i18n import _
from nova.objects import base

View File

@ -17,7 +17,7 @@ import functools
from oslo_utils import uuidutils
from nova import cache_utils
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova.objects import base
from nova.objects import fields

View File

@ -21,8 +21,7 @@ from sqlalchemy import sql
from sqlalchemy.sql import expression
import nova.conf
from nova.db.sqlalchemy import api as db_api
from nova.db.sqlalchemy.api import require_context
from nova.db.main import api as db_api
from nova.db.sqlalchemy import api_models
from nova import exception
from nova.notifications.objects import base as notification
@ -282,7 +281,7 @@ class Flavor(base.NovaPersistentObject, base.NovaObject,
return query
@staticmethod
@require_context
@db_api.require_context
def _flavor_get_from_db(context, id):
"""Returns a dict describing specific flavor."""
result = Flavor._flavor_get_query_from_db(context).\
@ -293,7 +292,7 @@ class Flavor(base.NovaPersistentObject, base.NovaObject,
return _dict_with_extra_specs(result)
@staticmethod
@require_context
@db_api.require_context
def _flavor_get_by_name_from_db(context, name):
"""Returns a dict describing specific flavor."""
result = Flavor._flavor_get_query_from_db(context).\
@ -304,7 +303,7 @@ class Flavor(base.NovaPersistentObject, base.NovaObject,
return _dict_with_extra_specs(result)
@staticmethod
@require_context
@db_api.require_context
def _flavor_get_by_flavor_id_from_db(context, flavor_id):
"""Returns a dict describing specific flavor_id."""
result = Flavor._flavor_get_query_from_db(context).\

View File

@ -14,7 +14,7 @@ from oslo_db import exception as db_exc
from sqlalchemy import orm
from nova import context
from nova.db.sqlalchemy import api as db_api
from nova.db.main import api as db_api
from nova.db.sqlalchemy import api_models
from nova import exception
from nova.i18n import _

View File

@ -27,9 +27,8 @@ from sqlalchemy.sql import func
from nova import availability_zones as avail_zone
from nova.compute import task_states
from nova.compute import vm_states
from nova.db import api as db
from nova.db.sqlalchemy import api as db_api
from nova.db.sqlalchemy import models
from nova.db.main import api as db
from nova.db.main import models
from nova import exception
from nova.i18n import _
from nova.network import model as network_model
@ -1254,7 +1253,7 @@ def _make_instance_list(context, inst_list, db_inst_list, expected_attrs):
return inst_list
@db_api.pick_context_manager_writer
@db.pick_context_manager_writer
def populate_missing_availability_zones(context, count):
# instances without host have no reasonable AZ to set
not_empty_host = models.Instance.host != None # noqa E711
@ -1344,7 +1343,7 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
expected_attrs)
@staticmethod
@db_api.pick_context_manager_reader
@db.pick_context_manager_reader
def _get_uuids_by_host_and_node(context, host, node):
return context.session.query(
models.Instance.uuid).filter_by(
@ -1495,7 +1494,7 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
return db.instance_get_all_uuids_by_hosts(context, hosts)
@staticmethod
@db_api.pick_context_manager_reader
@db.pick_context_manager_reader
def _get_count_by_vm_state_in_db(context, project_id, user_id, vm_state):
return context.session.query(models.Instance.id).\
filter_by(deleted=0).\
@ -1510,9 +1509,9 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
vm_state)
@staticmethod
@db_api.pick_context_manager_reader
@db.pick_context_manager_reader
def _get_counts_in_db(context, project_id, user_id=None):
# NOTE(melwitt): Copied from nova/db/sqlalchemy/api.py:
# NOTE(melwitt): Copied from nova/db/main/api.py:
# It would be better to have vm_state not be nullable
# but until then we test it explicitly as a workaround.
not_soft_deleted = sa.or_(
@ -1567,7 +1566,7 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
return cls._get_counts_in_db(context, project_id, user_id=user_id)
@staticmethod
@db_api.pick_context_manager_reader
@db.pick_context_manager_reader
def _get_count_by_hosts(context, hosts):
return context.session.query(models.Instance).\
filter_by(deleted=0).\

View File

@ -16,7 +16,7 @@ from oslo_utils import timeutils
from oslo_utils import versionutils
from nova.compute import utils as compute_utils
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova import objects
from nova.objects import base

View File

@ -16,7 +16,7 @@ import itertools
from oslo_log import log as logging
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova import objects
from nova.objects import base

View File

@ -22,7 +22,7 @@ from oslo_utils import versionutils
from sqlalchemy import orm
from nova.compute import utils as compute_utils
from nova.db.sqlalchemy import api as db_api
from nova.db.main import api as db_api
from nova.db.sqlalchemy import api_models
from nova import exception
from nova import objects

View File

@ -14,7 +14,7 @@
from oslo_log import log as logging
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova.objects import base
from nova.objects import fields

View File

@ -20,7 +20,7 @@ from sqlalchemy import sql
from sqlalchemy.sql import func
from nova import context as nova_context
from nova.db.sqlalchemy import api as db_api
from nova.db.main import api as db_api
from nova.db.sqlalchemy import api_models
from nova import exception
from nova.i18n import _

View File

@ -17,7 +17,7 @@ import itertools
from oslo_serialization import jsonutils
from oslo_utils import versionutils
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova.i18n import _
from nova.objects import base

View File

@ -13,7 +13,7 @@
from oslo_serialization import jsonutils
from oslo_utils import versionutils
from nova.db import api as db
from nova.db.main import api as db
from nova.objects import base
from nova.objects import fields

View File

@ -17,8 +17,7 @@ from oslo_db.sqlalchemy import utils as sqlalchemyutils
from oslo_log import log as logging
from oslo_utils import versionutils
from nova.db import api as db
from nova.db.sqlalchemy import api as db_api
from nova.db.main import api as db
from nova.db.sqlalchemy import api_models
from nova import exception
from nova import objects
@ -30,7 +29,7 @@ KEYPAIR_TYPE_X509 = 'x509'
LOG = logging.getLogger(__name__)
@db_api.api_context_manager.reader
@db.api_context_manager.reader
def _get_from_db(context, user_id, name=None, limit=None, marker=None):
query = context.session.query(api_models.KeyPair).\
filter(api_models.KeyPair.user_id == user_id)
@ -55,14 +54,14 @@ def _get_from_db(context, user_id, name=None, limit=None, marker=None):
return query.all()
@db_api.api_context_manager.reader
@db.api_context_manager.reader
def _get_count_from_db(context, user_id):
return context.session.query(api_models.KeyPair).\
filter(api_models.KeyPair.user_id == user_id).\
count()
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _create_in_db(context, values):
kp = api_models.KeyPair()
kp.update(values)
@ -73,7 +72,7 @@ def _create_in_db(context, values):
return kp
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _destroy_in_db(context, user_id, name):
result = context.session.query(api_models.KeyPair).\
filter_by(user_id=user_id).\

View File

@ -16,7 +16,7 @@ from oslo_db import exception as db_exc
from oslo_utils import uuidutils
from oslo_utils import versionutils
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova.i18n import _
from nova import objects

View File

@ -16,7 +16,7 @@ from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import versionutils
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova import objects
from nova.objects import base

View File

@ -22,9 +22,8 @@ from oslo_serialization import jsonutils
from oslo_utils import uuidutils
from oslo_utils import versionutils
from nova.db import api as db
from nova.db.sqlalchemy import api as db_api
from nova.db.sqlalchemy import models as db_models
from nova.db.main import api as db
from nova.db.main import models as db_models
from nova import exception
from nova import objects
from nova.objects import base
@ -208,7 +207,7 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject):
@classmethod
def populate_dev_uuids(cls, context, count):
@db_api.pick_context_manager_reader
@db.pick_context_manager_reader
def get_devs_no_uuid(context):
return context.session.query(db_models.PciDevice).\
filter_by(uuid=None).limit(count).all()
@ -264,7 +263,7 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject):
# normally a read operation. Forcing everything (transitively) which
# reads a PCI device to be in a write transaction for a narrow
# temporary edge case is undesirable.
tctxt = db_api.get_context_manager(context).writer.independent
tctxt = db.get_context_manager(context).writer.independent
with tctxt.using(context):
query = context.session.query(db_models.PciDevice).\
filter_by(id=dev_id)

View File

@ -16,10 +16,9 @@ import collections
from oslo_db import exception as db_exc
from nova.db import api as db
from nova.db.sqlalchemy import api as db_api
from nova.db.main import api as db
from nova.db.main import models as main_models
from nova.db.sqlalchemy import api_models
from nova.db.sqlalchemy import models as main_models
from nova import exception
from nova.objects import base
from nova.objects import fields
@ -83,7 +82,7 @@ class Quotas(base.NovaObject):
self.obj_reset_changes(fields=[attr])
@staticmethod
@db_api.api_context_manager.reader
@db.api_context_manager.reader
def _get_from_db(context, project_id, resource, user_id=None):
model = api_models.ProjectUserQuota if user_id else api_models.Quota
query = context.session.query(model).\
@ -101,14 +100,14 @@ class Quotas(base.NovaObject):
return result
@staticmethod
@db_api.api_context_manager.reader
@db.api_context_manager.reader
def _get_all_from_db(context, project_id):
return context.session.query(api_models.ProjectUserQuota).\
filter_by(project_id=project_id).\
all()
@staticmethod
@db_api.api_context_manager.reader
@db.api_context_manager.reader
def _get_all_from_db_by_project(context, project_id):
# by_project refers to the returned dict that has a 'project_id' key
rows = context.session.query(api_models.Quota).\
@ -120,7 +119,7 @@ class Quotas(base.NovaObject):
return result
@staticmethod
@db_api.api_context_manager.reader
@db.api_context_manager.reader
def _get_all_from_db_by_project_and_user(context, project_id, user_id):
# by_project_and_user refers to the returned dict that has
# 'project_id' and 'user_id' keys
@ -136,7 +135,7 @@ class Quotas(base.NovaObject):
return result
@staticmethod
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _destroy_all_in_db_by_project(context, project_id):
per_project = context.session.query(api_models.Quota).\
filter_by(project_id=project_id).\
@ -148,7 +147,7 @@ class Quotas(base.NovaObject):
raise exception.ProjectQuotaNotFound(project_id=project_id)
@staticmethod
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _destroy_all_in_db_by_project_and_user(context, project_id, user_id):
result = context.session.query(api_models.ProjectUserQuota).\
filter_by(project_id=project_id).\
@ -159,7 +158,7 @@ class Quotas(base.NovaObject):
user_id=user_id)
@staticmethod
@db_api.api_context_manager.reader
@db.api_context_manager.reader
def _get_class_from_db(context, class_name, resource):
result = context.session.query(api_models.QuotaClass).\
filter_by(class_name=class_name).\
@ -170,7 +169,7 @@ class Quotas(base.NovaObject):
return result
@staticmethod
@db_api.api_context_manager.reader
@db.api_context_manager.reader
def _get_all_class_from_db_by_name(context, class_name):
# by_name refers to the returned dict that has a 'class_name' key
rows = context.session.query(api_models.QuotaClass).\
@ -182,14 +181,14 @@ class Quotas(base.NovaObject):
return result
@staticmethod
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _create_limit_in_db(context, project_id, resource, limit,
user_id=None):
# TODO(melwitt): We won't have per project resources after nova-network
# is removed.
# TODO(stephenfin): We need to do something here now...but what?
per_user = (user_id and
resource not in db_api.quota_get_per_project_resources())
resource not in db.quota_get_per_project_resources())
quota_ref = (api_models.ProjectUserQuota() if per_user
else api_models.Quota())
if per_user:
@ -205,14 +204,14 @@ class Quotas(base.NovaObject):
return quota_ref
@staticmethod
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _update_limit_in_db(context, project_id, resource, limit,
user_id=None):
# TODO(melwitt): We won't have per project resources after nova-network
# is removed.
# TODO(stephenfin): We need to do something here now...but what?
per_user = (user_id and
resource not in db_api.quota_get_per_project_resources())
resource not in db.quota_get_per_project_resources())
model = api_models.ProjectUserQuota if per_user else api_models.Quota
query = context.session.query(model).\
filter_by(project_id=project_id).\
@ -229,7 +228,7 @@ class Quotas(base.NovaObject):
raise exception.ProjectQuotaNotFound(project_id=project_id)
@staticmethod
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _create_class_in_db(context, class_name, resource, limit):
# NOTE(melwitt): There's no unique constraint on the QuotaClass model,
# so check for duplicate manually.
@ -248,7 +247,7 @@ class Quotas(base.NovaObject):
return quota_class_ref
@staticmethod
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _update_class_in_db(context, class_name, resource, limit):
result = context.session.query(api_models.QuotaClass).\
filter_by(class_name=class_name).\
@ -467,7 +466,7 @@ class Quotas(base.NovaObject):
def get_default_class(cls, context):
try:
qclass = cls._get_all_class_from_db_by_name(
context, db_api._DEFAULT_QUOTA_NAME)
context, db._DEFAULT_QUOTA_NAME)
except exception.QuotaClassNotFound:
qclass = db.quota_class_get_default(context)
return qclass
@ -502,8 +501,8 @@ class QuotasNoOp(Quotas):
pass
@db_api.require_context
@db_api.pick_context_manager_reader
@db.require_context
@db.pick_context_manager_reader
def _get_main_per_project_limits(context, limit):
return context.session.query(main_models.Quota).\
filter_by(deleted=0).\
@ -511,8 +510,8 @@ def _get_main_per_project_limits(context, limit):
all()
@db_api.require_context
@db_api.pick_context_manager_reader
@db.require_context
@db.pick_context_manager_reader
def _get_main_per_user_limits(context, limit):
return context.session.query(main_models.ProjectUserQuota).\
filter_by(deleted=0).\
@ -520,8 +519,8 @@ def _get_main_per_user_limits(context, limit):
all()
@db_api.require_context
@db_api.pick_context_manager_writer
@db.require_context
@db.pick_context_manager_writer
def _destroy_main_per_project_limits(context, project_id, resource):
context.session.query(main_models.Quota).\
filter_by(deleted=0).\
@ -530,8 +529,8 @@ def _destroy_main_per_project_limits(context, project_id, resource):
soft_delete(synchronize_session=False)
@db_api.require_context
@db_api.pick_context_manager_writer
@db.require_context
@db.pick_context_manager_writer
def _destroy_main_per_user_limits(context, project_id, resource, user_id):
context.session.query(main_models.ProjectUserQuota).\
filter_by(deleted=0).\
@ -541,7 +540,7 @@ def _destroy_main_per_user_limits(context, project_id, resource, user_id):
soft_delete(synchronize_session=False)
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _create_limits_in_api_db(context, db_limits, per_user=False):
for db_limit in db_limits:
user_id = db_limit.user_id if per_user else None
@ -588,8 +587,8 @@ def migrate_quota_limits_to_api_db(context, count):
return len(main_per_project_limits) + len(main_per_user_limits), done
@db_api.require_context
@db_api.pick_context_manager_reader
@db.require_context
@db.pick_context_manager_reader
def _get_main_quota_classes(context, limit):
return context.session.query(main_models.QuotaClass).\
filter_by(deleted=0).\
@ -597,7 +596,7 @@ def _get_main_quota_classes(context, limit):
all()
@db_api.pick_context_manager_writer
@db.pick_context_manager_writer
def _destroy_main_quota_classes(context, db_classes):
for db_class in db_classes:
context.session.query(main_models.QuotaClass).\
@ -606,7 +605,7 @@ def _destroy_main_quota_classes(context, db_classes):
soft_delete(synchronize_session=False)
@db_api.api_context_manager.writer
@db.api_context_manager.writer
def _create_classes_in_api_db(context, db_classes):
for db_class in db_classes:
Quotas._create_class_in_db(context, db_class.class_name,

View File

@ -20,7 +20,7 @@ from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import versionutils
from nova.db.sqlalchemy import api as db
from nova.db.main import api as db
from nova.db.sqlalchemy import api_models
from nova import exception
from nova import objects

View File

@ -14,7 +14,7 @@
from oslo_serialization import jsonutils
from nova.db import api as db
from nova.db.main import api as db
from nova.objects import base
from nova.objects import fields

View File

@ -18,9 +18,8 @@
from oslo_utils import uuidutils
from oslo_utils import versionutils
from nova.db import api as db
from nova.db.sqlalchemy import api as db_api
from nova.db.sqlalchemy import models
from nova.db.main import api as db
from nova.db.main import models
from nova import objects
from nova.objects import base
from nova.objects import fields
@ -115,7 +114,7 @@ class SecurityGroupList(base.ObjectListBase, base.NovaObject):
self.obj_reset_changes()
@staticmethod
@db_api.pick_context_manager_reader
@db.pick_context_manager_reader
def _get_counts_from_db(context, project_id, user_id=None):
query = context.session.query(models.SecurityGroup.id).\
filter_by(deleted=0).\

View File

@ -18,7 +18,7 @@ from oslo_utils import versionutils
from nova import availability_zones
from nova import context as nova_context
from nova.db import api as db
from nova.db.main import api as db
from nova import exception
from nova.notifications.objects import base as notification
from nova.notifications.objects import service as service_notification

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.db import api as db
from nova.db.main import api as db
from nova import objects
from nova.objects import base
from nova.objects import fields

View File

<
@ -10,7 +10,7 @@