diff --git a/etc/nova/nova-config-generator.conf b/etc/nova/nova-config-generator.conf index 50a2f75c46..1b946d6af8 100644 --- a/etc/nova/nova-config-generator.conf +++ b/etc/nova/nova-config-generator.conf @@ -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 diff --git a/nova/cmd/common.py b/nova/cmd/common.py index 1d4d5b4612..88dabc2c45 100644 --- a/nova/cmd/common.py +++ b/nova/cmd/common.py @@ -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. diff --git a/nova/cmd/compute.py b/nova/cmd/compute.py index 24ce1b3ba8..a433aeb693 100644 --- a/nova/cmd/compute.py +++ b/nova/cmd/compute.py @@ -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', diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index cb141dc32d..335ad29225 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -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: diff --git a/nova/cmd/policy.py b/nova/cmd/policy.py index 051983d102..4273463fd9 100644 --- a/nova/cmd/policy.py +++ b/nova/cmd/policy.py @@ -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 diff --git a/nova/cmd/status.py b/nova/cmd/status.py index 75ae63d07d..8e8f8b0dcd 100644 --- a/nova/cmd/status.py +++ b/nova/cmd/status.py @@ -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 diff --git a/nova/compute/api.py b/nova/compute/api.py index d1fd60e5ce..909cd52962 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -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() diff --git a/nova/compute/flavors.py b/nova/compute/flavors.py index 153abbd375..c12b0de65a 100644 --- a/nova/compute/flavors.py +++ b/nova/compute/flavors.py @@ -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: diff --git a/nova/compute/instance_list.py b/nova/compute/instance_list.py index 782e8fac20..de9f7d3aee 100644 --- a/nova/compute/instance_list.py +++ b/nova/compute/instance_list.py @@ -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 diff --git a/nova/compute/migration_list.py b/nova/compute/migration_list.py index 77b36c83fe..933b0d6c6e 100644 --- a/nova/compute/migration_list.py +++ b/nova/compute/migration_list.py @@ -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 diff --git a/nova/conf/database.py b/nova/conf/database.py index f7e1c7cc2c..f6223f65cc 100644 --- a/nova/conf/database.py +++ b/nova/conf/database.py @@ -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, } diff --git a/nova/config.py b/nova/config.py index af745bc485..1af8458976 100644 --- a/nova/config.py +++ b/nova/config.py @@ -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) diff --git a/nova/context.py b/nova/context.py index a6d706fdb0..619c39e212 100644 --- a/nova/context.py +++ b/nova/context.py @@ -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. diff --git a/nova/db/__init__.py b/nova/db/__init__.py index 8c26ee86a2..e69de29bb2 100644 --- a/nova/db/__init__.py +++ b/nova/db/__init__.py @@ -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.""" diff --git a/nova/db/api.py b/nova/db/api.py deleted file mode 100644 index 35ddc64758..0000000000 --- a/nova/db/api.py +++ /dev/null @@ -1,1463 +0,0 @@ -# Copyright (c) 2011 X.commerce, a business unit of eBay Inc. -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# All Rights Reserved. -# -# 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. - -"""Defines interface for DB access. - -Functions in this module are imported into the nova.db namespace. Call these -functions from nova.db namespace, not the nova.db.api namespace. - -All functions in this module return objects that implement a dictionary-like -interface. Currently, many of these objects are sqlalchemy objects that -implement a dictionary interface. However, a future goal is to have all of -these objects be simple dictionaries. - -""" - -from oslo_db import api -from oslo_log import log as logging - -import nova.conf - -CONF = nova.conf.CONF -LOG = logging.getLogger(__name__) - -IMPL = api.DBAPI.from_config( - conf=CONF, backend_mapping={'sqlalchemy': 'nova.db.sqlalchemy.api'}, -) - - -################### - - -def constraint(**conditions): - """Return a constraint object suitable for use with some updates.""" - return IMPL.constraint(**conditions) - - -def equal_any(*values): - """Return an equality condition object suitable for use in a constraint. - - Equal_any conditions require that a model object's attribute equal any - one of the given values. - """ - return IMPL.equal_any(*values) - - -def not_equal(*values): - """Return an inequality condition object suitable for use in a constraint. - - Not_equal conditions require that a model object's attribute differs from - all of the given values. - """ - return IMPL.not_equal(*values) - - -def create_context_manager(connection=None): - """Create a database context manager object for a cell database connection. - - :param connection: The database connection string - """ - return IMPL.create_context_manager(connection=connection) - - -################### - - -def select_db_reader_mode(f): - """Decorator to select synchronous or asynchronous reader mode. - - The kwarg argument 'use_slave' defines reader mode. Asynchronous reader - will be used if 'use_slave' is True and synchronous reader otherwise. - If 'use_slave' is not specified default value 'False' will be used. - - Wrapped function must have a context in the arguments. - """ - return IMPL.select_db_reader_mode(f) - - -################### - - -def service_destroy(context, service_id): - """Destroy the service or raise if it does not exist.""" - return IMPL.service_destroy(context, service_id) - - -def service_get(context, service_id): - """Get a service or raise if it does not exist.""" - return IMPL.service_get(context, service_id) - - -def service_get_by_uuid(context, service_uuid): - """Get a service by it's uuid or raise ServiceNotFound if it does not - exist. - """ - return IMPL.service_get_by_uuid(context, service_uuid) - - -def service_get_minimum_version(context, binaries): - """Get the minimum service version in the database.""" - return IMPL.service_get_minimum_version(context, binaries) - - -def service_get_by_host_and_topic(context, host, topic): - """Get a service by hostname and topic it listens to.""" - return IMPL.service_get_by_host_and_topic(context, host, topic) - - -def service_get_by_host_and_binary(context, host, binary): - """Get a service by hostname and binary.""" - return IMPL.service_get_by_host_and_binary(context, host, binary) - - -def service_get_all(context, disabled=None): - """Get all services.""" - return IMPL.service_get_all(context, disabled) - - -def service_get_all_by_topic(context, topic): - """Get all services for a given topic.""" - return IMPL.service_get_all_by_topic(context, topic) - - -def service_get_all_by_binary(context, binary, include_disabled=False): - """Get services for a given binary. - - Includes disabled services if 'include_disabled' parameter is True - """ - return IMPL.service_get_all_by_binary(context, binary, - include_disabled=include_disabled) - - -def service_get_all_computes_by_hv_type(context, hv_type, - include_disabled=False): - """Get all compute services for a given hypervisor type. - - Includes disabled services if 'include_disabled' parameter is True. - """ - return IMPL.service_get_all_computes_by_hv_type(context, hv_type, - include_disabled=include_disabled) - - -def service_get_all_by_host(context, host): - """Get all services for a given host.""" - return IMPL.service_get_all_by_host(context, host) - - -def service_get_by_compute_host(context, host): - """Get the service entry for a given compute host. - - Returns the service entry joined with the compute_node entry. - """ - return IMPL.service_get_by_compute_host(context, host) - - -def service_create(context, values): - """Create a service from the values dictionary.""" - return IMPL.service_create(context, values) - - -def service_update(context, service_id, values): - """Set the given properties on a service and update it. - - :raises: NotFound if service does not exist. - """ - return IMPL.service_update(context, service_id, values) - - -################### - - -def compute_node_get(context, compute_id): - """Get a compute node by its id. - - :param context: The security context - :param compute_id: ID of the compute node - - :returns: Dictionary-like object containing properties of the compute node - :raises: ComputeHostNotFound if compute node with the given ID doesn't - exist. - """ - return IMPL.compute_node_get(context, compute_id) - - -# TODO(edleafe): remove once the compute node resource provider migration is -# complete, and this distinction is no longer necessary. -def compute_node_get_model(context, compute_id): - """Get a compute node sqlalchemy model object by its id. - - :param context: The security context - :param compute_id: ID of the compute node - - :returns: Sqlalchemy model object containing properties of the compute node - :raises: ComputeHostNotFound if compute node with the given ID doesn't - exist. - """ - return IMPL.compute_node_get_model(context, compute_id) - - -def compute_nodes_get_by_service_id(context, service_id): - """Get a list of compute nodes by their associated service id. - - :param context: The security context - :param service_id: ID of the associated service - - :returns: List of dictionary-like objects, each containing properties of - the compute node, including its corresponding service and statistics - :raises: ServiceNotFound if service with the given ID doesn't exist. - """ - return IMPL.compute_nodes_get_by_service_id(context, service_id) - - -def compute_node_get_by_host_and_nodename(context, host, nodename): - """Get a compute node by its associated host and nodename. - - :param context: The security context (admin) - :param host: Name of the host - :param nodename: Name of the node - - :returns: Dictionary-like object containing properties of the compute node, - including its statistics - :raises: ComputeHostNotFound if host with the given name doesn't exist. - """ - return IMPL.compute_node_get_by_host_and_nodename(context, host, nodename) - - -def compute_node_get_by_nodename(context, hypervisor_hostname): - """Get a compute node by hypervisor_hostname. - - :param context: The security context (admin) - :param hypervisor_hostname: Name of the node - - :returns: Dictionary-like object containing properties of the compute node, - including its statistics - :raises: ComputeHostNotFound if hypervisor_hostname with the given name - doesn't exist. - """ - return IMPL.compute_node_get_by_nodename(context, hypervisor_hostname) - - -def compute_node_get_all(context): - """Get all compute nodes. - - :param context: The security context - - :returns: List of dictionaries each containing compute node properties - """ - return IMPL.compute_node_get_all(context) - - -def compute_node_get_all_mapped_less_than(context, mapped_less_than): - """Get all compute nodes with specific mapped values. - - :param context: The security context - :param mapped_less_than: Get compute nodes with mapped less than this value - - :returns: List of dictionaries each containing compute node properties - """ - return IMPL.compute_node_get_all_mapped_less_than(context, - mapped_less_than) - - -def compute_node_get_all_by_pagination(context, limit=None, marker=None): - """Get all compute nodes by pagination. - - :param context: The security context - :param limit: Maximum number of items to return - :param marker: The last item of the previous page, the next results after - this value will be returned - - :returns: List of dictionaries each containing compute node properties - """ - return IMPL.compute_node_get_all_by_pagination(context, - limit=limit, marker=marker) - - -def compute_node_get_all_by_host(context, host): - """Get all compute nodes by host name. - - :param context: The security context (admin) - :param host: Name of the host - - :returns: List of dictionaries each containing compute node properties - """ - return IMPL.compute_node_get_all_by_host(context, host) - - -def compute_node_search_by_hypervisor(context, hypervisor_match): - """Get all compute nodes by hypervisor hostname. - - :param context: The security context - :param hypervisor_match: The hypervisor hostname - - :returns: List of dictionary-like objects each containing compute node - properties - """ - return IMPL.compute_node_search_by_hypervisor(context, hypervisor_match) - - -def compute_node_create(context, values): - """Create a compute node from the values dictionary. - - :param context: The security context - :param values: Dictionary containing compute node properties - - :returns: Dictionary-like object containing the properties of the created - node, including its corresponding service and statistics - """ - return IMPL.compute_node_create(context, values) - - -def compute_node_update(context, compute_id, values): - """Set the given properties on a compute node and update it. - - :param context: The security context - :param compute_id: ID of the compute node - :param values: Dictionary containing compute node properties to be updated - - :returns: Dictionary-like object containing the properties of the updated - compute node, including its corresponding service and statistics - :raises: ComputeHostNotFound if compute node with the given ID doesn't - exist. - """ - return IMPL.compute_node_update(context, compute_id, values) - - -def compute_node_delete(context, compute_id): - """Delete a compute node from the database. - - :param context: The security context - :param compute_id: ID of the compute node - :raises: ComputeHostNotFound if compute node with the given ID doesn't - exist. - """ - return IMPL.compute_node_delete(context, compute_id) - - -def compute_node_statistics(context): - """Get aggregate statistics over all compute nodes. - - :param context: The security context - - :returns: Dictionary containing compute node characteristics summed up - over all the compute nodes, e.g. 'vcpus', 'free_ram_mb' etc. - """ - return IMPL.compute_node_statistics(context) - - -################### - - -def certificate_create(context, values): - """Create a certificate from the values dictionary.""" - return IMPL.certificate_create(context, values) - - -def certificate_get_all_by_project(context, project_id): - """Get all certificates for a project.""" - return IMPL.certificate_get_all_by_project(context, project_id) - - -def certificate_get_all_by_user(context, user_id): - """Get all certificates for a user.""" - return IMPL.certificate_get_all_by_user(context, user_id) - - -def certificate_get_all_by_user_and_project(context, user_id, project_id): - """Get all certificates for a user and project.""" - return IMPL.certificate_get_all_by_user_and_project(context, - user_id, - project_id) - - -#################### - - -def migration_update(context, migration_id, values): - """Update a migration instance.""" - return IMPL.migration_update(context, migration_id, values) - - -def migration_create(context, values): - """Create a migration record.""" - return IMPL.migration_create(context, values) - - -def migration_get(context, migration_id): - """Finds a migration by the ID.""" - return IMPL.migration_get(context, migration_id) - - -def migration_get_by_uuid(context, migration_uuid): - """Finds a migration by the migration UUID.""" - return IMPL.migration_get_by_uuid(context, migration_uuid) - - -def migration_get_by_id_and_instance(context, migration_id, instance_uuid): - """Finds a migration by the migration ID and the instance UUID.""" - return IMPL.migration_get_by_id_and_instance(context, - migration_id, - instance_uuid) - - -def migration_get_by_instance_and_status(context, instance_uuid, status): - """Finds a migration by the instance UUID it's migrating.""" - return IMPL.migration_get_by_instance_and_status(context, instance_uuid, - status) - - -def migration_get_unconfirmed_by_dest_compute(context, confirm_window, - dest_compute): - """Finds all unconfirmed migrations within the confirmation window for - a specific destination compute host. - """ - return IMPL.migration_get_unconfirmed_by_dest_compute(context, - confirm_window, dest_compute) - - -def migration_get_in_progress_by_host_and_node(context, host, node): - """Finds all migrations for the given host + node that are not yet - confirmed or reverted. - """ - return IMPL.migration_get_in_progress_by_host_and_node(context, host, node) - - -def migration_get_all_by_filters(context, filters, sort_keys=None, - sort_dirs=None, limit=None, marker=None): - """Finds all migrations using the provided filters.""" - return IMPL.migration_get_all_by_filters(context, filters, - sort_keys=sort_keys, - sort_dirs=sort_dirs, - limit=limit, marker=marker) - - -def migration_get_in_progress_by_instance(context, instance_uuid, - migration_type=None): - """Finds all migrations of an instance in progress.""" - return IMPL.migration_get_in_progress_by_instance(context, instance_uuid, - migration_type) - - -def migration_get_by_sort_filters(context, sort_keys, sort_dirs, values): - """Get the uuid of the first migration in a sort order. - - Return the first migration (uuid) of the set where each column value - is greater than or equal to the matching one in @values, for each key - in @sort_keys. This is used to try to find a marker migration when we don't - have a marker uuid. - - :returns: A UUID of the migration that matched. - """ - return IMPL.migration_get_by_sort_filters(context, sort_keys, sort_dirs, - values) - - -def migration_get_in_progress_and_error_by_host_and_node(context, host, node): - """Finds all in progress migrations and error migrations for the given - host and node. - """ - return IMPL.migration_get_in_progress_and_error_by_host_and_node( - context, host, node) - - -#################### - - -def virtual_interface_create(context, values): - """Create a new virtual interface record. - - :param values: Dict containing column values. - """ - return IMPL.virtual_interface_create(context, values) - - -def virtual_interface_update(context, address, values): - """Create a virtual interface record in the database.""" - return IMPL.virtual_interface_update(context, address, values) - - -def virtual_interface_get(context, vif_id): - """Get a virtual interface by ID. - - :param vif_id: ID of the virtual interface. - """ - return IMPL.virtual_interface_get(context, vif_id) - - -def virtual_interface_get_by_address(context, address): - """Get a virtual interface by address. - - :param address: The address of the interface you're looking to get. - """ - return IMPL.virtual_interface_get_by_address(context, address) - - -def virtual_interface_get_by_uuid(context, vif_uuid): - """Get a virtual interface by UUID. - - :param vif_uuid: The uuid of the interface you're looking to get - """ - return IMPL.virtual_interface_get_by_uuid(context, vif_uuid) - - -def virtual_interface_get_by_instance(context, instance_uuid): - """Gets all virtual interfaces for instance. - - :param instance_uuid: UUID of the instance to filter on. - """ - return IMPL.virtual_interface_get_by_instance(context, instance_uuid) - - -def virtual_interface_get_by_instance_and_network( - context, instance_uuid, network_id, -): - """Get all virtual interface for instance that's associated with - network. - """ - return IMPL.virtual_interface_get_by_instance_and_network( - context, instance_uuid, network_id, - ) - - -def virtual_interface_delete_by_instance(context, instance_uuid): - """Delete virtual interface records associated with instance. - - :param instance_uuid: UUID of the instance to filter on. - """ - return IMPL.virtual_interface_delete_by_instance(context, instance_uuid) - - -def virtual_interface_delete(context, id): - """Delete a virtual interface records. - - :param id: ID of the interface. - """ - return IMPL.virtual_interface_delete(context, id) - - -def virtual_interface_get_all(context): - """Get all virtual interface records.""" - return IMPL.virtual_interface_get_all(context) - - -#################### - - -def instance_create(context, values): - """Create an instance from the values dictionary. - - :param context: Request context object - :param values: Dict containing column values. - """ - return IMPL.instance_create(context, values) - - -def instance_destroy(context, instance_uuid, constraint=None, - hard_delete=False): - """Destroy the instance or raise if it does not exist. - - :param context: request context object - :param instance_uuid: uuid of the instance to delete - :param constraint: a constraint object - :param hard_delete: when set to True, removes all records related to the - instance - """ - return IMPL.instance_destroy(context, instance_uuid, - constraint=constraint, - hard_delete=hard_delete) - - -def instance_get_by_uuid(context, uuid, columns_to_join=None): - """Get an instance or raise if it does not exist.""" - return IMPL.instance_get_by_uuid(context, uuid, columns_to_join) - - -def instance_get(context, instance_id, columns_to_join=None): - """Get an instance or raise if it does not exist.""" - return IMPL.instance_get(context, instance_id, - columns_to_join=columns_to_join) - - -def instance_get_all(context, columns_to_join=None): - """Get all instances.""" - return IMPL.instance_get_all(context, columns_to_join=columns_to_join) - - -def instance_get_all_uuids_by_hosts(context, hosts): - """Get a dict, keyed by hostname, of a list of the instance UUIDs on the - host for each supplied hostname, not Instance model objects. - - The dict is a defaultdict of list, thus inspecting the dict for a host not - in the dict will return an empty list not a KeyError. - """ - return IMPL.instance_get_all_uuids_by_hosts(context, hosts) - - -def instance_get_all_by_filters(context, filters, sort_key='created_at', - sort_dir='desc', limit=None, marker=None, - columns_to_join=None): - """Get all instances matching all filters sorted by the primary key. - - See instance_get_all_by_filters_sort for more information. - """ - # Note: This function exists for backwards compatibility since calls to - # the instance layer coming in over RPC may specify the single sort - # key/direction values; in this case, this function is invoked instead - # of the 'instance_get_all_by_filters_sort' function. - return IMPL.instance_get_all_by_filters(context, filters, sort_key, - sort_dir, limit=limit, - marker=marker, - columns_to_join=columns_to_join) - - -def instance_get_all_by_filters_sort(context, filters, limit=None, - marker=None, columns_to_join=None, - sort_keys=None, sort_dirs=None): - """Get all instances that match all filters sorted by the given keys. - - Deleted instances will be returned by default, unless there's a filter that - says otherwise. - - Depending on the name of a filter, matching for that filter is - performed using either exact matching or as regular expression - matching. Exact matching is applied for the following filters:: - - | ['project_id', 'user_id', 'image_ref', - | 'vm_state', 'instance_type_id', 'uuid', - | 'metadata', 'host', 'system_metadata', 'locked', 'hidden'] - - Hidden instances will *not* be returned by default, unless there's a - filter that says otherwise. - - A third type of filter (also using exact matching), filters - based on instance metadata tags when supplied under a special - key named 'filter':: - - | filters = { - | 'filter': [ - | {'name': 'tag-key', 'value': ''}, - | {'name': 'tag-value', 'value': ''}, - | {'name': 'tag:', 'value': ''} - | ] - | } - - Special keys are used to tweek the query further:: - - | 'changes-since' - only return instances updated after - | 'changes-before' - only return instances updated before - | 'deleted' - only return (or exclude) deleted instances - | 'soft_deleted' - modify behavior of 'deleted' to either - | include or exclude instances whose - | vm_state is SOFT_DELETED. - - A fourth type of filter (also using exact matching), filters - based on instance tags (not metadata tags). There are two types - of these tags: - - `tags` -- One or more strings that will be used to filter results - in an AND expression: T1 AND T2 - - `tags-any` -- One or more strings that will be used to filter results in - an OR expression: T1 OR T2 - - `not-tags` -- One or more strings that will be used to filter results in - an NOT AND expression: NOT (T1 AND T2) - - `not-tags-any` -- One or more strings that will be used to filter results - in an NOT OR expression: NOT (T1 OR T2) - - Tags should be represented as list:: - - | filters = { - | 'tags': [some-tag, some-another-tag], - | 'tags-any: [some-any-tag, some-another-any-tag], - | 'not-tags: [some-not-tag, some-another-not-tag], - | 'not-tags-any: [some-not-any-tag, some-another-not-any-tag] - | } - """ - return IMPL.instance_get_all_by_filters_sort( - context, filters, limit=limit, marker=marker, - columns_to_join=columns_to_join, sort_keys=sort_keys, - sort_dirs=sort_dirs) - - -def instance_get_by_sort_filters(context, sort_keys, sort_dirs, values): - """Get the UUID of the first instance in a sort order. - - Attempt to get a single instance based on a combination of sort - keys, directions and filter values. This is used to try to find a - marker instance when we don't have a marker uuid. - - :returns: The UUID of the instance that matched, if any. - """ - return IMPL.instance_get_by_sort_filters(context, sort_keys, sort_dirs, - values) - - -def instance_get_active_by_window_joined(context, begin, end=None, - project_id=None, host=None, - columns_to_join=None, limit=None, - marker=None): - """Get instances and joins active during a certain time window. - - Specifying a project_id will filter for a certain project. - Specifying a host will filter for instances on a given compute host. - """ - return IMPL.instance_get_active_by_window_joined(context, begin, end, - project_id, host, - columns_to_join=columns_to_join, - limit=limit, marker=marker) - - -def instance_get_all_by_host(context, host, columns_to_join=None): - """Get all instances belonging to a host.""" - return IMPL.instance_get_all_by_host(context, host, columns_to_join) - - -def instance_get_all_by_host_and_node(context, host, node, - columns_to_join=None): - """Get all instances belonging to a node.""" - return IMPL.instance_get_all_by_host_and_node( - context, host, node, columns_to_join=columns_to_join) - - -def instance_get_all_by_host_and_not_type(context, host, type_id=None): - """Get all instances belonging to a host with a different type_id.""" - return IMPL.instance_get_all_by_host_and_not_type(context, host, type_id) - - -# NOTE(hanlind): This method can be removed as conductor RPC API moves to v2.0. -def instance_get_all_hung_in_rebooting(context, reboot_window): - """Get all instances stuck in a rebooting state.""" - return IMPL.instance_get_all_hung_in_rebooting(context, reboot_window) - - -def instance_update(context, instance_uuid, values, expected=None): - """Set the given properties on an instance and update it. - - :raises: NotFound if instance does not exist. - """ - return IMPL.instance_update(context, instance_uuid, values, - expected=expected) - - -def instance_update_and_get_original(context, instance_uuid, values, - columns_to_join=None, expected=None): - """Set the given properties on an instance and update it. - - Return a shallow copy of the original instance reference, as well as the - updated one. - - If "expected_task_state" exists in values, the update can only happen - when the task state before update matches expected_task_state. Otherwise - a UnexpectedTaskStateError is thrown. - - :param context: request context object - :param instance_uuid: instance uuid - :param values: dict containing column values - :returns: a tuple of the form (old_instance_ref, new_instance_ref) - :raises: NotFound if instance does not exist. - """ - rv = IMPL.instance_update_and_get_original(context, instance_uuid, values, - columns_to_join=columns_to_join, - expected=expected) - return rv - - -def instance_add_security_group(context, instance_uuid, security_group_id): - """Associate the given security group with the given instance.""" - return IMPL.instance_add_security_group( - context, instance_uuid, security_group_id, - ) - - -def instance_remove_security_group(context, instance_uuid, security_group_id): - """Disassociate the given security group from the given instance.""" - return IMPL.instance_remove_security_group( - context, instance_uuid, security_group_id, - ) - - -#################### - - -def instance_info_cache_get(context, instance_uuid): - """Gets an instance info cache from the table. - - :param instance_uuid: = uuid of the info cache's instance - """ - return IMPL.instance_info_cache_get(context, instance_uuid) - - -def instance_info_cache_update(context, instance_uuid, values): - """Update an instance info cache record in the table. - - :param instance_uuid: = uuid of info cache's instance - :param values: = dict containing column values to update - """ - return IMPL.instance_info_cache_update(context, instance_uuid, values) - - -def instance_info_cache_delete(context, instance_uuid): - """Deletes an existing instance_info_cache record - - :param instance_uuid: = uuid of the instance tied to the cache record - """ - return IMPL.instance_info_cache_delete(context, instance_uuid) - - -################### - - -def instance_extra_get_by_instance_uuid(context, instance_uuid, columns=None): - """Get the instance extra record - - :param instance_uuid: UUID of the instance tied to the topology record - :param columns: A list of the columns to load, or None for 'all of them' - """ - return IMPL.instance_extra_get_by_instance_uuid( - context, instance_uuid, columns=columns) - - -def instance_extra_update_by_uuid(context, instance_uuid, updates): - """Update the instance extra record by instance uuid - - :param instance_uuid: UUID of the instance tied to the record - :param updates: A dict of updates to apply - """ - return IMPL.instance_extra_update_by_uuid(context, instance_uuid, - updates) - - -################### - - -def key_pair_create(context, values): - """Create a key_pair from the values dictionary.""" - return IMPL.key_pair_create(context, values) - - -def key_pair_destroy(context, user_id, name): - """Destroy the key_pair or raise if it does not exist.""" - return IMPL.key_pair_destroy(context, user_id, name) - - -def key_pair_get(context, user_id, name): - """Get a key_pair or raise if it does not exist.""" - return IMPL.key_pair_get(context, user_id, name) - - -def key_pair_get_all_by_user(context, user_id, limit=None, marker=None): - """Get all key_pairs by user.""" - return IMPL.key_pair_get_all_by_user( - context, user_id, limit=limit, marker=marker) - - -def key_pair_count_by_user(context, user_id): - """Count number of key pairs for the given user ID.""" - return IMPL.key_pair_count_by_user(context, user_id) - - -############### - - -def quota_create(context, project_id, resource, limit, user_id=None): - """Create a quota for the given project and resource.""" - return IMPL.quota_create(context, project_id, resource, limit, - user_id=user_id) - - -def quota_get(context, project_id, resource, user_id=None): - """Retrieve a quota or raise if it does not exist.""" - return IMPL.quota_get(context, project_id, resource, user_id=user_id) - - -def quota_get_all_by_project_and_user(context, project_id, user_id): - """Retrieve all quotas associated with a given project and user.""" - return IMPL.quota_get_all_by_project_and_user(context, project_id, user_id) - - -def quota_get_all_by_project(context, project_id): - """Retrieve all quotas associated with a given project.""" - return IMPL.quota_get_all_by_project(context, project_id) - - -def quota_get_per_project_resources(): - """Retrieve the names of resources whose quotas are calculated on a - per-project rather than a per-user basis. - """ - return IMPL.quota_get_per_project_resources() - - -def quota_get_all(context, project_id): - """Retrieve all user quotas associated with a given project.""" - return IMPL.quota_get_all(context, project_id) - - -def quota_update(context, project_id, resource, limit, user_id=None): - """Update a quota or raise if it does not exist.""" - return IMPL.quota_update(context, project_id, resource, limit, - user_id=user_id) - - -################### - - -def quota_class_create(context, class_name, resource, limit): - """Create a quota class for the given name and resource.""" - return IMPL.quota_class_create(context, class_name, resource, limit) - - -def quota_class_get(context, class_name, resource): - """Retrieve a quota class or raise if it does not exist.""" - return IMPL.quota_class_get(context, class_name, resource) - - -def quota_class_get_default(context): - """Retrieve all default quotas.""" - return IMPL.quota_class_get_default(context) - - -def quota_class_get_all_by_name(context, class_name): - """Retrieve all quotas associated with a given quota class.""" - return IMPL.quota_class_get_all_by_name(context, class_name) - - -def quota_class_update(context, class_name, resource, limit): - """Update a quota class or raise if it does not exist.""" - return IMPL.quota_class_update(context, class_name, resource, limit) - - -################### - - -def quota_destroy_all_by_project_and_user(context, project_id, user_id): - """Destroy all quotas associated with a given project and user.""" - return IMPL.quota_destroy_all_by_project_and_user(context, - project_id, user_id) - - -def quota_destroy_all_by_project(context, project_id): - """Destroy all quotas associated with a given project.""" - return IMPL.quota_destroy_all_by_project(context, project_id) - - -################### - - -def block_device_mapping_create(context, values, legacy=True): - """Create an entry of block device mapping.""" - return IMPL.block_device_mapping_create(context, values, legacy) - - -def block_device_mapping_update(context, bdm_id, values, legacy=True): - """Update an entry of block device mapping.""" - return IMPL.block_device_mapping_update(context, bdm_id, values, legacy) - - -def block_device_mapping_update_or_create(context, values, legacy=True): - """Update an entry of block device mapping. - - If not existed, create a new entry - """ - return IMPL.block_device_mapping_update_or_create(context, values, legacy) - - -def block_device_mapping_get_all_by_instance_uuids(context, instance_uuids): - """Get all block device mapping belonging to a list of instances.""" - return IMPL.block_device_mapping_get_all_by_instance_uuids(context, - instance_uuids) - - -def block_device_mapping_get_all_by_instance(context, instance_uuid): - """Get all block device mapping belonging to an instance.""" - return IMPL.block_device_mapping_get_all_by_instance(context, - instance_uuid) - - -def block_device_mapping_get_all_by_volume_id(context, volume_id, - columns_to_join=None): - """Get block device mapping for a given volume.""" - return IMPL.block_device_mapping_get_all_by_volume_id(context, volume_id, - columns_to_join) - - -def block_device_mapping_get_by_instance_and_volume_id(context, volume_id, - instance_uuid, - columns_to_join=None): - """Get block device mapping for a given volume ID and instance UUID.""" - return IMPL.block_device_mapping_get_by_instance_and_volume_id( - context, volume_id, instance_uuid, columns_to_join) - - -def block_device_mapping_destroy(context, bdm_id): - """Destroy the block device mapping.""" - return IMPL.block_device_mapping_destroy(context, bdm_id) - - -def block_device_mapping_destroy_by_instance_and_device(context, instance_uuid, - device_name): - """Destroy the block device mapping.""" - return IMPL.block_device_mapping_destroy_by_instance_and_device( - context, instance_uuid, device_name) - - -def block_device_mapping_destroy_by_instance_and_volume(context, instance_uuid, - volume_id): - """Destroy the block device mapping.""" - return IMPL.block_device_mapping_destroy_by_instance_and_volume( - context, instance_uuid, volume_id) - - -#################### - - -def security_group_get_all(context): - """Get all security groups.""" - return IMPL.security_group_get_all(context) - - -def security_group_get(context, security_group_id, columns_to_join=None): - """Get security group by its ID.""" - return IMPL.security_group_get(context, security_group_id, - columns_to_join) - - -def security_group_get_by_name(context, project_id, group_name, - columns_to_join=None): - """Returns a security group with the specified name from a project.""" - return IMPL.security_group_get_by_name(context, project_id, group_name, - columns_to_join=None) - - -def security_group_get_by_project(context, project_id): - """Get all security groups belonging to a project.""" - return IMPL.security_group_get_by_project(context, project_id) - - -def security_group_get_by_instance(context, instance_uuid): - """Get security groups to which the instance is assigned.""" - return IMPL.security_group_get_by_instance(context, instance_uuid) - - -def security_group_in_use(context, group_id): - """Indicates if a security group is currently in use.""" - return IMPL.security_group_in_use(context, group_id) - - -def security_group_create(context, values): - """Create a new security group.""" - return IMPL.security_group_create(context, values) - - -def security_group_update(context, security_group_id, values, - columns_to_join=None): - """Update a security group.""" - return IMPL.security_group_update(context, security_group_id, values, - columns_to_join=columns_to_join) - - -def security_group_ensure_default(context): - """Ensure default security group exists for a project_id. - - Returns a tuple with the first element being a bool indicating - if the default security group previously existed. Second - element is the dict used to create the default security group. - """ - return IMPL.security_group_ensure_default(context) - - -def security_group_destroy(context, security_group_id): - """Deletes a security group.""" - return IMPL.security_group_destroy(context, security_group_id) - - -################### - - -def pci_device_get_by_addr(context, node_id, dev_addr): - """Get PCI device by address.""" - return IMPL.pci_device_get_by_addr(context, node_id, dev_addr) - - -def pci_device_get_by_id(context, id): - """Get PCI device by id.""" - return IMPL.pci_device_get_by_id(context, id) - - -def pci_device_get_all_by_node(context, node_id): - """Get all PCI devices for one host.""" - return IMPL.pci_device_get_all_by_node(context, node_id) - - -def pci_device_get_all_by_instance_uuid(context, instance_uuid): - """Get PCI devices allocated to instance.""" - return IMPL.pci_device_get_all_by_instance_uuid(context, instance_uuid) - - -def pci_device_get_all_by_parent_addr(context, node_id, parent_addr): - """Get all PCI devices by parent address.""" - return IMPL.pci_device_get_all_by_parent_addr(context, node_id, - parent_addr) - - -def pci_device_destroy(context, node_id, address): - """Delete a PCI device record.""" - return IMPL.pci_device_destroy(context, node_id, address) - - -def pci_device_update(context, node_id, address, values): - """Update a pci device.""" - return IMPL.pci_device_update(context, node_id, address, values) - - -#################### - - -def instance_metadata_get(context, instance_uuid): - """Get all metadata for an instance.""" - return IMPL.instance_metadata_get(context, instance_uuid) - - -def instance_metadata_delete(context, instance_uuid, key): - """Delete the given metadata item.""" - IMPL.instance_metadata_delete(context, instance_uuid, key) - - -def instance_metadata_update(context, instance_uuid, metadata, delete): - """Update metadata if it exists, otherwise create it.""" - return IMPL.instance_metadata_update(context, instance_uuid, - metadata, delete) - - -#################### - - -def instance_system_metadata_get(context, instance_uuid): - """Get all system metadata for an instance.""" - return IMPL.instance_system_metadata_get(context, instance_uuid) - - -def instance_system_metadata_update(context, instance_uuid, metadata, delete): - """Update metadata if it exists, otherwise create it.""" - IMPL.instance_system_metadata_update( - context, instance_uuid, metadata, delete) - - -#################### - - -def bw_usage_get(context, uuid, start_period, mac): - """Return bw usage for instance and mac in a given audit period.""" - return IMPL.bw_usage_get(context, uuid, start_period, mac) - - -def bw_usage_get_by_uuids(context, uuids, start_period): - """Return bw usages for instance(s) in a given audit period.""" - return IMPL.bw_usage_get_by_uuids(context, uuids, start_period) - - -def bw_usage_update(context, uuid, mac, start_period, bw_in, bw_out, - last_ctr_in, last_ctr_out, last_refreshed=None): - """Update cached bandwidth usage for an instance's network based on mac - address. Creates new record if needed. - """ - rv = IMPL.bw_usage_update(context, uuid, mac, start_period, bw_in, - bw_out, last_ctr_in, last_ctr_out, last_refreshed=last_refreshed) - return rv - - -################### - - -def vol_get_usage_by_time(context, begin): - """Return volumes usage that have been updated after a specified time.""" - return IMPL.vol_get_usage_by_time(context, begin) - - -def vol_usage_update(context, id, rd_req, rd_bytes, wr_req, wr_bytes, - instance_id, project_id, user_id, availability_zone, - update_totals=False): - """Update cached volume usage for a volume - - Creates new record if needed. - """ - return IMPL.vol_usage_update(context, id, rd_req, rd_bytes, wr_req, - wr_bytes, instance_id, project_id, user_id, - availability_zone, - update_totals=update_totals) - - -################### - - -def s3_image_get(context, image_id): - """Find local s3 image represented by the provided id.""" - return IMPL.s3_image_get(context, image_id) - - -def s3_image_get_by_uuid(context, image_uuid): - """Find local s3 image represented by the provided uuid.""" - return IMPL.s3_image_get_by_uuid(context, image_uuid) - - -def s3_image_create(context, image_uuid): - """Create local s3 image represented by provided uuid.""" - return IMPL.s3_image_create(context, image_uuid) - - -#################### - - -def instance_fault_create(context, values): - """Create a new instance fault.""" - return IMPL.instance_fault_create(context, values) - - -def instance_fault_get_by_instance_uuids(context, instance_uuids, - latest=False): - """Get all instance faults for the provided instance_uuids. - - :param instance_uuids: List of UUIDs of instances to grab faults for - :param latest: Optional boolean indicating we should only return the latest - fault for the instance - """ - return IMPL.instance_fault_get_by_instance_uuids(context, instance_uuids, - latest=latest) - - -#################### - - -def action_start(context, values): - """Start an action for an instance.""" - return IMPL.action_start(context, values) - - -def action_finish(context, values): - """Finish an action for an instance.""" - return IMPL.action_finish(context, values) - - -def actions_get(context, instance_uuid, limit=None, marker=None, - filters=None): - """Get all instance actions for the provided instance and filters.""" - return IMPL.actions_get(context, instance_uuid, limit, marker, filters) - - -def action_get_by_request_id(context, instance_uuid, request_id): - """Get the action by request_id and given instance.""" - return IMPL.action_get_by_request_id(context, instance_uuid, request_id) - - -def action_event_start(context, values): - """Start an event on an instance action.""" - return IMPL.action_event_start(context, values) - - -def action_event_finish(context, values): - """Finish an event on an instance action.""" - return IMPL.action_event_finish(context, values) - - -def action_events_get(context, action_id): - """Get the events by action id.""" - return IMPL.action_events_get(context, action_id) - - -def action_event_get_by_id(context, action_id, event_id): - return IMPL.action_event_get_by_id(context, action_id, event_id) - - -#################### - - -def get_instance_uuid_by_ec2_id(context, ec2_id): - """Get UUID through EC2 ID from instance_id_mappings table.""" - return IMPL.get_instance_uuid_by_ec2_id(context, ec2_id) - - -def ec2_instance_create(context, instance_uuid, id=None): - """Create the EC2 ID to instance UUID mapping on demand.""" - return IMPL.ec2_instance_create(context, instance_uuid, id) - - -def ec2_instance_get_by_uuid(context, instance_uuid): - return IMPL.ec2_instance_get_by_uuid(context, instance_uuid) - - -def ec2_instance_get_by_id(context, instance_id): - return IMPL.ec2_instance_get_by_id(context, instance_id) - - -#################### - - -def task_log_end_task(context, task_name, - period_beginning, - period_ending, - host, - errors, - message=None): - """Mark a task as complete for a given host/time period.""" - return IMPL.task_log_end_task(context, task_name, - period_beginning, - period_ending, - host, - errors, - message) - - -def task_log_begin_task(context, task_name, - period_beginning, - period_ending, - host, - task_items=None, - message=None): - """Mark a task as started for a given host/time period.""" - return IMPL.task_log_begin_task(context, task_name, - period_beginning, - period_ending, - host, - task_items, - message) - - -def task_log_get_all(context, task_name, period_beginning, - period_ending, host=None, state=None): - return IMPL.task_log_get_all(context, task_name, period_beginning, - period_ending, host, state) - - -def task_log_get(context, task_name, period_beginning, - period_ending, host, state=None): - return IMPL.task_log_get(context, task_name, period_beginning, - period_ending, host, state) - - -#################### - - -def archive_deleted_rows(context=None, max_rows=None, before=None, - task_log=None): - """Move up to max_rows rows from production tables to the corresponding - shadow tables. - - :param context: nova.context.RequestContext for database access - :param max_rows: Maximum number of rows to archive (required) - :param before: optional datetime which when specified filters the records - to only archive those records deleted before the given date - :param task_log: Optional for whether to archive task_log table records - :returns: 3-item tuple: - - - dict that maps table name to number of rows archived from that table, - for example:: - - { - 'instances': 5, - 'block_device_mapping': 5, - 'pci_devices': 2, - } - - list of UUIDs of instances that were archived - - total number of rows that were archived - """ - return IMPL.archive_deleted_rows(context=context, max_rows=max_rows, - before=before, task_log=task_log) - - -#################### - - -def instance_tag_add(context, instance_uuid, tag): - """Add tag to the instance.""" - return IMPL.instance_tag_add(context, instance_uuid, tag) - - -def instance_tag_set(context, instance_uuid, tags): - """Replace all of the instance tags with specified list of tags.""" - return IMPL.instance_tag_set(context, instance_uuid, tags) - - -def instance_tag_get_by_instance_uuid(context, instance_uuid): - """Get all tags for a given instance.""" - return IMPL.instance_tag_get_by_instance_uuid(context, instance_uuid) - - -def instance_tag_delete(context, instance_uuid, tag): - """Delete specified tag from the instance.""" - return IMPL.instance_tag_delete(context, instance_uuid, tag) - - -def instance_tag_delete_all(context, instance_uuid): - """Delete all tags from the instance.""" - return IMPL.instance_tag_delete_all(context, instance_uuid) - - -def instance_tag_exists(context, instance_uuid, tag): - """Check if specified tag exist on the instance.""" - return IMPL.instance_tag_exists(context, instance_uuid, tag) - - -#################### - - -def console_auth_token_create(context, values): - """Create a console authorization.""" - return IMPL.console_auth_token_create(context, values) - - -def console_auth_token_get_valid(context, token_hash, instance_uuid=None): - """Get a valid console authorization by token_hash and instance_uuid. - - The console authorizations expire at the time specified by their - 'expires' column. An expired console auth token will not be returned - to the caller - it is treated as if it does not exist. - - If instance_uuid is specified, the token is validated against both - expiry and instance_uuid. - - If instance_uuid is not specified, the token is validated against - expiry only. - """ - return IMPL.console_auth_token_get_valid(context, - token_hash, - instance_uuid=instance_uuid) - - -def console_auth_token_destroy_all_by_instance(context, instance_uuid): - """Delete all console authorizations belonging to the instance.""" - return IMPL.console_auth_token_destroy_all_by_instance(context, - instance_uuid) - - -def console_auth_token_destroy_expired(context): - """Delete expired console authorizations. - - The console authorizations expire at the time specified by their - 'expires' column. This function is used to garbage collect expired tokens. - """ - return IMPL.console_auth_token_destroy_expired(context) - - -def console_auth_token_destroy_expired_by_host(context, host): - """Delete expired console authorizations belonging to the host. - - The console authorizations expire at the time specified by their - 'expires' column. This function is used to garbage collect expired - tokens associated with the given host. - """ - return IMPL.console_auth_token_destroy_expired_by_host(context, host) diff --git a/nova/db/main/__init__.py b/nova/db/main/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/nova/db/sqlalchemy/api.py b/nova/db/main/api.py similarity index 99% rename from nova/db/sqlalchemy/api.py rename to nova/db/main/api.py index 816bcc63d4..b19d761b5c 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/main/api.py @@ -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) diff --git a/nova/db/sqlalchemy/models.py b/nova/db/main/models.py similarity index 100% rename from nova/db/sqlalchemy/models.py rename to nova/db/main/models.py diff --git a/nova/db/migration.py b/nova/db/migration.py index fa2294ca8b..366fc13e26 100644 --- a/nova/db/migration.py +++ b/nova/db/migration.py @@ -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 _ diff --git a/nova/hacking/checks.py b/nova/hacking/checks.py index 4bdba6991b..b45f7254b5 100644 --- a/nova/hacking/checks.py +++ b/nova/hacking/checks.py @@ -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 diff --git a/nova/manager.py b/nova/manager.py index a53db41efc..9c00401b96 100644 --- a/nova/manager.py +++ b/nova/manager.py @@ -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 diff --git a/nova/objects/aggregate.py b/nova/objects/aggregate.py index 368c102f5d..3c53e43042 100644 --- a/nova/objects/aggregate.py +++ b/nova/objects/aggregate.py @@ -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 _ diff --git a/nova/objects/bandwidth_usage.py b/nova/objects/bandwidth_usage.py index adf9ed67e9..1c19b0a5e1 100644 --- a/nova/objects/bandwidth_usage.py +++ b/nova/objects/bandwidth_usage.py @@ -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 diff --git a/nova/objects/block_device.py b/nova/objects/block_device.py index 0e3ceae344..97199cf17a 100644 --- a/nova/objects/block_device.py +++ b/nova/objects/block_device.py @@ -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) diff --git a/nova/objects/build_request.py b/nova/objects/build_request.py index 173e89ec70..03ebdbd331 100644 --- a/nova/objects/build_request.py +++ b/nova/objects/build_request.py @@ -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 diff --git a/nova/objects/cell_mapping.py b/nova/objects/cell_mapping.py index 7633ad0e75..cfd8179033 100644 --- a/nova/objects/cell_mapping.py +++ b/nova/objects/cell_mapping.py @@ -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 diff --git a/nova/objects/compute_node.py b/nova/objects/compute_node.py index 6de7822cde..41e0c87a56 100644 --- a/nova/objects/compute_node.py +++ b/nova/objects/compute_node.py @@ -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) diff --git a/nova/objects/console_auth_token.py b/nova/objects/console_auth_token.py index cb2e1c6aaa..d701d7aa01 100644 --- a/nova/objects/console_auth_token.py +++ b/nova/objects/console_auth_token.py @@ -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 diff --git a/nova/objects/ec2.py b/nova/objects/ec2.py index 8f622e4f8d..179a0e13d9 100644 --- a/nova/objects/ec2.py +++ b/nova/objects/ec2.py @@ -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 diff --git a/nova/objects/flavor.py b/nova/objects/flavor.py index 546b525dad..ad223f84df 100644 --- a/nova/objects/flavor.py +++ b/nova/objects/flavor.py @@ -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).\ diff --git a/nova/objects/host_mapping.py b/nova/objects/host_mapping.py index 52f39be70b..c3df439746 100644 --- a/nova/objects/host_mapping.py +++ b/nova/objects/host_mapping.py @@ -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 _ diff --git a/nova/objects/instance.py b/nova/objects/instance.py index 0c43f0f275..578b6ce379 100644 --- a/nova/objects/instance.py +++ b/nova/objects/instance.py @@ -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).\ diff --git a/nova/objects/instance_action.py b/nova/objects/instance_action.py index da8e619349..d5adb6fa2f 100644 --- a/nova/objects/instance_action.py +++ b/nova/objects/instance_action.py @@ -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 diff --git a/nova/objects/instance_fault.py b/nova/objects/instance_fault.py index 0c2d9bc15d..6d69e13ceb 100644 --- a/nova/objects/instance_fault.py +++ b/nova/objects/instance_fault.py @@ -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 diff --git a/nova/objects/instance_group.py b/nova/objects/instance_group.py index 9e4f8e0b7e..344457b060 100644 --- a/nova/objects/instance_group.py +++ b/nova/objects/instance_group.py @@ -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 diff --git a/nova/objects/instance_info_cache.py b/nova/objects/instance_info_cache.py index 1efb5d630a..06e0af3f3b 100644 --- a/nova/objects/instance_info_cache.py +++ b/nova/objects/instance_info_cache.py @@ -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 diff --git a/nova/objects/instance_mapping.py b/nova/objects/instance_mapping.py index 7da9c5df61..43130acf30 100644 --- a/nova/objects/instance_mapping.py +++ b/nova/objects/instance_mapping.py @@ -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 _ diff --git a/nova/objects/instance_numa.py b/nova/objects/instance_numa.py index f7e6b6e3cd..b2cb8a8a68 100644 --- a/nova/objects/instance_numa.py +++ b/nova/objects/instance_numa.py @@ -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 diff --git a/nova/objects/instance_pci_requests.py b/nova/objects/instance_pci_requests.py index c5484d977b..ee94db87dd 100644 --- a/nova/objects/instance_pci_requests.py +++ b/nova/objects/instance_pci_requests.py @@ -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 diff --git a/nova/objects/keypair.py b/nova/objects/keypair.py index 915c71a6c3..bbd624d717 100644 --- a/nova/objects/keypair.py +++ b/nova/objects/keypair.py @@ -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).\ diff --git a/nova/objects/migration.py b/nova/objects/migration.py index 34e30922a4..b9afe1632f 100644 --- a/nova/objects/migration.py +++ b/nova/objects/migration.py @@ -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 diff --git a/nova/objects/migration_context.py b/nova/objects/migration_context.py index b9504c8ae6..c00e471b0e 100644 --- a/nova/objects/migration_context.py +++ b/nova/objects/migration_context.py @@ -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 diff --git a/nova/objects/pci_device.py b/nova/objects/pci_device.py index bf5fac68b0..0be94897e3 100644 --- a/nova/objects/pci_device.py +++ b/nova/objects/pci_device.py @@ -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) diff --git a/nova/objects/quotas.py b/nova/objects/quotas.py index 6165607497..355e8c3105 100644 --- a/nova/objects/quotas.py +++ b/nova/objects/quotas.py @@ -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, diff --git a/nova/objects/request_spec.py b/nova/objects/request_spec.py index 5478a1e9c9..b97d3f14cd 100644 --- a/nova/objects/request_spec.py +++ b/nova/objects/request_spec.py @@ -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 diff --git a/nova/objects/resource.py b/nova/objects/resource.py index 6ac97a5785..69a7c951a3 100644 --- a/nova/objects/resource.py +++ b/nova/objects/resource.py @@ -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 diff --git a/nova/objects/security_group.py b/nova/objects/security_group.py index ecf02fd80f..d0f2237ceb 100644 --- a/nova/objects/security_group.py +++ b/nova/objects/security_group.py @@ -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).\ diff --git a/nova/objects/service.py b/nova/objects/service.py index f51b3a96f4..e730ddbdcf 100644 --- a/nova/objects/service.py +++ b/nova/objects/service.py @@ -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 diff --git a/nova/objects/tag.py b/nova/objects/tag.py index 8088fdf537..2511d45d4b 100644 --- a/nova/objects/tag.py +++ b/nova/objects/tag.py @@ -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 diff --git a/nova/objects/task_log.py b/nova/objects/task_log.py index ef40c56582..42d6b025e0 100644 --- a/nova/objects/task_log.py +++ b/nova/objects/task_log.py @@ -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 diff --git a/nova/objects/trusted_certs.py b/nova/objects/trusted_certs.py index ed4d8c9dda..856ca3feb6 100644 --- a/nova/objects/trusted_certs.py +++ b/nova/objects/trusted_certs.py @@ -12,7 +12,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 diff --git a/nova/objects/vcpu_model.py b/nova/objects/vcpu_model.py index 78c9aa7767..078f7b6c9e 100644 --- a/nova/objects/vcpu_model.py +++ b/nova/objects/vcpu_model.py @@ -12,7 +12,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 diff --git a/nova/objects/virt_device_metadata.py b/nova/objects/virt_device_metadata.py index 4573114b82..a518c92a82 100644 --- a/nova/objects/virt_device_metadata.py +++ b/nova/objects/virt_device_metadata.py @@ -15,7 +15,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 diff --git a/nova/objects/virtual_interface.py b/nova/objects/virtual_interface.py index b44eeb83ef..e9a769a7b5 100644 --- a/nova/objects/virtual_interface.py +++ b/nova/objects/virtual_interface.py @@ -16,9 +16,8 @@ from oslo_log import log as logging from oslo_utils import versionutils from nova import context as nova_context -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 import objects from nova.objects import base @@ -150,7 +149,7 @@ class VirtualInterfaceList(base.ObjectListBase, base.NovaObject): objects.VirtualInterface, db_vifs) -@db_api.api_context_manager.writer +@db.api_context_manager.writer def fill_virtual_interface_list(context, max_count): """This fills missing VirtualInterface Objects in Nova DB""" count_hit = 0 @@ -288,7 +287,7 @@ def fill_virtual_interface_list(context, max_count): # we checked. # Please notice that because of virtual_interfaces_instance_uuid_fkey # we need to have FAKE_UUID instance object, even deleted one. -@db_api.pick_context_manager_writer +@db.pick_context_manager_writer def _set_or_delete_marker_for_migrate_instances(context, marker=None): context.session.query(models.VirtualInterface).filter_by( instance_uuid=FAKE_UUID).delete() @@ -317,7 +316,7 @@ def _set_or_delete_marker_for_migrate_instances(context, marker=None): db_mapping.create() -@db_api.pick_context_manager_reader +@db.pick_context_manager_reader def _get_marker_for_migrate_instances(context): vif = (context.session.query(models.VirtualInterface).filter_by( instance_uuid=FAKE_UUID)).first() diff --git a/nova/objects/volume_usage.py b/nova/objects/volume_usage.py index 4e75dbec68..6771dddd10 100644 --- a/nova/objects/volume_usage.py +++ b/nova/objects/volume_usage.py @@ -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 diff --git a/nova/quota.py b/nova/quota.py index 4c680bd1c1..be78b44163 100644 --- a/nova/quota.py +++ b/nova/quota.py @@ -24,8 +24,7 @@ from sqlalchemy import sql import nova.conf from nova import context as nova_context -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 @@ -1046,7 +1045,7 @@ class QuotaEngine(object): return 0 -@db_api.api_context_manager.reader +@db.api_context_manager.reader def _user_id_queued_for_delete_populated(context, project_id=None): """Determine whether user_id and queued_for_delete are set. diff --git a/nova/test.py b/nova/test.py index 63562f9220..cc4f9336b2 100644 --- a/nova/test.py +++ b/nova/test.py @@ -56,7 +56,7 @@ import testtools from nova.api.openstack import wsgi_app from nova.compute import rpcapi as compute_rpcapi from nova import context -from nova.db.sqlalchemy import api as sqlalchemy_api +from nova.db.main import api as db_api from nova import exception from nova import objects from nova.objects import base as objects_base @@ -382,7 +382,7 @@ class TestCase(base.BaseTestCase): def enforce_fk_constraints(self, engine=None): if engine is None: - engine = sqlalchemy_api.get_engine() + engine = db_api.get_engine() dialect = engine.url.get_dialect() if dialect == sqlite.dialect: engine.connect().execute("PRAGMA foreign_keys = ON") diff --git a/nova/tests/fixtures/nova.py b/nova/tests/fixtures/nova.py index aec2bce08b..048adbd1b9 100644 --- a/nova/tests/fixtures/nova.py +++ b/nova/tests/fixtures/nova.py @@ -43,8 +43,8 @@ from nova.api import wsgi from nova.compute import multi_cell_list from nova.compute import rpcapi as compute_rpcapi from nova import context +from nova.db.main import api as session from nova.db import migration -from nova.db.sqlalchemy import api as session from nova import exception from nova import objects from nova.objects import base as obj_base @@ -554,8 +554,9 @@ class CellDatabases(fixtures.Fixture): # a new database created with the schema we need and the # context manager for it stashed. with fixtures.MonkeyPatch( - 'nova.db.sqlalchemy.api.get_context_manager', - get_context_manager): + 'nova.db.main.api.get_context_manager', + get_context_manager, + ): engine = ctxt_mgr.writer.get_engine() engine.dispose() self._cache_schema(connection_str) @@ -571,10 +572,10 @@ class CellDatabases(fixtures.Fixture): # duration of the test (unlike the temporary ones above) and # provide the actual "runtime" switching of connections for us. self.useFixture(fixtures.MonkeyPatch( - 'nova.db.sqlalchemy.api.create_context_manager', + 'nova.db.main.api.create_context_manager', self._wrap_create_context_manager)) self.useFixture(fixtures.MonkeyPatch( - 'nova.db.sqlalchemy.api.get_context_manager', + 'nova.db.main.api.get_context_manager', self._wrap_get_context_manager)) self.useFixture(fixtures.MonkeyPatch( 'nova.context.target_cell', diff --git a/nova/tests/functional/api_sample_tests/test_migrate_server.py b/nova/tests/functional/api_sample_tests/test_migrate_server.py index 2fc545459a..59321c845a 100644 --- a/nova/tests/functional/api_sample_tests/test_migrate_server.py +++ b/nova/tests/functional/api_sample_tests/test_migrate_server.py @@ -71,7 +71,7 @@ class MigrateServerSamplesJsonTest(test_servers.ServersSampleBase): 'nova.conductor.manager.ComputeTaskManager._live_migrate', fake_live_migrate) self.stub_out( - 'nova.db.api.service_get_by_compute_host', + 'nova.db.main.api.service_get_by_compute_host', fake_get_compute) response = self._do_post('servers/%s/action' % self.uuid, @@ -218,7 +218,7 @@ class MigrateServerSamplesJsonTestV268(test_servers.ServersSampleBase): 'nova.conductor.manager.ComputeTaskManager._live_migrate', fake_live_migrate) self.stub_out( - 'nova.db.api.service_get_by_compute_host', + 'nova.db.main.api.service_get_by_compute_host', fake_get_compute) response = self._do_post('servers/%s/action' % self.uuid, diff --git a/nova/tests/functional/api_sample_tests/test_server_migrations.py b/nova/tests/functional/api_sample_tests/test_server_migrations.py index 477bc81cb0..15fb72945c 100644 --- a/nova/tests/functional/api_sample_tests/test_server_migrations.py +++ b/nova/tests/functional/api_sample_tests/test_server_migrations.py @@ -20,7 +20,7 @@ import mock from nova.conductor import manager as conductor_manager from nova import context -from nova.db import api as db +from nova.db.main import api as db from nova import objects from nova.tests.functional.api_sample_tests import test_servers from nova.tests.unit import fake_instance diff --git a/nova/tests/functional/api_sample_tests/test_server_tags.py b/nova/tests/functional/api_sample_tests/test_server_tags.py index cada20577f..a0dc50dc20 100644 --- a/nova/tests/functional/api_sample_tests/test_server_tags.py +++ b/nova/tests/functional/api_sample_tests/test_server_tags.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from nova.db.sqlalchemy import models +from nova.db.main import models from nova.tests.functional.api_sample_tests import test_servers TAG1 = 'tag1' diff --git a/nova/tests/functional/api_sample_tests/test_servers.py b/nova/tests/functional/api_sample_tests/test_servers.py index 5ca0d9809f..b984dc540b 100644 --- a/nova/tests/functional/api_sample_tests/test_servers.py +++ b/nova/tests/functional/api_sample_tests/test_servers.py @@ -116,7 +116,7 @@ class ServersSampleJsonTest(ServersSampleBase): def test_servers_get(self): self.stub_out( - 'nova.db.api.block_device_mapping_get_all_by_instance_uuids', + 'nova.db.main.api.block_device_mapping_get_all_by_instance_uuids', fakes.stub_bdm_get_all_by_instance_uuids) uuid = self.test_servers_post() response = self._do_get('servers/%s' % uuid) @@ -142,7 +142,7 @@ class ServersSampleJsonTest(ServersSampleBase): def test_servers_details(self): self.stub_out( - 'nova.db.api.block_device_mapping_get_all_by_instance_uuids', + 'nova.db.main.api.block_device_mapping_get_all_by_instance_uuids', fakes.stub_bdm_get_all_by_instance_uuids) uuid = self.test_servers_post() response = self._do_get('servers/detail?limit=1') diff --git a/nova/tests/functional/api_sample_tests/test_services.py b/nova/tests/functional/api_sample_tests/test_services.py index 7bb0b1da07..e5bcfd7474 100644 --- a/nova/tests/functional/api_sample_tests/test_services.py +++ b/nova/tests/functional/api_sample_tests/test_services.py @@ -31,11 +31,11 @@ class ServicesJsonTest(api_sample_base.ApiSampleTestBaseV21): def setUp(self): super(ServicesJsonTest, self).setUp() self.api.microversion = self.microversion - self.stub_out("nova.db.api.service_get_all", + self.stub_out("nova.db.main.api.service_get_all", test_services.fake_db_api_service_get_all) - self.stub_out("nova.db.api.service_get_by_host_and_binary", + self.stub_out("nova.db.main.api.service_get_by_host_and_binary", test_services.fake_service_get_by_host_binary) - self.stub_out("nova.db.api.service_update", + self.stub_out("nova.db.main.api.service_update", test_services.fake_service_update) # If we are not using real services, we need to stub out # HostAPI._update_compute_provider_status so we don't actually @@ -154,9 +154,9 @@ class ServicesV253JsonTest(ServicesV211JsonTest): def fake_get_provider_uuids_in_tree(context, compute_node_id): return [compute_node_id] - self.stub_out('nova.db.api.service_get_by_uuid', + self.stub_out('nova.db.main.api.service_get_by_uuid', db_service_get_by_uuid) - self.stub_out('nova.db.api.compute_node_get_all_by_host', + self.stub_out('nova.db.main.api.compute_node_get_all_by_host', fake_cn_get_all_by_host) self.stub_out( 'nova.objects.host_mapping.HostMapping._get_by_host_from_db', diff --git a/nova/tests/functional/compute/test_instance_list.py b/nova/tests/functional/compute/test_instance_list.py index 0c26861762..8a63102764 100644 --- a/nova/tests/functional/compute/test_instance_list.py +++ b/nova/tests/functional/compute/test_instance_list.py @@ -16,7 +16,7 @@ from oslo_utils.fixture import uuidsentinel as uuids from nova.compute import instance_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 import test diff --git a/nova/tests/functional/db/test_aggregate.py b/nova/tests/functional/db/test_aggregate.py index ed0adfbc63..2af5c06b74 100644 --- a/nova/tests/functional/db/test_aggregate.py +++ b/nova/tests/functional/db/test_aggregate.py @@ -18,7 +18,7 @@ from oslo_utils.fixture import uuidsentinel from oslo_utils import timeutils 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 import nova.objects.aggregate as aggregate_obj diff --git a/nova/tests/functional/db/test_aggregate_model.py b/nova/tests/functional/db/test_aggregate_model.py index 774436bc55..79173fd5ef 100644 --- a/nova/tests/functional/db/test_aggregate_model.py +++ b/nova/tests/functional/db/test_aggregate_model.py @@ -10,8 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +from nova.db.main import models from nova.db.sqlalchemy import api_models -from nova.db.sqlalchemy import models from nova import test diff --git a/nova/tests/functional/db/test_archive.py b/nova/tests/functional/db/test_archive.py index 27ff5d5d5a..c38735bbaf 100644 --- a/nova/tests/functional/db/test_archive.py +++ b/nova/tests/functional/db/test_archive.py @@ -22,8 +22,7 @@ import sqlalchemy as sa from sqlalchemy import func from nova import context -from nova.db import api as db -from nova.db.sqlalchemy import api as sqlalchemy_api +from nova.db.main import api as db from nova import objects from nova.tests.functional import integrated_helpers from nova import utils as nova_utils @@ -176,11 +175,11 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase): self.assertFalse(exceptions) def _get_table_counts(self): - engine = sqlalchemy_api.get_engine() + engine = db.get_engine() conn = engine.connect() meta = sa.MetaData(engine) meta.reflect() - shadow_tables = sqlalchemy_api._purgeable_tables(meta) + shadow_tables = db._purgeable_tables(meta) results = {} for table in shadow_tables: r = conn.execute( @@ -222,8 +221,7 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase): def status(msg): lines.append(msg) - deleted = sqlalchemy_api.purge_shadow_tables(admin_context, - None, status_fn=status) + deleted = db.purge_shadow_tables(admin_context, None, status_fn=status) self.assertNotEqual(0, deleted) self.assertNotEqual(0, len(lines)) self.assertEqual(sum(results.values()), archived) @@ -277,8 +275,7 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase): # Make sure we didn't delete anything if the marker is before # we started past = timeutils.utcnow() - datetime.timedelta(days=31) - deleted = sqlalchemy_api.purge_shadow_tables(admin_context, - past) + deleted = db.purge_shadow_tables(admin_context, past) self.assertEqual(0, deleted) # Nothing should be changed if we didn't purge anything @@ -288,7 +285,7 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase): # Make sure we deleted things when the marker is after # we started future = timeutils.utcnow() + datetime.timedelta(hours=1) - deleted = sqlalchemy_api.purge_shadow_tables(admin_context, future) + deleted = db.purge_shadow_tables(admin_context, future) self.assertNotEqual(0, deleted) # There should be no rows in any table if we purged everything @@ -306,6 +303,6 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase): self.assertEqual([server_id], deleted_ids) date = dateutil_parser.parse('oct 21 2015', fuzzy=True) admin_context = context.get_admin_context() - deleted = sqlalchemy_api.purge_shadow_tables(admin_context, date) + deleted = db.purge_shadow_tables(admin_context, date) self.assertEqual(0, deleted) self.assertEqual(sum(results.values()), archived) diff --git a/nova/tests/functional/db/test_compute_node.py b/nova/tests/functional/db/test_compute_node.py index 55b47ef893..0c605121e4 100644 --- a/nova/tests/functional/db/test_compute_node.py +++ b/nova/tests/functional/db/test_compute_node.py @@ -15,7 +15,7 @@ from oslo_utils.fixture import uuidsentinel 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 objects from nova.objects import compute_node from nova.objects import fields as obj_fields diff --git a/nova/tests/functional/db/test_flavor.py b/nova/tests/functional/db/test_flavor.py index 51c72cf012..bb4541ad92 100644 --- a/nova/tests/functional/db/test_flavor.py +++ b/nova/tests/functional/db/test_flavor.py @@ -11,7 +11,7 @@ # under the License. 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 import objects diff --git a/nova/tests/functional/db/test_flavor_model.py b/nova/tests/functional/db/test_flavor_model.py index 447c2268e6..76480df766 100644 --- a/nova/tests/functional/db/test_flavor_model.py +++ b/nova/tests/functional/db/test_flavor_model.py @@ -10,8 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +from nova.db.main import models from nova.db.sqlalchemy import api_models -from nova.db.sqlalchemy import models from nova import test diff --git a/nova/tests/functional/db/test_instance.py b/nova/tests/functional/db/test_instance.py index a908dadead..2223f72036 100644 --- a/nova/tests/functional/db/test_instance.py +++ b/nova/tests/functional/db/test_instance.py @@ -15,7 +15,7 @@ from oslo_utils import uuidutils from nova.compute import vm_states from nova import context -from nova.db import api as db +from nova.db.main import api as db from nova import objects from nova import test diff --git a/nova/tests/functional/db/test_keypair.py b/nova/tests/functional/db/test_keypair.py index 109208ca5b..e09d3c10f7 100644 --- a/nova/tests/functional/db/test_keypair.py +++ b/nova/tests/functional/db/test_keypair.py @@ -11,7 +11,7 @@ # under the License. from nova import context -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 objects from nova.objects import keypair diff --git a/nova/tests/functional/db/test_quota_model.py b/nova/tests/functional/db/test_quota_model.py index 9ef09bd4da..c62fd44c39 100644 --- a/nova/tests/functional/db/test_quota_model.py +++ b/nova/tests/functional/db/test_quota_model.py @@ -10,8 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. +from nova.db.main import models from nova.db.sqlalchemy import api_models -from nova.db.sqlalchemy import models from nova import test diff --git a/nova/tests/functional/db/test_quotas.py b/nova/tests/functional/db/test_quotas.py index 13af8811c8..a6ad5af517 100644 --- a/nova/tests/functional/db/test_quotas.py +++ b/nova/tests/functional/db/test_quotas.py @@ -11,11 +11,11 @@ # under the License. from nova import context -from nova.db.sqlalchemy import api as db_api +from nova.db.main import api as db_api from nova import exception from nova.objects import quotas from nova import test -from nova.tests.unit.db import test_db_api +from nova.tests.unit.db.main import test_api as test_db_api class QuotasObjectTestCase(test.TestCase, diff --git a/nova/tests/functional/db/test_security_group.py b/nova/tests/functional/db/test_security_group.py index 10d90843da..1c5bdda9af 100644 --- a/nova/tests/functional/db/test_security_group.py +++ b/nova/tests/functional/db/test_security_group.py @@ -11,7 +11,7 @@ # under the License. from nova import context -from nova.db.sqlalchemy import api as db_api +from nova.db.main import api as db_api from nova import objects from nova import test diff --git a/nova/tests/functional/integrated_helpers.py b/nova/tests/functional/integrated_helpers.py index 1755b4abbd..6d94fc56c0 100644 --- a/nova/tests/functional/integrated_helpers.py +++ b/nova/tests/functional/integrated_helpers.py @@ -31,7 +31,7 @@ from nova.compute import rpcapi as compute_rpcapi from nova.compute import utils as compute_utils import nova.conf from nova import context -from nova.db import api as db +from nova.db.main import api as db import nova.image.glance from nova import objects from nova.objects import base as objects_base diff --git a/nova/tests/functional/notification_sample_tests/test_service.py b/nova/tests/functional/notification_sample_tests/test_service.py index 057c6e8696..08de4a16a2 100644 --- a/nova/tests/functional/notification_sample_tests/test_service.py +++ b/nova/tests/functional/notification_sample_tests/test_service.py @@ -44,9 +44,9 @@ class TestServiceUpdateNotificationSamplev2_52(TestServiceNotificationBase): def setUp(self): super(TestServiceUpdateNotificationSamplev2_52, self).setUp() - self.stub_out("nova.db.api.service_get_by_host_and_binary", + self.stub_out("nova.db.main.api.service_get_by_host_and_binary", test_services.fake_service_get_by_host_binary) - self.stub_out("nova.db.api.service_update", + self.stub_out("nova.db.main.api.service_update", test_services.fake_service_update) # NOTE(gibi): enable / disable a compute service tries to call # the compute service via RPC to update placement. However in these @@ -111,7 +111,7 @@ class TestServiceUpdateNotificationSampleLatest( if svc['uuid'] == service_uuid: return svc raise exception.ServiceNotFound(service_id=service_uuid) - self.stub_out('nova.db.api.service_get_by_uuid', + self.stub_out('nova.db.main.api.service_get_by_uuid', db_service_get_by_uuid) def test_service_enable(self): diff --git a/nova/tests/functional/regressions/test_bug_1764556.py b/nova/tests/functional/regressions/test_bug_1764556.py index 6579c88b98..70ec52ccfb 100644 --- a/nova/tests/functional/regressions/test_bug_1764556.py +++ b/nova/tests/functional/regressions/test_bug_1764556.py @@ -11,7 +11,7 @@ # under the License. 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 test from nova.tests import fixtures as nova_fixtures from nova.tests.functional import fixtures as func_fixtures diff --git a/nova/tests/functional/regressions/test_bug_1778305.py b/nova/tests/functional/regressions/test_bug_1778305.py index dc9e945f30..0d6a40a0a4 100644 --- a/nova/tests/functional/regressions/test_bug_1778305.py +++ b/nova/tests/functional/regressions/test_bug_1778305.py @@ -11,7 +11,7 @@ # under the License. import nova.context -from nova.db import api as db +from nova.db.main import api as db from nova import objects from nova import test diff --git a/nova/tests/functional/regressions/test_bug_1825034.py b/nova/tests/functional/regressions/test_bug_1825034.py index 99b66c0130..97473a4b33 100644 --- a/nova/tests/functional/regressions/test_bug_1825034.py +++ b/nova/tests/functional/regressions/test_bug_1825034.py @@ -11,7 +11,7 @@ # under the License. from nova import context as nova_context -from nova.db import api as db_api +from nova.db.main import api as db_api from nova.objects import virtual_interface from nova import test from nova.tests import fixtures as nova_fixtures diff --git a/nova/tests/functional/regressions/test_bug_1839560.py b/nova/tests/functional/regressions/test_bug_1839560.py index 090d88899d..32e8e03f1b 100644 --- a/nova/tests/functional/regressions/test_bug_1839560.py +++ b/nova/tests/functional/regressions/test_bug_1839560.py @@ -13,7 +13,7 @@ from oslo_log import log as logging from nova import context -from nova.db import api as db_api +from nova.db.main import api as db_api from nova import objects from nova import test from nova.tests import fixtures as nova_fixtures diff --git a/nova/tests/functional/test_cross_cell_migrate.py b/nova/tests/functional/test_cross_cell_migrate.py index 872036b0af..a1186ca7a5 100644 --- a/nova/tests/functional/test_cross_cell_migrate.py +++ b/nova/tests/functional/test_cross_cell_migrate.py @@ -21,7 +21,7 @@ from oslo_utils import timeutils from nova.compute import instance_actions from nova import conf from nova import context as nova_context -from nova.db import api as db_api +from nova.db.main import api as db_api from nova import exception from nova import objects from nova.policies import base as base_policies diff --git a/nova/tests/functional/test_server_group.py b/nova/tests/functional/test_server_group.py index 72d9b03440..08e47b3971 100644 --- a/nova/tests/functional/test_server_group.py +++ b/nova/tests/functional/test_server_group.py @@ -18,8 +18,7 @@ from oslo_config import cfg from nova.compute import instance_actions from nova import context -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 import test from nova.tests import fixtures as nova_fixtures from nova.tests.functional.api import client @@ -261,9 +260,9 @@ class ServerGroupTestV21(ServerGroupTestBase): ctxt = context.get_admin_context() servers = db.instance_get_all(ctxt) self.assertEqual(1, len(servers)) - ctxt_mgr = db_api.get_context_manager(ctxt) + ctxt_mgr = db.get_context_manager(ctxt) with ctxt_mgr.reader.using(ctxt): - bdms = db_api._block_device_mapping_get_query(ctxt).all() + bdms = db._block_device_mapping_get_query(ctxt).all() self.assertEqual(1, len(bdms)) self.assertEqual(servers[0]['uuid'], bdms[0]['instance_uuid']) diff --git a/nova/tests/unit/api/openstack/compute/test_availability_zone.py b/nova/tests/unit/api/openstack/compute/test_availability_zone.py index 9a50b40ee1..f355eb436a 100644 --- a/nova/tests/unit/api/openstack/compute/test_availability_zone.py +++ b/nova/tests/unit/api/openstack/compute/test_availability_zone.py @@ -24,7 +24,7 @@ from nova.api.openstack.compute import servers as servers_v21 from nova import availability_zones from nova.compute import api as compute_api 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 import test diff --git a/nova/tests/unit/api/openstack/compute/test_disk_config.py b/nova/tests/unit/api/openstack/compute/test_disk_config.py index 8f78f3f012..bf3be1d0a3 100644 --- a/nova/tests/unit/api/openstack/compute/test_disk_config.py +++ b/nova/tests/unit/api/openstack/compute/test_disk_config.py @@ -88,7 +88,7 @@ class DiskConfigTestCaseV21(test.TestCase): return inst - self.stub_out('nova.db.api.instance_create', fake_instance_create) + self.stub_out('nova.db.main.api.instance_create', fake_instance_create) def _set_up_app(self): self.app = compute.APIRouterV21() diff --git a/nova/tests/unit/api/openstack/compute/test_hosts.py b/nova/tests/unit/api/openstack/compute/test_hosts.py index 5f05b60472..7adc698093 100644 --- a/nova/tests/unit/api/openstack/compute/test_hosts.py +++ b/nova/tests/unit/api/openstack/compute/test_hosts.py @@ -22,7 +22,7 @@ from nova.api.openstack.compute import hosts as os_hosts_v21 from nova.compute import power_state from nova.compute import vm_states from nova import context as context_maker -from nova.db import api as db +from nova.db.main import api as db from nova import exception from nova import test from nova.tests import fixtures @@ -135,10 +135,10 @@ class HostTestCaseV21(test.TestCase): def _setup_stubs(self): # Pretend we have fake_hosts.HOST_LIST in the DB - self.stub_out('nova.db.api.service_get_all', + self.stub_out('nova.db.main.api.service_get_all', stub_service_get_all) # Only hosts in our fake DB exist - self.stub_out('nova.db.api.service_get_by_host_and_binary', + self.stub_out('nova.db.main.api.service_get_by_host_and_binary', stub_service_get_by_host_and_binary) # 'host_c1' always succeeds, and 'host_c2' self.stub_out('nova.compute.api.HostAPI.set_host_enabled', @@ -233,7 +233,7 @@ class HostTestCaseV21(test.TestCase): def stub_service_get_all_notimpl(self, req): return [{'host': 'notimplemented', 'topic': None, 'availability_zone': None}] - self.stub_out('nova.db.api.service_get_all', + self.stub_out('nova.db.main.api.service_get_all', stub_service_get_all_notimpl) body = {key: val} self.assertRaises(webob.exc.HTTPNotImplemented, diff --git a/nova/tests/unit/api/openstack/compute/test_hypervisors.py b/nova/tests/unit/api/openstack/compute/test_hypervisors.py index 6a66c2f4e7..facc5389be 100644 --- a/nova/tests/unit/api/openstack/compute/test_hypervisors.py +++ b/nova/tests/unit/api/openstack/compute/test_hypervisors.py @@ -250,7 +250,7 @@ class HypervisorsTestV21(test.NoDBTestCase): host_api.compute_node_get = mock.MagicMock( side_effect=fake_compute_node_get) - self.stub_out('nova.db.api.compute_node_statistics', + self.stub_out('nova.db.main.api.compute_node_statistics', fake_compute_node_statistics) def test_view_hypervisor_nodetail_noservers(self): diff --git a/nova/tests/unit/api/openstack/compute/test_instance_actions.py b/nova/tests/unit/api/openstack/compute/test_instance_actions.py index fc6fd0d211..04e9ae443e 100644 --- a/nova/tests/unit/api/openstack/compute/test_instance_actions.py +++ b/nova/tests/unit/api/openstack/compute/test_instance_actions.py @@ -25,7 +25,7 @@ from webob import exc from nova.api.openstack.compute import instance_actions as instance_actions_v21 from nova.api.openstack import wsgi as os_wsgi from nova.compute import api as compute_api -from nova.db.sqlalchemy import models +from nova.db.main import models from nova import exception from nova import objects from nova import policy @@ -134,7 +134,7 @@ class InstanceActionsTestV21(test.NoDBTestCase): actions.append(action) return actions - self.stub_out('nova.db.api.actions_get', fake_get_actions) + self.stub_out('nova.db.main.api.actions_get', fake_get_actions) req = self._get_http_req('os-instance-actions') res_dict = self.controller.index(req, FAKE_UUID) for res in res_dict['instanceActions']: @@ -155,8 +155,9 @@ class InstanceActionsTestV21(test.NoDBTestCase): events.append(event) return events - self.stub_out('nova.db.api.action_get_by_request_id', fake_get_action) - self.stub_out('nova.db.api.action_events_get', fake_get_events) + self.stub_out( + 'nova.db.main.api.action_get_by_request_id', fake_get_action) + self.stub_out('nova.db.main.api.action_events_get', fake_get_events) req = self._get_http_req('os-instance-actions/1', use_admin_context=True) res_dict = self.controller.show(req, FAKE_UUID, FAKE_REQUEST_ID) @@ -177,8 +178,9 @@ class InstanceActionsTestV21(test.NoDBTestCase): def fake_get_events(context, action_id): return self.fake_events[action_id] - self.stub_out('nova.db.api.action_get_by_request_id', fake_get_action) - self.stub_out('nova.db.api.action_events_get', fake_get_events) + self.stub_out( + 'nova.db.main.api.action_get_by_request_id', fake_get_action) + self.stub_out('nova.db.main.api.action_events_get', fake_get_events) self._set_policy_rules() req = self._get_http_req('os-instance-actions/1') @@ -202,7 +204,8 @@ class InstanceActionsTestV21(test.NoDBTestCase): def fake_no_action(context, uuid, action_id): return None - self.stub_out('nova.db.api.action_get_by_request_id', fake_no_action) + self.stub_out( + 'nova.db.main.api.action_get_by_request_id', fake_no_action) req = self._get_http_req('os-instance-actions/1') self.assertRaises(exc.HTTPNotFound, self.controller.show, req, FAKE_UUID, FAKE_REQUEST_ID) @@ -431,8 +434,9 @@ class InstanceActionsTestV284(InstanceActionsTestV266): def fake_get_events(context, action_id): return self.fake_events[action_id] - self.stub_out('nova.db.api.action_get_by_request_id', fake_get_action) - self.stub_out('nova.db.api.action_events_get', fake_get_events) + self.stub_out( + 'nova.db.main.api.action_get_by_request_id', fake_get_action) + self.stub_out('nova.db.main.api.action_events_get', fake_get_events) self._set_policy_rules(overwrite=False) req = self._get_http_req('os-instance-actions/1') @@ -448,8 +452,9 @@ class InstanceActionsTestV284(InstanceActionsTestV266): def fake_get_events(context, action_id): return self.fake_events[action_id] - self.stub_out('nova.db.api.action_get_by_request_id', fake_get_action) - self.stub_out('nova.db.api.action_events_get', fake_get_events) + self.stub_out( + 'nova.db.main.api.action_get_by_request_id', fake_get_action) + self.stub_out('nova.db.main.api.action_events_get', fake_get_events) req = self._get_http_req_with_version('os-instance-actions/1', version="2.83") diff --git a/nova/tests/unit/api/openstack/compute/test_instance_usage_audit_log.py b/nova/tests/unit/api/openstack/compute/test_instance_usage_audit_log.py index 584625ec65..9ff09bd40c 100644 --- a/nova/tests/unit/api/openstack/compute/test_instance_usage_audit_log.py +++ b/nova/tests/unit/api/openstack/compute/test_instance_usage_audit_log.py @@ -119,10 +119,12 @@ class InstanceUsageAuditLogTestV21(test.NoDBTestCase): self.assertIsNone(disabled) return TEST_COMPUTE_SERVICES - self.stub_out('nova.utils.last_completed_audit_period', - fake_last_completed_audit_period) - self.stub_out('nova.db.api.service_get_all', fake_service_get_all) - self.stub_out('nova.db.api.task_log_get_all', fake_task_log_get_all) + self.stub_out( + 'nova.utils.last_completed_audit_period', + fake_last_completed_audit_period) + self.stub_out('nova.db.main.api.service_get_all', fake_service_get_all) + self.stub_out( + 'nova.db.main.api.task_log_get_all', fake_task_log_get_all) self.req = fakes.HTTPRequest.blank('') diff --git a/nova/tests/unit/api/openstack/compute/test_keypairs.py b/nova/tests/unit/api/openstack/compute/test_keypairs.py index 5cf5471308..afe4f6e516 100644 --- a/nova/tests/unit/api/openstack/compute/test_keypairs.py +++ b/nova/tests/unit/api/openstack/compute/test_keypairs.py @@ -74,11 +74,11 @@ class KeypairsTestV21(test.TestCase): fakes.stub_out_networking(self) fakes.stub_out_secgroup_api(self) - self.stub_out("nova.db.api.key_pair_get_all_by_user", + self.stub_out("nova.db.main.api.key_pair_get_all_by_user", db_key_pair_get_all_by_user) - self.stub_out("nova.db.api.key_pair_create", + self.stub_out("nova.db.main.api.key_pair_create", db_key_pair_create) - self.stub_out("nova.db.api.key_pair_destroy", + self.stub_out("nova.db.main.api.key_pair_destroy", db_key_pair_destroy) self._setup_app_and_controller() @@ -282,7 +282,7 @@ class KeypairsTestV21(test.TestCase): def db_key_pair_get_not_found(context, user_id, name): raise exception.KeypairNotFound(user_id=user_id, name=name) - self.stub_out("nova.db.api.key_pair_destroy", + self.stub_out("nova.db.main.api.key_pair_destroy", db_key_pair_get_not_found) self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete, self.req, 'FAKE') @@ -294,7 +294,7 @@ class KeypairsTestV21(test.TestCase): name='foo', public_key='XXX', fingerprint='YYY', type='ssh') - self.stub_out("nova.db.api.key_pair_get", _db_key_pair_get) + self.stub_out("nova.db.main.api.key_pair_get", _db_key_pair_get) res_dict = self.controller.show(self.req, 'FAKE') self.assertEqual('foo', res_dict['keypair']['name']) @@ -307,7 +307,7 @@ class KeypairsTestV21(test.TestCase): def _db_key_pair_get(context, user_id, name): raise exception.KeypairNotFound(user_id=user_id, name=name) - self.stub_out("nova.db.api.key_pair_get", _db_key_pair_get) + self.stub_out("nova.db.main.api.key_pair_get", _db_key_pair_get) self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, self.req, 'FAKE') @@ -432,7 +432,7 @@ class KeypairsTestV235(test.TestCase): super(KeypairsTestV235, self).setUp() self._setup_app_and_controller() - @mock.patch("nova.db.api.key_pair_get_all_by_user") + @mock.patch("nova.db.main.api.key_pair_get_all_by_user") def test_keypair_list_limit_and_marker(self, mock_kp_get): mock_kp_get.side_effect = db_key_pair_get_all_by_user @@ -467,7 +467,7 @@ class KeypairsTestV235(test.TestCase): self.assertRaises(exception.ValidationError, self.controller.index, req) - @mock.patch("nova.db.api.key_pair_get_all_by_user") + @mock.patch("nova.db.main.api.key_pair_get_all_by_user") def test_keypair_list_limit_and_marker_invalid_in_old_microversion( self, mock_kp_get): mock_kp_get.side_effect = db_key_pair_get_all_by_user @@ -488,7 +488,7 @@ class KeypairsTestV275(test.TestCase): super(KeypairsTestV275, self).setUp() self.controller = keypairs_v21.KeypairController() - @mock.patch("nova.db.api.key_pair_get_all_by_user") + @mock.patch("nova.db.main.api.key_pair_get_all_by_user") @mock.patch('nova.objects.KeyPair.get_by_name') def test_keypair_list_additional_param_old_version(self, mock_get_by_name, mock_kp_get): diff --git a/nova/tests/unit/api/openstack/compute/test_security_groups.py b/nova/tests/unit/api/openstack/compute/test_security_groups.py index d9ba3df804..71cdcbc871 100644 --- a/nova/tests/unit/api/openstack/compute/test_security_groups.py +++ b/nova/tests/unit/api/openstack/compute/test_security_groups.py @@ -24,7 +24,7 @@ import webob from nova.api.openstack.compute import security_groups as secgroups_v21 from nova import context as context_maker -import nova.db.api +import nova.db.main.api from nova import exception from nova.network import model from nova.network import neutron as neutron_api @@ -636,7 +636,7 @@ class TestSecurityGroupsV21(test.TestCase): _context, instance_obj.Instance(), db_inst, expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS) neutron = neutron_api.API() - with mock.patch.object(nova.db.api, 'instance_get_by_uuid', + with mock.patch.object(nova.db.main.api, 'instance_get_by_uuid', return_value=db_inst): neutron.allocate_for_instance(_context, instance, None, security_groups=[sg['id']]) diff --git a/nova/tests/unit/api/openstack/compute/test_server_actions.py b/nova/tests/unit/api/openstack/compute/test_server_actions.py index 3e581aa51b..006bac3033 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_actions.py +++ b/nova/tests/unit/api/openstack/compute/test_server_actions.py @@ -1038,8 +1038,9 @@ class ServerActionsControllerTestV21(test.TestCase): 'delete_on_termination': False, 'no_device': None})] - self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance', - fake_block_device_mapping_get_all_by_instance) + self.stub_out( + 'nova.db.main.api.block_device_mapping_get_all_by_instance', + fake_block_device_mapping_get_all_by_instance) system_metadata = dict(image_kernel_id=_fake_id('b'), image_ramdisk_id=_fake_id('c'), @@ -1150,8 +1151,9 @@ class ServerActionsControllerTestV21(test.TestCase): 'delete_on_termination': False, 'no_device': None})] - self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance', - fake_block_device_mapping_get_all_by_instance) + self.stub_out( + 'nova.db.main.api.block_device_mapping_get_all_by_instance', + fake_block_device_mapping_get_all_by_instance) instance = fakes.fake_compute_get( project_id=fakes.FAKE_PROJECT_ID, diff --git a/nova/tests/unit/api/openstack/compute/test_server_metadata.py b/nova/tests/unit/api/openstack/compute/test_server_metadata.py index cb9de8f056..a454597305 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_metadata.py +++ b/nova/tests/unit/api/openstack/compute/test_server_metadata.py @@ -23,7 +23,7 @@ import webob from nova.api.openstack.compute import server_metadata \ as server_metadata_v21 from nova.compute import vm_states -import nova.db.api +import nova.db.main.api from nova import exception from nova import test from nova.tests.unit.api.openstack import fakes @@ -96,7 +96,7 @@ class ServerMetaDataTestV21(test.TestCase): 'vm_state': vm_states.ACTIVE, 'metadata': metadata})) - self.stub_out('nova.db.api.instance_metadata_get', + self.stub_out('nova.db.main.api.instance_metadata_get', return_server_metadata) self._set_up_resources() @@ -124,14 +124,14 @@ class ServerMetaDataTestV21(test.TestCase): self.assertEqual(expected, res_dict) def test_index_nonexistent_server(self): - self.stub_out('nova.db.api.instance_metadata_get', + self.stub_out('nova.db.main.api.instance_metadata_get', return_server_nonexistent) req = self._get_request() self.assertRaises(webob.exc.HTTPNotFound, self.controller.index, req, self.url) def test_index_no_data(self): - self.stub_out('nova.db.api.instance_metadata_get', + self.stub_out('nova.db.main.api.instance_metadata_get', return_empty_server_metadata) req = self._get_request() res_dict = self.controller.index(req, self.uuid) @@ -145,23 +145,23 @@ class ServerMetaDataTestV21(test.TestCase): self.assertEqual(expected, res_dict) def test_show_nonexistent_server(self): - self.stub_out('nova.db.api.instance_metadata_get', + self.stub_out('nova.db.main.api.instance_metadata_get', return_server_nonexistent) req = self._get_request('/key2') self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req, self.uuid, 'key2') def test_show_meta_not_found(self): - self.stub_out('nova.db.api.instance_metadata_get', + self.stub_out('nova.db.main.api.instance_metadata_get', return_empty_server_metadata) req = self._get_request('/key6') self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req, self.uuid, 'key6') def test_delete(self): - self.stub_out('nova.db.api.instance_metadata_get', + self.stub_out('nova.db.main.api.instance_metadata_get', return_server_metadata) - self.stub_out('nova.db.api.instance_metadata_delete', + self.stub_out('nova.db.main.api.instance_metadata_delete', delete_server_metadata) req = self._get_request('/key2') req.method = 'DELETE' @@ -179,7 +179,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.delete, req, self.uuid, 'key1') def test_delete_meta_not_found(self): - self.stub_out('nova.db.api.instance_metadata_get', + self.stub_out('nova.db.main.api.instance_metadata_get', return_empty_server_metadata) req = self._get_request('/key6') req.method = 'DELETE' @@ -203,7 +203,7 @@ class ServerMetaDataTestV21(test.TestCase): self.assertEqual(body, res_dict) def test_create_empty_body(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'POST' @@ -213,7 +213,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.create, req, self.uuid, body=None) def test_create_item_empty_key(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -225,7 +225,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.create, req, self.uuid, body=body) def test_create_item_non_dict(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -237,7 +237,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.create, req, self.uuid, body=body) def test_create_item_key_too_long(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -250,7 +250,7 @@ class ServerMetaDataTestV21(test.TestCase): req, self.uuid, body=body) def test_create_malformed_container(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url + '/key1') req.method = 'PUT' @@ -262,7 +262,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.create, req, self.uuid, body=body) def test_create_malformed_data(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url + '/key1') req.method = 'PUT' @@ -329,7 +329,7 @@ class ServerMetaDataTestV21(test.TestCase): self.assertEqual(expected, res_dict) def test_update_all_empty_body_item(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url + '/key1') req.method = 'PUT' @@ -340,7 +340,7 @@ class ServerMetaDataTestV21(test.TestCase): body=None) def test_update_all_with_non_dict_item(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url + '/bad') req.method = 'PUT' @@ -353,7 +353,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_all_malformed_container(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'PUT' @@ -366,7 +366,7 @@ class ServerMetaDataTestV21(test.TestCase): body=expected) def test_update_all_malformed_data(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'PUT' @@ -392,7 +392,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_all_non_dict(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'PUT' @@ -428,7 +428,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_item_empty_body(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -439,7 +439,7 @@ class ServerMetaDataTestV21(test.TestCase): body=None) def test_update_malformed_container(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = 'PUT' @@ -452,7 +452,7 @@ class ServerMetaDataTestV21(test.TestCase): body=expected) def test_update_malformed_data(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = 'PUT' @@ -465,7 +465,7 @@ class ServerMetaDataTestV21(test.TestCase): body=expected) def test_update_item_empty_key(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -478,7 +478,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_item_key_too_long(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -491,7 +491,7 @@ class ServerMetaDataTestV21(test.TestCase): req, self.uuid, ("a" * 260), body=body) def test_update_item_value_too_long(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -504,7 +504,7 @@ class ServerMetaDataTestV21(test.TestCase): req, self.uuid, "key1", body=body) def test_update_item_too_many_keys(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -517,7 +517,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_item_body_uri_mismatch(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/bad') req.method = 'PUT' @@ -530,7 +530,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_item_non_dict(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/bad') req.method = 'PUT' @@ -556,7 +556,7 @@ class ServerMetaDataTestV21(test.TestCase): body=expected) def test_too_many_metadata_items_on_create(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) data = {"metadata": {}} for num in range(CONF.quota.metadata_items + 1): @@ -570,7 +570,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.create, req, self.uuid, body=data) def test_invalid_metadata_items_on_create(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'POST' @@ -595,7 +595,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.create, req, self.uuid, body=data) def test_too_many_metadata_items_on_update_item(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) data = {"metadata": {}} for num in range(CONF.quota.metadata_items + 1): @@ -609,7 +609,7 @@ class ServerMetaDataTestV21(test.TestCase): req, self.uuid, body=data) def test_invalid_metadata_items_on_update_item(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) data = {"metadata": {}} for num in range(CONF.quota.metadata_items + 1): @@ -645,14 +645,14 @@ class BadStateServerMetaDataTestV21(test.TestCase): def setUp(self): super(BadStateServerMetaDataTestV21, self).setUp() - self.stub_out('nova.db.api.instance_metadata_get', + self.stub_out('nova.db.main.api.instance_metadata_get', return_server_metadata) self.stub_out('nova.compute.api.API.get', fakes.fake_compute_get( **{'uuid': '0cc3346e-9fef-4445-abe6-5d2b2690ec64', 'name': 'fake', 'vm_state': vm_states.BUILDING})) - self.stub_out('nova.db.api.instance_metadata_delete', + self.stub_out('nova.db.main.api.instance_metadata_delete', delete_server_metadata) self._set_up_resources() @@ -672,7 +672,7 @@ class BadStateServerMetaDataTestV21(test.TestCase): req, self.uuid, 'key2') def test_invalid_state_on_update_metadata(self): - self.stub_out('nova.db.api.instance_metadata_update', + self.stub_out('nova.db.main.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'POST' diff --git a/nova/tests/unit/api/openstack/compute/test_server_start_stop.py b/nova/tests/unit/api/openstack/compute/test_server_start_stop.py index 3e3d2e6919..60d12d0c43 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_start_stop.py +++ b/nova/tests/unit/api/openstack/compute/test_server_start_stop.py @@ -18,7 +18,7 @@ import webob from nova.api.openstack.compute import servers from nova.compute import api as compute_api -from nova.db import api as db +from nova.db.main import api as db from nova import exception from nova import test from nova.tests import fixtures as nova_fixtures @@ -32,7 +32,7 @@ class ServerStartStopTestV21(test.TestCase): self._setup_controller() self.req = fakes.HTTPRequest.blank('') self.useFixture(nova_fixtures.SingleCellSimple()) - self.stub_out('nova.db.api.instance_get_by_uuid', + self.stub_out('nova.db.main.api.instance_get_by_uuid', fakes.fake_instance_get( project_id=fakes.FAKE_PROJECT_ID)) diff --git a/nova/tests/unit/api/openstack/compute/test_server_tags.py b/nova/tests/unit/api/openstack/compute/test_server_tags.py index 0e5f945a46..b121c75c3a 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_tags.py +++ b/nova/tests/unit/api/openstack/compute/test_server_tags.py @@ -17,7 +17,7 @@ from nova.api.openstack.compute import server_tags from nova.api.openstack.compute import servers from nova.compute import vm_states from nova import context -from nova.db.sqlalchemy import models +from nova.db.main import models from nova import exception from nova import objects from nova.objects import instance @@ -68,7 +68,7 @@ class ServerTagsTest(test.TestCase): request.method = method return request - @mock.patch('nova.db.api.instance_tag_exists') + @mock.patch('nova.db.main.api.instance_tag_exists') def test_show(self, mock_exists): mock_exists.return_value = True req = self._get_request( @@ -78,7 +78,7 @@ class ServerTagsTest(test.TestCase): self.controller.show(req, UUID, TAG1) mock_exists.assert_called_once_with(mock.ANY, UUID, TAG1) - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') def test_index(self, mock_db_get_inst_tags): fake_tags = [self._get_tag(tag) for tag in TAGS] mock_db_get_inst_tags.return_value = fake_tags @@ -91,7 +91,7 @@ class ServerTagsTest(test.TestCase): mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID) @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.api.instance_tag_set') + @mock.patch('nova.db.main.api.instance_tag_set') def test_update_all(self, mock_db_set_inst_tags, mock_notify): self.stub_out('nova.api.openstack.common.get_instance', return_server) fake_tags = [self._get_tag(tag) for tag in TAGS] @@ -162,7 +162,7 @@ class ServerTagsTest(test.TestCase): self.assertRaises(exc.HTTPConflict, self.controller.update_all, req, UUID, body={'tags': TAGS}) - @mock.patch('nova.db.api.instance_tag_exists') + @mock.patch('nova.db.main.api.instance_tag_exists') def test_show_non_existing_tag(self, mock_exists): mock_exists.return_value = False req = self._get_request( @@ -172,8 +172,8 @@ class ServerTagsTest(test.TestCase): req, UUID, TAG1) @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.api.instance_tag_add') - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_add') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') def test_update(self, mock_db_get_inst_tags, mock_db_add_inst_tags, mock_notify): self.stub_out('nova.api.openstack.common.get_instance', return_server) @@ -192,7 +192,7 @@ class ServerTagsTest(test.TestCase): self.assertEqual(2, mock_db_get_inst_tags.call_count) self.assertEqual(1, mock_notify.call_count) - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') def test_update_existing_tag(self, mock_db_get_inst_tags): self.stub_out('nova.api.openstack.common.get_instance', return_server) mock_db_get_inst_tags.return_value = [self._get_tag(TAG1)] @@ -206,7 +206,7 @@ class ServerTagsTest(test.TestCase): self.assertEqual(0, len(res.body)) mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID) - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') def test_update_tag_limit_exceed(self, mock_db_get_inst_tags): self.stub_out('nova.api.openstack.common.get_instance', return_server) fake_tags = [self._get_tag(str(i)) @@ -219,7 +219,7 @@ class ServerTagsTest(test.TestCase): self.assertRaises(exc.HTTPBadRequest, self.controller.update, req, UUID, TAG2, body=None) - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') def test_update_too_long_tag(self, mock_db_get_inst_tags): self.stub_out('nova.api.openstack.common.get_instance', return_server) mock_db_get_inst_tags.return_value = [] @@ -231,7 +231,7 @@ class ServerTagsTest(test.TestCase): self.assertRaises(exc.HTTPBadRequest, self.controller.update, req, UUID, tag, body=None) - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') def test_update_forbidden_characters(self, mock_db_get_inst_tags): self.stub_out('nova.api.openstack.common.get_instance', return_server) mock_db_get_inst_tags.return_value = [] @@ -251,9 +251,9 @@ class ServerTagsTest(test.TestCase): self.assertRaises(exc.HTTPConflict, self.controller.update, req, UUID, TAG1, body=None) - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.api.instance_tag_delete') + @mock.patch('nova.db.main.api.instance_tag_delete') def test_delete(self, mock_db_delete_inst_tags, mock_notify, mock_db_get_inst_tags): self.stub_out('nova.api.openstack.common.get_instance', return_server) @@ -265,7 +265,7 @@ class ServerTagsTest(test.TestCase): mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID) self.assertEqual(1, mock_notify.call_count) - @mock.patch('nova.db.api.instance_tag_delete') + @mock.patch('nova.db.main.api.instance_tag_delete') def test_delete_non_existing_tag(self, mock_db_delete_inst_tags): self.stub_out('nova.api.openstack.common.get_instance', return_server) @@ -291,7 +291,7 @@ class ServerTagsTest(test.TestCase): TAG1) @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.api.instance_tag_delete_all') + @mock.patch('nova.db.main.api.instance_tag_delete_all') def test_delete_all(self, mock_db_delete_inst_tags, mock_notify): self.stub_out('nova.api.openstack.common.get_instance', return_server) req = self._get_request('/v2/%s/servers/%s/tags' % ( diff --git a/nova/tests/unit/api/openstack/compute/test_servers.py b/nova/tests/unit/api/openstack/compute/test_servers.py index 9211bca88c..d932c5598a 100644 --- a/nova/tests/unit/api/openstack/compute/test_servers.py +++ b/nova/tests/unit/api/openstack/compute/test_servers.py @@ -52,8 +52,8 @@ from nova.compute import vm_states import nova.conf from nova import context from nova.db import constants as db_const -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.image import glance from nova import objects @@ -241,9 +241,9 @@ class ControllerTest(test.TestCase): compute_api.API, 'get_all', side_effect=return_servers)).mock self.mock_get = self.useFixture(fixtures.MockPatchObject( compute_api.API, 'get', side_effect=return_server)).mock - self.stub_out('nova.db.api.instance_update_and_get_original', + self.stub_out('nova.db.main.api.instance_update_and_get_original', instance_update_and_get_original) - self.stub_out('nova.db.api.' + self.stub_out('nova.db.main.api.' 'block_device_mapping_get_all_by_instance_uuids', fake_bdms_get_all_by_instance_uuids) self.stub_out('nova.objects.InstanceMappingList.' @@ -2923,7 +2923,8 @@ class ServersControllerDeleteTest(ControllerTest): self.server_delete_called = True deleted_at = timeutils.utcnow() return fake_instance.fake_db_instance(deleted_at=deleted_at) - self.stub_out('nova.db.api.instance_destroy', instance_destroy_mock) + self.stub_out( + 'nova.db.main.api.instance_destroy', instance_destroy_mock) self.controller.delete(req, FAKE_UUID) # delete() should be called for instance which has never been active, @@ -3258,7 +3259,7 @@ class ServersControllerRebuildInstanceTest(ControllerTest): self.controller._stop_server, req, FAKE_UUID, body) @mock.patch( - 'nova.db.api.instance_get_by_uuid', + 'nova.db.main.api.instance_get_by_uuid', fake_instance_get_by_uuid_not_found) def test_start_with_bogus_id(self): req = fakes.HTTPRequestV21.blank(self.path_action % 'test_inst') @@ -3267,7 +3268,7 @@ class ServersControllerRebuildInstanceTest(ControllerTest): self.controller._start_server, req, 'test_inst', body) @mock.patch( - 'nova.db.api.instance_get_by_uuid', + 'nova.db.main.api.instance_get_by_uuid', fake_instance_get_by_uuid_not_found) def test_stop_with_bogus_id(self): req = fakes.HTTPRequestV21.blank(self.path_action % 'test_inst') @@ -3336,7 +3337,7 @@ class ServersControllerRebuildTestV254(ServersControllerRebuildInstanceTest): def test_rebuild_user_has_no_key_pair(self): def no_key_pair(context, user_id, name): raise exception.KeypairNotFound(user_id=user_id, name=name) - self.stub_out('nova.db.api.key_pair_get', no_key_pair) + self.stub_out('nova.db.main.api.key_pair_get', no_key_pair) fake_get = fakes.fake_compute_get(vm_state=vm_states.ACTIVE, key_name=None, project_id=self.req_project_id, @@ -3478,7 +3479,7 @@ class ServersControllerRebuildTestV257(ServersControllerRebuildTestV254): self.assertIn('user_data', str(ex)) @mock.patch.object(context.RequestContext, 'can') - @mock.patch('nova.db.api.instance_update_and_get_original') + @mock.patch('nova.db.main.api.instance_update_and_get_original') def test_rebuild_reset_user_data(self, mock_update, mock_policy): """Tests that passing user_data=None resets the user_data on the instance. @@ -3806,7 +3807,7 @@ class ServersControllerUpdateTest(ControllerTest): req, FAKE_UUID, body=body) def test_update_server_name_all_blank_spaces(self): - self.stub_out('nova.db.api.instance_get', + self.stub_out('nova.db.main.api.instance_get', fakes.fake_instance_get(name='server_test')) req = fakes.HTTPRequest.blank(self.path_with_id % FAKE_UUID) req.method = 'PUT' @@ -3822,7 +3823,7 @@ class ServersControllerUpdateTest(ControllerTest): self.controller.update(req, FAKE_UUID, body=body) def test_update_server_name_with_leading_trailing_spaces(self): - self.stub_out('nova.db.api.instance_get', + self.stub_out('nova.db.main.api.instance_get', fakes.fake_instance_get(name='server_test')) req = fakes.HTTPRequest.blank(self.path_with_id % FAKE_UUID) req.method = 'PUT' @@ -5494,7 +5495,7 @@ class ServersControllerCreateTest(test.TestCase): mock_get_all_p.return_value = {'project_id': fakes.FAKE_PROJECT_ID} mock_get_all_pu.return_value = {'project_id': fakes.FAKE_PROJECT_ID, 'user_id': 'fake_user'} - if resource in db_api.PER_PROJECT_QUOTAS: + if resource in db.PER_PROJECT_QUOTAS: mock_get_all_p.return_value[resource] = quota else: mock_get_all_pu.return_value[resource] = quota @@ -5550,7 +5551,8 @@ class ServersControllerCreateTest(test.TestCase): return fakes.stub_instance(1) mock_limit_check.side_effect = fake_limit_check - self.stub_out('nova.db.api.instance_destroy', fake_instance_destroy) + self.stub_out( + 'nova.db.main.api.instance_destroy', fake_instance_destroy) self.body['os:scheduler_hints'] = {'group': fake_group.uuid} self.req.body = jsonutils.dump_as_bytes(self.body) expected_msg = "Quota exceeded, too many servers in group" @@ -5573,7 +5575,8 @@ class ServersControllerCreateTest(test.TestCase): def fake_instance_destroy(context, uuid, constraint): return fakes.stub_instance(1) - self.stub_out('nova.db.api.instance_destroy', fake_instance_destroy) + self.stub_out( + 'nova.db.main.api.instance_destroy', fake_instance_destroy) self.body['os:scheduler_hints'] = {'group': test_group.uuid} self.req.body = jsonutils.dump_as_bytes(self.body) server = self.controller.create(self.req, body=self.body).obj['server'] @@ -5613,7 +5616,8 @@ class ServersControllerCreateTest(test.TestCase): def fake_instance_destroy(context, uuid, constraint): return fakes.stub_instance(1) - self.stub_out('nova.db.api.instance_destroy', fake_instance_destroy) + self.stub_out( + 'nova.db.main.api.instance_destroy', fake_instance_destroy) self.body['os:scheduler_hints'] = { 'group': '5b674f73-c8cf-40ef-9965-3b6fe4b304b1'} self.req.body = jsonutils.dump_as_bytes(self.body) @@ -7102,7 +7106,7 @@ class ServersViewBuilderTest(test.TestCase): fakes.stub_out_secgroup_api( self, security_groups=[{'name': 'default'}]) - self.stub_out('nova.db.api.' + self.stub_out('nova.db.main.api.' 'block_device_mapping_get_all_by_instance_uuids', fake_bdms_get_all_by_instance_uuids) self.stub_out('nova.objects.InstanceMappingList.' diff --git a/nova/tests/unit/api/openstack/compute/test_services.py b/nova/tests/unit/api/openstack/compute/test_services.py index bd593552a2..5d83bc5a91 100644 --- a/nova/tests/unit/api/openstack/compute/test_services.py +++ b/nova/tests/unit/api/openstack/compute/test_services.py @@ -191,9 +191,9 @@ class ServicesTestV21(test.TestCase): mock.Mock(side_effect=fake_service_get_all(fake_services_list))) self.useFixture(utils_fixture.TimeFixture(fake_utcnow())) - self.stub_out('nova.db.api.service_get_by_host_and_binary', + self.stub_out('nova.db.main.api.service_get_by_host_and_binary', fake_db_service_get_by_host_binary(fake_services_list)) - self.stub_out('nova.db.api.service_update', + self.stub_out('nova.db.main.api.service_update', fake_db_service_update(fake_services_list)) # NOTE(gibi): enable / disable a compute service tries to call @@ -595,7 +595,7 @@ class ServicesTestV21(test.TestCase): self.assertIsNone(values['disabled_reason']) return dict(test_service.fake_service, id=service_id, **values) - self.stub_out('nova.db.api.service_update', _service_update) + self.stub_out('nova.db.main.api.service_update', _service_update) body = {'host': 'host1', 'binary': 'nova-compute'} res_dict = self.controller.update(self.req, "enable", body=body) diff --git a/nova/tests/unit/api/openstack/fakes.py b/nova/tests/unit/api/openstack/fakes.py index 66b2ef4eef..4a112a8afe 100644 --- a/nova/tests/unit/api/openstack/fakes.py +++ b/nova/tests/unit/api/openstack/fakes.py @@ -33,7 +33,7 @@ from nova.compute import flavors from nova.compute import vm_states import nova.conf from nova import context -from nova.db.sqlalchemy import models +from nova.db.main import models from nova import exception as exc from nova import objects from nova.objects import base @@ -105,10 +105,12 @@ def stub_out_key_pair_funcs(testcase, have_key_pair=True, **kwargs): return [] if have_key_pair: - testcase.stub_out('nova.db.api.key_pair_get_all_by_user', key_pair) - testcase.stub_out('nova.db.api.key_pair_get', one_key_pair) + testcase.stub_out( + 'nova.db.main.api.key_pair_get_all_by_user', key_pair) + testcase.stub_out('nova.db.main.api.key_pair_get', one_key_pair) else: - testcase.stub_out('nova.db.api.key_pair_get_all_by_user', no_key_pair) + testcase.stub_out( + 'nova.db.main.api.key_pair_get_all_by_user', no_key_pair) def stub_out_trusted_certs(test, certs=None): diff --git a/nova/tests/unit/api/openstack/test_wsgi_app.py b/nova/tests/unit/api/openstack/test_wsgi_app.py index 4cb7459c98..b6306af0e1 100644 --- a/nova/tests/unit/api/openstack/test_wsgi_app.py +++ b/nova/tests/unit/api/openstack/test_wsgi_app.py @@ -46,7 +46,7 @@ document_root = /tmp self.useFixture(config_fixture.Config()) @mock.patch('sys.argv', return_value=mock.sentinel.argv) - @mock.patch('nova.db.sqlalchemy.api.configure') + @mock.patch('nova.db.main.api.configure') @mock.patch('nova.api.openstack.wsgi_app._setup_service') @mock.patch('nova.api.openstack.wsgi_app._get_config_files') def test_init_application_called_twice(self, mock_get_files, mock_setup, diff --git a/nova/tests/unit/cmd/test_common.py b/nova/tests/unit/cmd/test_common.py index e5df911ede..cabb54f9d4 100644 --- a/nova/tests/unit/cmd/test_common.py +++ b/nova/tests/unit/cmd/test_common.py @@ -24,23 +24,12 @@ import fixtures import mock from nova.cmd import common as cmd_common -from nova.db import api from nova import exception from nova import test class TestCmdCommon(test.NoDBTestCase): - @mock.patch.object(cmd_common, 'LOG') - @mock.patch.object(api, 'IMPL') - def test_block_db_access(self, mock_db_IMPL, mock_LOG): - cmd_common.block_db_access('unit-tests') - - self.assertEqual(api.IMPL, api.IMPL.foo) - self.assertRaises(exception.DBNotAllowed, api.IMPL) - self.assertEqual('unit-tests', - mock_LOG.error.call_args[0][1]['service_name']) - def test_args_decorator(self): @cmd_common.args(bar='') @cmd_common.args('foo') diff --git a/nova/tests/unit/cmd/test_cmd_db_blocks.py b/nova/tests/unit/cmd/test_compute.py similarity index 83% rename from nova/tests/unit/cmd/test_cmd_db_blocks.py rename to nova/tests/unit/cmd/test_compute.py index a109afdc07..acfcea50d2 100644 --- a/nova/tests/unit/cmd/test_cmd_db_blocks.py +++ b/nova/tests/unit/cmd/test_compute.py @@ -17,18 +17,19 @@ import contextlib import mock from nova.cmd import compute -from nova.db import api as db +from nova import context +from nova.db.main import api as db from nova import exception from nova import test @contextlib.contextmanager def restore_db(): - orig = db.IMPL + orig = db.DISABLE_DB_ACCESS try: yield finally: - db.IMPL = orig + db.DISABLE_DB_ACCESS = orig class ComputeMainTest(test.NoDBTestCase): @@ -43,7 +44,7 @@ class ComputeMainTest(test.NoDBTestCase): run_main() def test_compute_main_blocks_db(self): + ctxt = context.get_admin_context() with restore_db(): self._call_main(compute) - self.assertRaises(exception.DBNotAllowed, - db.instance_get, 1, 2) + self.assertRaises(exception.DBNotAllowed, db.instance_get, ctxt, 2) diff --git a/nova/tests/unit/cmd/test_manage.py b/nova/tests/unit/cmd/test_manage.py index 5b41ce7930..fccce4d8b5 100644 --- a/nova/tests/unit/cmd/test_manage.py +++ b/nova/tests/unit/cmd/test_manage.py @@ -29,7 +29,7 @@ from oslo_utils import uuidutils from nova.cmd import manage from nova import conf from nova import context -from nova.db import api as db +from nova.db.main import api as db from nova.db import migration from nova import exception from nova import objects @@ -333,7 +333,7 @@ Archiving.....complete def test_archive_deleted_rows_until_complete_quiet(self): self.test_archive_deleted_rows_until_complete(verbose=False) - @mock.patch('nova.db.sqlalchemy.api.purge_shadow_tables') + @mock.patch('nova.db.main.api.purge_shadow_tables') @mock.patch.object(db, 'archive_deleted_rows') @mock.patch.object(objects.CellMappingList, 'get_all') def test_archive_deleted_rows_until_stopped(self, mock_get_all, @@ -546,14 +546,14 @@ is set and run this command again. self.assertEqual(expected, output) self.assertEqual(3, result) - @mock.patch('nova.db.sqlalchemy.api.purge_shadow_tables') + @mock.patch('nova.db.main.api.purge_shadow_tables') def test_purge_all(self, mock_purge): mock_purge.return_value = 1 ret = self.commands.purge(purge_all=True) self.assertEqual(0, ret) mock_purge.assert_called_once_with(mock.ANY, None, status_fn=mock.ANY) - @mock.patch('nova.db.sqlalchemy.api.purge_shadow_tables') + @mock.patch('nova.db.main.api.purge_shadow_tables') def test_purge_date(self, mock_purge): mock_purge.return_value = 1 ret = self.commands.purge(before='oct 21 2015') @@ -562,25 +562,25 @@ is set and run this command again. datetime.datetime(2015, 10, 21), status_fn=mock.ANY) - @mock.patch('nova.db.sqlalchemy.api.purge_shadow_tables') + @mock.patch('nova.db.main.api.purge_shadow_tables') def test_purge_date_fail(self, mock_purge): ret = self.commands.purge(before='notadate') self.assertEqual(2, ret) self.assertFalse(mock_purge.called) - @mock.patch('nova.db.sqlalchemy.api.purge_shadow_tables') + @mock.patch('nova.db.main.api.purge_shadow_tables') def test_purge_no_args(self, mock_purge): ret = self.commands.purge() self.assertEqual(1, ret) self.assertFalse(mock_purge.called) - @mock.patch('nova.db.sqlalchemy.api.purge_shadow_tables') + @mock.patch('nova.db.main.api.purge_shadow_tables') def test_purge_nothing_deleted(self, mock_purge): mock_purge.return_value = 0 ret = self.commands.purge(purge_all=True) self.assertEqual(3, ret) - @mock.patch('nova.db.sqlalchemy.api.purge_shadow_tables') + @mock.patch('nova.db.main.api.purge_shadow_tables') @mock.patch('nova.objects.CellMappingList.get_all') def test_purge_all_cells(self, mock_get_cells, mock_purge): cell1 = objects.CellMapping(uuid=uuidsentinel.cell1, name='cell1', diff --git a/nova/tests/unit/cmd/test_policy.py b/nova/tests/unit/cmd/test_policy.py index 4f44c9fffc..4c990a8ff1 100644 --- a/nova/tests/unit/cmd/test_policy.py +++ b/nova/tests/unit/cmd/test_policy.py @@ -25,7 +25,7 @@ import mock from nova.cmd import policy import nova.conf 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.policies import base as base_policies from nova.policies import instance_actions as ia_policies diff --git a/nova/tests/unit/compute/test_api.py b/nova/tests/unit/compute/test_api.py index 17a1811981..6392779f76 100644 --- a/nova/tests/unit/compute/test_api.py +++ b/nova/tests/unit/compute/test_api.py @@ -39,7 +39,7 @@ from nova.compute import vm_states from nova import conductor 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.image import glance as image_api from nova.network import constants @@ -4508,7 +4508,7 @@ class _ComputeAPIUnitTestMixIn(object): name='network-changed'), ] - with mock.patch('nova.db.sqlalchemy.api.migration_get', migration_get): + with mock.patch('nova.db.main.api.migration_get', migration_get): self.compute_api.compute_rpcapi = mock.MagicMock() self.compute_api.external_instance_event(self.context, instances, events) diff --git a/nova/tests/unit/compute/test_claims.py b/nova/tests/unit/compute/test_claims.py index abbf728f92..8997511e73 100644 --- a/nova/tests/unit/compute/test_claims.py +++ b/nova/tests/unit/compute/test_claims.py @@ -93,7 +93,7 @@ class ClaimTestCase(test.NoDBTestCase): requests = requests or self.empty_requests - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid', + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid', return_value=db_numa_topology) def get_claim(mock_extra_get): return claims.Claim(self.context, instance, _NODENAME, @@ -343,7 +343,7 @@ class MoveClaimTestCase(ClaimTestCase): @mock.patch('nova.virt.hardware.numa_get_constraints', return_value=numa_topology) - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid', + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid', return_value=self.db_numa_topology) def get_claim(mock_extra_get, mock_numa_get): return claims.MoveClaim( diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index a48eb98d32..f280963d55 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -54,7 +54,7 @@ from nova.compute import vm_states import nova.conf from nova.console import type as ctype 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.image import glance as image_api from nova.network import model as network_model @@ -205,7 +205,7 @@ class BaseTestCase(test.TestCase): self.stub_out( 'nova.compute.manager.ComputeManager._get_compute_nodes_in_db', fake_get_compute_nodes_in_db) - self.stub_out('nova.db.api.compute_node_delete', + self.stub_out('nova.db.main.api.compute_node_delete', fake_compute_node_delete) self.compute.update_available_resource( @@ -372,8 +372,10 @@ class ComputeVolumeTestCase(BaseTestCase): self.cinfo = jsonutils.loads(args[-1].get('connection_info')) return self.fake_volume - self.stub_out('nova.db.api.block_device_mapping_create', store_cinfo) - self.stub_out('nova.db.api.block_device_mapping_update', store_cinfo) + self.stub_out( + 'nova.db.main.api.block_device_mapping_create', store_cinfo) + self.stub_out( + 'nova.db.main.api.block_device_mapping_update', store_cinfo) @mock.patch.object(compute_utils, 'EventReporter') def test_attach_volume_serial(self, mock_event): @@ -6789,7 +6791,7 @@ class ComputeTestCase(BaseTestCase, except NotImplementedError: exc_info = sys.exc_info() - self.stub_out('nova.db.api.instance_fault_create', + self.stub_out('nova.db.main.api.instance_fault_create', fake_db_fault_create) ctxt = context.get_admin_context() @@ -6827,7 +6829,7 @@ class ComputeTestCase(BaseTestCase, raised_exc = exc exc_info = sys.exc_info() - self.stub_out('nova.db.api.instance_fault_create', + self.stub_out('nova.db.main.api.instance_fault_create', fake_db_fault_create) ctxt = context.get_admin_context() @@ -6857,7 +6859,7 @@ class ComputeTestCase(BaseTestCase, except exception.Invalid: exc_info = sys.exc_info() - self.stub_out('nova.db.api.instance_fault_create', + self.stub_out('nova.db.main.api.instance_fault_create', fake_db_fault_create) ctxt = context.get_admin_context() @@ -6878,7 +6880,7 @@ class ComputeTestCase(BaseTestCase, self.assertEqual(expected, values) return self._fill_fault(expected) - self.stub_out('nova.db.api.instance_fault_create', + self.stub_out('nova.db.main.api.instance_fault_create', fake_db_fault_create) ctxt = context.get_admin_context() @@ -6902,7 +6904,7 @@ class ComputeTestCase(BaseTestCase, self.assertEqual(expected, values) return self._fill_fault(expected) - self.stub_out('nova.db.api.instance_fault_create', + self.stub_out('nova.db.main.api.instance_fault_create', fake_db_fault_create) ctxt = context.get_admin_context() @@ -6934,7 +6936,7 @@ class ComputeTestCase(BaseTestCase, except NotImplementedError: exc_info = sys.exc_info() - self.stub_out('nova.db.api.instance_fault_create', + self.stub_out('nova.db.main.api.instance_fault_create', fake_db_fault_create) ctxt = context.get_admin_context() @@ -7180,9 +7182,9 @@ class ComputeTestCase(BaseTestCase, raise exception.InstanceInfoCacheNotFound( instance_uuid=instance['uuid']) - self.stub_out('nova.db.api.instance_get_all_by_host', + self.stub_out('nova.db.main.api.instance_get_all_by_host', fake_instance_get_all_by_host) - self.stub_out('nova.db.api.instance_get_by_uuid', + self.stub_out('nova.db.main.api.instance_get_by_uuid', fake_instance_get_by_uuid) self.stub_out('nova.compute.manager.ComputeManager.' @@ -7443,13 +7445,15 @@ class ComputeTestCase(BaseTestCase, migration['instance_uuid']): migration2['status'] = 'confirmed' - self.stub_out('nova.db.api.instance_get_by_uuid', - fake_instance_get_by_uuid) - self.stub_out('nova.db.api.migration_get_unconfirmed_by_dest_compute', - fake_migration_get_unconfirmed_by_dest_compute) - self.stub_out('nova.db.api.migration_update', fake_migration_update) - self.stub_out('nova.compute.api.API.confirm_resize', - fake_confirm_resize) + self.stub_out( + 'nova.db.main.api.instance_get_by_uuid', fake_instance_get_by_uuid) + self.stub_out( + 'nova.db.main.api.migration_get_unconfirmed_by_dest_compute', + fake_migration_get_unconfirmed_by_dest_compute) + self.stub_out( + 'nova.db.main.api.migration_update', fake_migration_update) + self.stub_out( + 'nova.compute.api.API.confirm_resize', fake_confirm_resize) def fetch_instance_migration_status(instance_uuid): for migration in migrations: @@ -7745,22 +7749,21 @@ class ComputeTestCase(BaseTestCase, instance.deleted = True self.stub_out('nova.objects.instance.Instance.destroy', fake_destroy) - - self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance', - lambda *a, **k: None) - - self.stub_out('nova.compute.manager.ComputeManager.' - '_complete_deletion', - lambda *a, **k: None) - - self.stub_out('nova.objects.quotas.Quotas.reserve', - lambda *a, **k: None) - - self.stub_out('nova.compute.utils.notify_about_instance_usage', - lambda *a, **k: None) - - self.stub_out('nova.compute.utils.notify_about_instance_action', - lambda *a, **k: None) + self.stub_out( + 'nova.db.main.api.block_device_mapping_get_all_by_instance', + lambda *a, **k: None) + self.stub_out( + 'nova.compute.manager.ComputeManager._complete_deletion', + lambda *a, **k: None) + self.stub_out( + 'nova.objects.quotas.Quotas.reserve', + lambda *a, **k: None) + self.stub_out( + 'nova.compute.utils.notify_about_instance_usage', + lambda *a, **k: None) + self.stub_out( + 'nova.compute.utils.notify_about_instance_action', + lambda *a, **k: None) self.compute._complete_partial_deletion(admin_context, instance) @@ -11969,7 +11972,7 @@ class ComputeAPITestCase(BaseTestCase): self.assertIsInstance(called_context, context.RequestContext) self.assertNotEqual(self.context, called_context) - @mock.patch("nova.db.api.migration_get_in_progress_by_instance") + @mock.patch("nova.db.main.api.migration_get_in_progress_by_instance") def test_get_migrations_in_progress_by_instance(self, mock_get): migration = test_migration.fake_db_migration( instance_uuid=uuids.instance) @@ -11980,7 +11983,7 @@ class ComputeAPITestCase(BaseTestCase): self.assertEqual(migrations[0].id, migration['id']) mock_get.assert_called_once_with(self.context, uuids.instance, None) - @mock.patch("nova.db.api.migration_get_by_id_and_instance") + @mock.patch("nova.db.main.api.migration_get_by_id_and_instance") def test_get_migration_by_id_and_instance(self, mock_get): migration = test_migration.fake_db_migration( instance_uuid=uuids.instance) diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 3a8fa207db..6c6345d849 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -46,7 +46,7 @@ from nova.compute import vm_states from nova.conductor import api as conductor_api 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.network import model as network_model from nova.network import neutron as neutronv2_api @@ -2819,8 +2819,8 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase, @mock.patch('nova.compute.utils.notify_about_volume_swap') @mock.patch( - 'nova.db.api.block_device_mapping_get_by_instance_and_volume_id') - @mock.patch('nova.db.api.block_device_mapping_update') + 'nova.db.main.api.block_device_mapping_get_by_instance_and_volume_id') + @mock.patch('nova.db.main.api.block_device_mapping_update') @mock.patch('nova.volume.cinder.API.get') @mock.patch('nova.virt.libvirt.LibvirtDriver.get_volume_connector') @mock.patch('nova.compute.manager.ComputeManager._swap_volume') diff --git a/nova/tests/unit/compute/test_host_api.py b/nova/tests/unit/compute/test_host_api.py index 96b41dab1c..e4c310deb0 100644 --- a/nova/tests/unit/compute/test_host_api.py +++ b/nova/tests/unit/compute/test_host_api.py @@ -102,7 +102,7 @@ class ComputeHostAPITestCase(test.TestCase): _do_test() - @mock.patch('nova.db.api.service_get_by_compute_host') + @mock.patch('nova.db.main.api.service_get_by_compute_host') def test_get_host_uptime_service_down( self, mock_get_service_get_by_compute_host, ): @@ -229,7 +229,7 @@ class ComputeHostAPITestCase(test.TestCase): None, set_zones=False) mock_get_hm.assert_called_once_with(self.ctxt, cells[1].id) - @mock.patch('nova.db.api.service_get_all') + @mock.patch('nova.db.main.api.service_get_all') def test_service_get_all_no_zones(self, mock_service_get_all): services = [dict(test_service.fake_service, id=1, topic='compute', host='host1'), @@ -258,7 +258,7 @@ class ComputeHostAPITestCase(test.TestCase): disabled=None) self._compare_objs(result, [services[1]]) - @mock.patch('nova.db.api.service_get_all') + @mock.patch('nova.db.main.api.service_get_all') def test_service_get_all(self, mock_service_get_all): services = [dict(test_service.fake_service, topic='compute', host='host1'), @@ -305,7 +305,7 @@ class ComputeHostAPITestCase(test.TestCase): self._compare_objs(result, exp_services) @mock.patch( - 'nova.db.api.service_get_by_compute_host', + 'nova.db.main.api.service_get_by_compute_host', return_value=test_service.fake_service) def test_service_get_by_compute_host( self, mock_service_get_by_compute_host, @@ -314,8 +314,8 @@ class ComputeHostAPITestCase(test.TestCase): self.ctxt, 'fake-host') self.assertEqual(test_service.fake_service['id'], result.id) - @mock.patch('nova.db.api.service_get_by_host_and_binary') - @mock.patch('nova.db.api.service_update') + @mock.patch('nova.db.main.api.service_get_by_host_and_binary') + @mock.patch('nova.db.main.api.service_update') def test_service_update_by_host_and_binary( self, mock_service_update, mock_service_get_by_host_and_binary, ): @@ -397,7 +397,8 @@ class ComputeHostAPITestCase(test.TestCase): 'fake-host') self.assertEqual(['fake-responses'], result) - @mock.patch('nova.db.api.task_log_get_all', return_value='fake-response') + @mock.patch( + 'nova.db.main.api.task_log_get_all', return_value='fake-response') def test_task_log_get_all(self, mock_task_log_get_all): result = self.host_api.task_log_get_all(self.ctxt, 'fake-name', 'fake-begin', 'fake-end', @@ -487,7 +488,7 @@ class ComputeHostAPITestCase(test.TestCase): mock_remove_host.assert_called_once_with( mock.ANY, aggregate.uuid, 'fake-compute-host') - @mock.patch('nova.db.api.compute_node_statistics') + @mock.patch('nova.db.main.api.compute_node_statistics') def test_compute_node_statistics(self, mock_cns): # Note this should only be called twice mock_cns.side_effect = [ diff --git a/nova/tests/unit/compute/test_instance_list.py b/nova/tests/unit/compute/test_instance_list.py index 4ee1190479..e6e195e9cc 100644 --- a/nova/tests/unit/compute/test_instance_list.py +++ b/nova/tests/unit/compute/test_instance_list.py @@ -61,7 +61,7 @@ class TestInstanceList(test.NoDBTestCase): self.assertEqual(['created_at', 'id', 'uuid'], ctx.sort_keys) self.assertEqual(['desc', 'desc', 'asc'], ctx.sort_dirs) - @mock.patch('nova.db.api.instance_get_all_by_filters_sort') + @mock.patch('nova.db.main.api.instance_get_all_by_filters_sort') @mock.patch('nova.objects.CellMappingList.get_all') def test_get_instances_sorted(self, mock_cells, mock_inst): mock_cells.return_value = self.cells @@ -341,7 +341,7 @@ class TestInstanceListBig(test.NoDBTestCase): self.context = nova_context.RequestContext() self.useFixture(fixtures.SpawnIsSynchronousFixture()) - @mock.patch('nova.db.api.instance_get_all_by_filters_sort') + @mock.patch('nova.db.main.api.instance_get_all_by_filters_sort') @mock.patch('nova.objects.CellMappingList.get_all') def test_get_instances_batched(self, mock_cells, mock_inst): mock_cells.return_value = self.cells diff --git a/nova/tests/unit/compute/test_keypairs.py b/nova/tests/unit/compute/test_keypairs.py index d0b204a970..c946641a3f 100644 --- a/nova/tests/unit/compute/test_keypairs.py +++ b/nova/tests/unit/compute/test_keypairs.py @@ -74,11 +74,11 @@ class KeypairAPITestCase(test_compute.BaseTestCase): else: raise exception.KeypairNotFound(user_id=user_id, name=name) - self.stub_out("nova.db.api.key_pair_get_all_by_user", + self.stub_out("nova.db.main.api.key_pair_get_all_by_user", db_key_pair_get_all_by_user) - self.stub_out("nova.db.api.key_pair_create", db_key_pair_create) - self.stub_out("nova.db.api.key_pair_destroy", db_key_pair_destroy) - self.stub_out("nova.db.api.key_pair_get", db_key_pair_get) + self.stub_out("nova.db.main.api.key_pair_create", db_key_pair_create) + self.stub_out("nova.db.main.api.key_pair_destroy", db_key_pair_destroy) + self.stub_out("nova.db.main.api.key_pair_get", db_key_pair_get) def _check_notifications(self, action='create', key_name='foo'): self.assertEqual(2, len(self.notifier.notifications)) @@ -141,7 +141,7 @@ class CreateImportSharedTestMixIn(object): def db_key_pair_create_duplicate(context, keypair): raise exception.KeyPairExists(key_name=keypair.get('name', '')) - self.stub_out("nova.db.api.key_pair_create", + self.stub_out("nova.db.main.api.key_pair_create", db_key_pair_create_duplicate) msg = ("Key pair '%(key_name)s' already exists." % diff --git a/nova/tests/unit/compute/test_shelve.py b/nova/tests/unit/compute/test_shelve.py index ee79ed256c..12bf23bda2 100644 --- a/nova/tests/unit/compute/test_shelve.py +++ b/nova/tests/unit/compute/test_shelve.py @@ -24,7 +24,7 @@ from nova.compute import task_states from nova.compute import utils as compute_utils from nova.compute import vm_states import nova.conf -from nova.db import api as db +from nova.db.main import api as db from nova import exception from nova.network import neutron as neutron_api from nova import objects diff --git a/nova/tests/unit/conductor/tasks/test_cross_cell_migrate.py b/nova/tests/unit/conductor/tasks/test_cross_cell_migrate.py index 938bbf1c15..127d763477 100644 --- a/nova/tests/unit/conductor/tasks/test_cross_cell_migrate.py +++ b/nova/tests/unit/conductor/tasks/test_cross_cell_migrate.py @@ -31,7 +31,7 @@ from nova.objects import base as obj_base from nova.objects import fields from nova.objects import instance as instance_obj from nova import test -from nova.tests.unit.db import test_db_api +from nova.tests.unit.db.main import test_api as test_db_api from nova.tests.unit import fake_block_device from nova.tests.unit import fake_instance from nova.tests.unit.objects import test_compute_node diff --git a/nova/tests/unit/conductor/test_conductor.py b/nova/tests/unit/conductor/test_conductor.py index 7366ea7ec1..fc0fd860ec 100644 --- a/nova/tests/unit/conductor/test_conductor.py +++ b/nova/tests/unit/conductor/test_conductor.py @@ -39,8 +39,7 @@ from nova.conductor.tasks import live_migrate from nova.conductor.tasks import migrate from nova import conf from nova import context -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 as exc from nova.image import glance as image_api @@ -2741,7 +2740,7 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase): self.assertEqual(0, len(build_requests)) - @db_api.api_context_manager.reader + @db.api_context_manager.reader def request_spec_get_all(context): return context.session.query(api_models.RequestSpec).all() diff --git a/nova/tests/unit/db/main/__init__.py b/nova/tests/unit/db/main/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/main/test_api.py similarity index 97% rename from nova/tests/unit/db/test_db_api.py rename to nova/tests/unit/db/main/test_api.py index 8683d4a239..7254f9262b 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/main/test_api.py @@ -49,9 +49,8 @@ from nova.compute import task_states from nova.compute import vm_states import nova.conf from nova import context -from nova.db import api as db -from nova.db.sqlalchemy import api as sqlalchemy_api -from nova.db.sqlalchemy import models +from nova.db.main import api as db +from nova.db.main import models from nova.db import types as col_types from nova import exception from nova.objects import fields @@ -63,8 +62,6 @@ from nova import utils CONF = nova.conf.CONF -get_engine = sqlalchemy_api.get_engine - def _make_compute_node(host, node, hv_type, service_id): compute_node_dict = dict(vcpus=2, memory_mb=1024, local_gb=2048, @@ -116,13 +113,13 @@ def _quota_create(context, project_id, user_id): user_id=user_id).hard_limit -@sqlalchemy_api.pick_context_manager_reader +@db.pick_context_manager_reader def _assert_instance_id_mapping(_ctxt, tc, inst_uuid, expected_existing=False): # NOTE(mriedem): We can't use ec2_instance_get_by_uuid to assert # the instance_id_mappings record is gone because it hard-codes # read_deleted='yes' and will read the soft-deleted record. So we # do the model_query directly here. See bug 1061166. - inst_id_mapping = sqlalchemy_api.model_query( + inst_id_mapping = db.model_query( _ctxt, models.InstanceIdMapping).filter_by(uuid=inst_uuid).first() if not expected_existing: tc.assertFalse(inst_id_mapping, @@ -171,7 +168,7 @@ class DbTestCase(test.TestCase): class HelperTestCase(test.TestCase): @mock.patch('sqlalchemy.orm.joinedload') def test_joinedload_helper(self, mock_jl): - query = sqlalchemy_api._joinedload_all('foo.bar.baz') + query = db._joinedload_all('foo.bar.baz') # We call sqlalchemy.orm.joinedload() on the first element mock_jl.assert_called_once_with('foo') @@ -188,7 +185,7 @@ class HelperTestCase(test.TestCase): @mock.patch('sqlalchemy.orm.joinedload') def test_joinedload_helper_single(self, mock_jl): - query = sqlalchemy_api._joinedload_all('foo') + query = db._joinedload_all('foo') # We call sqlalchemy.orm.joinedload() on the first element mock_jl.assert_called_once_with('foo') @@ -210,7 +207,7 @@ class DecoratorTestCase(test.TestCase): self.assertEqual(test_func.__module__, decorated_func.__module__) def test_require_context_decorator_wraps_functions_properly(self): - self._test_decorator_wraps_helper(sqlalchemy_api.require_context) + self._test_decorator_wraps_helper(db.require_context) def test_require_deadlock_retry_wraps_functions_properly(self): self._test_decorator_wraps_helper( @@ -268,6 +265,54 @@ class DecoratorTestCase(test.TestCase): mock_clone.assert_called_once_with(mode=enginefacade._READER) mock_using.assert_called_once_with(ctxt) + @mock.patch.object(db, 'LOG') + @mock.patch.object(db, 'DISABLE_DB_ACCESS', return_value=True) + def _test_pick_context_manager_disable_db_access( + self, func, mock_DISABLE_DB_ACCESS, mock_log, + ): + ctxt = context.get_admin_context() + value = 'some_value' + + with mock_DISABLE_DB_ACCESS: + self.assertRaises(exception.DBNotAllowed, func, ctxt, value) + + self.assertIn( + 'No DB access allowed in ', + mock_log.error.call_args[0][0]) + + @mock.patch.object(db, 'LOG') + @mock.patch.object(db, 'DISABLE_DB_ACCESS', return_value=True) + def test_pick_context_manager_writer_disable_db_access( + self, mock_DISABLE_DB_ACCESS, mock_log, + ): + @db.pick_context_manager_writer + def func(context, value): + pass + + self._test_pick_context_manager_disable_db_access(func) + + @mock.patch.object(db, 'LOG') + @mock.patch.object(db, 'DISABLE_DB_ACCESS', return_value=True) + def test_pick_context_manager_reader_disable_db_access( + self, mock_DISABLE_DB_ACCESS, mock_log, + ): + @db.pick_context_manager_reader + def func(context, value): + pass + + self._test_pick_context_manager_disable_db_access(func) + + @mock.patch.object(db, 'LOG') + @mock.patch.object(db, 'DISABLE_DB_ACCESS', return_value=True) + def test_pick_context_manager_reader_allow_async_disable_db_access( + self, mock_DISABLE_DB_ACCESS, mock_log, + ): + @db.pick_context_manager_reader_allow_async + def func(context, value): + pass + + self._test_pick_context_manager_disable_db_access(func) + def _get_fake_aggr_values(): return {'name': 'fake_aggregate'} @@ -300,7 +345,7 @@ def _create_aggregate_with_hosts(context=context.get_admin_context(), return result -@mock.patch.object(sqlalchemy_api, '_get_regexp_ops', +@mock.patch.object(db, '_get_regexp_ops', return_value=(lambda x: x, 'LIKE')) class UnsupportedDbRegexpTestCase(DbTestCase): @@ -565,28 +610,28 @@ class UnsupportedDbRegexpTestCase(DbTestCase): class ModelQueryTestCase(DbTestCase): def test_model_query_invalid_arguments(self): - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test(context): # read_deleted shouldn't accept invalid values - self.assertRaises(ValueError, sqlalchemy_api.model_query, + self.assertRaises(ValueError, db.model_query, context, models.Instance, read_deleted=False) - self.assertRaises(ValueError, sqlalchemy_api.model_query, + self.assertRaises(ValueError, db.model_query, context, models.Instance, read_deleted="foo") # Check model is a valid model - self.assertRaises(TypeError, sqlalchemy_api.model_query, + self.assertRaises(TypeError, db.model_query, context, "") test(self.context) @mock.patch.object(sqlalchemyutils, 'model_query') def test_model_query_use_context_session(self, mock_model_query): - @sqlalchemy_api.main_context_manager.reader + @db.main_context_manager.reader def fake_method(context): session = context.session - sqlalchemy_api.model_query(context, models.Instance) + db.model_query(context, models.Instance) return session session = fake_method(self.context) @@ -597,18 +642,18 @@ class ModelQueryTestCase(DbTestCase): class EngineFacadeTestCase(DbTestCase): def test_use_single_context_session_writer(self): # Checks that session in context would not be overwritten by - # annotation @sqlalchemy_api.main_context_manager.writer if annotation + # annotation @db.main_context_manager.writer if annotation # is used twice. - @sqlalchemy_api.main_context_manager.writer + @db.main_context_manager.writer def fake_parent_method(context): session = context.session return fake_child_method(context), session - @sqlalchemy_api.main_context_manager.writer + @db.main_context_manager.writer def fake_child_method(context): session = context.session - sqlalchemy_api.model_query(context, models.Instance) + db.model_query(context, models.Instance) return session parent_session, child_session = fake_parent_method(self.context) @@ -616,18 +661,18 @@ class EngineFacadeTestCase(DbTestCase): def test_use_single_context_session_reader(self): # Checks that session in context would not be overwritten by - # annotation @sqlalchemy_api.main_context_manager.reader if annotation + # annotation @db.main_context_manager.reader if annotation # is used twice. - @sqlalchemy_api.main_context_manager.reader + @db.main_context_manager.reader def fake_parent_method(context): session = context.session return fake_child_method(context), session - @sqlalchemy_api.main_context_manager.reader + @db.main_context_manager.reader def fake_child_method(context): session = context.session - sqlalchemy_api.model_query(context, models.Instance) + db.model_query(context, models.Instance) return session parent_session, child_session = fake_parent_method(self.context) @@ -641,7 +686,7 @@ class SqlAlchemyDbApiNoDbTestCase(test.NoDBTestCase): # Tests that _manual_join_columns doesn't modify the list passed in. columns_to_join = ['system_metadata', 'test'] manual_joins, columns_to_join2 = ( - sqlalchemy_api._manual_join_columns(columns_to_join)) + db._manual_join_columns(columns_to_join)) self.assertEqual(['system_metadata'], manual_joins) self.assertEqual(['test'], columns_to_join2) self.assertEqual(['system_metadata', 'test'], columns_to_join) @@ -659,17 +704,17 @@ class SqlAlchemyDbApiNoDbTestCase(test.NoDBTestCase): test1 = {'created_at': t1, 'deleted_at': t2, 'updated_at': t3} expected_dict = {'created_at': t1, 'deleted_at': t2, 'updated_at': t3} - sqlalchemy_api.convert_objects_related_datetimes(test1, *datetime_keys) + db.convert_objects_related_datetimes(test1, *datetime_keys) self.assertEqual(test1, expected_dict) test2 = {'created_at': t1, 'deleted_at': t2_utc, 'updated_at': t3} expected_dict = {'created_at': t1, 'deleted_at': t2, 'updated_at': t3} - sqlalchemy_api.convert_objects_related_datetimes(test2, *datetime_keys) + db.convert_objects_related_datetimes(test2, *datetime_keys) self.assertEqual(test2, expected_dict) test3 = {'deleted_at': t2_utc, 'updated_at': t3_utc} expected_dict = {'deleted_at': t2, 'updated_at': t3_utc} - sqlalchemy_api.convert_objects_related_datetimes(test3, *datetime_keys) + db.convert_objects_related_datetimes(test3, *datetime_keys) self.assertEqual(test3, expected_dict) def test_convert_objects_related_datetimes_with_strings(self): @@ -684,81 +729,81 @@ class SqlAlchemyDbApiNoDbTestCase(test.NoDBTestCase): 'deleted_at': timeutils.parse_isotime(t2).replace(tzinfo=None), 'updated_at': timeutils.parse_isotime(t3).replace(tzinfo=None)} - sqlalchemy_api.convert_objects_related_datetimes(test1) + db.convert_objects_related_datetimes(test1) self.assertEqual(test1, expected_dict) - sqlalchemy_api.convert_objects_related_datetimes(test1, *datetime_keys) + db.convert_objects_related_datetimes(test1, *datetime_keys) self.assertEqual(test1, expected_dict) def test_get_regexp_op_for_database_sqlite(self): - filter, op = sqlalchemy_api._get_regexp_ops('sqlite:///') + filter, op = db._get_regexp_ops('sqlite:///') self.assertEqual('|', filter('|')) self.assertEqual('REGEXP', op) def test_get_regexp_op_for_database_mysql(self): - filter, op = sqlalchemy_api._get_regexp_ops( + filter, op = db._get_regexp_ops( 'mysql+pymysql://root@localhost') self.assertEqual('\\|', filter('|')) self.assertEqual('REGEXP', op) def test_get_regexp_op_for_database_postgresql(self): - filter, op = sqlalchemy_api._get_regexp_ops( + filter, op = db._get_regexp_ops( 'postgresql://localhost') self.assertEqual('|', filter('|')) self.assertEqual('~', op) def test_get_regexp_op_for_database_unknown(self): - filter, op = sqlalchemy_api._get_regexp_ops('notdb:///') + filter, op = db._get_regexp_ops('notdb:///') self.assertEqual('|', filter('|')) self.assertEqual('LIKE', op) - @mock.patch.object(sqlalchemy_api, 'main_context_manager') + @mock.patch.object(db, 'main_context_manager') def test_get_engine(self, mock_ctxt_mgr): - sqlalchemy_api.get_engine() + db.get_engine() mock_ctxt_mgr.writer.get_engine.assert_called_once_with() - @mock.patch.object(sqlalchemy_api, 'main_context_manager') + @mock.patch.object(db, 'main_context_manager') def test_get_engine_use_slave(self, mock_ctxt_mgr): - sqlalchemy_api.get_engine(use_slave=True) + db.get_engine(use_slave=True) mock_ctxt_mgr.reader.get_engine.assert_called_once_with() def test_get_db_conf_with_connection(self): mock_conf_group = mock.MagicMock() mock_conf_group.connection = 'fakemain://' - db_conf = sqlalchemy_api._get_db_conf(mock_conf_group, + db_conf = db._get_db_conf(mock_conf_group, connection='fake://') self.assertEqual('fake://', db_conf['connection']) - @mock.patch.object(sqlalchemy_api, 'api_context_manager') + @mock.patch.object(db, 'api_context_manager') def test_get_api_engine(self, mock_ctxt_mgr): - sqlalchemy_api.get_api_engine() + db.get_api_engine() mock_ctxt_mgr.writer.get_engine.assert_called_once_with() - @mock.patch.object(sqlalchemy_api, '_instance_get_by_uuid') - @mock.patch.object(sqlalchemy_api, '_instances_fill_metadata') + @mock.patch.object(db, '_instance_get_by_uuid') + @mock.patch.object(db, '_instances_fill_metadata') @mock.patch('oslo_db.sqlalchemy.utils.paginate_query') def test_instance_get_all_by_filters_paginated_allows_deleted_marker( self, mock_paginate, mock_fill, mock_get): ctxt = mock.MagicMock() ctxt.elevated.return_value = mock.sentinel.elevated - sqlalchemy_api.instance_get_all_by_filters_sort(ctxt, {}, marker='foo') + db.instance_get_all_by_filters_sort(ctxt, {}, marker='foo') mock_get.assert_called_once_with(mock.sentinel.elevated, 'foo') ctxt.elevated.assert_called_once_with(read_deleted='yes') def test_replace_sub_expression(self): - ret = sqlalchemy_api._safe_regex_mysql('|') + ret = db._safe_regex_mysql('|') self.assertEqual('\\|', ret) - ret = sqlalchemy_api._safe_regex_mysql('||') + ret = db._safe_regex_mysql('||') self.assertEqual('\\|\\|', ret) - ret = sqlalchemy_api._safe_regex_mysql('a||') + ret = db._safe_regex_mysql('a||') self.assertEqual('a\\|\\|', ret) - ret = sqlalchemy_api._safe_regex_mysql('|a|') + ret = db._safe_regex_mysql('|a|') self.assertEqual('\\|a\\|', ret) - ret = sqlalchemy_api._safe_regex_mysql('||a') + ret = db._safe_regex_mysql('||a') self.assertEqual('\\|\\|a', ret) @@ -770,9 +815,9 @@ class SqlAlchemyDbApiTestCase(DbTestCase): self.create_instance_with_args() self.create_instance_with_args(host='host2') - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test(context): - return sqlalchemy_api.instance_get_all_by_host( + return db.instance_get_all_by_host( context, 'host1') result = test(ctxt) @@ -789,9 +834,9 @@ class SqlAlchemyDbApiTestCase(DbTestCase): """ self.create_instance_with_args() - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test(ctxt): - return sqlalchemy_api.instance_get_all_by_host( + return db.instance_get_all_by_host( ctxt, 'host1', columns_to_join=[]) result = test(context.get_admin_context()) @@ -807,14 +852,13 @@ class SqlAlchemyDbApiTestCase(DbTestCase): self.create_instance_with_args() self.create_instance_with_args(host='host2') - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test1(context): - return sqlalchemy_api._instance_get_all_uuids_by_hosts( - context, ['host1']) + return db._instance_get_all_uuids_by_hosts(context, ['host1']) - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test2(context): - return sqlalchemy_api._instance_get_all_uuids_by_hosts( + return db._instance_get_all_uuids_by_hosts( context, ['host1', 'host2']) result = test1(ctxt) @@ -841,19 +885,19 @@ class SqlAlchemyDbApiTestCase(DbTestCase): self.create_instance_with_args(project_id='project-AAA') # no limit or marker - result = sqlalchemy_api.instance_get_active_by_window_joined( + result = db.instance_get_active_by_window_joined( ctxt, begin=now, columns_to_join=[]) actual_uuids = [row['uuid'] for row in result] self.assertEqual(['CCC', 'AAA', 'BBB', 'ZZZ'], actual_uuids) # just limit - result = sqlalchemy_api.instance_get_active_by_window_joined( + result = db.instance_get_active_by_window_joined( ctxt, begin=now, columns_to_join=[], limit=2) actual_uuids = [row['uuid'] for row in result] self.assertEqual(['CCC', 'AAA'], actual_uuids) # limit & marker - result = sqlalchemy_api.instance_get_active_by_window_joined( + result = db.instance_get_active_by_window_joined( ctxt, begin=now, columns_to_join=[], limit=2, marker='CCC') actual_uuids = [row['uuid'] for row in result] self.assertEqual(['AAA', 'BBB'], actual_uuids) @@ -861,7 +905,7 @@ class SqlAlchemyDbApiTestCase(DbTestCase): # unknown marker self.assertRaises( exception.MarkerNotFound, - sqlalchemy_api.instance_get_active_by_window_joined, + db.instance_get_active_by_window_joined, ctxt, begin=now, columns_to_join=[], limit=2, marker='unknown') def test_instance_get_active_by_window_joined(self): @@ -886,7 +930,7 @@ class SqlAlchemyDbApiTestCase(DbTestCase): self.create_instance_with_args(launched_at=now3, terminated_at=None, **sample_data) - result = sqlalchemy_api.instance_get_active_by_window_joined( + result = db.instance_get_active_by_window_joined( ctxt, begin=now) self.assertEqual(4, len(result)) # verify that all default columns are joined @@ -896,7 +940,7 @@ class SqlAlchemyDbApiTestCase(DbTestCase): self.assertEqual(sample_data['system_metadata'], sys_meta) self.assertIn('info_cache', result[0]) - result = sqlalchemy_api.instance_get_active_by_window_joined( + result = db.instance_get_active_by_window_joined( ctxt, begin=now3, columns_to_join=['info_cache']) self.assertEqual(2, len(result)) # verify that only info_cache is loaded @@ -904,11 +948,11 @@ class SqlAlchemyDbApiTestCase(DbTestCase): self.assertEqual({}, meta) self.assertIn('info_cache', result[0]) - result = sqlalchemy_api.instance_get_active_by_window_joined( + result = db.instance_get_active_by_window_joined( ctxt, begin=start_time, end=now) self.assertEqual(0, len(result)) - result = sqlalchemy_api.instance_get_active_by_window_joined( + result = db.instance_get_active_by_window_joined( ctxt, begin=start_time, end=now2, columns_to_join=['system_metadata']) self.assertEqual(2, len(result)) @@ -919,7 +963,7 @@ class SqlAlchemyDbApiTestCase(DbTestCase): self.assertEqual(sample_data['system_metadata'], sys_meta) self.assertNotIn('info_cache', result[0]) - result = sqlalchemy_api.instance_get_active_by_window_joined( + result = db.instance_get_active_by_window_joined( ctxt, begin=now2, end=now3, columns_to_join=['metadata', 'info_cache']) self.assertEqual(2, len(result)) @@ -931,14 +975,15 @@ class SqlAlchemyDbApiTestCase(DbTestCase): self.assertIn('info_cache', result[0]) self.assertEqual(network_info, result[0]['info_cache']['network_info']) - @mock.patch('nova.db.sqlalchemy.api.instance_get_all_by_filters_sort') + @mock.patch('nova.db.main.api.instance_get_all_by_filters_sort') def test_instance_get_all_by_filters_calls_sort(self, mock_get_all_filters_sort): '''Verifies instance_get_all_by_filters calls the sort function.''' # sort parameters should be wrapped in a list, all other parameters # should be passed through ctxt = context.get_admin_context() - sqlalchemy_api.instance_get_all_by_filters(ctxt, {'foo': 'bar'}, + db.instance_get_all_by_filters( + ctxt, {'foo': 'bar'}, 'sort_key', 'sort_dir', limit=100, marker='uuid', columns_to_join='columns') mock_get_all_filters_sort.assert_called_once_with(ctxt, {'foo': 'bar'}, @@ -959,11 +1004,11 @@ class SqlAlchemyDbApiTestCase(DbTestCase): # Create a hidden instance record. self.create_instance_with_args(hidden=True) # Get instances which by default will filter out the hidden instance. - instances = sqlalchemy_api.instance_get_all_by_filters_sort( + instances = db.instance_get_all_by_filters_sort( self.context, filters={}, limit=10) self.assertEqual(0, len(instances)) # Now explicitly filter for hidden instances. - instances = sqlalchemy_api.instance_get_all_by_filters_sort( + instances = db.instance_get_all_by_filters_sort( self.context, filters={'hidden': True}, limit=10) self.assertEqual(1, len(instances)) @@ -972,44 +1017,44 @@ class ProcessSortParamTestCase(test.TestCase): def test_process_sort_params_defaults(self): '''Verifies default sort parameters.''' - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params([], []) + sort_keys, sort_dirs = db.process_sort_params([], []) self.assertEqual(['created_at', 'id'], sort_keys) self.assertEqual(['asc', 'asc'], sort_dirs) - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params(None, None) + sort_keys, sort_dirs = db.process_sort_params(None, None) self.assertEqual(['created_at', 'id'], sort_keys) self.assertEqual(['asc', 'asc'], sort_dirs) def test_process_sort_params_override_default_keys(self): '''Verifies that the default keys can be overridden.''' - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( [], [], default_keys=['key1', 'key2', 'key3']) self.assertEqual(['key1', 'key2', 'key3'], sort_keys) self.assertEqual(['asc', 'asc', 'asc'], sort_dirs) def test_process_sort_params_override_default_dir(self): '''Verifies that the default direction can be overridden.''' - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( [], [], default_dir='dir1') self.assertEqual(['created_at', 'id'], sort_keys) self.assertEqual(['dir1', 'dir1'], sort_dirs) def test_process_sort_params_override_default_key_and_dir(self): '''Verifies that the default key and dir can be overridden.''' - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( [], [], default_keys=['key1', 'key2', 'key3'], default_dir='dir1') self.assertEqual(['key1', 'key2', 'key3'], sort_keys) self.assertEqual(['dir1', 'dir1', 'dir1'], sort_dirs) - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( [], [], default_keys=[], default_dir='dir1') self.assertEqual([], sort_keys) self.assertEqual([], sort_dirs) def test_process_sort_params_non_default(self): '''Verifies that non-default keys are added correctly.''' - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( ['key1', 'key2'], ['asc', 'desc']) self.assertEqual(['key1', 'key2', 'created_at', 'id'], sort_keys) # First sort_dir in list is used when adding the default keys @@ -1017,13 +1062,13 @@ class ProcessSortParamTestCase(test.TestCase): def test_process_sort_params_default(self): '''Verifies that default keys are added correctly.''' - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( ['id', 'key2'], ['asc', 'desc']) self.assertEqual(['id', 'key2', 'created_at'], sort_keys) self.assertEqual(['asc', 'desc', 'asc'], sort_dirs) # Include default key value, rely on default direction - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( ['id', 'key2'], []) self.assertEqual(['id', 'key2', 'created_at'], sort_keys) self.assertEqual(['asc', 'asc', 'asc'], sort_dirs) @@ -1031,31 +1076,31 @@ class ProcessSortParamTestCase(test.TestCase): def test_process_sort_params_default_dir(self): '''Verifies that the default dir is applied to all keys.''' # Direction is set, ignore default dir - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( ['id', 'key2'], ['desc'], default_dir='dir') self.assertEqual(['id', 'key2', 'created_at'], sort_keys) self.assertEqual(['desc', 'desc', 'desc'], sort_dirs) # But should be used if no direction is set - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( ['id', 'key2'], [], default_dir='dir') self.assertEqual(['id', 'key2', 'created_at'], sort_keys) self.assertEqual(['dir', 'dir', 'dir'], sort_dirs) def test_process_sort_params_unequal_length(self): '''Verifies that a sort direction list is applied correctly.''' - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( ['id', 'key2', 'key3'], ['desc']) self.assertEqual(['id', 'key2', 'key3', 'created_at'], sort_keys) self.assertEqual(['desc', 'desc', 'desc', 'desc'], sort_dirs) # Default direction is the first key in the list - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( ['id', 'key2', 'key3'], ['desc', 'asc']) self.assertEqual(['id', 'key2', 'key3', 'created_at'], sort_keys) self.assertEqual(['desc', 'asc', 'desc', 'desc'], sort_dirs) - sort_keys, sort_dirs = sqlalchemy_api.process_sort_params( + sort_keys, sort_dirs = db.process_sort_params( ['id', 'key2', 'key3'], ['desc', 'asc', 'asc']) self.assertEqual(['id', 'key2', 'key3', 'created_at'], sort_keys) self.assertEqual(['desc', 'asc', 'asc', 'desc'], sort_dirs) @@ -1063,7 +1108,7 @@ class ProcessSortParamTestCase(test.TestCase): def test_process_sort_params_extra_dirs_lengths(self): '''InvalidInput raised if more directions are given.''' self.assertRaises(exception.InvalidInput, - sqlalchemy_api.process_sort_params, + db.process_sort_params, ['key1', 'key2'], ['asc', 'desc', 'desc']) @@ -1071,7 +1116,7 @@ class ProcessSortParamTestCase(test.TestCase): '''InvalidInput raised if invalid directions are given.''' for dirs in [['foo'], ['asc', 'foo'], ['asc', 'desc', 'foo']]: self.assertRaises(exception.InvalidInput, - sqlalchemy_api.process_sort_params, + db.process_sort_params, ['key'], dirs) @@ -1179,16 +1224,15 @@ class MigrationTestCase(test.TestCase): def test_migration_get_by_uuid_soft_deleted_and_deleted(self): migration1 = self._create(uuid=uuidsentinel.migration1_uuid) - @sqlalchemy_api.pick_context_manager_writer + @db.pick_context_manager_writer def soft_delete_it(context): - sqlalchemy_api.model_query(context, models.Migration).\ + db.model_query(context, models.Migration).\ filter_by(uuid=uuidsentinel.migration1_uuid).\ soft_delete() - @sqlalchemy_api.pick_context_manager_writer + @db.pick_context_manager_writer def delete_it(context): - sqlalchemy_api.model_query(context, models.Migration, - read_deleted="yes").\ + db.model_query(context, models.Migration, read_deleted="yes").\ filter_by(uuid=uuidsentinel.migration1_uuid).\ delete() @@ -1623,7 +1667,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): instance = self.create_instance_with_args() self.assertTrue(uuidutils.is_uuid_like(instance['uuid'])) - @mock.patch.object(sqlalchemy_api, 'security_group_ensure_default') + @mock.patch.object(db, 'security_group_ensure_default') def test_instance_create_with_deadlock_retry(self, mock_sg): mock_sg.side_effect = [db_exc.DBDeadlock(), None] instance = self.create_instance_with_args() @@ -1823,10 +1867,9 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): def test_instance_metadata_get_multi(self): uuids = [self.create_instance_with_args()['uuid'] for i in range(3)] - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test(context): - return sqlalchemy_api._instance_metadata_get_multi( - context, uuids) + return db._instance_metadata_get_multi(context, uuids) meta = test(self.ctxt) for row in meta: @@ -1834,17 +1877,16 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): @mock.patch.object(query.Query, 'filter') def test_instance_metadata_get_multi_no_uuids(self, mock_query_filter): - with sqlalchemy_api.main_context_manager.reader.using(self.ctxt): - sqlalchemy_api._instance_metadata_get_multi(self.ctxt, []) + with db.main_context_manager.reader.using(self.ctxt): + db._instance_metadata_get_multi(self.ctxt, []) self.assertFalse(mock_query_filter.called) def test_instance_system_system_metadata_get_multi(self): uuids = [self.create_instance_with_args()['uuid'] for i in range(3)] - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test(context): - return sqlalchemy_api._instance_system_metadata_get_multi( - context, uuids) + return db._instance_system_metadata_get_multi(context, uuids) sys_meta = test(self.ctxt) for row in sys_meta: @@ -1853,7 +1895,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): @mock.patch.object(query.Query, 'filter') def test_instance_system_metadata_get_multi_no_uuids(self, mock_query_filter): - sqlalchemy_api._instance_system_metadata_get_multi(self.ctxt, []) + db._instance_system_metadata_get_multi(self.ctxt, []) self.assertFalse(mock_query_filter.called) def test_instance_get_all_by_filters_regex(self): @@ -2118,8 +2160,8 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): self.assertEqual('bar', result[0]['system_metadata'][0]['value']) self.assertEqual(instance['uuid'], result[0]['extra']['instance_uuid']) - @mock.patch('nova.db.sqlalchemy.api._instances_fill_metadata') - @mock.patch('nova.db.sqlalchemy.api._instance_get_all_query') + @mock.patch('nova.db.main.api._instances_fill_metadata') + @mock.patch('nova.db.main.api._instance_get_all_query') def test_instance_get_all_by_host_and_node_fills_manually(self, mock_getall, mock_fill): @@ -2306,7 +2348,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): self.assertEqual(meta, {'mk1': 'mv3'}) def test_instance_update_and_get_original_no_conflict_on_session(self): - @sqlalchemy_api.pick_context_manager_writer + @db.pick_context_manager_writer def test(context): instance = self.create_instance_with_args() (old_ref, new_ref) = db.instance_update_and_get_original( @@ -2365,15 +2407,18 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): # we ensure that the first time we fetch the instance object we get # out-of-date data. This forces us to retry the operation to find out # what really went wrong. - with mock.patch.object(sqlalchemy_api, '_instance_get_by_uuid', - side_effect=[instance_out_of_date, instance]), \ - mock.patch.object(sqlalchemy_api, '_instance_update', - side_effect=sqlalchemy_api._instance_update): + with mock.patch.object( + db, '_instance_get_by_uuid', + side_effect=[instance_out_of_date, instance] + ), mock.patch.object( + db, '_instance_update', + side_effect=db._instance_update + ): self.assertRaises(exception.UnexpectedTaskStateError, db.instance_update_and_get_original, self.ctxt, instance['uuid'], {'expected_task_state': [None]}) - sqlalchemy_api._instance_update.assert_has_calls([ + db._instance_update.assert_has_calls([ mock.call(self.ctxt, instance['uuid'], {'expected_task_state': [None]}, None, original=instance_out_of_date), @@ -2617,7 +2662,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): self.assertIsInstance(instance['access_ip_v4'], str) self.assertIsInstance(instance['access_ip_v6'], str) - @mock.patch('nova.db.sqlalchemy.api._check_instance_exists_in_project', + @mock.patch('nova.db.main.api._check_instance_exists_in_project', return_value=None) def test_instance_destroy(self, mock_check_inst_exists): ctxt = context.get_admin_context() @@ -2657,7 +2702,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): # Save the real implementation of _instance_get_by_uuid before we mock # it later. - real_get_i = sqlalchemy_api._instance_get_by_uuid + real_get_i = db._instance_get_by_uuid # We will delete the instance record before we begin and mock # _instance_get_by_uuid to simulate the instance still existing at the @@ -2677,8 +2722,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): return instance return real_get_i(*a, **kw) - with mock.patch.object(sqlalchemy_api, - '_instance_get_by_uuid') as mock_get_i: + with mock.patch.object(db, '_instance_get_by_uuid') as mock_get_i: fake_get_i.called = False mock_get_i.side_effect = fake_get_i # We expect InstanceNotFound to be raised in the case of the @@ -2800,18 +2844,18 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): def test_check_instance_exists(self): instance = self.create_instance_with_args() - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test(context): - self.assertIsNone(sqlalchemy_api._check_instance_exists_in_project( + self.assertIsNone(db._check_instance_exists_in_project( context, instance['uuid'])) test(self.ctxt) def test_check_instance_exists_non_existing_instance(self): - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test(ctxt): self.assertRaises(exception.InstanceNotFound, - sqlalchemy_api._check_instance_exists_in_project, + db._check_instance_exists_in_project, self.ctxt, '123') test(self.ctxt) @@ -2821,17 +2865,17 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): context2 = context.RequestContext('user2', 'project2') instance = self.create_instance_with_args(context=context1) - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test1(context): - self.assertIsNone(sqlalchemy_api._check_instance_exists_in_project( + self.assertIsNone(db._check_instance_exists_in_project( context, instance['uuid'])) test1(context1) - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test2(context): self.assertRaises(exception.InstanceNotFound, - sqlalchemy_api._check_instance_exists_in_project, + db._check_instance_exists_in_project, context, instance['uuid']) test2(context2) @@ -2840,10 +2884,10 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): some_context = context.RequestContext('some_user', 'some_project') instance = self.create_instance_with_args(context=some_context) - @sqlalchemy_api.pick_context_manager_reader + @db.pick_context_manager_reader def test(context): # Check that method works correctly with admin context - self.assertIsNone(sqlalchemy_api._check_instance_exists_in_project( + self.assertIsNone(db._check_instance_exists_in_project( context, instance['uuid'])) test(self.ctxt) @@ -2914,9 +2958,9 @@ class InstanceExtraTestCase(test.TestCase): self.assertEqual("['res0', 'res1']", inst_extra.resources) def test_instance_extra_update_by_uuid_and_create(self): - @sqlalchemy_api.pick_context_manager_writer + @db.pick_context_manager_writer def test(context): - sqlalchemy_api.model_query(context, models.InstanceExtra).\ + db.model_query(context, models.InstanceExtra).\ filter_by(instance_uuid=self.instance['uuid']).\ delete() @@ -3262,7 +3306,7 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin): self.ctxt, values) def test_migration_migrate_to_uuid(self): - total, done = sqlalchemy_api.migration_migrate_to_uuid(self.ctxt, 10) + total, done = db.migration_migrate_to_uuid(self.ctxt, 10) self.assertEqual(0, total) self.assertEqual(0, done) @@ -3278,7 +3322,7 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin): uuid=uuidsentinel.migration2)) # Now migrate them, we should find one and update one - total, done = sqlalchemy_api.migration_migrate_to_uuid(self.ctxt, 10) + total, done = db.migration_migrate_to_uuid(self.ctxt, 10) self.assertEqual(1, total) self.assertEqual(1, done) @@ -3289,7 +3333,7 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin): self.assertNotIn(None, uuids) # Run the online migration again to see nothing was processed. - total, done = sqlalchemy_api.migration_migrate_to_uuid(self.ctxt, 10) + total, done = db.migration_migrate_to_uuid(self.ctxt, 10) self.assertEqual(0, total) self.assertEqual(0, done) @@ -4330,17 +4374,17 @@ class BlockDeviceMappingTestCase(test.TestCase): def test_scrub_empty_str_values_no_effect(self): values = {'volume_size': 5} expected = copy.copy(values) - sqlalchemy_api._scrub_empty_str_values(values, ['volume_size']) + db._scrub_empty_str_values(values, ['volume_size']) self.assertEqual(values, expected) def test_scrub_empty_str_values_empty_string(self): values = {'volume_size': ''} - sqlalchemy_api._scrub_empty_str_values(values, ['volume_size']) + db._scrub_empty_str_values(values, ['volume_size']) self.assertEqual(values, {}) def test_scrub_empty_str_values_empty_unicode(self): values = {'volume_size': u''} - sqlalchemy_api._scrub_empty_str_values(values, ['volume_size']) + db._scrub_empty_str_values(values, ['volume_size']) self.assertEqual(values, {}) def test_block_device_mapping_create(self): @@ -5780,13 +5824,13 @@ class ComputeNodeTestCase(test.TestCase, ModelsObjectComparatorMixin): db.compute_node_get_model, self.ctxt, item_old['id']) - @mock.patch("nova.db.sqlalchemy.api.compute_node_get_model") + @mock.patch("nova.db.main.api.compute_node_get_model") def test_dbapi_compute_node_get_model(self, mock_get_model): cid = self.item["id"] db.compute_node_get_model(self.ctxt, cid) mock_get_model.assert_called_once_with(self.ctxt, cid) - @mock.patch("nova.db.sqlalchemy.api.model_query") + @mock.patch("nova.db.main.api.model_query") def test_compute_node_get_model(self, mock_model_query): class FakeFiltered(object): @@ -5800,8 +5844,7 @@ class ComputeNodeTestCase(test.TestCase, ModelsObjectComparatorMixin): return fake_filtered_cn mock_model_query.return_value = FakeModelQuery() - result = sqlalchemy_api.compute_node_get_model(self.ctxt, - self.item["id"]) + result = db.compute_node_get_model(self.ctxt, self.item["id"]) self.assertEqual(result, mock.sentinel.first) mock_model_query.assert_called_once_with(self.ctxt, models.ComputeNode) @@ -5895,7 +5938,7 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): def setUp(self): super(ArchiveTestCase, self).setUp() - self.engine = get_engine() + self.engine = db.get_engine() self.metadata = sa.MetaData(self.engine) self.conn = self.engine.connect() self.instance_id_mappings = models.InstanceIdMapping.__table__ @@ -6176,11 +6219,8 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): # Verify we have 0 in shadow self.assertEqual(len(rows), 0) # Archive 2 rows - sqlalchemy_api._archive_deleted_rows_for_table(self.metadata, - tablename, - max_rows=2, - before=None, - task_log=False) + db._archive_deleted_rows_for_table( + self.metadata, tablename, max_rows=2, before=None, task_log=False) # Verify we have 4 left in main rows = self.conn.execute(qmt).fetchall() self.assertEqual(len(rows), 4) @@ -6188,11 +6228,8 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): rows = self.conn.execute(qst).fetchall() self.assertEqual(len(rows), 2) # Archive 2 more rows - sqlalchemy_api._archive_deleted_rows_for_table(self.metadata, - tablename, - max_rows=2, - before=None, - task_log=False) + db._archive_deleted_rows_for_table( + self.metadata, tablename, max_rows=2, before=None, task_log=False) # Verify we have 2 left in main rows = self.conn.execute(qmt).fetchall() self.assertEqual(len(rows), 2) @@ -6200,11 +6237,8 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): rows = self.conn.execute(qst).fetchall() self.assertEqual(len(rows), 4) # Try to archive more, but there are no deleted rows left. - sqlalchemy_api._archive_deleted_rows_for_table(self.metadata, - tablename, - max_rows=2, - before=None, - task_log=False) + db._archive_deleted_rows_for_table( + self.metadata, tablename, max_rows=2, before=None, task_log=False) # Verify we still have 2 left in main rows = self.conn.execute(qmt).fetchall() self.assertEqual(len(rows), 2) @@ -6261,11 +6295,9 @@ class ArchiveTestCase(test.TestCase, ModelsObjectComparatorMixin): self.conn.execute(ins_stmt) # Archiving instances should result in migrations related to the # instances also being archived. - num = sqlalchemy_api._archive_deleted_rows_for_table(self.metadata, - "instances", - max_rows=None, - before=None, - task_log=False) + num = db._archive_deleted_rows_for_table( + self.metadata, "instances", max_rows=None, before=None, + task_log=False) self.assertEqual(1, num[0]) self._assert_shadow_tables_empty_except( 'shadow_instances', @@ -6749,7 +6781,7 @@ class TestDBInstanceTags(test.TestCase): expected = [(uuid, tag3), (uuid, tag4), (uuid, tag2)] self.assertEqual(set(expected), set(tags)) - @mock.patch('nova.db.sqlalchemy.models.Tag.__table__.insert', + @mock.patch('nova.db.main.models.Tag.__table__.insert', return_value=models.Tag.__table__.insert()) def test_instance_tag_set_empty_add(self, mock_insert): uuid = self._create_instance() diff --git a/nova/tests/unit/db/test_migration.py b/nova/tests/unit/db/test_migration.py index 15496a2ee7..f9c4d7e72e 100644 --- a/nova/tests/unit/db/test_migration.py +++ b/nova/tests/unit/db/test_migration.py @@ -17,8 +17,8 @@ from migrate.versioning import api as versioning_api import mock import sqlalchemy +from nova.db.main import api as db_api from nova.db import migration -from nova.db.sqlalchemy import api as db_api from nova import test diff --git a/nova/tests/unit/db/test_migrations.py b/nova/tests/unit/db/test_migrations.py index 5f7f2ef9d6..63f3eee614 100644 --- a/nova/tests/unit/db/test_migrations.py +++ b/nova/tests/unit/db/test_migrations.py @@ -47,8 +47,8 @@ import sqlalchemy.exc import testtools from nova.db.main import legacy_migrations +from nova.db.main import models from nova.db import migration -from nova.db.sqlalchemy import models from nova import test from nova.tests import fixtures as nova_fixtures diff --git a/nova/tests/unit/db/test_models.py b/nova/tests/unit/db/test_models.py index fd85758950..0834ccff3b 100644 --- a/nova/tests/unit/db/test_models.py +++ b/nova/tests/unit/db/test_models.py @@ -13,8 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +from nova.db.main import models from nova.db.sqlalchemy import api_models -from nova.db.sqlalchemy import models from nova import test diff --git a/nova/tests/unit/fake_network.py b/nova/tests/unit/fake_network.py index 63d24f9e6f..eb3f74da06 100644 --- a/nova/tests/unit/fake_network.py +++ b/nova/tests/unit/fake_network.py @@ -17,7 +17,7 @@ from oslo_serialization import jsonutils from oslo_utils.fixture import uuidsentinel as uuids from nova.compute import manager as compute_manager -from nova.db import api as db +from nova.db.main import api as db from nova.network import model as network_model from nova import objects from nova.objects import base as obj_base @@ -38,7 +38,8 @@ def fake_get_instance_nw_info(test, num_networks=1): } return fake_info_cache - test.stub_out('nova.db.api.instance_info_cache_update', update_cache_fake) + test.stub_out( + 'nova.db.main.api.instance_info_cache_update', update_cache_fake) # TODO(stephenfin): This doesn't match the kind of object we would receive # from '_build_vif_model' and callers of same. We should fix that. diff --git a/nova/tests/unit/fake_server_actions.py b/nova/tests/unit/fake_server_actions.py index 8f7299a36a..2eeacab8c3 100644 --- a/nova/tests/unit/fake_server_actions.py +++ b/nova/tests/unit/fake_server_actions.py @@ -124,5 +124,7 @@ def fake_action_event_finish(*args): def stub_out_action_events(test): - test.stub_out('nova.db.api.action_event_start', fake_action_event_start) - test.stub_out('nova.db.api.action_event_finish', fake_action_event_finish) + test.stub_out( + 'nova.db.main.api.action_event_start', fake_action_event_start) + test.stub_out( + 'nova.db.main.api.action_event_finish', fake_action_event_finish) diff --git a/nova/tests/unit/network/test_neutron.py b/nova/tests/unit/network/test_neutron.py index 56983dff81..9ed0a630ba 100644 --- a/nova/tests/unit/network/test_neutron.py +++ b/nova/tests/unit/network/test_neutron.py @@ -33,7 +33,7 @@ from oslo_utils import uuidutils import requests_mock from nova import context -from nova.db.sqlalchemy import api as db_api +from nova.db.main import api as db_api from nova import exception from nova.network import constants from nova.network import model diff --git a/nova/tests/unit/notifications/objects/test_notification.py b/nova/tests/unit/notifications/objects/test_notification.py index a55bbc0b9e..42f41f9635 100644 --- a/nova/tests/unit/notifications/objects/test_notification.py +++ b/nova/tests/unit/notifications/objects/test_notification.py @@ -137,7 +137,7 @@ class TestNotificationBase(test.NoDBTestCase): def setUp(self): super(TestNotificationBase, self).setUp() with mock.patch( - 'nova.db.api.service_update') as mock_db_service_update: + 'nova.db.main.api.service_update') as mock_db_service_update: self.service_obj = objects.Service(context=mock.sentinel.context, id=self.fake_service['id']) self.service_obj.obj_reset_changes(['version']) diff --git a/nova/tests/unit/notifications/objects/test_service.py b/nova/tests/unit/notifications/objects/test_service.py index c681163874..6f0f5c7f7a 100644 --- a/nova/tests/unit/notifications/objects/test_service.py +++ b/nova/tests/unit/notifications/objects/test_service.py @@ -60,7 +60,7 @@ class TestServiceStatusNotification(test.TestCase): mock_notification.return_value.emit.assert_called_once_with(self.ctxt) - @mock.patch('nova.db.api.service_update') + @mock.patch('nova.db.main.api.service_update') def test_service_update_with_notification(self, mock_db_service_update): service_obj = objects.Service(context=self.ctxt, id=fake_service['id']) mock_db_service_update.return_value = fake_service @@ -72,7 +72,7 @@ class TestServiceStatusNotification(test.TestCase): fields.NotificationAction.UPDATE) @mock.patch('nova.notifications.objects.service.ServiceStatusNotification') - @mock.patch('nova.db.api.service_update') + @mock.patch('nova.db.main.api.service_update') def test_service_update_without_notification(self, mock_db_service_update, mock_notification): @@ -85,7 +85,7 @@ class TestServiceStatusNotification(test.TestCase): service_obj.save() self.assertFalse(mock_notification.called) - @mock.patch('nova.db.api.service_create') + @mock.patch('nova.db.main.api.service_create') def test_service_create_with_notification(self, mock_db_service_create): service_obj = objects.Service(context=self.ctxt) service_obj["uuid"] = fake_service["uuid"] @@ -93,7 +93,7 @@ class TestServiceStatusNotification(test.TestCase): self._verify_notification(service_obj, fields.NotificationAction.CREATE) - @mock.patch('nova.db.api.service_destroy') + @mock.patch('nova.db.main.api.service_destroy') def test_service_destroy_with_notification(self, mock_db_service_destroy): service = copy.deepcopy(fake_service) service.pop("version") diff --git a/nova/tests/unit/objects/test_bandwidth_usage.py b/nova/tests/unit/objects/test_bandwidth_usage.py index b439adc2b1..9cede796ac 100644 --- a/nova/tests/unit/objects/test_bandwidth_usage.py +++ b/nova/tests/unit/objects/test_bandwidth_usage.py @@ -18,7 +18,7 @@ from oslo_utils.fixture import uuidsentinel as uuids from oslo_utils import timeutils from nova import context -from nova.db import api as db +from nova.db.main import api as db from nova.objects import bandwidth_usage from nova import test from nova.tests.unit.objects import test_objects diff --git a/nova/tests/unit/objects/test_block_device.py b/nova/tests/unit/objects/test_block_device.py index 7120c3c336..80c9e9a1fa 100644 --- a/nova/tests/unit/objects/test_block_device.py +++ b/nova/tests/unit/objects/test_block_device.py @@ -16,9 +16,8 @@ import mock from oslo_utils.fixture import uuidsentinel as uuids from nova import context -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 block_device as block_device_obj @@ -331,7 +330,7 @@ class TestBlockDeviceMappingUUIDMigration(test.TestCase): objects.BlockDeviceMapping._create_uuid @staticmethod - @db_api.pick_context_manager_writer + @db.pick_context_manager_writer def _create_legacy_bdm(context, deleted=False): # Create a BDM with no uuid values = {'instance_uuid': uuids.instance_uuid} @@ -402,9 +401,10 @@ class TestBlockDeviceMappingUUIDMigration(test.TestCase): # Create 2 BDMs, one with a uuid and one without self._create_legacy_bdm(self.context) - db_api.block_device_mapping_create(self.context, - {'uuid': uuids.bdm2, 'instance_uuid': uuids.instance_uuid}, - legacy=False) + db.block_device_mapping_create( + self.context, + {'uuid': uuids.bdm2, 'instance_uuid': uuids.instance_uuid}, + legacy=False) # Run the online migration. We should find 1 and update 1 self._assert_online_migration(1, 1) diff --git a/nova/tests/unit/objects/test_compute_node.py b/nova/tests/unit/objects/test_compute_node.py index aeaf4b957f..5b6a456f85 100644 --- a/nova/tests/unit/objects/test_compute_node.py +++ b/nova/tests/unit/objects/test_compute_node.py @@ -23,7 +23,7 @@ from oslo_versionedobjects import base as ovo_base from oslo_versionedobjects import exception as ovo_exc from nova import conf -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 @@ -261,7 +261,7 @@ class _TestComputeNodeObject(object): subs=self.subs(), comparators=self.comparators()) - @mock.patch('nova.db.api.compute_node_get_all_by_host') + @mock.patch('nova.db.main.api.compute_node_get_all_by_host') def test_get_first_node_by_host_for_old_compat( self, cn_get_all_by_host): another_node = fake_compute_node.copy() @@ -288,7 +288,8 @@ class _TestComputeNodeObject(object): self.context, 'fake') @mock.patch.object(db, 'compute_node_create') - @mock.patch('nova.db.api.compute_node_get', return_value=fake_compute_node) + @mock.patch( + 'nova.db.main.api.compute_node_get', return_value=fake_compute_node) def test_create(self, mock_get, mock_create): mock_create.return_value = fake_compute_node compute = compute_node.ComputeNode(context=self.context) @@ -313,9 +314,10 @@ class _TestComputeNodeObject(object): } mock_create.assert_called_once_with(self.context, param_dict) - @mock.patch('nova.db.api.compute_node_create') + @mock.patch('nova.db.main.api.compute_node_create') @mock.patch('oslo_utils.uuidutils.generate_uuid') - @mock.patch('nova.db.api.compute_node_get', return_value=fake_compute_node) + @mock.patch( + 'nova.db.main.api.compute_node_get', return_value=fake_compute_node) def test_create_allocates_uuid(self, mock_get, mock_gu, mock_create): mock_create.return_value = fake_compute_node mock_gu.return_value = fake_compute_node['uuid'] @@ -325,8 +327,9 @@ class _TestComputeNodeObject(object): mock_create.assert_called_once_with( self.context, {'uuid': fake_compute_node['uuid']}) - @mock.patch('nova.db.api.compute_node_create') - @mock.patch('nova.db.api.compute_node_get', return_value=fake_compute_node) + @mock.patch('nova.db.main.api.compute_node_create') + @mock.patch( + 'nova.db.main.api.compute_node_get', return_value=fake_compute_node) def test_recreate_fails(self, mock_get, mock_create): mock_create.return_value = fake_compute_node compute = compute_node.ComputeNode(context=self.context) @@ -339,7 +342,8 @@ class _TestComputeNodeObject(object): mock_create.assert_called_once_with(self.context, param_dict) @mock.patch.object(db, 'compute_node_update') - @mock.patch('nova.db.api.compute_node_get', return_value=fake_compute_node) + @mock.patch( + 'nova.db.main.api.compute_node_get', return_value=fake_compute_node) def test_save(self, mock_get, mock_update): mock_update.return_value = fake_compute_node compute = compute_node.ComputeNode(context=self.context) @@ -363,7 +367,7 @@ class _TestComputeNodeObject(object): } mock_update.assert_called_once_with(self.context, 123, param_dict) - @mock.patch('nova.db.api.compute_node_update') + @mock.patch('nova.db.main.api.compute_node_update') def test_save_pci_device_pools_empty(self, mock_update): fake_pci = jsonutils.dumps( objects.PciDevicePoolList(objects=[]).obj_to_primitive()) @@ -382,7 +386,7 @@ class _TestComputeNodeObject(object): mock_update.assert_called_once_with( self.context, 123, {'pci_stats': fake_pci}) - @mock.patch('nova.db.api.compute_node_update') + @mock.patch('nova.db.main.api.compute_node_update') def test_save_pci_device_pools_null(self, mock_update): compute_dict = fake_compute_node.copy() compute_dict['pci_stats'] = None @@ -438,7 +442,7 @@ class _TestComputeNodeObject(object): comparators=self.comparators()) mock_search.assert_called_once_with(self.context, 'hyper') - @mock.patch('nova.db.api.compute_node_get_all_by_pagination', + @mock.patch('nova.db.main.api.compute_node_get_all_by_pagination', return_value=[fake_compute_node]) def test_get_by_pagination(self, fake_get_by_pagination): computes = compute_node.ComputeNodeList.get_by_pagination( @@ -448,7 +452,7 @@ class _TestComputeNodeObject(object): subs=self.subs(), comparators=self.comparators()) - @mock.patch('nova.db.api.compute_nodes_get_by_service_id') + @mock.patch('nova.db.main.api.compute_nodes_get_by_service_id') def test__get_by_service(self, cn_get_by_svc_id): cn_get_by_svc_id.return_value = [fake_compute_node] computes = compute_node.ComputeNodeList._get_by_service(self.context, @@ -458,7 +462,7 @@ class _TestComputeNodeObject(object): subs=self.subs(), comparators=self.comparators()) - @mock.patch('nova.db.api.compute_node_get_all_by_host') + @mock.patch('nova.db.main.api.compute_node_get_all_by_host') def test_get_all_by_host(self, cn_get_all_by_host): cn_get_all_by_host.return_value = [fake_compute_node] computes = compute_node.ComputeNodeList.get_all_by_host(self.context, @@ -600,7 +604,7 @@ class _TestComputeNodeObject(object): primitive = compute.obj_to_primitive(target_version='1.16') self.assertIn('disk_allocation_ratio', primitive['nova_object.data']) - @mock.patch('nova.db.api.compute_node_update') + @mock.patch('nova.db.main.api.compute_node_update') def test_compat_allocation_ratios_old_compute(self, mock_update): """Tests the scenario that allocation ratios are overridden in config and the legacy compute node record from the database has None set for @@ -626,7 +630,7 @@ class _TestComputeNodeObject(object): 'ram_allocation_ratio': 3.0, 'disk_allocation_ratio': 0.9}) - @mock.patch('nova.db.api.compute_node_update') + @mock.patch('nova.db.main.api.compute_node_update') def test_compat_allocation_ratios_zero_conf(self, mock_update): """Tests that the override allocation ratios are set to 0.0 for whatever reason (maybe an old nova.conf sample file is being used) @@ -656,7 +660,7 @@ class _TestComputeNodeObject(object): 'ram_allocation_ratio': 1.5, 'disk_allocation_ratio': 1.0}) - @mock.patch('nova.db.api.compute_node_update') + @mock.patch('nova.db.main.api.compute_node_update') def test_compat_allocation_ratios_None_conf_zero_values(self, mock_update): """Tests the scenario that the CONF.*_allocation_ratio overrides are left to the default (None) and the compute node record allocation @@ -684,7 +688,7 @@ class _TestComputeNodeObject(object): 'ram_allocation_ratio': 1.5, 'disk_allocation_ratio': 1.0}) - @mock.patch('nova.db.api.compute_node_update') + @mock.patch('nova.db.main.api.compute_node_update') def test_compat_allocation_ratios_None_conf_None_values(self, mock_update): """Tests the scenario that the override CONF.*_allocation_ratio options are the default values (None), the compute node record from the DB has diff --git a/nova/tests/unit/objects/test_console_auth_token.py b/nova/tests/unit/objects/test_console_auth_token.py index edcb9a9d09..9c92e798b0 100644 --- a/nova/tests/unit/objects/test_console_auth_token.py +++ b/nova/tests/unit/objects/test_console_auth_token.py @@ -29,7 +29,7 @@ from nova.tests.unit.objects import test_objects class _TestConsoleAuthToken(object): - @mock.patch('nova.db.api.console_auth_token_create') + @mock.patch('nova.db.main.api.console_auth_token_create') def _test_authorize(self, console_type, mock_create): # the expires time is calculated from the current time and # a ttl value in the object. Fix the current time so we can @@ -91,7 +91,7 @@ class _TestConsoleAuthToken(object): def test_authorize_novnc(self): self._test_authorize('novnc') - @mock.patch('nova.db.api.console_auth_token_create') + @mock.patch('nova.db.main.api.console_auth_token_create') def test_authorize_duplicate_token(self, mock_create): mock_create.side_effect = DBDuplicateEntry() @@ -109,7 +109,7 @@ class _TestConsoleAuthToken(object): obj.authorize, 100) - @mock.patch('nova.db.api.console_auth_token_create') + @mock.patch('nova.db.main.api.console_auth_token_create') def test_authorize_instance_not_found(self, mock_create): mock_create.side_effect = exception.InstanceNotFound( instance_id=fakes.fake_token_dict['instance_uuid']) @@ -128,7 +128,7 @@ class _TestConsoleAuthToken(object): obj.authorize, 100) - @mock.patch('nova.db.api.console_auth_token_create') + @mock.patch('nova.db.main.api.console_auth_token_create') def test_authorize_object_already_created(self, mock_create): # the expires time is calculated from the current time and # a ttl value in the object. Fix the current time so we can @@ -156,19 +156,19 @@ class _TestConsoleAuthToken(object): obj.authorize, 100) - @mock.patch('nova.db.api.console_auth_token_destroy_all_by_instance') + @mock.patch('nova.db.main.api.console_auth_token_destroy_all_by_instance') def test_clean_console_auths_for_instance(self, mock_destroy): token_obj.ConsoleAuthToken.clean_console_auths_for_instance( self.context, uuidsentinel.instance) mock_destroy.assert_called_once_with( self.context, uuidsentinel.instance) - @mock.patch('nova.db.api.console_auth_token_destroy_expired') + @mock.patch('nova.db.main.api.console_auth_token_destroy_expired') def test_clean_expired_console_auths(self, mock_destroy): token_obj.ConsoleAuthToken.clean_expired_console_auths(self.context) mock_destroy.assert_called_once_with(self.context) - @mock.patch('nova.db.api.console_auth_token_destroy_expired_by_host') + @mock.patch('nova.db.main.api.console_auth_token_destroy_expired_by_host') def test_clean_expired_console_auths_for_host(self, mock_destroy): token_obj.ConsoleAuthToken.clean_expired_console_auths_for_host( self.context, 'fake-host') diff --git a/nova/tests/unit/objects/test_ec2.py b/nova/tests/unit/objects/test_ec2.py index 5e33159d22..8261fd6173 100644 --- a/nova/tests/unit/objects/test_ec2.py +++ b/nova/tests/unit/objects/test_ec2.py @@ -15,7 +15,7 @@ import mock from oslo_utils.fixture import uuidsentinel as uuids -from nova.db import api as db +from nova.db.main import api as db from nova import objects from nova.objects import ec2 as ec2_obj from nova.tests.unit.objects import test_objects diff --git a/nova/tests/unit/objects/test_flavor.py b/nova/tests/unit/objects/test_flavor.py index 8d89c36b64..1524731eb5 100644 --- a/nova/tests/unit/objects/test_flavor.py +++ b/nova/tests/unit/objects/test_flavor.py @@ -19,7 +19,7 @@ from oslo_db import exception as db_exc from oslo_utils import uuidutils 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 import objects diff --git a/nova/tests/unit/objects/test_instance.py b/nova/tests/unit/objects/test_instance.py index e9e67ae7b1..e187a4c251 100644 --- a/nova/tests/unit/objects/test_instance.py +++ b/nova/tests/unit/objects/test_instance.py @@ -25,9 +25,8 @@ from oslo_versionedobjects import base as ovo_base 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 sql_api -from nova.db.sqlalchemy import models as sql_models +from nova.db.main import api as db +from nova.db.main import models as sql_models from nova import exception from nova.network import model as network_model from nova import notifications @@ -544,7 +543,7 @@ class _TestInstanceObject(object): 'system_metadata']) mock_send.assert_called_once_with(self.context, mock.ANY, mock.ANY) - @mock.patch('nova.db.api.instance_extra_update_by_uuid') + @mock.patch('nova.db.main.api.instance_extra_update_by_uuid') def test_save_object_pci_requests(self, mock_instance_extra_update): expected_json = ('[{"count": 1, "alias_name": null, "is_new": false,' '"request_id": null, "requester_id": null,' @@ -576,7 +575,7 @@ class _TestInstanceObject(object): inst.save() self.assertFalse(mock_instance_extra_update.called) - @mock.patch('nova.db.api.instance_update_and_get_original') + @mock.patch('nova.db.main.api.instance_update_and_get_original') @mock.patch.object(instance.Instance, '_from_db_object') def test_save_does_not_refresh_pci_devices(self, mock_fdo, mock_update): # NOTE(danms): This tests that we don't update the pci_devices @@ -592,8 +591,8 @@ class _TestInstanceObject(object): self.assertNotIn('pci_devices', mock_fdo.call_args_list[0][1]['expected_attrs']) - @mock.patch('nova.db.api.instance_extra_update_by_uuid') - @mock.patch('nova.db.api.instance_update_and_get_original') + @mock.patch('nova.db.main.api.instance_extra_update_by_uuid') + @mock.patch('nova.db.main.api.instance_update_and_get_original') @mock.patch.object(instance.Instance, '_from_db_object') def test_save_updates_numa_topology(self, mock_fdo, mock_update, mock_extra_update): @@ -630,7 +629,7 @@ class _TestInstanceObject(object): mock_extra_update.assert_called_once_with( self.context, inst.uuid, {'numa_topology': None}) - @mock.patch('nova.db.api.instance_extra_update_by_uuid') + @mock.patch('nova.db.main.api.instance_extra_update_by_uuid') def test_save_vcpu_model(self, mock_update): inst = fake_instance.fake_instance_obj(self.context) inst.vcpu_model = test_vcpu_model.fake_vcpumodel @@ -650,7 +649,7 @@ class _TestInstanceObject(object): mock_update.assert_called_once_with( self.context, inst.uuid, {'vcpu_model': None}) - @mock.patch('nova.db.api.instance_extra_update_by_uuid') + @mock.patch('nova.db.main.api.instance_extra_update_by_uuid') def test_save_migration_context_model(self, mock_update): inst = fake_instance.fake_instance_obj(self.context) inst.migration_context = test_mig_ctxt.get_fake_migration_context_obj( @@ -677,11 +676,11 @@ class _TestInstanceObject(object): flavor=objects.Flavor()) inst.obj_reset_changes() with mock.patch( - 'nova.db.api.instance_extra_update_by_uuid') as mock_upd: + 'nova.db.main.api.instance_extra_update_by_uuid') as mock_upd: inst.save() self.assertFalse(mock_upd.called) - @mock.patch('nova.db.api.instance_extra_update_by_uuid') + @mock.patch('nova.db.main.api.instance_extra_update_by_uuid') def test_save_multiple_extras_updates_once(self, mock_update): inst = fake_instance.fake_instance_obj(self.context) inst.numa_topology = None @@ -945,7 +944,7 @@ class _TestInstanceObject(object): mock_fault_get.assert_called_once_with(self.context, [fake_uuid]) @mock.patch('nova.objects.EC2Ids.get_by_instance') - @mock.patch('nova.db.api.instance_get_by_uuid') + @mock.patch('nova.db.main.api.instance_get_by_uuid') def test_with_ec2_ids(self, mock_get, mock_ec2): fake_inst = dict(self.fake_instance) fake_uuid = fake_inst['uuid'] @@ -959,7 +958,7 @@ class _TestInstanceObject(object): self.assertEqual(fake_ec2_ids.instance_id, inst.ec2_ids.instance_id) - @mock.patch('nova.db.api.instance_get_by_uuid') + @mock.patch('nova.db.main.api.instance_get_by_uuid') def test_with_image_meta(self, mock_get): fake_inst = dict(self.fake_instance) mock_get.return_value = fake_inst @@ -1269,7 +1268,7 @@ class _TestInstanceObject(object): expected_attrs=['security_groups']) self.assertEqual([], inst.security_groups.objects) - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid', + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid', return_value=None) def test_from_db_object_no_extra_db_calls(self, mock_get): db_inst = fake_instance.fake_db_instance() @@ -1408,7 +1407,8 @@ class _TestInstanceObject(object): inst.migration_context.instance_uuid = inst.uuid inst.migration_context.id = 7 with mock.patch( - 'nova.db.api.instance_extra_update_by_uuid') as update_extra: + 'nova.db.main.api.instance_extra_update_by_uuid', + ) as update_extra: inst.drop_migration_context() self.assertIsNone(inst.migration_context) update_extra.assert_called_once_with(self.context, inst.uuid, @@ -1499,7 +1499,7 @@ class _TestInstanceObject(object): uuid=uuids.instance, expected_attrs=['vm_state']) - @mock.patch('nova.db.api.instance_fault_get_by_instance_uuids') + @mock.patch('nova.db.main.api.instance_fault_get_by_instance_uuids') def test_load_fault(self, mock_get): fake_fault = test_instance_fault.fake_faults['fake-uuid'][0] mock_get.return_value = {uuids.load_fault_instance: [fake_fault]} @@ -1797,7 +1797,7 @@ class _TestInstanceListObject(object): type_id='bar') @mock.patch('nova.objects.instance._expected_cols') - @mock.patch('nova.db.api.instance_get_all') + @mock.patch('nova.db.main.api.instance_get_all') def test_get_all(self, mock_get_all, mock_exp): fakes = [self.fake_instance(1), self.fake_instance(2)] mock_get_all.return_value = fakes @@ -1958,7 +1958,7 @@ class _TestInstanceListObject(object): inst.destroy() self.assertFalse(db.security_group_in_use(self.context, db_sg.id)) - @mock.patch('nova.db.api.instance_get_all_uuids_by_hosts') + @mock.patch('nova.db.main.api.instance_get_all_uuids_by_hosts') def test_get_uuids_by_host_no_match(self, mock_get_all): mock_get_all.return_value = collections.defaultdict(list) actual_uuids = objects.InstanceList.get_uuids_by_host( @@ -1966,7 +1966,7 @@ class _TestInstanceListObject(object): self.assertEqual([], actual_uuids) mock_get_all.assert_called_once_with(self.context, ['b']) - @mock.patch('nova.db.api.instance_get_all_uuids_by_hosts') + @mock.patch('nova.db.main.api.instance_get_all_uuids_by_hosts') def test_get_uuids_by_host(self, mock_get_all): fake_instances = [uuids.inst1, uuids.inst2] mock_get_all.return_value = { @@ -1977,7 +1977,7 @@ class _TestInstanceListObject(object): self.assertEqual(fake_instances, actual_uuids) mock_get_all.assert_called_once_with(self.context, ['b']) - @mock.patch('nova.db.api.instance_get_all_uuids_by_hosts') + @mock.patch('nova.db.main.api.instance_get_all_uuids_by_hosts') def test_get_uuids_by_hosts(self, mock_get_all): fake_instances_a = [uuids.inst1, uuids.inst2] fake_instances_b = [uuids.inst3, uuids.inst4] @@ -2013,7 +2013,7 @@ class TestInstanceListObject(test_objects._LocalTest, # NOTE(danms): Because the model has default=False, we can not use # it to create an instance with a hidden value of NULL. So, do it # manually here. - engine = sql_api.get_engine() + engine = db.get_engine() table = sql_models.Instance.__table__ with engine.connect() as conn: update = table.insert().values(user_id=self.context.user_id, diff --git a/nova/tests/unit/objects/test_instance_action.py b/nova/tests/unit/objects/test_instance_action.py index aa9fc20025..1743623b1c 100644 --- a/nova/tests/unit/objects/test_instance_action.py +++ b/nova/tests/unit/objects/test_instance_action.py @@ -20,7 +20,7 @@ from oslo_utils import fixture as utils_fixture from oslo_utils.fixture import uuidsentinel as uuids from oslo_utils import timeutils -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_action @@ -188,7 +188,7 @@ class _TestInstanceActionObject(object): ex = self.assertRaises(exception.ObjectActionError, action.create) self.assertIn('already created', str(ex)) - @mock.patch('nova.db.api.action_start') + @mock.patch('nova.db.main.api.action_start') def test_create(self, mock_action_start): mock_action_start.return_value = fake_action action = instance_action.InstanceAction(self.context) @@ -404,7 +404,7 @@ class _TestInstanceActionEventObject(object): fake_action['instance_uuid'], fake_action['request_id']) self.assertIn('already created', str(ex)) - @mock.patch('nova.db.api.action_event_start') + @mock.patch('nova.db.main.api.action_event_start') def test_create(self, mock_action_event_start): mock_action_event_start.return_value = fake_event event = instance_action.InstanceActionEvent(self.context) diff --git a/nova/tests/unit/objects/test_instance_device_metadata.py b/nova/tests/unit/objects/test_instance_device_metadata.py index ee9266479a..6f998db84e 100644 --- a/nova/tests/unit/objects/test_instance_device_metadata.py +++ b/nova/tests/unit/objects/test_instance_device_metadata.py @@ -65,7 +65,7 @@ class _TestInstanceDeviceMetadata(object): self.assertEqual(obj_meta.bus.address, '0000:00:09.0') self.assertEqual(obj_meta.tags, ['nfvfunc3']) - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid') def test_get_by_instance_uuid(self, mock_get): mock_get.return_value = fake_db_metadata inst_meta = objects.InstanceDeviceMetadata diff --git a/nova/tests/unit/objects/test_instance_fault.py b/nova/tests/unit/objects/test_instance_fault.py index 767071760f..b19d8663c1 100644 --- a/nova/tests/unit/objects/test_instance_fault.py +++ b/nova/tests/unit/objects/test_instance_fault.py @@ -15,7 +15,7 @@ import mock from oslo_utils.fixture import uuidsentinel as uuids -from nova.db import api as db +from nova.db.main import api as db from nova import exception from nova.objects import instance_fault from nova.tests.unit.objects import test_objects @@ -72,7 +72,7 @@ class _TestInstanceFault(object): self.assertEqual(0, len(faults)) get_mock.assert_called_once_with(self.context, ['fake-uuid']) - @mock.patch('nova.db.api.instance_fault_create') + @mock.patch('nova.db.main.api.instance_fault_create') def test_create(self, mock_create): mock_create.return_value = fake_faults['fake-uuid'][1] fault = instance_fault.InstanceFault(context=self.context) diff --git a/nova/tests/unit/objects/test_instance_info_cache.py b/nova/tests/unit/objects/test_instance_info_cache.py index 839a9fab99..2df596f5af 100644 --- a/nova/tests/unit/objects/test_instance_info_cache.py +++ b/nova/tests/unit/objects/test_instance_info_cache.py @@ -18,7 +18,7 @@ import mock from oslo_utils.fixture import uuidsentinel as uuids from oslo_utils import timeutils -from nova.db import api as db +from nova.db.main import api as db from nova import exception from nova.network import model as network_model from nova.objects import instance_info_cache diff --git a/nova/tests/unit/objects/test_instance_numa.py b/nova/tests/unit/objects/test_instance_numa.py index 059f740ea8..f7a9ef7a1d 100644 --- a/nova/tests/unit/objects/test_instance_numa.py +++ b/nova/tests/unit/objects/test_instance_numa.py @@ -225,7 +225,7 @@ class TestInstanceNUMACellRemote( class _TestInstanceNUMATopology(object): - @mock.patch('nova.db.api.instance_extra_update_by_uuid') + @mock.patch('nova.db.main.api.instance_extra_update_by_uuid') def test_create(self, mock_update): topo_obj = get_fake_obj_numa_topology(self.context) topo_obj.instance_uuid = fake_db_topology['instance_uuid'] @@ -245,12 +245,12 @@ class _TestInstanceNUMATopology(object): self.assertEqual(topo_cell.memory, obj_cell.memory) self.assertEqual(topo_cell.pagesize, obj_cell.pagesize) - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid') def test_get_by_instance_uuid(self, mock_get): mock_get.return_value = fake_db_topology self._test_get_by_instance_uuid() - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid') def test_get_by_instance_uuid_missing(self, mock_get): mock_get.return_value = None self.assertRaises( diff --git a/nova/tests/unit/objects/test_instance_pci_requests.py b/nova/tests/unit/objects/test_instance_pci_requests.py index f3b324cdb1..9b6003ca49 100644 --- a/nova/tests/unit/objects/test_instance_pci_requests.py +++ b/nova/tests/unit/objects/test_instance_pci_requests.py @@ -57,7 +57,7 @@ fake_legacy_pci_requests = [ class _TestInstancePCIRequests(object): - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid') def test_get_by_instance_uuid(self, mock_get): mock_get.return_value = { 'instance_uuid': FAKE_UUID, diff --git a/nova/tests/unit/objects/test_keypair.py b/nova/tests/unit/objects/test_keypair.py index a0a33efce1..42691fd7f6 100644 --- a/nova/tests/unit/objects/test_keypair.py +++ b/nova/tests/unit/objects/test_keypair.py @@ -38,7 +38,7 @@ fake_keypair = { class _TestKeyPairObject(object): - @mock.patch('nova.db.api.key_pair_get') + @mock.patch('nova.db.main.api.key_pair_get') @mock.patch('nova.objects.KeyPair._get_from_db') def test_get_by_name_main(self, mock_api_get, mock_kp_get): mock_api_get.side_effect = exception.KeypairNotFound(user_id='foo', @@ -103,8 +103,8 @@ class _TestKeyPairObject(object): mock_kp_destroy.assert_called_once_with( self.context, 'fake-user', 'foo-keypair') - @mock.patch('nova.db.api.key_pair_get_all_by_user') - @mock.patch('nova.db.api.key_pair_count_by_user') + @mock.patch('nova.db.main.api.key_pair_get_all_by_user') + @mock.patch('nova.db.main.api.key_pair_count_by_user') @mock.patch('nova.objects.KeyPairList._get_from_db') @mock.patch('nova.objects.KeyPairList._get_count_from_db') def test_get_by_user(self, mock_api_count, mock_api_get, mock_kp_count, @@ -134,7 +134,7 @@ class _TestKeyPairObject(object): keypair_obj.obj_make_compatible(fake_keypair_copy, '1.1') self.assertNotIn('type', fake_keypair_copy) - @mock.patch('nova.db.api.key_pair_get_all_by_user') + @mock.patch('nova.db.main.api.key_pair_get_all_by_user') @mock.patch('nova.objects.KeyPairList._get_from_db') def test_get_by_user_limit(self, mock_api_get, mock_kp_get): api_keypair = copy.deepcopy(fake_keypair) @@ -151,7 +151,7 @@ class _TestKeyPairObject(object): limit=1, marker=None) self.assertFalse(mock_kp_get.called) - @mock.patch('nova.db.api.key_pair_get_all_by_user') + @mock.patch('nova.db.main.api.key_pair_get_all_by_user') @mock.patch('nova.objects.KeyPairList._get_from_db') def test_get_by_user_marker(self, mock_api_get, mock_kp_get): api_kp_name = 'api_kp' @@ -169,7 +169,7 @@ class _TestKeyPairObject(object): limit=None, marker=api_kp_name) - @mock.patch('nova.db.api.key_pair_get_all_by_user') + @mock.patch('nova.db.main.api.key_pair_get_all_by_user') @mock.patch('nova.objects.KeyPairList._get_from_db') def test_get_by_user_limit_and_marker_api(self, mock_api_get, mock_kp_get): first_api_kp_name = 'first_api_kp' @@ -191,7 +191,7 @@ class _TestKeyPairObject(object): mock_kp_get.assert_called_once_with(self.context, 'fake-user', limit=4, marker=None) - @mock.patch('nova.db.api.key_pair_get_all_by_user') + @mock.patch('nova.db.main.api.key_pair_get_all_by_user') @mock.patch('nova.objects.KeyPairList._get_from_db') def test_get_by_user_limit_and_marker_main(self, mock_api_get, mock_kp_get): @@ -211,7 +211,7 @@ class _TestKeyPairObject(object): mock_kp_get.assert_called_once_with(self.context, 'fake-user', limit=5, marker=first_main_kp_name) - @mock.patch('nova.db.api.key_pair_get_all_by_user') + @mock.patch('nova.db.main.api.key_pair_get_all_by_user') @mock.patch('nova.objects.KeyPairList._get_from_db') def test_get_by_user_limit_and_marker_invalid_marker( self, mock_api_get, mock_kp_get): diff --git a/nova/tests/unit/objects/test_migration.py b/nova/tests/unit/objects/test_migration.py index 7637a5819d..6d365c01d6 100644 --- a/nova/tests/unit/objects/test_migration.py +++ b/nova/tests/unit/objects/test_migration.py @@ -17,7 +17,7 @@ from oslo_utils.fixture import uuidsentinel from oslo_utils import timeutils 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 migration @@ -85,7 +85,7 @@ class _TestMigrationObject(object): fake_migration['id'], 'migrating') - @mock.patch('nova.db.api.migration_get_in_progress_by_instance') + @mock.patch('nova.db.main.api.migration_get_in_progress_by_instance') def test_get_in_progress_by_instance(self, m_get_mig): ctxt = context.get_admin_context() fake_migration = fake_db_migration() @@ -261,7 +261,7 @@ class _TestMigrationObject(object): def test_migrate_old_resize_record(self): db_migration = dict(fake_db_migration(), migration_type=None) - with mock.patch('nova.db.api.migration_get') as fake_get: + with mock.patch('nova.db.main.api.migration_get') as fake_get: fake_get.return_value = db_migration mig = objects.Migration.get_by_id(context.get_admin_context(), 1) self.assertTrue(mig.obj_attr_is_set('migration_type')) @@ -271,7 +271,7 @@ class _TestMigrationObject(object): db_migration = dict( fake_db_migration(), migration_type=None, old_instance_type_id=1, new_instance_type_id=1) - with mock.patch('nova.db.api.migration_get') as fake_get: + with mock.patch('nova.db.main.api.migration_get') as fake_get: fake_get.return_value = db_migration mig = objects.Migration.get_by_id(context.get_admin_context(), 1) self.assertTrue(mig.obj_attr_is_set('migration_type')) @@ -299,7 +299,7 @@ class _TestMigrationObject(object): self.assertFalse(mig.cross_cell_move) self.assertIn('cross_cell_move', mig) - @mock.patch('nova.db.api.migration_get_by_id_and_instance') + @mock.patch('nova.db.main.api.migration_get_by_id_and_instance') def test_get_by_id_and_instance(self, fake_get): ctxt = context.get_admin_context() fake_migration = fake_db_migration() @@ -353,7 +353,7 @@ class _TestMigrationObject(object): self.assertIn('source_compute', primitive) self.assertNotIn('migration_type', primitive) - @mock.patch('nova.db.api.migration_get_by_uuid') + @mock.patch('nova.db.main.api.migration_get_by_uuid') def test_get_by_uuid(self, mock_db_get): mock_db_get.return_value = fake_db_migration(uuid=uuidsentinel.mig) mig = objects.Migration.get_by_uuid(self.context, uuidsentinel.mig) diff --git a/nova/tests/unit/objects/test_migration_context.py b/nova/tests/unit/objects/test_migration_context.py index 69e3f0b958..94e8e9d57f 100644 --- a/nova/tests/unit/objects/test_migration_context.py +++ b/nova/tests/unit/objects/test_migration_context.py @@ -106,19 +106,19 @@ class _TestMigrationContext(object): else: self.assertIsNone(mig_context) - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid') def test_get_by_instance_uuid(self, mock_get): mock_get.return_value = fake_db_context self._test_get_by_instance_uuid(fake_db_context) - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid') def test_get_by_instance_uuid_none(self, mock_get): db_context = fake_db_context.copy() db_context['migration_context'] = None mock_get.return_value = db_context self._test_get_by_instance_uuid(db_context) - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid') def test_get_by_instance_uuid_missing(self, mock_get): mock_get.return_value = None self.assertRaises( diff --git a/nova/tests/unit/objects/test_pci_device.py b/nova/tests/unit/objects/test_pci_device.py index baf8d4797b..277a7fe7c4 100644 --- a/nova/tests/unit/objects/test_pci_device.py +++ b/nova/tests/unit/objects/test_pci_device.py @@ -21,9 +21,8 @@ from oslo_utils.fixture import uuidsentinel as uuids from oslo_utils import timeutils from nova import context -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 fields @@ -280,7 +279,7 @@ class _TestPciDeviceObject(object): return return_dev ctxt = context.get_admin_context() - self.stub_out('nova.db.api.pci_device_update', _fake_update) + self.stub_out('nova.db.main.api.pci_device_update', _fake_update) self.pci_device = pci_device.PciDevice.create(None, dev_dict) self.pci_device._context = ctxt self.pci_device.save() @@ -302,8 +301,8 @@ class _TestPciDeviceObject(object): def _fake_update(ctxt, node_id, addr, updates): self.called = True - self.stub_out('nova.db.api.pci_device_destroy', _fake_destroy) - self.stub_out('nova.db.api.pci_device_update', _fake_update) + self.stub_out('nova.db.main.api.pci_device_destroy', _fake_destroy) + self.stub_out('nova.db.main.api.pci_device_update', _fake_update) self._create_fake_pci_device() self.pci_device.status = fields.PciDeviceStatus.DELETED self.called = False @@ -840,7 +839,7 @@ class TestPciDeviceUUIDMigration(test.TestCase): 'fake-project-id') @staticmethod - @db_api.pick_context_manager_writer + @db.pick_context_manager_writer def _create_db_dev(context, deleted=False, **updates): """Create a PCI device with no UUID.""" values = copy.copy(dev_dict) diff --git a/nova/tests/unit/objects/test_quotas.py b/nova/tests/unit/objects/test_quotas.py index 1314b1de83..154c9f278a 100644 --- a/nova/tests/unit/objects/test_quotas.py +++ b/nova/tests/unit/objects/test_quotas.py @@ -15,7 +15,7 @@ import mock from nova import context -from nova.db.sqlalchemy import api as db_api +from nova.db.main import api as db_api from nova import exception from nova.objects import quotas as quotas_obj from nova import quota @@ -54,7 +54,8 @@ class _TestQuotasObject(object): self.instance = fake_instance.fake_db_instance( project_id='fake_proj2', user_id='fake_user2') - @mock.patch('nova.db.api.quota_get', side_effect=exception.QuotaNotFound) + @mock.patch( + 'nova.db.main.api.quota_get', side_effect=exception.QuotaNotFound) @mock.patch('nova.objects.Quotas._create_limit_in_db') def test_create_limit(self, mock_create, mock_get): quotas_obj.Quotas.create_limit(self.context, 'fake-project', @@ -62,7 +63,7 @@ class _TestQuotasObject(object): mock_create.assert_called_once_with(self.context, 'fake-project', 'foo', 10, user_id='user') - @mock.patch('nova.db.api.quota_get') + @mock.patch('nova.db.main.api.quota_get') @mock.patch('nova.objects.Quotas._create_limit_in_db') def test_create_limit_exists_in_main(self, mock_create, mock_get): self.assertRaises(exception.QuotaExists, @@ -203,7 +204,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._update_limit_in_db', side_effect=exception.QuotaNotFound) - @mock.patch('nova.db.api.quota_update') + @mock.patch('nova.db.main.api.quota_update') def test_update_limit_main(self, mock_update_main, mock_update): quotas_obj.Quotas.update_limit(self.context, 'fake-project', 'foo', 10, user_id='user') @@ -223,7 +224,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._get_from_db', side_effect=exception.QuotaNotFound) - @mock.patch('nova.db.api.quota_get') + @mock.patch('nova.db.main.api.quota_get') def test_get_main(self, mock_get_main, mock_get): quotas_obj.Quotas.get(self.context, 'fake-project', 'foo', user_id='user') @@ -233,7 +234,7 @@ class _TestQuotasObject(object): 'foo', user_id='user') @mock.patch('nova.objects.Quotas._get_all_from_db') - @mock.patch('nova.db.api.quota_get_all') + @mock.patch('nova.db.main.api.quota_get_all') def test_get_all(self, mock_get_all_main, mock_get_all): mock_get_all.return_value = ['api1'] mock_get_all_main.return_value = ['main1', 'main2'] @@ -243,7 +244,7 @@ class _TestQuotasObject(object): self.assertEqual(['api1', 'main1', 'main2'], quotas) @mock.patch('nova.objects.Quotas._get_all_from_db_by_project') - @mock.patch('nova.db.api.quota_get_all_by_project') + @mock.patch('nova.db.main.api.quota_get_all_by_project') def test_get_all_by_project(self, mock_get_all_main, mock_get_all): mock_get_all.return_value = {'project_id': 'fake-project', 'fixed_ips': 20, 'floating_ips': 5} @@ -258,7 +259,7 @@ class _TestQuotasObject(object): self.assertEqual(expected, quotas_dict) @mock.patch('nova.objects.Quotas._get_all_from_db_by_project_and_user') - @mock.patch('nova.db.api.quota_get_all_by_project_and_user') + @mock.patch('nova.db.main.api.quota_get_all_by_project_and_user') def test_get_all_by_project_and_user(self, mock_get_all_main, mock_get_all): mock_get_all.return_value = {'project_id': 'fake-project', @@ -285,7 +286,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._destroy_all_in_db_by_project', side_effect=exception.ProjectQuotaNotFound( project_id='fake-project')) - @mock.patch('nova.db.api.quota_destroy_all_by_project') + @mock.patch('nova.db.main.api.quota_destroy_all_by_project') def test_destroy_all_by_project_main(self, mock_destroy_all_main, mock_destroy_all): quotas_obj.Quotas.destroy_all_by_project(self.context, 'fake-project') @@ -304,7 +305,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._destroy_all_in_db_by_project_and_user', side_effect=exception.ProjectUserQuotaNotFound( user_id='user', project_id='fake-project')) - @mock.patch('nova.db.api.quota_destroy_all_by_project_and_user') + @mock.patch('nova.db.main.api.quota_destroy_all_by_project_and_user') def test_destroy_all_by_project_and_user_main(self, mock_destroy_all_main, mock_destroy_all): quotas_obj.Quotas.destroy_all_by_project_and_user(self.context, @@ -323,7 +324,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._get_class_from_db', side_effect=exception.QuotaClassNotFound(class_name='class')) - @mock.patch('nova.db.api.quota_class_get') + @mock.patch('nova.db.main.api.quota_class_get') def test_get_class_main(self, mock_get_main, mock_get): qclass = quotas_obj.Quotas.get_class(self.context, 'class', 'resource') mock_get.assert_called_once_with(self.context, 'class', 'resource') @@ -340,7 +341,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._get_all_class_from_db_by_name', side_effect=exception.QuotaClassNotFound(class_name='class')) - @mock.patch('nova.db.api.quota_class_get_default') + @mock.patch('nova.db.main.api.quota_class_get_default') def test_get_default_class_main(self, mock_get_default_main, mock_get_all): qclass = quotas_obj.Quotas.get_default_class(self.context) mock_get_all.assert_called_once_with(self.context, @@ -349,7 +350,7 @@ class _TestQuotasObject(object): self.assertEqual(mock_get_default_main.return_value, qclass) @mock.patch('nova.objects.Quotas._get_all_class_from_db_by_name') - @mock.patch('nova.db.api.quota_class_get_all_by_name') + @mock.patch('nova.db.main.api.quota_class_get_all_by_name') def test_get_class_by_name(self, mock_get_all_main, mock_get_all): mock_get_all.return_value = {'class_name': 'foo', 'cores': 10, 'instances': 5} @@ -363,7 +364,7 @@ class _TestQuotasObject(object): 'fixed_ips': 10} self.assertEqual(expected, quotas_dict) - @mock.patch('nova.db.api.quota_class_get', + @mock.patch('nova.db.main.api.quota_class_get', side_effect=exception.QuotaClassNotFound(class_name='class')) @mock.patch('nova.objects.Quotas._create_class_in_db') def test_create_class(self, mock_create, mock_get): @@ -372,7 +373,7 @@ class _TestQuotasObject(object): mock_create.assert_called_once_with(self.context, 'class', 'resource', 'limit') - @mock.patch('nova.db.api.quota_class_get') + @mock.patch('nova.db.main.api.quota_class_get') @mock.patch('nova.objects.Quotas._create_class_in_db') def test_create_class_exists_in_main(self, mock_create, mock_get): self.assertRaises(exception.QuotaClassExists, @@ -388,7 +389,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._update_class_in_db', side_effect=exception.QuotaClassNotFound(class_name='class')) - @mock.patch('nova.db.api.quota_class_update') + @mock.patch('nova.db.main.api.quota_class_update') def test_update_class_main(self, mock_update_main, mock_update): quotas_obj.Quotas.update_class(self.context, 'class', 'resource', 'limit') diff --git a/nova/tests/unit/objects/test_resource.py b/nova/tests/unit/objects/test_resource.py index 892562f11d..3ac12eee84 100644 --- a/nova/tests/unit/objects/test_resource.py +++ b/nova/tests/unit/objects/test_resource.py @@ -101,7 +101,7 @@ class TestResourceObject(test_objects._LocalTest): class _TestResourceListObject(object): - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid') def test_get_by_instance_uuid(self, mock_get): mock_get.return_value = fake_instance_extras resources = resource.ResourceList.get_by_instance_uuid( diff --git a/nova/tests/unit/objects/test_security_group.py b/nova/tests/unit/objects/test_security_group.py index 8b62018246..7d6a3773c5 100644 --- a/nova/tests/unit/objects/test_security_group.py +++ b/nova/tests/unit/objects/test_security_group.py @@ -16,7 +16,7 @@ import mock from oslo_utils.fixture import uuidsentinel as uuids from oslo_versionedobjects import fixture as ovo_fixture -from nova.db import api as db +from nova.db.main import api as db from nova.objects import instance from nova.objects import security_group from nova.tests.unit.objects import test_objects diff --git a/nova/tests/unit/objects/test_service.py b/nova/tests/unit/objects/test_service.py index e5ad835ff9..84cbd4bf6a 100644 --- a/nova/tests/unit/objects/test_service.py +++ b/nova/tests/unit/objects/test_service.py @@ -20,7 +20,7 @@ from oslo_versionedobjects import exception as ovo_exc from nova.compute import manager as compute_manager 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 aggregate @@ -206,7 +206,7 @@ class _TestServiceObject(object): self.compare_obj(services[0], fake_service, allow_missing=OPTIONAL) mock_service_get.assert_called_once_with(self.context, 'fake-topic') - @mock.patch('nova.db.api.service_get_all_by_binary') + @mock.patch('nova.db.main.api.service_get_all_by_binary') def test_get_by_binary(self, mock_get): mock_get.return_value = [fake_service] services = service.ServiceList.get_by_binary(self.context, @@ -216,7 +216,7 @@ class _TestServiceObject(object): 'fake-binary', include_disabled=False) - @mock.patch('nova.db.api.service_get_all_by_binary') + @mock.patch('nova.db.main.api.service_get_all_by_binary') def test_get_by_binary_disabled(self, mock_get): mock_get.return_value = [_fake_service(disabled=True)] services = service.ServiceList.get_by_binary(self.context, @@ -227,7 +227,7 @@ class _TestServiceObject(object): 'fake-binary', include_disabled=True) - @mock.patch('nova.db.api.service_get_all_by_binary') + @mock.patch('nova.db.main.api.service_get_all_by_binary') def test_get_by_binary_both(self, mock_get): mock_get.return_value = [_fake_service(), _fake_service(disabled=True)] @@ -319,7 +319,7 @@ class _TestServiceObject(object): version_manifest=versions), fake_service_dict['compute_node']) - @mock.patch('nova.db.api.service_get_minimum_version') + @mock.patch('nova.db.main.api.service_get_minimum_version') def test_get_minimum_version_none(self, mock_get): mock_get.return_value = None self.assertEqual(0, @@ -327,7 +327,7 @@ class _TestServiceObject(object): 'nova-compute')) mock_get.assert_called_once_with(self.context, ['nova-compute']) - @mock.patch('nova.db.api.service_get_minimum_version') + @mock.patch('nova.db.main.api.service_get_minimum_version') def test_get_minimum_version(self, mock_get): mock_get.return_value = {'nova-compute': 123} self.assertEqual(123, @@ -335,7 +335,7 @@ class _TestServiceObject(object): 'nova-compute')) mock_get.assert_called_once_with(self.context, ['nova-compute']) - @mock.patch('nova.db.api.service_get_minimum_version') + @mock.patch('nova.db.main.api.service_get_minimum_version') @mock.patch('nova.objects.service.LOG') def test_get_minimum_version_checks_binary(self, mock_log, mock_get): mock_get.return_value = None @@ -349,7 +349,7 @@ class _TestServiceObject(object): 'compute') self.assertTrue(mock_log.warning.called) - @mock.patch('nova.db.api.service_get_minimum_version') + @mock.patch('nova.db.main.api.service_get_minimum_version') def test_get_minimum_version_with_caching(self, mock_get): objects.Service.enable_min_version_cache() mock_get.return_value = {'nova-compute': 123} @@ -365,7 +365,7 @@ class _TestServiceObject(object): objects.Service._SERVICE_VERSION_CACHING = False objects.Service.clear_min_version_cache() - @mock.patch('nova.db.api.service_get_minimum_version') + @mock.patch('nova.db.main.api.service_get_minimum_version') def test_get_min_version_multiple_with_old(self, mock_gmv): mock_gmv.return_value = {'nova-api': None, 'nova-scheduler': 2, @@ -377,7 +377,7 @@ class _TestServiceObject(object): binaries) self.assertEqual(0, minimum) - @mock.patch('nova.db.api.service_get_minimum_version') + @mock.patch('nova.db.main.api.service_get_minimum_version') def test_get_min_version_multiple(self, mock_gmv): mock_gmv.return_value = {'nova-api': 1, 'nova-scheduler': 2, @@ -390,7 +390,7 @@ class _TestServiceObject(object): self.assertEqual(1, minimum) @mock.patch('nova.objects.Service._send_notification') - @mock.patch('nova.db.api.service_get_minimum_version', + @mock.patch('nova.db.main.api.service_get_minimum_version', return_value={'nova-compute': 2}) def test_create_above_minimum(self, mock_get, mock_notify): with mock.patch('nova.objects.service.SERVICE_VERSION', @@ -399,7 +399,7 @@ class _TestServiceObject(object): binary='nova-compute').create() @mock.patch('nova.objects.Service._send_notification') - @mock.patch('nova.db.api.service_get_minimum_version', + @mock.patch('nova.db.main.api.service_get_minimum_version', return_value={'nova-compute': 2}) def test_create_equal_to_minimum(self, mock_get, mock_notify): with mock.patch('nova.objects.service.SERVICE_VERSION', @@ -407,7 +407,7 @@ class _TestServiceObject(object): objects.Service(context=self.context, binary='nova-compute').create() - @mock.patch('nova.db.api.service_get_minimum_version', + @mock.patch('nova.db.main.api.service_get_minimum_version', return_value={'nova-compute': 2}) def test_create_below_minimum(self, mock_get): with mock.patch('nova.objects.service.SERVICE_VERSION', diff --git a/nova/tests/unit/objects/test_tag.py b/nova/tests/unit/objects/test_tag.py index e91f94bfd1..29579b1e78 100644 --- a/nova/tests/unit/objects/test_tag.py +++ b/nova/tests/unit/objects/test_tag.py @@ -40,7 +40,7 @@ def _get_tag(resource_id, tag_name, context=None): class _TestTagObject(object): - @mock.patch('nova.db.api.instance_tag_add') + @mock.patch('nova.db.main.api.instance_tag_add') def test_create(self, tag_add): tag_add.return_value = fake_tag1 tag_obj = _get_tag(RESOURCE_ID, TAG_NAME1, context=self.context) @@ -49,13 +49,13 @@ class _TestTagObject(object): tag_add.assert_called_once_with(self.context, RESOURCE_ID, TAG_NAME1) self.compare_obj(tag_obj, fake_tag1) - @mock.patch('nova.db.api.instance_tag_delete') + @mock.patch('nova.db.main.api.instance_tag_delete') def test_destroy(self, tag_delete): tag.Tag.destroy(self.context, RESOURCE_ID, TAG_NAME1) tag_delete.assert_called_once_with(self.context, RESOURCE_ID, TAG_NAME1) - @mock.patch('nova.db.api.instance_tag_exists') + @mock.patch('nova.db.main.api.instance_tag_exists') def test_exists(self, instance_tag_exists): tag.Tag.exists(self.context, RESOURCE_ID, TAG_NAME1) instance_tag_exists.assert_called_once_with( @@ -81,7 +81,7 @@ class _TestTagList(object): self.assertEqual(obj.tag, fake['tag']) self.assertEqual(obj.resource_id, fake['resource_id']) - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') def test_get_by_resource_id(self, get_by_inst): get_by_inst.return_value = fake_tag_list @@ -91,7 +91,7 @@ class _TestTagList(object): get_by_inst.assert_called_once_with(self.context, RESOURCE_ID) self._compare_tag_list(fake_tag_list, tag_list_obj) - @mock.patch('nova.db.api.instance_tag_set') + @mock.patch('nova.db.main.api.instance_tag_set') def test_create(self, tag_set): tag_set.return_value = fake_tag_list tag_list_obj = tag.TagList.create( @@ -101,7 +101,7 @@ class _TestTagList(object): RESOURCE_ID, [TAG_NAME1, TAG_NAME2]) self._compare_tag_list(fake_tag_list, tag_list_obj) - @mock.patch('nova.db.api.instance_tag_delete_all') + @mock.patch('nova.db.main.api.instance_tag_delete_all') def test_destroy(self, tag_delete_all): tag.TagList.destroy(self.context, RESOURCE_ID) tag_delete_all.assert_called_once_with(self.context, RESOURCE_ID) diff --git a/nova/tests/unit/objects/test_task_log.py b/nova/tests/unit/objects/test_task_log.py index fa15ab4e06..6d93ebab4c 100644 --- a/nova/tests/unit/objects/test_task_log.py +++ b/nova/tests/unit/objects/test_task_log.py @@ -40,7 +40,7 @@ fake_task_log = { class _TestTaskLog(object): - @mock.patch('nova.db.api.task_log_get', return_value=fake_task_log) + @mock.patch('nova.db.main.api.task_log_get', return_value=fake_task_log) def test_get(self, mock_get): task_log = objects.TaskLog.get(self.context, fake_task_log['task_name'], @@ -57,7 +57,7 @@ class _TestTaskLog(object): state=fake_task_log['state']) self.compare_obj(task_log, fake_task_log) - @mock.patch('nova.db.api.task_log_begin_task') + @mock.patch('nova.db.main.api.task_log_begin_task') def test_begin_task(self, mock_begin_task): task_log = objects.TaskLog(self.context) task_log.task_name = fake_task_log['task_name'] @@ -78,7 +78,7 @@ class _TestTaskLog(object): task_items=fake_task_log['task_items'], message=fake_task_log['message']) - @mock.patch('nova.db.api.task_log_end_task') + @mock.patch('nova.db.main.api.task_log_end_task') def test_end_task(self, mock_end_task): task_log = objects.TaskLog(self.context) task_log.task_name = fake_task_log['task_name'] @@ -109,7 +109,7 @@ class TestRemoteTaskLog(test_objects._RemoteTest, _TestTaskLog): class _TestTaskLogList(object): - @mock.patch('nova.db.api.task_log_get_all') + @mock.patch('nova.db.main.api.task_log_get_all') def test_get_all(self, mock_get_all): fake_task_logs = [dict(fake_task_log, id=1), dict(fake_task_log, id=2)] mock_get_all.return_value = fake_task_logs diff --git a/nova/tests/unit/objects/test_trusted_certs.py b/nova/tests/unit/objects/test_trusted_certs.py index 08166a886b..3010dd6b5c 100644 --- a/nova/tests/unit/objects/test_trusted_certs.py +++ b/nova/tests/unit/objects/test_trusted_certs.py @@ -25,7 +25,7 @@ fake_instance_extras = { class _TestTrustedCertsObject(object): - @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_extra_get_by_instance_uuid') def test_get_by_instance_uuid(self, mock_get): mock_get.return_value = fake_instance_extras certs = trusted_certs.TrustedCerts.get_by_instance_uuid( diff --git a/nova/tests/unit/objects/test_virtual_interface.py b/nova/tests/unit/objects/test_virtual_interface.py index 5c4d14fa61..a9049bac88 100644 --- a/nova/tests/unit/objects/test_virtual_interface.py +++ b/nova/tests/unit/objects/test_virtual_interface.py @@ -15,7 +15,7 @@ import mock from oslo_utils.fixture import uuidsentinel as uuids -from nova.db import api as db +from nova.db.main import api as db from nova.objects import virtual_interface as vif_obj from nova.tests.unit.objects import test_objects diff --git a/nova/tests/unit/objects/test_volume_usage.py b/nova/tests/unit/objects/test_volume_usage.py index 91207eef6d..a465955ad6 100644 --- a/nova/tests/unit/objects/test_volume_usage.py +++ b/nova/tests/unit/objects/test_volume_usage.py @@ -45,7 +45,8 @@ fake_vol_usage = { class _TestVolumeUsage(object): - @mock.patch('nova.db.api.vol_usage_update', return_value=fake_vol_usage) + @mock.patch( + 'nova.db.main.api.vol_usage_update', return_value=fake_vol_usage) def test_save(self, mock_upd): vol_usage = objects.VolumeUsage(self.context) vol_usage.volume_id = uuids.volume_id @@ -63,7 +64,8 @@ class _TestVolumeUsage(object): 'fake-project-id', 'fake-user-id', None, update_totals=False) self.compare_obj(vol_usage, fake_vol_usage) - @mock.patch('nova.db.api.vol_usage_update', return_value=fake_vol_usage) + @mock.patch( + 'nova.db.main.api.vol_usage_update', return_value=fake_vol_usage) def test_save_update_totals(self, mock_upd): vol_usage = objects.VolumeUsage(self.context) vol_usage.volume_id = uuids.volume_id diff --git a/nova/tests/unit/pci/test_manager.py b/nova/tests/unit/pci/test_manager.py index 7cacf52dd2..dbcaa8822d 100644 --- a/nova/tests/unit/pci/test_manager.py +++ b/nova/tests/unit/pci/test_manager.py @@ -150,7 +150,7 @@ class PciDevTrackerTestCase(test.NoDBTestCase): super(PciDevTrackerTestCase, self).setUp() self.fake_context = context.get_admin_context() self.fake_devs = fake_db_devs[:] - self.stub_out('nova.db.api.pci_device_get_all_by_node', + self.stub_out('nova.db.main.api.pci_device_get_all_by_node', self._fake_get_pci_devices) # The fake_pci_whitelist must be called before creating the fake # devices @@ -472,7 +472,7 @@ class PciDevTrackerTestCase(test.NoDBTestCase): return_value=False) def test_save(self, migrate_mock): self.stub_out( - 'nova.db.api.pci_device_update', + 'nova.db.main.api.pci_device_update', self._fake_pci_device_update) fake_pci_v3 = dict(fake_pci, address='0000:00:00.2', vendor_id='v3') fake_pci_devs = [copy.deepcopy(fake_pci), copy.deepcopy(fake_pci_2), @@ -484,10 +484,10 @@ class PciDevTrackerTestCase(test.NoDBTestCase): def test_save_removed(self): self.stub_out( - 'nova.db.api.pci_device_update', + 'nova.db.main.api.pci_device_update', self._fake_pci_device_update) self.stub_out( - 'nova.db.api.pci_device_destroy', + 'nova.db.main.api.pci_device_destroy', self._fake_pci_device_destroy) self.destroy_called = 0 self.assertEqual(len(self.tracker.pci_devs), 3) diff --git a/nova/tests/unit/policies/test_server_tags.py b/nova/tests/unit/policies/test_server_tags.py index 6af2027b56..b7efe86364 100644 --- a/nova/tests/unit/policies/test_server_tags.py +++ b/nova/tests/unit/policies/test_server_tags.py @@ -97,7 +97,7 @@ class ServerTagsPolicyTest(base.BasePolicyTest): self.req, self.instance.uuid, uuids.fake_id) @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') @mock.patch('nova.objects.Tag.create') def test_update_server_tags_policy(self, mock_create, mock_tag, mock_notf): @@ -110,7 +110,7 @@ class ServerTagsPolicyTest(base.BasePolicyTest): body=None) @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.api.instance_tag_set') + @mock.patch('nova.db.main.api.instance_tag_set') def test_update_all_server_tags_policy(self, mock_set, mock_notf): rule_name = policies.POLICY_ROOT % 'update_all' self.common_policy_check(self.admin_or_owner_authorized_contexts, @@ -131,7 +131,7 @@ class ServerTagsPolicyTest(base.BasePolicyTest): self.req, self.instance.uuid) @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid') @mock.patch('nova.objects.Tag.destroy') def test_delete_server_tags_policy(self, mock_destroy, mock_get, mock_notf): diff --git a/nova/tests/unit/test_availability_zones.py b/nova/tests/unit/test_availability_zones.py index 36f94ab422..438e8dba24 100644 --- a/nova/tests/unit/test_availability_zones.py +++ b/nova/tests/unit/test_availability_zones.py @@ -24,7 +24,7 @@ from nova import availability_zones as az from nova.compute import api as compute_api 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 objects from nova import test diff --git a/nova/tests/unit/test_conf.py b/nova/tests/unit/test_conf.py index 7b66cbb5e5..722f32d4c1 100644 --- a/nova/tests/unit/test_conf.py +++ b/nova/tests/unit/test_conf.py @@ -86,7 +86,7 @@ class TestParseArgs(test.NoDBTestCase): def setUp(self): super(TestParseArgs, self).setUp() - m = mock.patch('nova.db.sqlalchemy.api.configure') + m = mock.patch('nova.db.main.api.configure') self.nova_db_config_mock = m.start() self.addCleanup(self.nova_db_config_mock.stop) diff --git a/nova/tests/unit/test_context.py b/nova/tests/unit/test_context.py index 1481714695..cc3d7c7eea 100644 --- a/nova/tests/unit/test_context.py +++ b/nova/tests/unit/test_context.py @@ -239,7 +239,7 @@ class ContextTestCase(test.NoDBTestCase): mock.sentinel.target) @mock.patch('nova.rpc.create_transport') - @mock.patch('nova.db.api.create_context_manager') + @mock.patch('nova.db.main.api.create_context_manager') def test_target_cell(self, mock_create_ctxt_mgr, mock_rpc): mock_create_ctxt_mgr.return_value = mock.sentinel.cdb mock_rpc.return_value = mock.sentinel.cmq @@ -266,7 +266,7 @@ class ContextTestCase(test.NoDBTestCase): self.assertEqual(cctxt.cell_uuid, mapping.uuid) @mock.patch('nova.rpc.create_transport') - @mock.patch('nova.db.api.create_context_manager') + @mock.patch('nova.db.main.api.create_context_manager') def test_target_cell_unset(self, mock_create_ctxt_mgr, mock_rpc): """Tests that passing None as the mapping will temporarily untarget any previously set cell context. @@ -311,7 +311,7 @@ class ContextTestCase(test.NoDBTestCase): self.assertFalse(ctxt.is_admin) @mock.patch('nova.rpc.create_transport') - @mock.patch('nova.db.api.create_context_manager') + @mock.patch('nova.db.main.api.create_context_manager') def test_target_cell_caching(self, mock_create_cm, mock_create_tport): mock_create_cm.return_value = mock.sentinel.db_conn_obj mock_create_tport.return_value = mock.sentinel.mq_conn_obj diff --git a/nova/tests/unit/test_fixtures.py b/nova/tests/unit/test_fixtures.py index ed2aec89c2..48913d05ad 100644 --- a/nova/tests/unit/test_fixtures.py +++ b/nova/tests/unit/test_fixtures.py @@ -34,7 +34,7 @@ import testtools from nova.compute import rpcapi as compute_rpcapi from nova import conductor from nova import context -from nova.db.sqlalchemy import api as session +from nova.db.main import api as session from nova import exception from nova.network import neutron as neutron_api from nova import objects diff --git a/nova/tests/unit/test_metadata.py b/nova/tests/unit/test_metadata.py index b74a0a533e..96a1ab277e 100644 --- a/nova/tests/unit/test_metadata.py +++ b/nova/tests/unit/test_metadata.py @@ -358,8 +358,9 @@ class MetadataTestCase(test.TestCase): 'delete_on_termination': None, 'device_name': '/dev/sdb'})] - self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance', - fake_bdm_get) + self.stub_out( + 'nova.db.main.api.block_device_mapping_get_all_by_instance', + fake_bdm_get) expected = {'ami': 'sda1', 'root': '/dev/sda1', diff --git a/nova/tests/unit/test_quota.py b/nova/tests/unit/test_quota.py index 8238cb808d..312449b13a 100644 --- a/nova/tests/unit/test_quota.py +++ b/nova/tests/unit/test_quota.py @@ -21,7 +21,7 @@ from oslo_db.sqlalchemy import enginefacade from nova.compute import api as compute import nova.conf from nova import context -from nova.db.sqlalchemy import models as sqa_models +from nova.db.main import models from nova import exception from nova import objects from nova import quota @@ -596,9 +596,9 @@ class DbQuotaDriverTestCase(test.TestCase): 'injected_file_path_bytes': 127, } - self.stub_out('nova.db.api.quota_get_all_by_project_and_user', + self.stub_out('nova.db.main.api.quota_get_all_by_project_and_user', fake_qgabpau) - self.stub_out('nova.db.api.quota_get_all_by_project', fake_qgabp) + self.stub_out('nova.db.main.api.quota_get_all_by_project', fake_qgabp) self._stub_quota_class_get_all_by_name() @@ -751,7 +751,7 @@ class DbQuotaDriverTestCase(test.TestCase): return dict( test_resource=dict(in_use=20), ) - self.stub_out('nova.db.api.quota_get', fake_quota_get) + self.stub_out('nova.db.main.api.quota_get', fake_quota_get) def _stub_get_by_project(self): def fake_qgabp(context, project_id): @@ -766,13 +766,13 @@ class DbQuotaDriverTestCase(test.TestCase): def fake_quota_get_all(context, project_id): self.calls.append('quota_get_all') self.assertEqual(project_id, 'test_project') - return [sqa_models.ProjectUserQuota(resource='instances', - hard_limit=5), - sqa_models.ProjectUserQuota(resource='cores', - hard_limit=2)] + return [ + models.ProjectUserQuota(resource='instances', hard_limit=5), + models.ProjectUserQuota(resource='cores', hard_limit=2), + ] - self.stub_out('nova.db.api.quota_get_all_by_project', fake_qgabp) - self.stub_out('nova.db.api.quota_get_all', fake_quota_get_all) + self.stub_out('nova.db.main.api.quota_get_all_by_project', fake_qgabp) + self.stub_out('nova.db.main.api.quota_get_all', fake_quota_get_all) self._stub_quota_class_get_all_by_name() self._stub_quota_class_get_default() @@ -1410,13 +1410,13 @@ class DbQuotaDriverTestCase(test.TestCase): self.calls.append('quota_get_all_by_project_and_user') return {'instances': 2, 'cores': -1} - self.stub_out('nova.db.api.quota_get_all_by_project', + self.stub_out('nova.db.main.api.quota_get_all_by_project', fake_quota_get_all_by_project) self.stub_out('nova.quota.DbQuotaDriver.get_project_quotas', fake_get_project_quotas) self.stub_out('nova.quota.DbQuotaDriver._process_quotas', fake_process_quotas_in_get_user_quotas) - self.stub_out('nova.db.api.quota_get_all_by_project_and_user', + self.stub_out('nova.db.main.api.quota_get_all_by_project_and_user', fake_qgabpau) def test_get_settable_quotas_with_user(self): diff --git a/nova/tests/unit/test_test_utils.py b/nova/tests/unit/test_test_utils.py index 2511fbc9a0..7c3dab8454 100644 --- a/nova/tests/unit/test_test_utils.py +++ b/nova/tests/unit/test_test_utils.py @@ -18,7 +18,7 @@ from unittest import mock import fixtures -from nova.db import api as db +from nova.db.main import api as db from nova import test from nova.tests.unit import utils as test_utils diff --git a/nova/tests/unit/utils.py b/nova/tests/unit/utils.py index 32cd9325a8..6737702c7a 100644 --- a/nova/tests/unit/utils.py +++ b/nova/tests/unit/utils.py @@ -23,7 +23,7 @@ import mock from nova.compute import flavors import nova.conf import nova.context -from nova.db import api as db +from nova.db.main import api as db from nova import exception from nova.image import glance from nova.network import model as network_model diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 03eea0555f..eedf476792 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -67,8 +67,8 @@ from nova.compute import utils as compute_utils from nova.compute import vm_states import nova.conf 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 import exception from nova.network import model as network_model from nova import objects diff --git a/nova/virt/driver.py b/nova/virt/driver.py index eea6ae2440..cb33ed396e 100644 --- a/nova/virt/driver.py +++ b/nova/virt/driver.py @@ -1135,7 +1135,7 @@ class ComputeDriver(object): :param context: security context :param instance: - nova.db.sqlalchemy.models.Instance object + nova.db.main.models.Instance object instance object that is migrated. :param dest: destination host :param post_method: @@ -1265,7 +1265,7 @@ class ComputeDriver(object): back to the source host to check the results. :param context: security context - :param instance: nova.db.sqlalchemy.models.Instance + :param instance: nova.db.main.models.Instance :param src_compute_info: Info about the sending machine :param dst_compute_info: Info about the receiving machine :param block_migration: if true, prepare for block migration @@ -1307,7 +1307,7 @@ class ComputeDriver(object): results from check_can_live_migrate_destination. :param context: security context - :param instance: nova.db.sqlalchemy.models.Instance + :param instance: nova.db.main.models.Instance :param dest_check_data: result of check_can_live_migrate_destination :param block_device_info: result of _get_instance_block_device_info :returns: a LiveMigrateData object diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index cb7db5901f..22c4af0666 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -8984,7 +8984,7 @@ class LibvirtDriver(driver.ComputeDriver): back to the source host to check the results. :param context: security context - :param instance: nova.db.sqlalchemy.models.Instance + :param instance: nova.db.main.models.Instance :param block_migration: if true, prepare for block migration :param disk_over_commit: if true, allow disk over commit :returns: a LibvirtLiveMigrateData object @@ -9159,7 +9159,7 @@ class LibvirtDriver(driver.ComputeDriver): results from check_can_live_migrate_destination. :param context: security context - :param instance: nova.db.sqlalchemy.models.Instance + :param instance: nova.db.main.models.Instance :param dest_check_data: result of check_can_live_migrate_destination :param block_device_info: result of _get_instance_block_device_info :returns: a LibvirtLiveMigrateData object @@ -9414,7 +9414,7 @@ class LibvirtDriver(driver.ComputeDriver): :param context: security context :param instance: - nova.db.sqlalchemy.models.Instance object + nova.db.main.models.Instance object instance object that is migrated. :param dest: destination host :param post_method: @@ -9491,7 +9491,7 @@ class LibvirtDriver(driver.ComputeDriver): :param context: security context :param instance: - nova.db.sqlalchemy.models.Instance object + nova.db.main.models.Instance object instance object that is migrated. :param dest: destination host :param block_migration: if true, do block migration. @@ -9915,7 +9915,7 @@ class LibvirtDriver(driver.ComputeDriver): :param context: security context :param instance: - nova.db.sqlalchemy.models.Instance object + nova.db.main.models.Instance object instance object that is migrated. :param dest: destination host :param post_method: @@ -10310,7 +10310,7 @@ class LibvirtDriver(driver.ComputeDriver): disk_info, fallback_from_host=None): """:param context: security context :param instance: - nova.db.sqlalchemy.models.Instance object + nova.db.main.models.Instance object instance object that is migrated. :param instance_dir: instance path to use, calculated externally to handle block @@ -10421,7 +10421,7 @@ class LibvirtDriver(driver.ComputeDriver): :param context: security context :param instance: - nova.db.sqlalchemy.models.Instance object + nova.db.main.models.Instance object instance object that is migrated. :param network_info: instance network information :param block_migration: if true, post operation of block_migration. diff --git a/releasenotes/notes/drop-database-use_db_reconnect-opt-7e0062d3da76032a.yaml b/releasenotes/notes/drop-database-use_db_reconnect-opt-7e0062d3da76032a.yaml new file mode 100644 index 0000000000..6957128b67 --- /dev/null +++ b/releasenotes/notes/drop-database-use_db_reconnect-opt-7e0062d3da76032a.yaml @@ -0,0 +1,9 @@ +--- +upgrade: + - | + Support for automatically retrying all database interactions by configuring + the ``[database] use_db_reconnect`` config option has been removed. This + behavior was only ever supported for interactions with the main database + and was generally not necessary as a number of lookups were already + explicitly wrapped in retries. The ``[database] use_db_reconnect`` option + is provided by oslo.db and will now be ignored by nova. diff --git a/tools/generate-schemas b/tools/generate-schemas index c35078e758..4df396bf8c 100755 --- a/tools/generate-schemas +++ b/tools/generate-schemas @@ -27,7 +27,7 @@ set -o xtrace set -e source .tox/py36/bin/activate -pushd nova/db/sqlalchemy/migrate_repo +pushd nova/db/main/legacy_migrations INIT_VERSION=$(ls -1 versions/ | head -1 | awk -F_ '{print $1}') INIT_VERSION=$(($INIT_VERSION-1))