diff --git a/nova/api/openstack/compute/schemas/flavor_manage.py b/nova/api/openstack/compute/schemas/flavor_manage.py index 347f557efc..a035ed1bd0 100644 --- a/nova/api/openstack/compute/schemas/flavor_manage.py +++ b/nova/api/openstack/compute/schemas/flavor_manage.py @@ -15,7 +15,7 @@ import copy from nova.api.validation import parameter_types -from nova import db +from nova.db import api as db create = { 'type': 'object', diff --git a/nova/api/openstack/compute/schemas/quota_sets.py b/nova/api/openstack/compute/schemas/quota_sets.py index fddf074ca4..549617ad7d 100644 --- a/nova/api/openstack/compute/schemas/quota_sets.py +++ b/nova/api/openstack/compute/schemas/quota_sets.py @@ -15,7 +15,7 @@ import copy from nova.api.validation import parameter_types -from nova import db +from nova.db import api as db common_quota = { 'type': ['integer', 'string'], diff --git a/nova/api/validation/parameter_types.py b/nova/api/validation/parameter_types.py index edd01070ac..49d84f7801 100644 --- a/nova/api/validation/parameter_types.py +++ b/nova/api/validation/parameter_types.py @@ -21,7 +21,7 @@ import unicodedata import six -from nova import db +from nova.db import api as db from nova.i18n import _ from nova.objects import tag diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index 1edc9f0187..c696393f0f 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -50,7 +50,7 @@ from nova.cmd import common as cmd_common import nova.conf from nova import config from nova import context -from nova import db +from nova.db import api as db from nova.db import migration from nova.db.sqlalchemy import api as sa_db from nova import exception diff --git a/nova/cmd/policy.py b/nova/cmd/policy.py index 9026aed628..dee995b121 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 import db +from nova.db import api as db from nova import exception from nova.i18n import _ from nova import policies diff --git a/nova/compute/flavors.py b/nova/compute/flavors.py index 5bc08e4f74..a1f06ea42f 100644 --- a/nova/compute/flavors.py +++ b/nova/compute/flavors.py @@ -27,7 +27,7 @@ import six from nova.api.validation import parameter_types import nova.conf from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova.i18n import _ from nova import objects diff --git a/nova/compute/instance_list.py b/nova/compute/instance_list.py index 05c8322a38..d92629bcf0 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 import db +from nova.db 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 9ccbe8fb8c..a2b70c689b 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 import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import base diff --git a/nova/console/xvp.py b/nova/console/xvp.py index cdaf54b58f..4d926dcae2 100644 --- a/nova/console/xvp.py +++ b/nova/console/xvp.py @@ -25,7 +25,7 @@ from oslo_utils import excutils import nova.conf from nova import context -from nova import db +from nova.db import api as db from nova.i18n import _ diff --git a/nova/context.py b/nova/context.py index 56b6cd2e30..58ea26a993 100644 --- a/nova/context.py +++ b/nova/context.py @@ -356,7 +356,7 @@ def set_target_cell(context, cell_mapping): global CELL_CACHE if cell_mapping is not None: # avoid circular import - from nova import db + from nova.db 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 63b3b6fb08..8c26ee86a2 100644 --- a/nova/db/__init__.py +++ b/nova/db/__init__.py @@ -1,7 +1,3 @@ -# 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 @@ -13,8 +9,5 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -""" -DB abstraction for Nova -""" - -from nova.db.api import * # noqa +"""Use nova.db.api instead. In the past this file imported * from there, +which led to unwanted imports.""" diff --git a/nova/db/base.py b/nova/db/base.py index c52ad385f4..7285b61643 100644 --- a/nova/db/base.py +++ b/nova/db/base.py @@ -16,7 +16,7 @@ """Base class for classes that need database access.""" -import nova.db +import nova.db.api class Base(object): @@ -24,4 +24,4 @@ class Base(object): def __init__(self): super(Base, self).__init__() - self.db = nova.db + self.db = nova.db.api diff --git a/nova/hacking/checks.py b/nova/hacking/checks.py index 3780f89761..e6bbab2d27 100644 --- a/nova/hacking/checks.py +++ b/nova/hacking/checks.py @@ -154,8 +154,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 import db"): - yield (0, "N307: nova.db import not allowed in nova/virt/*") + if logical_line.startswith("from nova.db import api"): + yield (0, "N307: nova.db.api import not allowed in nova/virt/*") def no_db_session_in_public_api(logical_line, filename): diff --git a/nova/objects/agent.py b/nova/objects/agent.py index 1474fc50d3..9f5884453d 100644 --- a/nova/objects/agent.py +++ b/nova/objects/agent.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import base diff --git a/nova/objects/bandwidth_usage.py b/nova/objects/bandwidth_usage.py index 572a6e15b1..753309be36 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 import db +from nova.db 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 340128c512..180dc06186 100644 --- a/nova/objects/block_device.py +++ b/nova/objects/block_device.py @@ -21,7 +21,7 @@ from oslo_utils import versionutils from nova import block_device from nova.cells import opts as cells_opts from nova.cells import rpcapi as cells_rpcapi -from nova import db +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 import exception diff --git a/nova/objects/compute_node.py b/nova/objects/compute_node.py index 3d9ff538c8..4c99a8cfae 100644 --- a/nova/objects/compute_node.py +++ b/nova/objects/compute_node.py @@ -18,7 +18,7 @@ from oslo_utils import uuidutils from oslo_utils import versionutils import nova.conf -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import models from nova import exception from nova import objects diff --git a/nova/objects/console_auth_token.py b/nova/objects/console_auth_token.py index 8eef55dcf2..d5d01ab039 100644 --- a/nova/objects/console_auth_token.py +++ b/nova/objects/console_auth_token.py @@ -19,7 +19,7 @@ from oslo_utils import strutils from oslo_utils import timeutils from oslo_utils import uuidutils -from nova import db +from nova.db import api as db from nova import exception from nova.i18n import _ from nova.objects import base diff --git a/nova/objects/dns_domain.py b/nova/objects/dns_domain.py index 020e3ad5d7..b517c7ec69 100644 --- a/nova/objects/dns_domain.py +++ b/nova/objects/dns_domain.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from nova import db +from nova.db import api as db from nova import objects from nova.objects import base from nova.objects import fields diff --git a/nova/objects/ec2.py b/nova/objects/ec2.py index 49be2c1cc3..b4cc0b462a 100644 --- a/nova/objects/ec2.py +++ b/nova/objects/ec2.py @@ -13,7 +13,7 @@ # under the License. from nova.api.ec2 import ec2utils -from nova import db +from nova.db import api as db from nova import exception from nova.objects import base from nova.objects import fields diff --git a/nova/objects/fixed_ip.py b/nova/objects/fixed_ip.py index a423749ea0..4f0e05a3e5 100644 --- a/nova/objects/fixed_ip.py +++ b/nova/objects/fixed_ip.py @@ -15,7 +15,7 @@ from oslo_utils import timeutils from oslo_utils import versionutils -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import models from nova import exception diff --git a/nova/objects/floating_ip.py b/nova/objects/floating_ip.py index 960a75a321..8e799bdbab 100644 --- a/nova/objects/floating_ip.py +++ b/nova/objects/floating_ip.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import models from nova import exception diff --git a/nova/objects/instance.py b/nova/objects/instance.py index dadb9395dc..73af5d86a2 100644 --- a/nova/objects/instance.py +++ b/nova/objects/instance.py @@ -30,7 +30,7 @@ from nova.cells import rpcapi as cells_rpcapi from nova.cells import utils as cells_utils from nova.compute import task_states from nova.compute import vm_states -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import models from nova import exception diff --git a/nova/objects/instance_action.py b/nova/objects/instance_action.py index 1c6d64eefd..0f3832d821 100644 --- a/nova/objects/instance_action.py +++ b/nova/objects/instance_action.py @@ -15,7 +15,7 @@ from oslo_utils import timeutils from oslo_utils import versionutils -from nova import db +from nova.db import api as db from nova import objects from nova.objects import base from nova.objects import fields diff --git a/nova/objects/instance_fault.py b/nova/objects/instance_fault.py index 46db8bd83f..3010145e7e 100644 --- a/nova/objects/instance_fault.py +++ b/nova/objects/instance_fault.py @@ -18,7 +18,7 @@ from oslo_log import log as logging from nova.cells import opts as cells_opts from nova.cells import rpcapi as cells_rpcapi -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import base diff --git a/nova/objects/instance_info_cache.py b/nova/objects/instance_info_cache.py index 331719b423..4b1a1285cb 100644 --- a/nova/objects/instance_info_cache.py +++ b/nova/objects/instance_info_cache.py @@ -16,7 +16,7 @@ from oslo_log import log as logging from nova.cells import opts as cells_opts from nova.cells import rpcapi as cells_rpcapi -from nova import db +from nova.db import api as db from nova import exception from nova.objects import base from nova.objects import fields diff --git a/nova/objects/instance_numa_topology.py b/nova/objects/instance_numa_topology.py index 3f5809632f..ce7590716f 100644 --- a/nova/objects/instance_numa_topology.py +++ b/nova/objects/instance_numa_topology.py @@ -15,7 +15,7 @@ from oslo_serialization import jsonutils from oslo_utils import versionutils -from nova import db +from nova.db import api as db from nova import exception from nova.objects import base from nova.objects import fields as obj_fields diff --git a/nova/objects/instance_pci_requests.py b/nova/objects/instance_pci_requests.py index 711553d3b7..7a4f0b62c8 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 import db +from nova.db 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 0e0eb75847..6c141140cd 100644 --- a/nova/objects/keypair.py +++ b/nova/objects/keypair.py @@ -17,7 +17,7 @@ from oslo_db.sqlalchemy import utils as sqlalchemyutils from oslo_log import log as logging from oslo_utils import versionutils -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import api_models from nova.db.sqlalchemy import models as main_models diff --git a/nova/objects/migration.py b/nova/objects/migration.py index 8393a108b8..138e7937f7 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 import db +from nova.db 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 9774eeada5..cbc3adc1aa 100644 --- a/nova/objects/migration_context.py +++ b/nova/objects/migration_context.py @@ -15,7 +15,7 @@ from oslo_serialization import jsonutils from oslo_utils import versionutils -from nova import db +from nova.db import api as db from nova import exception from nova.objects import base from nova.objects import fields diff --git a/nova/objects/network.py b/nova/objects/network.py index 729c2aa69d..ec9819773d 100644 --- a/nova/objects/network.py +++ b/nova/objects/network.py @@ -16,7 +16,7 @@ import netaddr from oslo_utils import versionutils import nova.conf -from nova import db +from nova.db import api as db from nova import exception from nova.i18n import _ from nova import objects diff --git a/nova/objects/pci_device.py b/nova/objects/pci_device.py index 2c85c67657..56492a1d3d 100644 --- a/nova/objects/pci_device.py +++ b/nova/objects/pci_device.py @@ -21,7 +21,7 @@ from oslo_utils import uuidutils from oslo_utils import versionutils import six -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import base diff --git a/nova/objects/quotas.py b/nova/objects/quotas.py index ee5dbfdeda..574107c1a4 100644 --- a/nova/objects/quotas.py +++ b/nova/objects/quotas.py @@ -16,7 +16,7 @@ import collections from oslo_db import exception as db_exc -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import api_models from nova.db.sqlalchemy import models as main_models diff --git a/nova/objects/security_group.py b/nova/objects/security_group.py index 35755dece7..ecbdfba0c9 100644 --- a/nova/objects/security_group.py +++ b/nova/objects/security_group.py @@ -15,7 +15,7 @@ from oslo_utils import uuidutils from oslo_utils import versionutils -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import models from nova import objects diff --git a/nova/objects/security_group_rule.py b/nova/objects/security_group_rule.py index eea7019fab..2338cdf5cd 100644 --- a/nova/objects/security_group_rule.py +++ b/nova/objects/security_group_rule.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import base diff --git a/nova/objects/service.py b/nova/objects/service.py index 77dbe0508c..e7a531d43b 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 import db +from nova.db 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 081999c17b..8088fdf537 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 import db +from nova.db 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 687799b276..ef40c56582 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 import db +from nova.db 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 e4dd7e46c2..ed4d8c9dda 100644 --- a/nova/objects/trusted_certs.py +++ b/nova/objects/trusted_certs.py @@ -12,7 +12,7 @@ from oslo_serialization import jsonutils -from nova import db +from nova.db 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 9ffac10d7b..78c9aa7767 100644 --- a/nova/objects/vcpu_model.py +++ b/nova/objects/vcpu_model.py @@ -12,7 +12,7 @@ from oslo_serialization import jsonutils -from nova import db +from nova.db 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 cde7cf6d5e..4573114b82 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 import db +from nova.db 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 659611e538..6e4ead79a4 100644 --- a/nova/objects/virtual_interface.py +++ b/nova/objects/virtual_interface.py @@ -14,7 +14,7 @@ from oslo_utils import versionutils -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import base diff --git a/nova/objects/volume_usage.py b/nova/objects/volume_usage.py index 93b7975930..d7d3574523 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 import db +from nova.db 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 c8e4ad3168..ff1d52a4ef 100644 --- a/nova/quota.py +++ b/nova/quota.py @@ -23,7 +23,7 @@ from oslo_utils import importutils import nova.conf from nova import context as nova_context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova import utils diff --git a/nova/test.py b/nova/test.py index 63889d9b46..bff54624fe 100644 --- a/nova/test.py +++ b/nova/test.py @@ -52,7 +52,7 @@ import testtools from nova.api.openstack.placement.objects import resource_provider from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova.network import manager as network_manager from nova.network.security_group import openstack_driver diff --git a/nova/tests/functional/api_sample_tests/test_agents.py b/nova/tests/functional/api_sample_tests/test_agents.py index 346b67913b..6702a1092d 100644 --- a/nova/tests/functional/api_sample_tests/test_agents.py +++ b/nova/tests/functional/api_sample_tests/test_agents.py @@ -54,10 +54,14 @@ class AgentsJsonTest(api_sample_base.ApiSampleTestBaseV21): def fake_agent_build_destroy(context, agent_update_id): pass - self.stub_out("nova.db.agent_build_create", fake_agent_build_create) - self.stub_out("nova.db.agent_build_get_all", fake_agent_build_get_all) - self.stub_out("nova.db.agent_build_update", fake_agent_build_update) - self.stub_out("nova.db.agent_build_destroy", fake_agent_build_destroy) + self.stub_out("nova.db.api.agent_build_create", + fake_agent_build_create) + self.stub_out("nova.db.api.agent_build_get_all", + fake_agent_build_get_all) + self.stub_out("nova.db.api.agent_build_update", + fake_agent_build_update) + self.stub_out("nova.db.api.agent_build_destroy", + fake_agent_build_destroy) def test_agent_create(self): # Creates a new agent build. diff --git a/nova/tests/functional/api_sample_tests/test_cells.py b/nova/tests/functional/api_sample_tests/test_cells.py index feb3fd58e8..4824b5b5e2 100644 --- a/nova/tests/functional/api_sample_tests/test_cells.py +++ b/nova/tests/functional/api_sample_tests/test_cells.py @@ -56,7 +56,7 @@ class CellsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21): 'is_parent': our_id % 2 == 0}) self.cell_list.append(cell) - self.stub_out('nova.db.cell_get_all', _fake_cell_get_all) + self.stub_out('nova.db.api.cell_get_all', _fake_cell_get_all) self.stub_out('nova.cells.rpcapi.CellsAPI.cell_get', _fake_cell_get) def test_cells_empty_list(self): 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 8b39760fc0..7ae24c6afc 100644 --- a/nova/tests/functional/api_sample_tests/test_migrate_server.py +++ b/nova/tests/functional/api_sample_tests/test_migrate_server.py @@ -65,7 +65,8 @@ class MigrateServerSamplesJsonTest(test_servers.ServersSampleBase): versionutils.convert_version_to_int('1.0')), disabled=False) return {'compute_node': [service]} - self.stub_out("nova.db.service_get_by_compute_host", fake_get_compute) + self.stub_out("nova.db.api.service_get_by_compute_host", + fake_get_compute) response = self._do_post('servers/%s/action' % self.uuid, 'live-migrate-server', 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 4616e0fc9b..4a5ee20b25 100644 --- a/nova/tests/functional/api_sample_tests/test_server_migrations.py +++ b/nova/tests/functional/api_sample_tests/test_server_migrations.py @@ -19,7 +19,7 @@ import mock from nova.conductor import manager as conductor_manager from nova import context -from nova import db +from nova.db 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_servers.py b/nova/tests/functional/api_sample_tests/test_servers.py index c1e2212cbd..f1c42b8fab 100644 --- a/nova/tests/functional/api_sample_tests/test_servers.py +++ b/nova/tests/functional/api_sample_tests/test_servers.py @@ -99,8 +99,9 @@ class ServersSampleJsonTest(ServersSampleBase): use_common_server_api_samples=self.use_common_server_post) def test_servers_get(self): - self.stub_out('nova.db.block_device_mapping_get_all_by_instance_uuids', - fakes.stub_bdm_get_all_by_instance_uuids) + self.stub_out( + 'nova.db.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) subs = {} @@ -125,8 +126,9 @@ class ServersSampleJsonTest(ServersSampleBase): self._verify_response('servers-list-resp', subs, response, 200) def test_servers_details(self): - self.stub_out('nova.db.block_device_mapping_get_all_by_instance_uuids', - fakes.stub_bdm_get_all_by_instance_uuids) + self.stub_out( + 'nova.db.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') subs = {} diff --git a/nova/tests/functional/api_sample_tests/test_services.py b/nova/tests/functional/api_sample_tests/test_services.py index 29e129e22f..3f827c5f52 100644 --- a/nova/tests/functional/api_sample_tests/test_services.py +++ b/nova/tests/functional/api_sample_tests/test_services.py @@ -30,11 +30,11 @@ class ServicesJsonTest(api_sample_base.ApiSampleTestBaseV21): def setUp(self): super(ServicesJsonTest, self).setUp() self.api.microversion = self.microversion - self.stub_out("nova.db.service_get_all", + self.stub_out("nova.db.api.service_get_all", test_services.fake_db_api_service_get_all) - self.stub_out("nova.db.service_get_by_host_and_binary", + self.stub_out("nova.db.api.service_get_by_host_and_binary", test_services.fake_service_get_by_host_binary) - self.stub_out("nova.db.service_update", + self.stub_out("nova.db.api.service_update", test_services.fake_service_update) self.useFixture(utils_fixture.TimeFixture(test_services.fake_utcnow())) @@ -136,8 +136,9 @@ class ServicesV253JsonTest(ServicesV211JsonTest): def fake_hm_destroy(context, host): return 1 - self.stub_out('nova.db.service_get_by_uuid', db_service_get_by_uuid) - self.stub_out('nova.db.compute_node_get_all_by_host', + self.stub_out('nova.db.api.service_get_by_uuid', + db_service_get_by_uuid) + self.stub_out('nova.db.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/api_sample_tests/test_volumes.py b/nova/tests/functional/api_sample_tests/test_volumes.py index fa6202e1a9..e2f9e0ebcc 100644 --- a/nova/tests/functional/api_sample_tests/test_volumes.py +++ b/nova/tests/functional/api_sample_tests/test_volumes.py @@ -220,7 +220,7 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase): ] return bdms - self.stub_out('nova.db.block_device_mapping_get_all_by_instance', + self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance', fake_bdms_get_all_by_instance) def fake_bdm_get_by_volume_and_instance( diff --git a/nova/tests/functional/compute/test_instance_list.py b/nova/tests/functional/compute/test_instance_list.py index 6e711b64d3..8feef9f266 100644 --- a/nova/tests/functional/compute/test_instance_list.py +++ b/nova/tests/functional/compute/test_instance_list.py @@ -14,7 +14,7 @@ import datetime from nova.compute import instance_list from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova import test diff --git a/nova/tests/functional/db/test_archive.py b/nova/tests/functional/db/test_archive.py index c6bd59556b..3071bc32bb 100644 --- a/nova/tests/functional/db/test_archive.py +++ b/nova/tests/functional/db/test_archive.py @@ -23,7 +23,7 @@ from sqlalchemy import MetaData from sqlalchemy import select from nova import context -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as sqlalchemy_api from nova.tests.functional import test_servers from nova.tests.unit import fake_network diff --git a/nova/tests/functional/db/test_instance.py b/nova/tests/functional/db/test_instance.py index b14a763dd5..dee7de065d 100644 --- a/nova/tests/functional/db/test_instance.py +++ b/nova/tests/functional/db/test_instance.py @@ -14,7 +14,7 @@ from oslo_utils import uuidutils from nova.compute import vm_states from nova import context -from nova import db +from nova.db import api as db 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 24208f9bd9..86e83c08fe 100644 --- a/nova/tests/functional/integrated_helpers.py +++ b/nova/tests/functional/integrated_helpers.py @@ -25,7 +25,7 @@ from oslo_log import log as logging import nova.conf from nova import context -from nova import db +from nova.db import api as db import nova.image.glance from nova import test from nova.tests import fixtures as nova_fixtures diff --git a/nova/tests/functional/notification_sample_tests/test_service.py b/nova/tests/functional/notification_sample_tests/test_service.py index 19cd40dbf6..facb0a6b35 100644 --- a/nova/tests/functional/notification_sample_tests/test_service.py +++ b/nova/tests/functional/notification_sample_tests/test_service.py @@ -45,9 +45,9 @@ class TestServiceUpdateNotificationSamplev2_52(TestServiceNotificationBase): def setUp(self): super(TestServiceUpdateNotificationSamplev2_52, self).setUp() - self.stub_out("nova.db.service_get_by_host_and_binary", + self.stub_out("nova.db.api.service_get_by_host_and_binary", test_services.fake_service_get_by_host_binary) - self.stub_out("nova.db.service_update", + self.stub_out("nova.db.api.service_update", test_services.fake_service_update) self.useFixture(utils_fixture.TimeFixture(test_services.fake_utcnow())) self.useFixture(fixtures.SingleCellSimple()) @@ -105,7 +105,8 @@ class TestServiceUpdateNotificationSampleLatest( if svc['uuid'] == service_uuid: return svc raise exception.ServiceNotFound(service_id=service_uuid) - self.stub_out('nova.db.service_get_by_uuid', db_service_get_by_uuid) + self.stub_out('nova.db.api.service_get_by_uuid', + db_service_get_by_uuid) def test_service_enable(self): body = {'status': 'enabled'} diff --git a/nova/tests/functional/regressions/test_bug_1746509.py b/nova/tests/functional/regressions/test_bug_1746509.py index e5e86f2660..176b64e5ae 100644 --- a/nova/tests/functional/regressions/test_bug_1746509.py +++ b/nova/tests/functional/regressions/test_bug_1746509.py @@ -11,7 +11,7 @@ # under the License. import nova.context -from nova import db +from nova.db import api as db from nova import objects from nova import test diff --git a/nova/tests/functional/test_server_group.py b/nova/tests/functional/test_server_group.py index 8fa7546f14..cb5ae2838a 100644 --- a/nova/tests/functional/test_server_group.py +++ b/nova/tests/functional/test_server_group.py @@ -19,7 +19,7 @@ import mock from oslo_config import cfg from nova import context -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova import test from nova.tests import fixtures as nova_fixtures diff --git a/nova/tests/unit/api/openstack/compute/test_access_ips.py b/nova/tests/unit/api/openstack/compute/test_access_ips.py index f1bb563118..0d70119588 100644 --- a/nova/tests/unit/api/openstack/compute/test_access_ips.py +++ b/nova/tests/unit/api/openstack/compute/test_access_ips.py @@ -37,7 +37,7 @@ class AccessIPsAPIValidationTestV21(test.TestCase): fakes.stub_out_nw_api(self) self._set_up_controller() fake.stub_out_image_service(self) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get()) self.stub_out('nova.objects.instance.Instance.save', fake_save) self.stub_out('nova.compute.api.API.rebuild', fake_rebuild) diff --git a/nova/tests/unit/api/openstack/compute/test_agents.py b/nova/tests/unit/api/openstack/compute/test_agents.py index 0b51ccf8bd..c9e986d445 100644 --- a/nova/tests/unit/api/openstack/compute/test_agents.py +++ b/nova/tests/unit/api/openstack/compute/test_agents.py @@ -16,7 +16,7 @@ import mock import webob.exc from nova.api.openstack.compute import agents as agents_v21 -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import models from nova import exception from nova import test @@ -82,10 +82,14 @@ class AgentsTestV21(test.NoDBTestCase): def setUp(self): super(AgentsTestV21, self).setUp() - self.stub_out("nova.db.agent_build_get_all", fake_agent_build_get_all) - self.stub_out("nova.db.agent_build_update", fake_agent_build_update) - self.stub_out("nova.db.agent_build_destroy", fake_agent_build_destroy) - self.stub_out("nova.db.agent_build_create", fake_agent_build_create) + self.stub_out("nova.db.api.agent_build_get_all", + fake_agent_build_get_all) + self.stub_out("nova.db.api.agent_build_update", + fake_agent_build_update) + self.stub_out("nova.db.api.agent_build_destroy", + fake_agent_build_destroy) + self.stub_out("nova.db.api.agent_build_create", + fake_agent_build_create) self.req = self._get_http_request() def _get_http_request(self): @@ -151,7 +155,7 @@ class AgentsTestV21(test.NoDBTestCase): def fake_agent_build_create_with_exited_agent(context, values): raise exception.AgentBuildExists(**values) - self.stub_out('nova.db.agent_build_create', + self.stub_out('nova.db.api.agent_build_create', fake_agent_build_create_with_exited_agent) body = {'agent': {'hypervisor': 'kvm', 'os': 'win', 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 d3142b7ea2..3e67492930 100644 --- a/nova/tests/unit/api/openstack/compute/test_availability_zone.py +++ b/nova/tests/unit/api/openstack/compute/test_availability_zone.py @@ -22,7 +22,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 import db +from nova.db import api as db from nova import exception from nova import objects from nova import test @@ -83,7 +83,7 @@ class AvailabilityZoneApiTestV21(test.NoDBTestCase): super(AvailabilityZoneApiTestV21, self).setUp() availability_zones.reset_cache() fakes.stub_out_nw_api(self) - self.stub_out('nova.db.service_get_all', fake_service_get_all) + self.stub_out('nova.db.api.service_get_all', fake_service_get_all) self.stub_out('nova.availability_zones.set_availability_zones', lambda c, services: services) self.stub_out('nova.servicegroup.API.service_is_up', diff --git a/nova/tests/unit/api/openstack/compute/test_block_device_mapping_v1.py b/nova/tests/unit/api/openstack/compute/test_block_device_mapping_v1.py index 4b534e1156..53c40e28d1 100644 --- a/nova/tests/unit/api/openstack/compute/test_block_device_mapping_v1.py +++ b/nova/tests/unit/api/openstack/compute/test_block_device_mapping_v1.py @@ -19,7 +19,7 @@ from webob import exc from nova.api.openstack.compute import servers as servers_v21 from nova.compute import api as compute_api -from nova import db +from nova.db 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_config_drive.py b/nova/tests/unit/api/openstack/compute/test_config_drive.py index c87a0b5ac4..27ecd7722d 100644 --- a/nova/tests/unit/api/openstack/compute/test_config_drive.py +++ b/nova/tests/unit/api/openstack/compute/test_config_drive.py @@ -40,9 +40,9 @@ class ConfigDriveTestV21(test.TestCase): self._setup_wsgi() def test_show(self): - self.stub_out('nova.db.instance_get', + self.stub_out('nova.db.api.instance_get', fakes.fake_instance_get()) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get()) # NOTE(sdague): because of the way extensions work, we have to # also stub out the Request compute cache with a real compute diff --git a/nova/tests/unit/api/openstack/compute/test_consoles.py b/nova/tests/unit/api/openstack/compute/test_consoles.py index 37f68dc951..3748ca666a 100644 --- a/nova/tests/unit/api/openstack/compute/test_consoles.py +++ b/nova/tests/unit/api/openstack/compute/test_consoles.py @@ -124,9 +124,9 @@ class ConsolesControllerTestV21(test.NoDBTestCase): def setUp(self): super(ConsolesControllerTestV21, self).setUp() self.instance_db = FakeInstanceDB() - self.stub_out('nova.db.instance_get', + self.stub_out('nova.db.api.instance_get', self.instance_db.return_server_by_id) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', self.instance_db.return_server_by_uuid) self.uuid = uuids.fake self.url = '/v2/fake/servers/%s/consoles' % self.uuid 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 4db92f61bf..9469b39131 100644 --- a/nova/tests/unit/api/openstack/compute/test_disk_config.py +++ b/nova/tests/unit/api/openstack/compute/test_disk_config.py @@ -63,7 +63,7 @@ class DiskConfigTestCaseV21(test.TestCase): if id_ == instance['id']: return instance - self.stub_out('nova.db.instance_get', fake_instance_get) + self.stub_out('nova.db.api.instance_get', fake_instance_get) def fake_instance_get_by_uuid(context, uuid, columns_to_join=None, use_slave=False): @@ -71,14 +71,14 @@ class DiskConfigTestCaseV21(test.TestCase): if uuid == instance['uuid']: return instance - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fake_instance_get_by_uuid) def fake_instance_get_all(context, *args, **kwargs): return FAKE_INSTANCES - self.stub_out('nova.db.instance_get_all', fake_instance_get_all) - self.stub_out('nova.db.instance_get_all_by_filters', + self.stub_out('nova.db.api.instance_get_all', fake_instance_get_all) + self.stub_out('nova.db.api.instance_get_all_by_filters', fake_instance_get_all) self.stub_out('nova.objects.Instance.save', @@ -107,26 +107,26 @@ class DiskConfigTestCaseV21(test.TestCase): def fake_instance_get_for_create(context, id_, *args, **kwargs): return (inst, inst) - self.stub_out('nova.db.instance_update_and_get_original', + self.stub_out('nova.db.api.instance_update_and_get_original', fake_instance_get_for_create) def fake_instance_get_all_for_create(context, *args, **kwargs): return [inst] - self.stub_out('nova.db.instance_get_all', + self.stub_out('nova.db.api.instance_get_all', fake_instance_get_all_for_create) - self.stub_out('nova.db.instance_get_all_by_filters', + self.stub_out('nova.db.api.instance_get_all_by_filters', fake_instance_get_all_for_create) def fake_instance_add_security_group(context, instance_id, security_group_id): pass - self.stub_out('nova.db.instance_add_security_group', + self.stub_out('nova.db.api.instance_add_security_group', fake_instance_add_security_group) return inst - self.stub_out('nova.db.instance_create', fake_instance_create) + self.stub_out('nova.db.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_extended_availability_zone.py b/nova/tests/unit/api/openstack/compute/test_extended_availability_zone.py index 45fe240e72..ab1325d1f6 100644 --- a/nova/tests/unit/api/openstack/compute/test_extended_availability_zone.py +++ b/nova/tests/unit/api/openstack/compute/test_extended_availability_zone.py @@ -84,7 +84,7 @@ class ExtendedAvailabilityZoneTestV21(test.TestCase): self.stub_out('nova.availability_zones.get_host_availability_zone', fake_get_host_availability_zone) return_server = fakes.fake_instance_get() - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) def _make_request(self, url): req = fakes.HTTPRequest.blank(url) diff --git a/nova/tests/unit/api/openstack/compute/test_extended_server_attributes.py b/nova/tests/unit/api/openstack/compute/test_extended_server_attributes.py index dd01d14c01..8f55c001e8 100644 --- a/nova/tests/unit/api/openstack/compute/test_extended_server_attributes.py +++ b/nova/tests/unit/api/openstack/compute/test_extended_server_attributes.py @@ -85,7 +85,7 @@ class ExtendedServerAttributesTestV21(test.TestCase): fakes.stub_out_secgroup_api(self) self.stub_out('nova.compute.api.API.get', fake_compute_get) self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all) - self.stub_out('nova.db.instance_get_by_uuid', fake_compute_get) + self.stub_out('nova.db.api.instance_get_by_uuid', fake_compute_get) def _make_request(self, url): req = fakes.HTTPRequest.blank(url) diff --git a/nova/tests/unit/api/openstack/compute/test_extended_status.py b/nova/tests/unit/api/openstack/compute/test_extended_status.py index 0cb28d70d2..cbaa1a2ef5 100644 --- a/nova/tests/unit/api/openstack/compute/test_extended_status.py +++ b/nova/tests/unit/api/openstack/compute/test_extended_status.py @@ -69,7 +69,7 @@ class ExtendedStatusTestV21(test.TestCase): self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all) self._set_flags() return_server = fakes.fake_instance_get() - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) def _get_server(self, body): return jsonutils.loads(body).get('server') diff --git a/nova/tests/unit/api/openstack/compute/test_extended_volumes.py b/nova/tests/unit/api/openstack/compute/test_extended_volumes.py index 702745ca49..8fb8e771e7 100644 --- a/nova/tests/unit/api/openstack/compute/test_extended_volumes.py +++ b/nova/tests/unit/api/openstack/compute/test_extended_volumes.py @@ -94,12 +94,13 @@ class ExtendedVolumesTestV21(test.TestCase): fakes.stub_out_secgroup_api(self) self.stub_out('nova.compute.api.API.get', fake_compute_get) self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all) - self.stub_out('nova.db.block_device_mapping_get_all_by_instance_uuids', - fake_bdms_get_all_by_instance_uuids) + self.stub_out( + 'nova.db.api.block_device_mapping_get_all_by_instance_uuids', + fake_bdms_get_all_by_instance_uuids) self._setUp() self.app = self._setup_app() return_server = fakes.fake_instance_get() - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) def _setup_app(self): return fakes.wsgi_app_v21() diff --git a/nova/tests/unit/api/openstack/compute/test_flavor_manage.py b/nova/tests/unit/api/openstack/compute/test_flavor_manage.py index c7c356107c..2b6048d45c 100644 --- a/nova/tests/unit/api/openstack/compute/test_flavor_manage.py +++ b/nova/tests/unit/api/openstack/compute/test_flavor_manage.py @@ -22,7 +22,7 @@ from nova.api.openstack import api_version_request from nova.api.openstack.compute import flavor_access as flavor_access_v21 from nova.api.openstack.compute import flavor_manage as flavormanage_v21 from nova.compute import flavors -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova import policy diff --git a/nova/tests/unit/api/openstack/compute/test_floating_ip_dns.py b/nova/tests/unit/api/openstack/compute/test_floating_ip_dns.py index 54c2e3ffd7..275e14b8a4 100644 --- a/nova/tests/unit/api/openstack/compute/test_floating_ip_dns.py +++ b/nova/tests/unit/api/openstack/compute/test_floating_ip_dns.py @@ -21,7 +21,7 @@ import webob from nova.api.openstack.compute import floating_ip_dns \ as fipdns_v21 from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import network from nova import test diff --git a/nova/tests/unit/api/openstack/compute/test_floating_ips.py b/nova/tests/unit/api/openstack/compute/test_floating_ips.py index 7ba0704e49..f8934f5cab 100644 --- a/nova/tests/unit/api/openstack/compute/test_floating_ips.py +++ b/nova/tests/unit/api/openstack/compute/test_floating_ips.py @@ -21,7 +21,7 @@ import webob from nova.api.openstack.compute import floating_ips as fips_v21 from nova import compute from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import network from nova import objects @@ -238,7 +238,7 @@ class FloatingIpTestV21(test.TestCase): stub_nw_info(self)) fake_network.stub_out_nw_api_get_instance_nw_info(self) - self.stub_out('nova.db.instance_get', + self.stub_out('nova.db.api.instance_get', fake_instance_get) self.context = context.get_admin_context() @@ -942,7 +942,7 @@ class ExtendedFloatingIpTestV21(test.TestCase): stub_nw_info(self)) fake_network.stub_out_nw_api_get_instance_nw_info(self) - self.stub_out('nova.db.instance_get', + self.stub_out('nova.db.api.instance_get', fake_instance_get) self.context = context.get_admin_context() diff --git a/nova/tests/unit/api/openstack/compute/test_hide_server_addresses.py b/nova/tests/unit/api/openstack/compute/test_hide_server_addresses.py index 9fbcabfe3f..d084271a3f 100644 --- a/nova/tests/unit/api/openstack/compute/test_hide_server_addresses.py +++ b/nova/tests/unit/api/openstack/compute/test_hide_server_addresses.py @@ -47,7 +47,7 @@ class HideServerAddressesTestV21(test.TestCase): fakes.stub_out_nw_api(self) fakes.stub_out_secgroup_api(self) return_server = fakes.fake_instance_get() - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) self._setup_wsgi() def _make_request(self, url): diff --git a/nova/tests/unit/api/openstack/compute/test_hosts.py b/nova/tests/unit/api/openstack/compute/test_hosts.py index d7464b4361..48ac5e9a26 100644 --- a/nova/tests/unit/api/openstack/compute/test_hosts.py +++ b/nova/tests/unit/api/openstack/compute/test_hosts.py @@ -21,7 +21,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 import db +from nova.db import api as db from nova import exception from nova import test from nova.tests import fixtures @@ -136,10 +136,10 @@ class HostTestCaseV21(test.TestCase): def _setup_stubs(self): # Pretend we have fake_hosts.HOST_LIST in the DB - self.stub_out('nova.db.service_get_all', + self.stub_out('nova.db.api.service_get_all', stub_service_get_all) # Only hosts in our fake DB exist - self.stub_out('nova.db.service_get_by_host_and_binary', + self.stub_out('nova.db.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', @@ -234,7 +234,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.service_get_all', + self.stub_out('nova.db.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 f5e05886fd..00ce1dd5b5 100644 --- a/nova/tests/unit/api/openstack/compute/test_hypervisors.py +++ b/nova/tests/unit/api/openstack/compute/test_hypervisors.py @@ -248,7 +248,7 @@ class HypervisorsTestV21(test.NoDBTestCase): host_api.compute_node_get = mock.MagicMock( side_effect=fake_compute_node_get) - self.stub_out('nova.db.compute_node_statistics', + self.stub_out('nova.db.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 5b70f99787..a844a98c21 100644 --- a/nova/tests/unit/api/openstack/compute/test_instance_actions.py +++ b/nova/tests/unit/api/openstack/compute/test_instance_actions.py @@ -160,7 +160,7 @@ class InstanceActionsTestV21(test.NoDBTestCase): actions.append(action) return actions - self.stub_out('nova.db.actions_get', fake_get_actions) + self.stub_out('nova.db.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']: @@ -181,8 +181,8 @@ class InstanceActionsTestV21(test.NoDBTestCase): events.append(event) return events - self.stub_out('nova.db.action_get_by_request_id', fake_get_action) - self.stub_out('nova.db.action_events_get', fake_get_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) req = self._get_http_req('os-instance-actions/1', use_admin_context=True) res_dict = self.controller.show(req, FAKE_UUID, FAKE_REQUEST_ID) @@ -203,8 +203,8 @@ class InstanceActionsTestV21(test.NoDBTestCase): def fake_get_events(context, action_id): return self.fake_events[action_id] - self.stub_out('nova.db.action_get_by_request_id', fake_get_action) - self.stub_out('nova.db.action_events_get', fake_get_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._set_policy_rules() req = self._get_http_req('os-instance-actions/1') @@ -228,7 +228,7 @@ class InstanceActionsTestV21(test.NoDBTestCase): def fake_no_action(context, uuid, action_id): return None - self.stub_out('nova.db.action_get_by_request_id', fake_no_action) + self.stub_out('nova.db.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) 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 46d0274b31..b6f7a97845 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 @@ -122,8 +122,8 @@ class InstanceUsageAuditLogTestV21(test.NoDBTestCase): self.stub_out('nova.utils.last_completed_audit_period', fake_last_completed_audit_period) - self.stub_out('nova.db.service_get_all', fake_service_get_all) - self.stub_out('nova.db.task_log_get_all', fake_task_log_get_all) + 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.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 c16856b9d4..af8b4e7057 100644 --- a/nova/tests/unit/api/openstack/compute/test_keypairs.py +++ b/nova/tests/unit/api/openstack/compute/test_keypairs.py @@ -79,11 +79,11 @@ class KeypairsTestV21(test.TestCase): fakes.stub_out_networking(self) fakes.stub_out_secgroup_api(self) - self.stub_out("nova.db.key_pair_get_all_by_user", + self.stub_out("nova.db.api.key_pair_get_all_by_user", db_key_pair_get_all_by_user) - self.stub_out("nova.db.key_pair_create", + self.stub_out("nova.db.api.key_pair_create", db_key_pair_create) - self.stub_out("nova.db.key_pair_destroy", + self.stub_out("nova.db.api.key_pair_destroy", db_key_pair_destroy) self._setup_app_and_controller() @@ -287,7 +287,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.key_pair_destroy", + self.stub_out("nova.db.api.key_pair_destroy", db_key_pair_get_not_found) self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete, self.req, 'FAKE') @@ -299,7 +299,7 @@ class KeypairsTestV21(test.TestCase): name='foo', public_key='XXX', fingerprint='YYY', type='ssh') - self.stub_out("nova.db.key_pair_get", _db_key_pair_get) + self.stub_out("nova.db.api.key_pair_get", _db_key_pair_get) res_dict = self.controller.show(self.req, 'FAKE') self.assertEqual('foo', res_dict['keypair']['name']) @@ -312,15 +312,15 @@ 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.key_pair_get", _db_key_pair_get) + self.stub_out("nova.db.api.key_pair_get", _db_key_pair_get) self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, self.req, 'FAKE') def test_show_server(self): - self.stub_out('nova.db.instance_get', + self.stub_out('nova.db.api.instance_get', fakes.fake_instance_get()) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get()) # NOTE(sdague): because of the way extensions work, we have to # also stub out the Request compute cache with a real compute @@ -626,7 +626,7 @@ class KeypairsTestV235(test.TestCase): super(KeypairsTestV235, self).setUp() self._setup_app_and_controller() - @mock.patch("nova.db.key_pair_get_all_by_user") + @mock.patch("nova.db.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 @@ -661,7 +661,7 @@ class KeypairsTestV235(test.TestCase): self.assertRaises(exception.ValidationError, self.controller.index, req) - @mock.patch("nova.db.key_pair_get_all_by_user") + @mock.patch("nova.db.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 diff --git a/nova/tests/unit/api/openstack/compute/test_multiple_create.py b/nova/tests/unit/api/openstack/compute/test_multiple_create.py index 7a7c9f91c0..ac9b1db1d5 100644 --- a/nova/tests/unit/api/openstack/compute/test_multiple_create.py +++ b/nova/tests/unit/api/openstack/compute/test_multiple_create.py @@ -80,15 +80,16 @@ class MultiCreateExtensionTestV21(test.TestCase): fakes.stub_out_key_pair_funcs(self) fake.stub_out_image_service(self) - self.stub_out('nova.db.instance_add_security_group', + self.stub_out('nova.db.api.instance_add_security_group', return_security_group) - self.stub_out('nova.db.project_get_networks', project_get_networks) + self.stub_out('nova.db.api.project_get_networks', project_get_networks) self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance', create_db_entry_for_new_instance) - self.stub_out('nova.db.instance_system_metadata_update', fake_method) - self.stub_out('nova.db.instance_get', instance_get) - self.stub_out('nova.db.instance_update', instance_update) - self.stub_out('nova.db.instance_update_and_get_original', + self.stub_out('nova.db.api.instance_system_metadata_update', + fake_method) + self.stub_out('nova.db.api.instance_get', instance_get) + self.stub_out('nova.db.api.instance_update', instance_update) + self.stub_out('nova.db.api.instance_update_and_get_original', server_update) self.stub_out('nova.network.manager.VlanManager.allocate_fixed_ip', fake_method) diff --git a/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py b/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py index 98c6f91340..b663ae1fd4 100644 --- a/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py +++ b/nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py @@ -24,7 +24,7 @@ import webob from nova.api.openstack.compute import security_groups from nova import context -import nova.db +import nova.db.api from nova import exception from nova.network import model from nova.network.neutronv2 import api as neutron_api @@ -164,7 +164,7 @@ class TestNeutronSecurityGroupsV21( device_id=test_security_groups.FAKE_UUID1) expected = [{'rules': [], 'tenant_id': 'fake', 'id': sg['id'], 'name': 'test', 'description': 'test-description'}] - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', test_security_groups.return_server_by_uuid) req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/os-security-groups' % test_security_groups.FAKE_UUID1) @@ -202,7 +202,7 @@ class TestNeutronSecurityGroupsV21( _context, instance_obj.Instance(), db_inst, expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS) neutron = neutron_api.API() - with mock.patch.object(nova.db, 'instance_get_by_uuid', + with mock.patch.object(nova.db.api, 'instance_get_by_uuid', return_value=db_inst): neutron.allocate_for_instance(_context, instance, False, None, security_groups=[sg['id']]) @@ -231,7 +231,7 @@ class TestNeutronSecurityGroupsV21( network_id=net['network']['id'], security_groups=[sg['id']], device_id=UUID_SERVER) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', test_security_groups.return_server) body = dict(addSecurityGroup=dict(name="test")) @@ -249,7 +249,7 @@ class TestNeutronSecurityGroupsV21( network_id=net['network']['id'], security_groups=[sg1['id']], device_id=UUID_SERVER) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', test_security_groups.return_server) body = dict(addSecurityGroup=dict(name="sg1")) @@ -267,7 +267,7 @@ class TestNeutronSecurityGroupsV21( port_security_enabled=True, device_id=UUID_SERVER) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', test_security_groups.return_server) body = dict(addSecurityGroup=dict(name="test")) @@ -282,7 +282,7 @@ class TestNeutronSecurityGroupsV21( network_id=net['network']['id'], port_security_enabled=False, device_id=UUID_SERVER) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', test_security_groups.return_server) body = dict(addSecurityGroup=dict(name="test")) @@ -300,7 +300,7 @@ class TestNeutronSecurityGroupsV21( port_security_enabled=True, ip_allocation='deferred', device_id=UUID_SERVER) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', test_security_groups.return_server) body = dict(addSecurityGroup=dict(name="test")) @@ -309,7 +309,7 @@ class TestNeutronSecurityGroupsV21( self.manager._addSecurityGroup(req, UUID_SERVER, body) def test_disassociate_by_non_existing_security_group_name(self): - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', test_security_groups.return_server) body = dict(removeSecurityGroup=dict(name='non-existing')) @@ -338,7 +338,7 @@ class TestNeutronSecurityGroupsV21( network_id=net['network']['id'], security_groups=[sg['id']], device_id=UUID_SERVER) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', test_security_groups.return_server) body = dict(removeSecurityGroup=dict(name="test")) diff --git a/nova/tests/unit/api/openstack/compute/test_quotas.py b/nova/tests/unit/api/openstack/compute/test_quotas.py index 26aed6f638..bf481f164a 100644 --- a/nova/tests/unit/api/openstack/compute/test_quotas.py +++ b/nova/tests/unit/api/openstack/compute/test_quotas.py @@ -18,7 +18,7 @@ import mock import webob from nova.api.openstack.compute import quota_sets as quotas_v21 -from nova import db +from nova.db import api as db from nova import exception from nova import quota from nova import test diff --git a/nova/tests/unit/api/openstack/compute/test_security_group_default_rules.py b/nova/tests/unit/api/openstack/compute/test_security_group_default_rules.py index 75a8a1ffde..5f449ae5c3 100644 --- a/nova/tests/unit/api/openstack/compute/test_security_group_default_rules.py +++ b/nova/tests/unit/api/openstack/compute/test_security_group_default_rules.py @@ -18,7 +18,7 @@ import webob from nova.api.openstack.compute import \ security_group_default_rules as security_group_default_rules_v21 from nova import context -import nova.db +import nova.db.api from nova import exception from nova import test from nova.tests.unit.api.openstack import fakes @@ -226,7 +226,7 @@ class TestSecurityGroupDefaultRulesV21(test.TestCase): res_dict = self.controller.index(self.req) self.assertEqual(res_dict, expected) - @mock.patch('nova.db.security_group_default_rule_list', + @mock.patch('nova.db.api.security_group_default_rule_list', side_effect=(exception. SecurityGroupDefaultRuleNotFound("Rule Not Found"))) def test_non_existing_security_group_default_rules_list(self, @@ -252,7 +252,7 @@ class TestSecurityGroupDefaultRulesV21(test.TestCase): self.assertEqual(security_group_default_rule['ip_range']['cidr'], sgr['cidr']) - @mock.patch('nova.db.security_group_default_rule_get', + @mock.patch('nova.db.api.security_group_default_rule_get', side_effect=(exception. SecurityGroupDefaultRuleNotFound("Rule Not Found"))) def test_non_existing_security_group_default_rule_show(self, @@ -274,16 +274,16 @@ class TestSecurityGroupDefaultRulesV21(test.TestCase): self.assertEqual(sgr['id'], id) return security_group_default_rule_db(sgr) - self.stub_out('nova.db.security_group_default_rule_destroy', + self.stub_out('nova.db.api.security_group_default_rule_destroy', security_group_default_rule_destroy) - self.stub_out('nova.db.security_group_default_rule_get', + self.stub_out('nova.db.api.security_group_default_rule_get', return_security_group_default_rule) self.controller.delete(self.req, '1') self.assertTrue(self.called) - @mock.patch('nova.db.security_group_default_rule_destroy', + @mock.patch('nova.db.api.security_group_default_rule_destroy', side_effect=(exception. SecurityGroupDefaultRuleNotFound("Rule Not Found"))) def test_non_existing_security_group_default_rule_delete( @@ -299,8 +299,9 @@ class TestSecurityGroupDefaultRulesV21(test.TestCase): setattr(ctxt, 'project_id', 'new_project_id') - sg = nova.db.security_group_ensure_default(ctxt) - rules = nova.db.security_group_rule_get_by_security_group(ctxt, sg.id) + sg = nova.db.api.security_group_ensure_default(ctxt) + rules = nova.db.api.security_group_rule_get_by_security_group( + ctxt, sg.id) security_group_rule = rules[0] self.assertEqual(sgr['id'], security_group_rule.id) self.assertEqual(sgr['ip_protocol'], security_group_rule.protocol) 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 a65462f943..a3331b4dd4 100644 --- a/nova/tests/unit/api/openstack/compute/test_security_groups.py +++ b/nova/tests/unit/api/openstack/compute/test_security_groups.py @@ -25,7 +25,7 @@ from nova.api.openstack import wsgi from nova import compute from nova.compute import power_state from nova import context as context_maker -import nova.db +import nova.db.api from nova import exception from nova import objects from nova import test @@ -335,7 +335,7 @@ class TestSecurityGroupsV21(test.TestCase): def return_security_groups(context, project_id): return [security_group_db(sg) for sg in groups] - self.stub_out('nova.db.security_group_get_by_project', + self.stub_out('nova.db.api.security_group_get_by_project', return_security_groups) path = '/v2/fake/os-security-groups' @@ -407,13 +407,13 @@ class TestSecurityGroupsV21(test.TestCase): def return_all_security_groups(context): return [security_group_db(sg) for sg in all_groups] - self.stub_out('nova.db.security_group_get_all', + self.stub_out('nova.db.api.security_group_get_all', return_all_security_groups) def return_tenant_security_groups(context, project_id): return [security_group_db(sg) for sg in tenant_groups] - self.stub_out('nova.db.security_group_get_by_project', + self.stub_out('nova.db.api.security_group_get_by_project', return_tenant_security_groups) path = '/v2/fake/os-security-groups' @@ -469,14 +469,14 @@ class TestSecurityGroupsV21(test.TestCase): self.assertEqual(server_id, FAKE_UUID1) return return_server_by_uuid(context, server_id) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', return_instance) def return_security_groups(context, instance_uuid): self.assertEqual(instance_uuid, FAKE_UUID1) return [security_group_db(sg) for sg in groups] - self.stub_out('nova.db.security_group_get_by_instance', + self.stub_out('nova.db.api.security_group_get_by_instance', return_security_groups) # Stub out the security group API get() method to assert that we only @@ -498,8 +498,8 @@ class TestSecurityGroupsV21(test.TestCase): self.assertEqual(expected, res_dict) - @mock.patch('nova.db.instance_get_by_uuid') - @mock.patch('nova.db.security_group_get_by_instance', return_value=[]) + @mock.patch('nova.db.api.instance_get_by_uuid') + @mock.patch('nova.db.api.security_group_get_by_instance', return_value=[]) def test_get_security_group_empty_for_instance(self, mock_sec_group, mock_db_get_ins): expected = {'security_groups': []} @@ -515,8 +515,8 @@ class TestSecurityGroupsV21(test.TestCase): self.req.environ['nova.context'], FAKE_UUID1) def test_get_security_group_by_instance_non_existing(self): - self.stub_out('nova.db.instance_get', return_server_nonexistent) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', return_server_nonexistent) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_nonexistent) self.assertRaises(webob.exc.HTTPNotFound, self.server_controller.index, self.req, '1') @@ -532,7 +532,7 @@ class TestSecurityGroupsV21(test.TestCase): self.assertEqual(sg['id'], group_id) return security_group_db(sg) - self.stub_out('nova.db.security_group_get', + self.stub_out('nova.db.api.security_group_get', return_security_group) res_dict = self.controller.show(self.req, '2') @@ -564,9 +564,9 @@ class TestSecurityGroupsV21(test.TestCase): self.assertEqual(sg_update['description'], values['description']) return security_group_db(sg_update) - self.stub_out('nova.db.security_group_update', + self.stub_out('nova.db.api.security_group_update', return_update_security_group) - self.stub_out('nova.db.security_group_get', + self.stub_out('nova.db.api.security_group_get', return_security_group) res_dict = self.controller.update(self.req, '2', @@ -582,7 +582,7 @@ class TestSecurityGroupsV21(test.TestCase): self.assertEqual(sg['id'], group_id) return security_group_db(sg) - self.stub_out('nova.db.security_group_get', + self.stub_out('nova.db.api.security_group_get', return_security_group) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, @@ -607,9 +607,9 @@ class TestSecurityGroupsV21(test.TestCase): self.assertEqual(sg['id'], group_id) return security_group_db(sg) - self.stub_out('nova.db.security_group_destroy', + self.stub_out('nova.db.api.security_group_destroy', security_group_destroy) - self.stub_out('nova.db.security_group_get', + self.stub_out('nova.db.api.security_group_get', return_security_group) self.controller.delete(self.req, '1') @@ -651,9 +651,9 @@ class TestSecurityGroupsV21(test.TestCase): self.assertEqual(sg['id'], group_id) return security_group_db(sg) - self.stub_out('nova.db.security_group_in_use', + self.stub_out('nova.db.api.security_group_in_use', security_group_in_use) - self.stub_out('nova.db.security_group_get', + self.stub_out('nova.db.api.security_group_get', return_security_group) self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete, @@ -720,9 +720,9 @@ class TestSecurityGroupsV21(test.TestCase): self.controller.index(req) def test_associate_by_non_existing_security_group_name(self): - self.stub_out('nova.db.instance_get', return_server) + self.stub_out('nova.db.api.instance_get', return_server) self.assertEqual(return_server(None, '1'), - nova.db.instance_get(None, '1')) + nova.db.api.instance_get(None, '1')) body = dict(addSecurityGroup=dict(name='non-existing')) self.assertRaises(webob.exc.HTTPNotFound, @@ -736,29 +736,29 @@ class TestSecurityGroupsV21(test.TestCase): 'invalid', body) def test_associate_without_body(self): - self.stub_out('nova.db.instance_get', return_server) + self.stub_out('nova.db.api.instance_get', return_server) body = dict(addSecurityGroup=None) self.assertRaises(webob.exc.HTTPBadRequest, self.manager._addSecurityGroup, self.req, '1', body) def test_associate_no_security_group_name(self): - self.stub_out('nova.db.instance_get', return_server) + self.stub_out('nova.db.api.instance_get', return_server) body = dict(addSecurityGroup=dict()) self.assertRaises(webob.exc.HTTPBadRequest, self.manager._addSecurityGroup, self.req, '1', body) def test_associate_security_group_name_with_whitespaces(self): - self.stub_out('nova.db.instance_get', return_server) + self.stub_out('nova.db.api.instance_get', return_server) body = dict(addSecurityGroup=dict(name=" ")) self.assertRaises(webob.exc.HTTPBadRequest, self.manager._addSecurityGroup, self.req, '1', body) def test_associate_non_existing_instance(self): - self.stub_out('nova.db.instance_get', return_server_nonexistent) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', return_server_nonexistent) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_nonexistent) body = dict(addSecurityGroup=dict(name="test")) @@ -766,20 +766,20 @@ class TestSecurityGroupsV21(test.TestCase): self.manager._addSecurityGroup, self.req, '1', body) def test_associate_non_running_instance(self): - self.stub_out('nova.db.instance_get', return_non_running_server) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', return_non_running_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_non_running_server) - self.stub_out('nova.db.security_group_get_by_name', + self.stub_out('nova.db.api.security_group_get_by_name', return_security_group_without_instances) body = dict(addSecurityGroup=dict(name="test")) self.manager._addSecurityGroup(self.req, UUID_SERVER, body) def test_associate_already_associated_security_group_to_instance(self): - self.stub_out('nova.db.instance_get', return_server) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_by_uuid) - self.stub_out('nova.db.security_group_get_by_name', + self.stub_out('nova.db.api.security_group_get_by_name', return_security_group_by_name) body = dict(addSecurityGroup=dict(name="test")) @@ -787,13 +787,13 @@ class TestSecurityGroupsV21(test.TestCase): self.manager._addSecurityGroup, self.req, UUID_SERVER, body) - @mock.patch.object(nova.db, 'instance_add_security_group') + @mock.patch.object(nova.db.api, 'instance_add_security_group') def test_associate(self, mock_add_security_group): - self.stub_out('nova.db.instance_get', return_server) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_by_uuid) - self.stub_out('nova.db.security_group_get_by_name', + self.stub_out('nova.db.api.security_group_get_by_name', return_security_group_without_instances) body = dict(addSecurityGroup=dict(name="test")) @@ -804,9 +804,9 @@ class TestSecurityGroupsV21(test.TestCase): mock.ANY) def test_disassociate_by_non_existing_security_group_name(self): - self.stub_out('nova.db.instance_get', return_server) + self.stub_out('nova.db.api.instance_get', return_server) self.assertEqual(return_server(None, '1'), - nova.db.instance_get(None, '1')) + nova.db.api.instance_get(None, '1')) body = dict(removeSecurityGroup=dict(name='non-existing')) self.assertRaises(webob.exc.HTTPNotFound, @@ -814,7 +814,7 @@ class TestSecurityGroupsV21(test.TestCase): UUID_SERVER, body) def test_disassociate_by_invalid_server_id(self): - self.stub_out('nova.db.security_group_get_by_name', + self.stub_out('nova.db.api.security_group_get_by_name', return_security_group_by_name) body = dict(removeSecurityGroup=dict(name='test')) @@ -823,7 +823,7 @@ class TestSecurityGroupsV21(test.TestCase): 'invalid', body) def test_disassociate_without_body(self): - self.stub_out('nova.db.instance_get', return_server) + self.stub_out('nova.db.api.instance_get', return_server) body = dict(removeSecurityGroup=None) self.assertRaises(webob.exc.HTTPBadRequest, @@ -831,7 +831,7 @@ class TestSecurityGroupsV21(test.TestCase): '1', body) def test_disassociate_no_security_group_name(self): - self.stub_out('nova.db.instance_get', return_server) + self.stub_out('nova.db.api.instance_get', return_server) body = dict(removeSecurityGroup=dict()) self.assertRaises(webob.exc.HTTPBadRequest, @@ -839,7 +839,7 @@ class TestSecurityGroupsV21(test.TestCase): '1', body) def test_disassociate_security_group_name_with_whitespaces(self): - self.stub_out('nova.db.instance_get', return_server) + self.stub_out('nova.db.api.instance_get', return_server) body = dict(removeSecurityGroup=dict(name=" ")) self.assertRaises(webob.exc.HTTPBadRequest, @@ -847,8 +847,8 @@ class TestSecurityGroupsV21(test.TestCase): '1', body) def test_disassociate_non_existing_instance(self): - self.stub_out('nova.db.instance_get', return_server_nonexistent) - self.stub_out('nova.db.security_group_get_by_name', + self.stub_out('nova.db.api.instance_get', return_server_nonexistent) + self.stub_out('nova.db.api.security_group_get_by_name', return_security_group_by_name) body = dict(removeSecurityGroup=dict(name="test")) @@ -857,20 +857,20 @@ class TestSecurityGroupsV21(test.TestCase): self.req, '1', body) def test_disassociate_non_running_instance(self): - self.stub_out('nova.db.instance_get', return_non_running_server) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', return_non_running_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_non_running_server) - self.stub_out('nova.db.security_group_get_by_name', + self.stub_out('nova.db.api.security_group_get_by_name', return_security_group_by_name) body = dict(removeSecurityGroup=dict(name="test")) self.manager._removeSecurityGroup(self.req, UUID_SERVER, body) def test_disassociate_already_associated_security_group_to_instance(self): - self.stub_out('nova.db.instance_get', return_server) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_by_uuid) - self.stub_out('nova.db.security_group_get_by_name', + self.stub_out('nova.db.api.security_group_get_by_name', return_security_group_without_instances) body = dict(removeSecurityGroup=dict(name="test")) @@ -878,12 +878,12 @@ class TestSecurityGroupsV21(test.TestCase): self.manager._removeSecurityGroup, self.req, UUID_SERVER, body) - @mock.patch.object(nova.db, 'instance_remove_security_group') + @mock.patch.object(nova.db.api, 'instance_remove_security_group') def test_disassociate(self, mock_remove_sec_group): - self.stub_out('nova.db.instance_get', return_server) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_by_uuid) - self.stub_out('nova.db.security_group_get_by_name', + self.stub_out('nova.db.api.security_group_get_by_name', return_security_group_by_name) body = dict(removeSecurityGroup=dict(name="test")) @@ -929,7 +929,7 @@ class TestSecurityGroupRulesV21(test.TestCase): return db2 raise exception.SecurityGroupNotFound(security_group_id=group_id) - self.stub_out('nova.db.security_group_get', + self.stub_out('nova.db.api.security_group_get', return_security_group) self.parent_security_group = db2 @@ -1294,9 +1294,9 @@ class TestSecurityGroupRulesV21(test.TestCase): def security_group_rule_destroy(context, id): pass - self.stub_out('nova.db.security_group_rule_get', + self.stub_out('nova.db.api.security_group_rule_get', security_group_rule_get) - self.stub_out('nova.db.security_group_rule_destroy', + self.stub_out('nova.db.api.security_group_rule_destroy', security_group_rule_destroy) self.controller.delete(self.req, self.sg2['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 23c6efa643..c749992881 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_actions.py +++ b/nova/tests/unit/api/openstack/compute/test_server_actions.py @@ -77,10 +77,10 @@ class ServerActionsControllerTestV21(test.TestCase): def setUp(self): super(ServerActionsControllerTestV21, self).setUp() self.flags(group='glance', api_servers=['http://localhost:9292']) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get(vm_state=vm_states.ACTIVE, host='fake_host')) - self.stub_out('nova.db.instance_update_and_get_original', + self.stub_out('nova.db.api.instance_update_and_get_original', instance_update_and_get_original) fakes.stub_out_nw_api(self) @@ -195,7 +195,7 @@ class ServerActionsControllerTestV21(test.TestCase): self.req, FAKE_UUID, body=body) def test_reboot_not_found(self): - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_not_found) body = dict(reboot=dict(type="HARD")) @@ -219,7 +219,7 @@ class ServerActionsControllerTestV21(test.TestCase): def test_reboot_soft_with_soft_in_progress_raises_conflict(self): body = dict(reboot=dict(type="SOFT")) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get(vm_state=vm_states.ACTIVE, task_state=task_states.REBOOTING)) self.assertRaises(webob.exc.HTTPConflict, @@ -228,21 +228,21 @@ class ServerActionsControllerTestV21(test.TestCase): def test_reboot_hard_with_soft_in_progress_does_not_raise(self): body = dict(reboot=dict(type="HARD")) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get(vm_state=vm_states.ACTIVE, task_state=task_states.REBOOTING)) self.controller._action_reboot(self.req, FAKE_UUID, body=body) def test_reboot_hard_with_hard_in_progress(self): body = dict(reboot=dict(type="HARD")) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get(vm_state=vm_states.ACTIVE, task_state=task_states.REBOOTING_HARD)) self.controller._action_reboot(self.req, FAKE_UUID, body=body) def test_reboot_soft_with_hard_in_progress_raises_conflict(self): body = dict(reboot=dict(type="SOFT")) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get(vm_state=vm_states.ACTIVE, task_state=task_states.REBOOTING_HARD)) self.assertRaises(webob.exc.HTTPConflict, @@ -254,7 +254,7 @@ class ServerActionsControllerTestV21(test.TestCase): return_server = fakes.fake_instance_get(image_ref='2', vm_state=vm_states.ACTIVE, host='fake_host') - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) body = { "rebuild": { @@ -286,7 +286,7 @@ class ServerActionsControllerTestV21(test.TestCase): def test_rebuild_accepted_minimum(self): return_server = fakes.fake_instance_get(image_ref='2', vm_state=vm_states.ACTIVE, host='fake_host') - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) self_href = 'http://localhost/v2/servers/%s' % FAKE_UUID body = { @@ -310,7 +310,7 @@ class ServerActionsControllerTestV21(test.TestCase): def rebuild(self2, context, instance, image_href, *args, **kwargs): info['image_href_in_call'] = image_href - self.stub_out('nova.db.instance_get', + self.stub_out('nova.db.api.instance_get', fakes.fake_instance_get(vm_state=vm_states.ACTIVE)) self.stub_out('nova.compute.api.API.rebuild', rebuild) @@ -343,7 +343,7 @@ class ServerActionsControllerTestV21(test.TestCase): return_server = fakes.fake_instance_get(image_ref='2', vm_state=vm_states.ACTIVE, host='fake_host') - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) self_href = 'http://localhost/v2/servers/%s' % FAKE_UUID body = { @@ -383,7 +383,7 @@ class ServerActionsControllerTestV21(test.TestCase): return_server = fakes.fake_instance_get(metadata=metadata, vm_state=vm_states.ACTIVE, host='fake_host') - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) body = { "rebuild": { @@ -437,7 +437,7 @@ class ServerActionsControllerTestV21(test.TestCase): def test_rebuild_admin_pass(self): return_server = fakes.fake_instance_get(image_ref='2', vm_state=vm_states.ACTIVE, host='fake_host') - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) body = { "rebuild": { @@ -459,7 +459,7 @@ class ServerActionsControllerTestV21(test.TestCase): return_server = fakes.fake_instance_get(image_ref='2', vm_state=vm_states.ACTIVE, host='fake_host') - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) body = { "rebuild": { @@ -478,7 +478,7 @@ class ServerActionsControllerTestV21(test.TestCase): def server_not_found(self, instance_id, columns_to_join=None, use_slave=False): raise exception.InstanceNotFound(instance_id=instance_id) - self.stub_out('nova.db.instance_get_by_uuid', server_not_found) + self.stub_out('nova.db.api.instance_get_by_uuid', server_not_found) body = { "rebuild": { @@ -958,7 +958,7 @@ class ServerActionsControllerTestV21(test.TestCase): 'delete_on_termination': False, 'no_device': None})] - self.stub_out('nova.db.block_device_mapping_get_all_by_instance', + self.stub_out('nova.db.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'), @@ -970,7 +970,7 @@ class ServerActionsControllerTestV21(test.TestCase): vm_state=vm_states.ACTIVE, root_device_name='/dev/vda', system_metadata=system_metadata) - self.stub_out('nova.db.instance_get_by_uuid', instance) + self.stub_out('nova.db.api.instance_get_by_uuid', instance) volume = dict(id=_fake_id('a'), size=1, @@ -1069,7 +1069,7 @@ class ServerActionsControllerTestV21(test.TestCase): 'delete_on_termination': False, 'no_device': None})] - self.stub_out('nova.db.block_device_mapping_get_all_by_instance', + self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance', fake_block_device_mapping_get_all_by_instance) instance = fakes.fake_instance_get( @@ -1078,7 +1078,7 @@ class ServerActionsControllerTestV21(test.TestCase): root_device_name='/dev/vda', system_metadata={'image_test_key1': 'test_value1', 'image_test_key2': 'test_value2'}) - self.stub_out('nova.db.instance_get_by_uuid', instance) + self.stub_out('nova.db.api.instance_get_by_uuid', instance) volume = dict(id=_fake_id('a'), size=1, 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 92b6a0cda4..5ec3894a50 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 +import nova.db.api from nova import exception from nova import test from nova.tests.unit.api.openstack import fakes @@ -116,11 +116,11 @@ class ServerMetaDataTestV21(test.TestCase): def setUp(self): super(ServerMetaDataTestV21, self).setUp() fakes.stub_out_key_pair_funcs(self) - self.stub_out('nova.db.instance_get', return_server) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_by_uuid) - self.stub_out('nova.db.instance_metadata_get', + self.stub_out('nova.db.api.instance_metadata_get', return_server_metadata) self.stub_out( @@ -150,14 +150,14 @@ class ServerMetaDataTestV21(test.TestCase): self.assertEqual(expected, res_dict) def test_index_nonexistent_server(self): - self.stub_out('nova.db.instance_metadata_get', + self.stub_out('nova.db.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.instance_metadata_get', + self.stub_out('nova.db.api.instance_metadata_get', return_empty_server_metadata) req = self._get_request() res_dict = self.controller.index(req, self.uuid) @@ -171,23 +171,23 @@ class ServerMetaDataTestV21(test.TestCase): self.assertEqual(expected, res_dict) def test_show_nonexistent_server(self): - self.stub_out('nova.db.instance_metadata_get', + self.stub_out('nova.db.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.instance_metadata_get', + self.stub_out('nova.db.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.instance_metadata_get', + self.stub_out('nova.db.api.instance_metadata_get', return_server_metadata) - self.stub_out('nova.db.instance_metadata_delete', + self.stub_out('nova.db.api.instance_metadata_delete', delete_server_metadata) req = self._get_request('/key2') req.method = 'DELETE' @@ -196,7 +196,7 @@ class ServerMetaDataTestV21(test.TestCase): self.assertIsNone(res) def test_delete_nonexistent_server(self): - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_nonexistent) req = self._get_request('/key1') req.method = 'DELETE' @@ -204,7 +204,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.delete, req, self.uuid, 'key1') def test_delete_meta_not_found(self): - self.stub_out('nova.db.instance_metadata_get', + self.stub_out('nova.db.api.instance_metadata_get', return_empty_server_metadata) req = self._get_request('/key6') req.method = 'DELETE' @@ -228,7 +228,7 @@ class ServerMetaDataTestV21(test.TestCase): self.assertEqual(body, res_dict) def test_create_empty_body(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'POST' @@ -238,7 +238,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.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -250,7 +250,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.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -262,7 +262,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.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -275,7 +275,7 @@ class ServerMetaDataTestV21(test.TestCase): req, self.uuid, body=body) def test_create_malformed_container(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url + '/key1') req.method = 'PUT' @@ -287,7 +287,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.create, req, self.uuid, body=body) def test_create_malformed_data(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url + '/key1') req.method = 'PUT' @@ -299,7 +299,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.create, req, self.uuid, body=body) def test_create_nonexistent_server(self): - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_nonexistent) req = self._get_request() req.method = 'POST' @@ -353,7 +353,7 @@ class ServerMetaDataTestV21(test.TestCase): self.assertEqual(expected, res_dict) def test_update_all_empty_body_item(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url + '/key1') req.method = 'PUT' @@ -364,7 +364,7 @@ class ServerMetaDataTestV21(test.TestCase): body=None) def test_update_all_with_non_dict_item(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url + '/bad') req.method = 'PUT' @@ -377,7 +377,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_all_malformed_container(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'PUT' @@ -390,7 +390,7 @@ class ServerMetaDataTestV21(test.TestCase): body=expected) def test_update_all_malformed_data(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'PUT' @@ -403,7 +403,7 @@ class ServerMetaDataTestV21(test.TestCase): body=expected) def test_update_all_nonexistent_server(self): - self.stub_out('nova.db.instance_get', return_server_nonexistent) + self.stub_out('nova.db.api.instance_get', return_server_nonexistent) req = self._get_request() req.method = 'PUT' req.content_type = "application/json" @@ -414,7 +414,7 @@ class ServerMetaDataTestV21(test.TestCase): self.controller.update_all, req, '100', body=body) def test_update_all_non_dict(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'PUT' @@ -437,7 +437,7 @@ class ServerMetaDataTestV21(test.TestCase): self.assertEqual(expected, res_dict) def test_update_item_nonexistent_server(self): - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', return_server_nonexistent) req = self._get_request('/key1') req.method = 'PUT' @@ -450,7 +450,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_item_empty_body(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -461,7 +461,7 @@ class ServerMetaDataTestV21(test.TestCase): body=None) def test_update_malformed_container(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = 'PUT' @@ -474,7 +474,7 @@ class ServerMetaDataTestV21(test.TestCase): body=expected) def test_update_malformed_data(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = fakes.HTTPRequest.blank(self.url) req.method = 'PUT' @@ -487,7 +487,7 @@ class ServerMetaDataTestV21(test.TestCase): body=expected) def test_update_item_empty_key(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -500,7 +500,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_item_key_too_long(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -513,7 +513,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.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -526,7 +526,7 @@ class ServerMetaDataTestV21(test.TestCase): req, self.uuid, "key1", body=body) def test_update_item_too_many_keys(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/key1') req.method = 'PUT' @@ -539,7 +539,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_item_body_uri_mismatch(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/bad') req.method = 'PUT' @@ -552,7 +552,7 @@ class ServerMetaDataTestV21(test.TestCase): body=body) def test_update_item_non_dict(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request('/bad') req.method = 'PUT' @@ -578,7 +578,7 @@ class ServerMetaDataTestV21(test.TestCase): body=expected) def test_too_many_metadata_items_on_create(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) data = {"metadata": {}} for num in range(CONF.quota.metadata_items + 1): @@ -592,7 +592,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.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) req = self._get_request() req.method = 'POST' @@ -617,7 +617,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.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) data = {"metadata": {}} for num in range(CONF.quota.metadata_items + 1): @@ -631,7 +631,7 @@ class ServerMetaDataTestV21(test.TestCase): req, self.uuid, body=data) def test_invalid_metadata_items_on_update_item(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.api.instance_metadata_update', return_create_instance_metadata) data = {"metadata": {}} for num in range(CONF.quota.metadata_items + 1): @@ -668,15 +668,15 @@ class BadStateServerMetaDataTestV21(test.TestCase): def setUp(self): super(BadStateServerMetaDataTestV21, self).setUp() fakes.stub_out_key_pair_funcs(self) - self.stub_out('nova.db.instance_metadata_get', + self.stub_out('nova.db.api.instance_metadata_get', return_server_metadata) self.stub_out( 'nova.compute.rpcapi.ComputeAPI.change_instance_metadata', fake_change_instance_metadata) - self.stub_out('nova.db.instance_get', self._return_server_in_build) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get', self._return_server_in_build) + self.stub_out('nova.db.api.instance_get_by_uuid', self._return_server_in_build_by_uuid) - self.stub_out('nova.db.instance_metadata_delete', + self.stub_out('nova.db.api.instance_metadata_delete', delete_server_metadata) self._set_up_resources() @@ -695,7 +695,7 @@ class BadStateServerMetaDataTestV21(test.TestCase): req, self.uuid, 'key2') def test_invalid_state_on_update_metadata(self): - self.stub_out('nova.db.instance_metadata_update', + self.stub_out('nova.db.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 b06ead5a92..ebd687c05d 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 @@ -20,7 +20,7 @@ import webob from nova.api.openstack.compute import servers \ as server_v21 from nova.compute import api as compute_api -from nova import db +from nova.db import api as db from nova import exception from nova import policy from nova import test @@ -36,7 +36,7 @@ class ServerStartStopTestV21(test.TestCase): self._setup_controller() self.req = fakes.HTTPRequest.blank('') self.useFixture(nova_fixtures.SingleCellSimple()) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get()) def _setup_controller(self): @@ -131,7 +131,7 @@ class ServerStartStopPolicyEnforcementV21(test.TestCase): self.req = fakes.HTTPRequest.blank('') self.useFixture(nova_fixtures.SingleCellSimple()) self.stub_out( - 'nova.db.instance_get_by_uuid', + 'nova.db.api.instance_get_by_uuid', fakes.fake_instance_get( project_id=self.req.environ['nova.context'].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 15c6231688..2e627b322d 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_tags.py +++ b/nova/tests/unit/api/openstack/compute/test_server_tags.py @@ -67,7 +67,7 @@ class ServerTagsTest(test.TestCase): request.method = method return request - @mock.patch('nova.db.instance_tag_exists') + @mock.patch('nova.db.api.instance_tag_exists') def test_show(self, mock_exists): mock_exists.return_value = True req = self._get_request( @@ -76,7 +76,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.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.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 @@ -88,7 +88,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.instance_tag_set') + @mock.patch('nova.db.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] @@ -153,7 +153,7 @@ class ServerTagsTest(test.TestCase): self.assertRaises(exc.HTTPConflict, self.controller.update_all, req, UUID, body={'tags': TAGS}) - @mock.patch('nova.db.instance_tag_exists') + @mock.patch('nova.db.api.instance_tag_exists') def test_show_non_existing_tag(self, mock_exists): mock_exists.return_value = False req = self._get_request( @@ -162,8 +162,8 @@ class ServerTagsTest(test.TestCase): req, UUID, TAG1) @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.instance_tag_add') - @mock.patch('nova.db.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.api.instance_tag_add') + @mock.patch('nova.db.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) @@ -182,7 +182,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.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.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)] @@ -195,7 +195,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.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.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)) @@ -207,7 +207,7 @@ class ServerTagsTest(test.TestCase): self.assertRaises(exc.HTTPBadRequest, self.controller.update, req, UUID, TAG2, body=None) - @mock.patch('nova.db.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.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 = [] @@ -218,7 +218,7 @@ class ServerTagsTest(test.TestCase): self.assertRaises(exc.HTTPBadRequest, self.controller.update, req, UUID, tag, body=None) - @mock.patch('nova.db.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.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 = [] @@ -236,9 +236,9 @@ class ServerTagsTest(test.TestCase): self.assertRaises(exc.HTTPConflict, self.controller.update, req, UUID, TAG1, body=None) - @mock.patch('nova.db.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.api.instance_tag_get_by_instance_uuid') @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.instance_tag_delete') + @mock.patch('nova.db.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) @@ -249,7 +249,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.instance_tag_delete') + @mock.patch('nova.db.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) @@ -273,7 +273,7 @@ class ServerTagsTest(test.TestCase): TAG1) @mock.patch('nova.notifications.base.send_instance_update_notification') - @mock.patch('nova.db.instance_tag_delete_all') + @mock.patch('nova.db.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/fake/servers/%s/tags' % UUID, 'DELETE') diff --git a/nova/tests/unit/api/openstack/compute/test_server_usage.py b/nova/tests/unit/api/openstack/compute/test_server_usage.py index aa65884772..9dfe7741ee 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_usage.py +++ b/nova/tests/unit/api/openstack/compute/test_server_usage.py @@ -66,7 +66,7 @@ class ServerUsageTestV21(test.TestCase): self.stub_out('nova.compute.api.API.get', fake_compute_get) self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all) return_server = fakes.fake_instance_get() - self.stub_out('nova.db.instance_get_by_uuid', return_server) + self.stub_out('nova.db.api.instance_get_by_uuid', return_server) def _make_request(self, url): req = fakes.HTTPRequest.blank(url) diff --git a/nova/tests/unit/api/openstack/compute/test_serversV21.py b/nova/tests/unit/api/openstack/compute/test_serversV21.py index fc2699dc53..8aeb6e63be 100644 --- a/nova/tests/unit/api/openstack/compute/test_serversV21.py +++ b/nova/tests/unit/api/openstack/compute/test_serversV21.py @@ -159,7 +159,7 @@ 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.instance_update_and_get_original', + self.stub_out('nova.db.api.instance_update_and_get_original', instance_update_and_get_original) self.flags(group='glance', api_servers=['http://localhost:9292']) @@ -1796,7 +1796,7 @@ 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.instance_destroy', instance_destroy_mock) + self.stub_out('nova.db.api.instance_destroy', instance_destroy_mock) self.controller.delete(req, FAKE_UUID) # delete() should be called for instance which has never been active, @@ -2108,7 +2108,8 @@ class ServersControllerRebuildInstanceTest(ControllerTest): self.controller._stop_server, req, FAKE_UUID, body) @mock.patch( - 'nova.db.instance_get_by_uuid', fake_instance_get_by_uuid_not_found) + 'nova.db.api.instance_get_by_uuid', + fake_instance_get_by_uuid_not_found) def test_start_with_bogus_id(self): req = fakes.HTTPRequestV21.blank('/fake/servers/test_inst/action') body = dict(start="") @@ -2116,7 +2117,8 @@ class ServersControllerRebuildInstanceTest(ControllerTest): self.controller._start_server, req, 'test_inst', body) @mock.patch( - 'nova.db.instance_get_by_uuid', fake_instance_get_by_uuid_not_found) + 'nova.db.api.instance_get_by_uuid', + fake_instance_get_by_uuid_not_found) def test_stop_with_bogus_id(self): req = fakes.HTTPRequestV21.blank('/fake/servers/test_inst/action') body = dict(stop="") @@ -2183,7 +2185,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.key_pair_get', no_key_pair) + self.stub_out('nova.db.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, @@ -2325,7 +2327,7 @@ class ServersControllerRebuildTestV257(ServersControllerRebuildTestV254): self.assertIn('user_data', six.text_type(ex)) @mock.patch.object(context.RequestContext, 'can') - @mock.patch('nova.db.instance_update_and_get_original') + @mock.patch('nova.db.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. @@ -2638,7 +2640,7 @@ class ServersControllerUpdateTest(ControllerTest): req, FAKE_UUID, body=body) def test_update_server_name_all_blank_spaces(self): - self.stub_out('nova.db.instance_get', + self.stub_out('nova.db.api.instance_get', fakes.fake_instance_get(name='server_test')) req = fakes.HTTPRequest.blank('/fake/servers/%s' % FAKE_UUID) req.method = 'PUT' @@ -2654,7 +2656,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.instance_get', + self.stub_out('nova.db.api.instance_get', fakes.fake_instance_get(name='server_test')) req = fakes.HTTPRequest.blank('/fake/servers/%s' % FAKE_UUID) req.method = 'PUT' @@ -2872,7 +2874,7 @@ class ServerStatusTest(test.TestCase): self.controller = servers.ServersController() def _get_with_state(self, vm_state, task_state=None): - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fakes.fake_instance_get(vm_state=vm_state, task_state=task_state)) @@ -3014,14 +3016,14 @@ class ServersControllerCreateTest(test.TestCase): fakes.stub_out_key_pair_funcs(self) fake.stub_out_image_service(self) self.stub_out('uuid.uuid4', lambda: FAKE_UUID) - self.stub_out('nova.db.project_get_networks', + self.stub_out('nova.db.api.project_get_networks', lambda c, u: dict(id='1', host='localhost')) - self.stub_out('nova.db.instance_create', instance_create) - self.stub_out('nova.db.instance_system_metadata_update', + self.stub_out('nova.db.api.instance_create', instance_create) + self.stub_out('nova.db.api.instance_system_metadata_update', lambda *a, **kw: None) - self.stub_out('nova.db.instance_get', instance_get) - self.stub_out('nova.db.instance_update', instance_update) - self.stub_out('nova.db.instance_update_and_get_original', + self.stub_out('nova.db.api.instance_get', instance_get) + self.stub_out('nova.db.api.instance_update', instance_update) + self.stub_out('nova.db.api.instance_update_and_get_original', server_update_and_get_original) self.stub_out('nova.network.manager.VlanManager.allocate_fixed_ip', lambda *a, **kw: None) @@ -3209,7 +3211,7 @@ class ServersControllerCreateTest(test.TestCase): # self.assertEqual(kwargs['key_name'], key_name) # return old_create(*args, **kwargs) # - # self.stub_out('nova.db.key_pair_get', key_pair_get) + # self.stub_out('nova.db.api.key_pair_get', key_pair_get) # self.stubs.Set(compute_api.API, 'create', create) # self._test_create_extra(params) # @@ -3681,7 +3683,7 @@ class ServersControllerCreateTest(test.TestCase): return fakes.stub_instance(1) mock_limit_check.side_effect = fake_limit_check - self.stub_out('nova.db.instance_destroy', fake_instance_destroy) + self.stub_out('nova.db.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" @@ -3704,7 +3706,7 @@ class ServersControllerCreateTest(test.TestCase): def fake_instance_destroy(context, uuid, constraint): return fakes.stub_instance(1) - self.stub_out('nova.db.instance_destroy', fake_instance_destroy) + self.stub_out('nova.db.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'] @@ -3716,7 +3718,7 @@ class ServersControllerCreateTest(test.TestCase): def fake_instance_destroy(context, uuid, constraint): return fakes.stub_instance(1) - self.stub_out('nova.db.instance_destroy', fake_instance_destroy) + self.stub_out('nova.db.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) diff --git a/nova/tests/unit/api/openstack/compute/test_services.py b/nova/tests/unit/api/openstack/compute/test_services.py index fb36081876..7759477eb2 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.service_get_by_host_and_binary', + self.stub_out('nova.db.api.service_get_by_host_and_binary', fake_db_service_get_by_host_binary(fake_services_list)) - self.stub_out('nova.db.service_update', + self.stub_out('nova.db.api.service_update', fake_db_service_update(fake_services_list)) self.req = fakes.HTTPRequest.blank('') @@ -585,7 +585,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.service_update', _service_update) + self.stub_out('nova.db.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 f1c80a2afb..c1ccbbd53f 100644 --- a/nova/tests/unit/api/openstack/fakes.py +++ b/nova/tests/unit/api/openstack/fakes.py @@ -99,10 +99,10 @@ def stub_out_key_pair_funcs(testcase, have_key_pair=True, **kwargs): return [] if have_key_pair: - testcase.stub_out('nova.db.key_pair_get_all_by_user', key_pair) - testcase.stub_out('nova.db.key_pair_get', one_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) else: - testcase.stub_out('nova.db.key_pair_get_all_by_user', no_key_pair) + testcase.stub_out('nova.db.api.key_pair_get_all_by_user', no_key_pair) def stub_out_trusted_certs(test, certs=None): diff --git a/nova/tests/unit/cells/fakes.py b/nova/tests/unit/cells/fakes.py index 94a02b8562..7135f14f46 100644 --- a/nova/tests/unit/cells/fakes.py +++ b/nova/tests/unit/cells/fakes.py @@ -21,7 +21,7 @@ from nova.cells import manager as cells_manager from nova.cells import state as cells_state from nova.cells import utils as cells_utils import nova.conf -import nova.db +import nova.db.api from nova.db import base from nova import exception from nova import objects @@ -52,7 +52,7 @@ class FakeDBApi(object): self.cell_db_entries = cell_db_entries def __getattr__(self, key): - return getattr(nova.db, key) + return getattr(nova.db.api, key) def cell_get_all(self, ctxt): return self.cell_db_entries diff --git a/nova/tests/unit/cells/test_cells_messaging.py b/nova/tests/unit/cells/test_cells_messaging.py index fa5384066a..913224b08d 100644 --- a/nova/tests/unit/cells/test_cells_messaging.py +++ b/nova/tests/unit/cells/test_cells_messaging.py @@ -30,7 +30,7 @@ from nova.compute import instance_actions from nova.compute import task_states from nova.compute import vm_states from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import base as objects_base diff --git a/nova/tests/unit/cells/test_cells_scheduler.py b/nova/tests/unit/cells/test_cells_scheduler.py index dcb81e6299..e7d9bac927 100644 --- a/nova/tests/unit/cells/test_cells_scheduler.py +++ b/nova/tests/unit/cells/test_cells_scheduler.py @@ -25,7 +25,7 @@ from nova.cells import filters from nova.cells import weights from nova.compute import vm_states from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova import test diff --git a/nova/tests/unit/cells/test_cells_state_manager.py b/nova/tests/unit/cells/test_cells_state_manager.py index 390cb1debe..8ea891a1e8 100644 --- a/nova/tests/unit/cells/test_cells_state_manager.py +++ b/nova/tests/unit/cells/test_cells_state_manager.py @@ -132,7 +132,7 @@ class TestCellsStateManager(test.NoDBTestCase): _fake_service_get_all_by_binary) self.stub_out('nova.objects.FlavorList.get_all', _fake_instance_type_all) - self.stub_out('nova.db.cell_get_all', _fake_cell_get_all) + self.stub_out('nova.db.api.cell_get_all', _fake_cell_get_all) def test_cells_config_not_found(self): self.flags(cells_config='no_such_file_exists.conf', group='cells') @@ -271,7 +271,7 @@ class TestCellsStateManagerNodeDown(test.NoDBTestCase): _fake_service_get_all_by_binary_nodedown) self.stub_out('nova.objects.FlavorList.get_all', _fake_instance_type_all) - self.stub_out('nova.db.cell_get_all', _fake_cell_get_all) + self.stub_out('nova.db.api.cell_get_all', _fake_cell_get_all) def test_capacity_no_reserve_nodedown(self): cap = self._capacity(0.0) diff --git a/nova/tests/unit/cmd/test_cmd_db_blocks.py b/nova/tests/unit/cmd/test_cmd_db_blocks.py index 8856ca2a50..4aff909581 100644 --- a/nova/tests/unit/cmd/test_cmd_db_blocks.py +++ b/nova/tests/unit/cmd/test_cmd_db_blocks.py @@ -18,18 +18,18 @@ import mock from nova.cmd import compute from nova.cmd import network -from nova import db +from nova.db import api as db from nova import exception from nova import test @contextlib.contextmanager def restore_db(): - orig = db.api.IMPL + orig = db.IMPL try: yield finally: - db.api.IMPL = orig + db.IMPL = orig class ComputeMainTest(test.NoDBTestCase): @@ -47,11 +47,11 @@ class ComputeMainTest(test.NoDBTestCase): with restore_db(): self._call_main(compute) self.assertRaises(exception.DBNotAllowed, - db.api.instance_get, 1, 2) + db.instance_get, 1, 2) def test_network_main_blocks_db(self): self.flags(enable=True, group='cells') with restore_db(): self._call_main(network) self.assertRaises(exception.DBNotAllowed, - db.api.instance_get, 1, 2) + db.instance_get, 1, 2) diff --git a/nova/tests/unit/cmd/test_policy.py b/nova/tests/unit/cmd/test_policy.py index 35a2eed2d8..cb38bab8ae 100644 --- a/nova/tests/unit/cmd/test_policy.py +++ b/nova/tests/unit/cmd/test_policy.py @@ -24,7 +24,7 @@ from six.moves import StringIO from nova.cmd import policy import nova.conf from nova import context as nova_context -from nova import db +from nova.db 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_claims.py b/nova/tests/unit/compute/test_claims.py index 3e1b7c2aff..b65e56560a 100644 --- a/nova/tests/unit/compute/test_claims.py +++ b/nova/tests/unit/compute/test_claims.py @@ -90,7 +90,7 @@ class ClaimTestCase(test.NoDBTestCase): requests = requests or self.empty_requests - @mock.patch('nova.db.instance_extra_get_by_instance_uuid', + @mock.patch('nova.db.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, @@ -410,7 +410,7 @@ class MoveClaimTestCase(ClaimTestCase): @mock.patch('nova.virt.hardware.numa_get_constraints', return_value=numa_topology) - @mock.patch('nova.db.instance_extra_get_by_instance_uuid', + @mock.patch('nova.db.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(self.context, self.instance, _NODENAME, diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index 10969ce998..26b55ac953 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -57,7 +57,7 @@ from nova.compute import vm_states import nova.conf from nova.console import type as ctype from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova.image import api as image_api from nova.network import model as network_model @@ -210,7 +210,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.compute_node_delete', + self.stub_out('nova.db.api.compute_node_delete', fake_compute_node_delete) self.compute.update_available_resource( @@ -378,8 +378,8 @@ class ComputeVolumeTestCase(BaseTestCase): self.cinfo = jsonutils.loads(args[-1].get('connection_info')) return self.fake_volume - self.stub_out('nova.db.block_device_mapping_create', store_cinfo) - self.stub_out('nova.db.block_device_mapping_update', store_cinfo) + self.stub_out('nova.db.api.block_device_mapping_create', store_cinfo) + self.stub_out('nova.db.api.block_device_mapping_update', store_cinfo) @mock.patch.object(compute_utils, 'EventReporter') def test_attach_volume_serial(self, mock_event): @@ -6823,7 +6823,8 @@ class ComputeTestCase(BaseTestCase, except NotImplementedError: exc_info = sys.exc_info() - self.stub_out('nova.db.instance_fault_create', fake_db_fault_create) + self.stub_out('nova.db.api.instance_fault_create', + fake_db_fault_create) ctxt = context.get_admin_context() compute_utils.add_instance_fault_from_exc(ctxt, @@ -6858,7 +6859,8 @@ class ComputeTestCase(BaseTestCase, raised_exc = exc exc_info = sys.exc_info() - self.stub_out('nova.db.instance_fault_create', fake_db_fault_create) + self.stub_out('nova.db.api.instance_fault_create', + fake_db_fault_create) ctxt = context.get_admin_context() compute_utils.add_instance_fault_from_exc(ctxt, @@ -6887,7 +6889,8 @@ class ComputeTestCase(BaseTestCase, except exception.Invalid: exc_info = sys.exc_info() - self.stub_out('nova.db.instance_fault_create', fake_db_fault_create) + self.stub_out('nova.db.api.instance_fault_create', + fake_db_fault_create) ctxt = context.get_admin_context() compute_utils.add_instance_fault_from_exc(ctxt, @@ -6907,7 +6910,8 @@ class ComputeTestCase(BaseTestCase, self.assertEqual(expected, values) return self._fill_fault(expected) - self.stub_out('nova.db.instance_fault_create', fake_db_fault_create) + self.stub_out('nova.db.api.instance_fault_create', + fake_db_fault_create) ctxt = context.get_admin_context() compute_utils.add_instance_fault_from_exc(ctxt, @@ -6930,7 +6934,8 @@ class ComputeTestCase(BaseTestCase, self.assertEqual(expected, values) return self._fill_fault(expected) - self.stub_out('nova.db.instance_fault_create', fake_db_fault_create) + self.stub_out('nova.db.api.instance_fault_create', + fake_db_fault_create) ctxt = context.get_admin_context() compute_utils.add_instance_fault_from_exc(ctxt, @@ -6959,7 +6964,8 @@ class ComputeTestCase(BaseTestCase, except NotImplementedError: exc_info = sys.exc_info() - self.stub_out('nova.db.instance_fault_create', fake_db_fault_create) + self.stub_out('nova.db.api.instance_fault_create', + fake_db_fault_create) ctxt = context.get_admin_context() compute_utils.add_instance_fault_from_exc(ctxt, @@ -7145,9 +7151,9 @@ class ComputeTestCase(BaseTestCase, raise exception.InstanceInfoCacheNotFound( instance_uuid=instance['uuid']) - self.stub_out('nova.db.instance_get_all_by_host', + self.stub_out('nova.db.api.instance_get_all_by_host', fake_instance_get_all_by_host) - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fake_instance_get_by_uuid) if CONF.use_neutron: self.stub_out( @@ -7370,11 +7376,11 @@ class ComputeTestCase(BaseTestCase, migration['instance_uuid']): migration2['status'] = 'confirmed' - self.stub_out('nova.db.instance_get_by_uuid', + self.stub_out('nova.db.api.instance_get_by_uuid', fake_instance_get_by_uuid) - self.stub_out('nova.db.migration_get_unconfirmed_by_dest_compute', + self.stub_out('nova.db.api.migration_get_unconfirmed_by_dest_compute', fake_migration_get_unconfirmed_by_dest_compute) - self.stub_out('nova.db.migration_update', fake_migration_update) + self.stub_out('nova.db.api.migration_update', fake_migration_update) self.stub_out('nova.compute.api.API.confirm_resize', fake_confirm_resize) @@ -7421,8 +7427,7 @@ class ComputeTestCase(BaseTestCase, # creating mocks with test.nested( - mock.patch.object(self.compute.db.sqlalchemy.api, - 'instance_get_all_by_filters', + mock.patch.object(db, 'instance_get_all_by_filters', return_value=instances), mock.patch.object(objects.Instance, 'save'), ) as ( @@ -7643,7 +7648,7 @@ class ComputeTestCase(BaseTestCase, self.stub_out('nova.objects.instance.Instance.destroy', fake_destroy) - self.stub_out('nova.db.block_device_mapping_get_all_by_instance', + self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance', lambda *a, **k: None) self.stub_out('nova.compute.manager.ComputeManager.' @@ -11365,7 +11370,7 @@ class ComputeAPITestCase(BaseTestCase): self.assertIsInstance(called_context, context.RequestContext) self.assertNotEqual(self.context, called_context) - @mock.patch("nova.db.migration_get_in_progress_by_instance") + @mock.patch("nova.db.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) @@ -11376,7 +11381,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.migration_get_by_id_and_instance") + @mock.patch("nova.db.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_api.py b/nova/tests/unit/compute/test_compute_api.py index e6c7b4b8f0..ca3b56d4a8 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -39,7 +39,7 @@ from nova import conductor import nova.conf from nova.consoleauth import rpcapi as consoleauth_rpcapi from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova.image import api as image_api from nova.network.neutronv2 import api as neutron_api diff --git a/nova/tests/unit/compute/test_compute_cells.py b/nova/tests/unit/compute/test_compute_cells.py index deb54a58ec..b8e03ade71 100644 --- a/nova/tests/unit/compute/test_compute_cells.py +++ b/nova/tests/unit/compute/test_compute_cells.py @@ -31,7 +31,7 @@ from nova.compute import power_state from nova.compute import utils as compute_utils from nova.compute import vm_states from nova import context -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import api_models from nova import exception diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index cc17cf83a3..7a82df57d1 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -42,7 +42,7 @@ from nova.compute import vm_states from nova.conductor import api as conductor_api import nova.conf from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova.network import api as network_api from nova.network import model as network_model @@ -2084,8 +2084,9 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase): self._test_swap_volume(expected_exception=test.TestingException) @mock.patch('nova.compute.utils.notify_about_volume_swap') - @mock.patch('nova.db.block_device_mapping_get_by_instance_and_volume_id') - @mock.patch('nova.db.block_device_mapping_update') + @mock.patch( + 'nova.db.api.block_device_mapping_get_by_instance_and_volume_id') + @mock.patch('nova.db.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 ef78a1ed68..27b2ff6cc8 100644 --- a/nova/tests/unit/compute/test_host_api.py +++ b/nova/tests/unit/compute/test_host_api.py @@ -451,7 +451,7 @@ class ComputeHostAPITestCase(test.TestCase): mock_remove_host.assert_called_once_with( mock.ANY, aggregate.uuid, 'fake-compute-host') - @mock.patch('nova.db.compute_node_statistics') + @mock.patch('nova.db.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 b6d668b2ae..3d86c9578d 100644 --- a/nova/tests/unit/compute/test_instance_list.py +++ b/nova/tests/unit/compute/test_instance_list.py @@ -55,7 +55,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.instance_get_all_by_filters_sort') + @mock.patch('nova.db.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 diff --git a/nova/tests/unit/compute/test_keypairs.py b/nova/tests/unit/compute/test_keypairs.py index c7b54165ed..0a5b544c7a 100644 --- a/nova/tests/unit/compute/test_keypairs.py +++ b/nova/tests/unit/compute/test_keypairs.py @@ -76,11 +76,11 @@ class KeypairAPITestCase(test_compute.BaseTestCase): else: raise exception.KeypairNotFound(user_id=user_id, name=name) - self.stub_out("nova.db.key_pair_get_all_by_user", + self.stub_out("nova.db.api.key_pair_get_all_by_user", db_key_pair_get_all_by_user) - self.stub_out("nova.db.key_pair_create", db_key_pair_create) - self.stub_out("nova.db.key_pair_destroy", db_key_pair_destroy) - self.stub_out("nova.db.key_pair_get", db_key_pair_get) + 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) def _check_notifications(self, action='create', key_name='foo'): self.assertEqual(2, len(fake_notifier.NOTIFICATIONS)) @@ -143,7 +143,8 @@ class CreateImportSharedTestMixIn(object): def db_key_pair_create_duplicate(context, keypair): raise exception.KeyPairExists(key_name=keypair.get('name', '')) - self.stub_out("nova.db.key_pair_create", db_key_pair_create_duplicate) + self.stub_out("nova.db.api.key_pair_create", + db_key_pair_create_duplicate) msg = ("Key pair '%(key_name)s' already exists." % {'key_name': self.existing_key_name}) diff --git a/nova/tests/unit/compute/test_shelve.py b/nova/tests/unit/compute/test_shelve.py index ff3f059a2c..1fc5b7a405 100644 --- a/nova/tests/unit/compute/test_shelve.py +++ b/nova/tests/unit/compute/test_shelve.py @@ -21,7 +21,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 import db +from nova.db import api as db from nova import exception from nova.network.neutronv2 import api as neutron_api from nova import objects diff --git a/nova/tests/unit/compute/test_virtapi.py b/nova/tests/unit/compute/test_virtapi.py index e5fd02acab..91e9d19471 100644 --- a/nova/tests/unit/compute/test_virtapi.py +++ b/nova/tests/unit/compute/test_virtapi.py @@ -16,7 +16,7 @@ import mock from nova.compute import manager as compute_manager from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova import test diff --git a/nova/tests/unit/conductor/test_conductor.py b/nova/tests/unit/conductor/test_conductor.py index b8a6a35166..719ff64bbe 100644 --- a/nova/tests/unit/conductor/test_conductor.py +++ b/nova/tests/unit/conductor/test_conductor.py @@ -36,7 +36,7 @@ from nova.conductor.tasks import live_migrate from nova.conductor.tasks import migrate from nova import conf from nova import context -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import api as db_api from nova.db.sqlalchemy import api_models from nova import exception as exc diff --git a/nova/tests/unit/console/test_console.py b/nova/tests/unit/console/test_console.py index 18aa46cfef..c9496e0618 100644 --- a/nova/tests/unit/console/test_console.py +++ b/nova/tests/unit/console/test_console.py @@ -23,7 +23,7 @@ from nova.compute import rpcapi as compute_rpcapi from nova.console import api as console_api from nova.console import manager as console_manager from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova import test @@ -164,12 +164,12 @@ class ConsoleAPITestCase(test.NoDBTestCase): def _fake_db_console_get(_ctxt, _console_uuid, _instance_uuid): return self.fake_console - self.stub_out('nova.db.console_get', _fake_db_console_get) + self.stub_out('nova.db.api.console_get', _fake_db_console_get) def _fake_db_console_get_all_by_instance(_ctxt, _instance_uuid, columns_to_join): return [self.fake_console] - self.stub_out('nova.db.console_get_all_by_instance', + self.stub_out('nova.db.api.console_get_all_by_instance', _fake_db_console_get_all_by_instance) def test_get_consoles(self): diff --git a/nova/tests/unit/db/fakes.py b/nova/tests/unit/db/fakes.py index e014665150..78bd5af900 100644 --- a/nova/tests/unit/db/fakes.py +++ b/nova/tests/unit/db/fakes.py @@ -329,7 +329,7 @@ def stub_out_db_network_api(test): fake_network_set_host, fake_network_update, fake_project_get_networks] - funcs = {'nova.db.%s' % fn.__name__.replace('fake_', ''): fn + funcs = {'nova.db.api.%s' % fn.__name__.replace('fake_', ''): fn for fn in funcs} stub_out(test, funcs) diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index 1e63efac75..cc87bfbd51 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -53,7 +53,7 @@ from nova.compute import task_states from nova.compute import vm_states import nova.conf from nova import context -from nova import db +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.sqlalchemy import types as col_types @@ -1796,7 +1796,7 @@ class SecurityGroupTestCase(test.TestCase, ModelsObjectComparatorMixin): self.assertEqual(1, len(security_groups)) self.assertEqual("default", security_groups[0]["name"]) - @mock.patch.object(db.sqlalchemy.api, '_security_group_get_by_names') + @mock.patch.object(sqlalchemy_api, '_security_group_get_by_names') def test_security_group_ensure_default_called_concurrently(self, sg_mock): # make sure NotFound is always raised here to trick Nova to insert the # duplicate security group entry @@ -1885,7 +1885,7 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin): instance = self.create_instance_with_args() self.assertTrue(uuidutils.is_uuid_like(instance['uuid'])) - @mock.patch.object(db.sqlalchemy.api, 'security_group_ensure_default') + @mock.patch.object(sqlalchemy_api, '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() @@ -7381,7 +7381,7 @@ class ComputeNodeTestCase(test.TestCase, ModelsObjectComparatorMixin): @mock.patch("nova.db.sqlalchemy.api.compute_node_get_model") def test_dbapi_compute_node_get_model(self, mock_get_model): cid = self.item["id"] - db.api.compute_node_get_model(self.ctxt, cid) + 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") diff --git a/nova/tests/unit/fake_network.py b/nova/tests/unit/fake_network.py index b45d9ed2f1..9b198ae32f 100644 --- a/nova/tests/unit/fake_network.py +++ b/nova/tests/unit/fake_network.py @@ -21,7 +21,7 @@ from nova.compute import api as compute_api from nova.compute import manager as compute_manager import nova.conf import nova.context -from nova import db +from nova.db import api as db from nova import exception from nova.network import manager as network_manager from nova.network import model as network_model @@ -322,8 +322,8 @@ def fake_get_instance_nw_info(test, num_networks=1, ips_per_vif=2, } return fake_info_cache - test.stub_out('nova.db.fixed_ip_get_by_instance', fixed_ips_fake) - test.stub_out('nova.db.instance_info_cache_update', update_cache_fake) + test.stub_out('nova.db.api.fixed_ip_get_by_instance', fixed_ips_fake) + test.stub_out('nova.db.api.instance_info_cache_update', update_cache_fake) class FakeContext(nova.context.RequestContext): def is_admin(self): @@ -403,7 +403,7 @@ def stub_compute_with_ips(test): def fake_pci_device_get_by_addr(context, node_id, dev_addr): return test_pci_device.fake_db_dev - test.stub_out('nova.db.pci_device_get_by_addr', + test.stub_out('nova.db.api.pci_device_get_by_addr', fake_pci_device_get_by_addr) test.stub_out('nova.compute.api.API.get', fake_get) test.stub_out('nova.compute.api.API.get_all', fake_get_all) diff --git a/nova/tests/unit/fake_server_actions.py b/nova/tests/unit/fake_server_actions.py index 5193f32c1b..707f4e50d9 100644 --- a/nova/tests/unit/fake_server_actions.py +++ b/nova/tests/unit/fake_server_actions.py @@ -121,5 +121,5 @@ def fake_action_event_finish(*args): def stub_out_action_events(test): - test.stub_out('nova.db.action_event_start', fake_action_event_start) - test.stub_out('nova.db.action_event_finish', fake_action_event_finish) + 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) diff --git a/nova/tests/unit/network/test_api.py b/nova/tests/unit/network/test_api.py index 8146e9e7dc..1f3a4be7d8 100644 --- a/nova/tests/unit/network/test_api.py +++ b/nova/tests/unit/network/test_api.py @@ -90,7 +90,7 @@ class ApiTestCase(test.TestCase): self.network_api.get(self.context, uuids.instance)) @mock.patch('nova.objects.Network.get_by_id') - @mock.patch('nova.db.virtual_interface_get_by_instance') + @mock.patch('nova.db.api.virtual_interface_get_by_instance') def test_get_vifs_by_instance(self, mock_get_by_instance, mock_get_by_id): mock_get_by_instance.return_value = [ @@ -110,7 +110,7 @@ class ApiTestCase(test.TestCase): project_only='allow_none') @mock.patch('nova.objects.Network.get_by_id') - @mock.patch('nova.db.virtual_interface_get_by_address') + @mock.patch('nova.db.api.virtual_interface_get_by_address') def test_get_vif_by_mac_address(self, mock_get_by_address, mock_get_by_id): mock_get_by_address.return_value = dict( @@ -492,7 +492,7 @@ class ApiTestCase(test.TestCase): self._test_refresh_cache('remove_fixed_ip_from_instance', self.context, instance, address) - @mock.patch('nova.db.fixed_ip_get_by_address') + @mock.patch('nova.db.api.fixed_ip_get_by_address') def test_get_fixed_ip_by_address(self, fip_get): fip_get.return_value = test_fixed_ip.fake_fixed_ip fip = self.network_api.get_fixed_ip_by_address(self.context, @@ -560,7 +560,7 @@ class ApiTestCase(test.TestCase): @mock.patch('nova.network.api.API') -@mock.patch('nova.db.instance_info_cache_update') +@mock.patch('nova.db.api.instance_info_cache_update') class TestUpdateInstanceCache(test.NoDBTestCase): def setUp(self): super(TestUpdateInstanceCache, self).setUp() diff --git a/nova/tests/unit/network/test_linux_net.py b/nova/tests/unit/network/test_linux_net.py index 0f1fde36a6..126214b580 100644 --- a/nova/tests/unit/network/test_linux_net.py +++ b/nova/tests/unit/network/test_linux_net.py @@ -28,7 +28,7 @@ from oslo_utils import timeutils import nova.conf from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova.network import driver from nova.network import linux_net @@ -367,9 +367,10 @@ class LinuxNetworkTestCase(test.NoDBTestCase): def get_instance(_context, instance_id): return instances[instance_id] - self.stub_out('nova.db.virtual_interface_get_by_instance', get_vifs) - self.stub_out('nova.db.instance_get', get_instance) - self.stub_out('nova.db.network_get_associated_fixed_ips', + self.stub_out('nova.db.api.virtual_interface_get_by_instance', + get_vifs) + self.stub_out('nova.db.api.instance_get', get_instance) + self.stub_out('nova.db.api.network_get_associated_fixed_ips', get_associated) @mock.patch.object(linux_net.iptables_manager.ipv4['nat'], 'add_rule') diff --git a/nova/tests/unit/network/test_manager.py b/nova/tests/unit/network/test_manager.py index a1e7a1114b..449859870f 100644 --- a/nova/tests/unit/network/test_manager.py +++ b/nova/tests/unit/network/test_manager.py @@ -30,7 +30,7 @@ import six import testtools from nova import context -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import models from nova import exception from nova import ipv6 @@ -1378,7 +1378,7 @@ class VlanNetworkTestCase(test.TestCase): self.network.deallocate_floating_ip(ctxt, 'fake-address') mock_dealloc.assert_called_once_with(ctxt, 'fake-address') - @mock.patch('nova.db.fixed_ip_get') + @mock.patch('nova.db.api.fixed_ip_get') def test_associate_floating_ip(self, fixed_get): ctxt = context.RequestContext('testuser', fakes.FAKE_PROJECT_ID, is_admin=False) @@ -1536,8 +1536,8 @@ class VlanNetworkTestCase(test.TestCase): 'fakeiface', 'fakenet') - @mock.patch('nova.db.floating_ip_get_all_by_host') - @mock.patch('nova.db.fixed_ip_get') + @mock.patch('nova.db.api.floating_ip_get_all_by_host') + @mock.patch('nova.db.api.fixed_ip_get') def _test_floating_ip_init_host(self, fixed_get, floating_get, public_interface, expected_arg): @@ -1723,8 +1723,8 @@ class VlanNetworkTestCase(test.TestCase): self.network.add_fixed_ip_to_instance(self.context, FAKEUUID, HOST, networks[0]['id']) - @mock.patch('nova.db.fixed_ip_get_by_address') - @mock.patch('nova.db.network_get') + @mock.patch('nova.db.api.fixed_ip_get_by_address') + @mock.patch('nova.db.api.network_get') def test_ip_association_and_allocation_of_other_project(self, net_get, fixed_get): """Makes sure that we cannot deallocaate or disassociate @@ -1783,10 +1783,10 @@ class VlanNetworkTestCase(test.TestCase): db.fixed_ip_disassociate(context1.elevated(), fix_addr) @mock.patch('nova.network.rpcapi.NetworkAPI.release_dhcp') - @mock.patch('nova.db.virtual_interface_get') - @mock.patch('nova.db.fixed_ip_get_by_address') - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.fixed_ip_update') + @mock.patch('nova.db.api.virtual_interface_get') + @mock.patch('nova.db.api.fixed_ip_get_by_address') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.fixed_ip_update') def test_deallocate_fixed(self, fixed_update, net_get, fixed_get, vif_get, release_dhcp): """Verify that release is called properly. @@ -1822,10 +1822,10 @@ class VlanNetworkTestCase(test.TestCase): @mock.patch.object(linux_net, 'release_dhcp') @mock.patch('nova.network.rpcapi.NetworkAPI.release_dhcp') - @mock.patch('nova.db.virtual_interface_get') - @mock.patch('nova.db.fixed_ip_get_by_address') - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.fixed_ip_update') + @mock.patch('nova.db.api.virtual_interface_get') + @mock.patch('nova.db.api.fixed_ip_get_by_address') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.fixed_ip_update') def test_deallocate_fixed_rpc_pinned(self, fixed_update, net_get, fixed_get, vif_get, release_dhcp, @@ -1866,9 +1866,9 @@ class VlanNetworkTestCase(test.TestCase): fixed_update.assert_called_once_with(context1, fix_addr.address, {'allocated': False}) - @mock.patch('nova.db.fixed_ip_get_by_address') - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.fixed_ip_update') + @mock.patch('nova.db.api.fixed_ip_get_by_address') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.fixed_ip_update') def _deallocate_fixed_with_dhcp(self, mock_dev_exists, fixed_update, net_get, fixed_get): net_get.return_value = dict(test_network.fake_network, @@ -1958,9 +1958,9 @@ class VlanNetworkTestCase(test.TestCase): self.assertRaises(test.TestingException, deallocate, context1, fix_addr, 'fake') - @mock.patch('nova.db.fixed_ip_get_by_address') - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.fixed_ip_update') + @mock.patch('nova.db.api.fixed_ip_get_by_address') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.fixed_ip_update') def test_deallocate_fixed_no_vif(self, fixed_update, net_get, fixed_get): """Verify that deallocate doesn't raise when no vif is returned. @@ -1972,7 +1972,7 @@ class VlanNetworkTestCase(test.TestCase): def vif_get(_context, _vif_id): return None - self.stub_out('nova.db.virtual_interface_get', vif_get) + self.stub_out('nova.db.api.virtual_interface_get', vif_get) context1 = context.RequestContext('user', fakes.FAKE_PROJECT_ID) instance = db.instance_create(context1, @@ -1993,9 +1993,9 @@ class VlanNetworkTestCase(test.TestCase): fixed_update.assert_called_once_with(context1, fix_addr.address, {'allocated': False}) - @mock.patch('nova.db.fixed_ip_get_by_address') - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.fixed_ip_update') + @mock.patch('nova.db.api.fixed_ip_get_by_address') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.fixed_ip_update') def test_fixed_ip_cleanup_fail(self, fixed_update, net_get, fixed_get): # Verify IP is not deallocated if the security group refresh fails. net_get.return_value = dict(test_network.fake_network, @@ -2106,7 +2106,7 @@ class CommonNetworkTestCase(test.TestCase): def dnsdomain_get(context, instance_domain): return domains.get(instance_domain) - self.stub_out('nova.db.dnsdomain_get', dnsdomain_get) + self.stub_out('nova.db.api.dnsdomain_get', dnsdomain_get) fake_instance = {'uuid': FAKEUUID, 'availability_zone': az} @@ -2132,8 +2132,8 @@ class CommonNetworkTestCase(test.TestCase): manager.get_instance_nw_info, self.context, FAKEUUID, 'fake_rxtx_factor', HOST) - @mock.patch('nova.db.instance_get') - @mock.patch('nova.db.fixed_ip_get_by_instance') + @mock.patch('nova.db.api.instance_get') + @mock.patch('nova.db.api.fixed_ip_get_by_instance') def test_deallocate_for_instance_passes_host_info(self, fixed_get, instance_get): manager = fake_network.FakeNetworkManager() @@ -2154,7 +2154,7 @@ class CommonNetworkTestCase(test.TestCase): (ctx, '1.2.3.4', 'fake-host') ], manager.deallocate_fixed_ip_calls) - @mock.patch('nova.db.fixed_ip_get_by_instance') + @mock.patch('nova.db.api.fixed_ip_get_by_instance') def test_deallocate_for_instance_passes_host_info_with_update_dns_entries( self, fixed_get): self.flags(update_dns_entries=True) @@ -2213,8 +2213,8 @@ class CommonNetworkTestCase(test.TestCase): (ctx, '1.2.3.4', 'fake-host'), (ctx, '4.3.2.1', 'fake-host') ], manager.deallocate_fixed_ip_calls) - @mock.patch('nova.db.fixed_ip_get_by_instance') - @mock.patch('nova.db.fixed_ip_disassociate') + @mock.patch('nova.db.api.fixed_ip_get_by_instance') + @mock.patch('nova.db.api.fixed_ip_disassociate') def test_remove_fixed_ip_from_instance(self, disassociate, get): manager = fake_network.FakeNetworkManager() get.return_value = [ @@ -2228,7 +2228,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertEqual('10.0.0.1', manager.deallocate_called) disassociate.assert_called_once_with(self.context, '10.0.0.1') - @mock.patch('nova.db.fixed_ip_get_by_instance') + @mock.patch('nova.db.api.fixed_ip_get_by_instance') def test_remove_fixed_ip_from_instance_bad_input(self, get): manager = fake_network.FakeNetworkManager() get.return_value = [] @@ -2257,7 +2257,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertIn('192.168.0.0/25', cidrs) self.assertIn('192.168.0.128/25', cidrs) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_validate_cidrs_split_cidr_in_use_middle_of_range(self, get_all): manager = fake_network.FakeNetworkManager() get_all.return_value = [dict(test_network.fake_network, @@ -2274,7 +2274,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertIn(exp_cidr, cidrs) self.assertNotIn('192.168.2.0/24', cidrs) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_validate_cidrs_smaller_subnet_in_use(self, get_all): manager = fake_network.FakeNetworkManager() get_all.return_value = [dict(test_network.fake_network, @@ -2286,7 +2286,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertRaises(exception.CidrConflict, manager.create_networks, *args) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_validate_cidrs_split_smaller_cidr_in_use(self, get_all): manager = fake_network.FakeNetworkManager() get_all.return_value = [dict(test_network.fake_network, @@ -2303,7 +2303,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertIn(exp_cidr, cidrs) self.assertNotIn('192.168.2.0/24', cidrs) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_validate_cidrs_split_smaller_cidr_in_use2(self, get_all): manager = fake_network.FakeNetworkManager() self.mox.StubOutWithMock(manager.db, 'network_get_all') @@ -2320,7 +2320,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertIn(exp_cidr, cidrs) self.assertNotIn('192.168.2.0/27', cidrs) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_validate_cidrs_split_all_in_use(self, get_all): manager = fake_network.FakeNetworkManager() in_use = [dict(test_network.fake_network, **values) for values in @@ -2343,7 +2343,7 @@ class CommonNetworkTestCase(test.TestCase): # ValueError: network_size * num_networks exceeds cidr size self.assertRaises(ValueError, manager.create_networks, *args) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_validate_cidrs_already_used(self, get_all): manager = fake_network.FakeNetworkManager() get_all.return_value = [dict(test_network.fake_network, @@ -2372,7 +2372,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertIn('192.168.0.0/24', returned_cidrs) self.assertIn('192.168.1.0/24', returned_cidrs) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_validate_cidrs_conflict_existing_supernet(self, get_all): manager = fake_network.FakeNetworkManager() get_all.return_value = [dict(test_network.fake_network, @@ -2407,7 +2407,7 @@ class CommonNetworkTestCase(test.TestCase): net = nets[0] self.assertEqual(uuid, net['uuid']) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_create_networks_cidr_already_used(self, get_all): manager = fake_network.FakeNetworkManager() get_all.return_value = [dict(test_network.fake_network, @@ -2426,8 +2426,8 @@ class CommonNetworkTestCase(test.TestCase): 'fd00::/48', None, None, None, None, None] self.assertTrue(manager.create_networks(*args)) - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.fixed_ips_by_virtual_interface') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.fixed_ips_by_virtual_interface') def test_get_instance_uuids_by_ip_regex(self, fixed_get, network_get): manager = fake_network.FakeNetworkManager(self.stubs) fixed_get.side_effect = manager.db.fixed_ips_by_virtual_interface @@ -2476,7 +2476,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertEqual(_vifs[1]['instance_uuid'], res[0]['instance_uuid']) self.assertEqual(_vifs[2]['instance_uuid'], res[1]['instance_uuid']) - @mock.patch('nova.db.network_get') + @mock.patch('nova.db.api.network_get') def test_get_instance_uuids_by_ipv6_regex(self, network_get): manager = fake_network.FakeNetworkManager(self.stubs) _vifs = manager.db.virtual_interface_get_all(None) @@ -2529,8 +2529,8 @@ class CommonNetworkTestCase(test.TestCase): self.assertEqual(_vifs[1]['instance_uuid'], res[0]['instance_uuid']) self.assertEqual(_vifs[2]['instance_uuid'], res[1]['instance_uuid']) - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.fixed_ips_by_virtual_interface') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.fixed_ips_by_virtual_interface') def test_get_instance_uuids_by_ip(self, fixed_get, network_get): manager = fake_network.FakeNetworkManager(self.stubs) fixed_get.side_effect = manager.db.fixed_ips_by_virtual_interface @@ -2566,7 +2566,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertEqual(1, len(res)) self.assertEqual(_vifs[2]['instance_uuid'], res[0]['instance_uuid']) - @mock.patch('nova.db.network_get_by_uuid') + @mock.patch('nova.db.api.network_get_by_uuid') def test_get_network(self, get): manager = fake_network.FakeNetworkManager() fake_context = context.RequestContext('user', 'project') @@ -2575,7 +2575,7 @@ class CommonNetworkTestCase(test.TestCase): network = manager.get_network(fake_context, uuid) self.assertEqual(uuid, network['uuid']) - @mock.patch('nova.db.network_get_by_uuid') + @mock.patch('nova.db.api.network_get_by_uuid') def test_get_network_not_found(self, get): manager = fake_network.FakeNetworkManager() fake_context = context.RequestContext('user', 'project') @@ -2584,7 +2584,7 @@ class CommonNetworkTestCase(test.TestCase): self.assertRaises(exception.NetworkNotFound, manager.get_network, fake_context, uuid) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_get_all_networks(self, get_all): manager = fake_network.FakeNetworkManager() fake_context = context.RequestContext('user', 'project') @@ -2597,8 +2597,8 @@ class CommonNetworkTestCase(test.TestCase): self.assertEqual('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', output[1]['uuid']) - @mock.patch('nova.db.network_get_by_uuid') - @mock.patch('nova.db.network_disassociate') + @mock.patch('nova.db.api.network_get_by_uuid') + @mock.patch('nova.db.api.network_disassociate') def test_disassociate_network(self, disassociate, get): manager = fake_network.FakeNetworkManager() disassociate.return_value = True @@ -2608,7 +2608,7 @@ class CommonNetworkTestCase(test.TestCase): uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' manager.disassociate_network(fake_context, uuid) - @mock.patch('nova.db.network_get_by_uuid') + @mock.patch('nova.db.api.network_get_by_uuid') def test_disassociate_network_not_found(self, get): manager = fake_network.FakeNetworkManager() fake_context = context.RequestContext('user', 'project') @@ -2947,11 +2947,11 @@ class FloatingIPTestCase(test.TestCase): self.context = context.RequestContext('testuser', self.project_id, is_admin=False) - @mock.patch('nova.db.fixed_ip_get') - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.instance_get_by_uuid') - @mock.patch('nova.db.service_get_by_host_and_binary') - @mock.patch('nova.db.floating_ip_get_by_address') + @mock.patch('nova.db.api.fixed_ip_get') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.instance_get_by_uuid') + @mock.patch('nova.db.api.service_get_by_host_and_binary') + @mock.patch('nova.db.api.floating_ip_get_by_address') def test_disassociate_floating_ip_multi_host_calls(self, floating_get, service_get, inst_get, net_get, @@ -2995,10 +2995,10 @@ class FloatingIPTestCase(test.TestCase): self.network.disassociate_floating_ip(ctxt, 'fl_ip', True) - @mock.patch('nova.db.fixed_ip_get_by_address') - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.instance_get_by_uuid') - @mock.patch('nova.db.floating_ip_get_by_address') + @mock.patch('nova.db.api.fixed_ip_get_by_address') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.instance_get_by_uuid') + @mock.patch('nova.db.api.floating_ip_get_by_address') def test_associate_floating_ip_multi_host_calls(self, floating_get, inst_get, net_get, fixed_get): @@ -3089,9 +3089,9 @@ class FloatingIPTestCase(test.TestCase): 'project_id': self.project_id}) self.network.deallocate_for_instance(self.context, instance=instance) - @mock.patch('nova.db.fixed_ip_get') - @mock.patch('nova.db.floating_ip_get_by_address') - @mock.patch('nova.db.floating_ip_update') + @mock.patch('nova.db.api.fixed_ip_get') + @mock.patch('nova.db.api.floating_ip_get_by_address') + @mock.patch('nova.db.api.floating_ip_update') def test_migrate_instance_start(self, floating_update, floating_get, fixed_get): called = {'count': 0} @@ -3138,8 +3138,8 @@ class FloatingIPTestCase(test.TestCase): self.assertEqual(2, called['count']) - @mock.patch('nova.db.fixed_ip_get') - @mock.patch('nova.db.floating_ip_update') + @mock.patch('nova.db.api.fixed_ip_get') + @mock.patch('nova.db.api.floating_ip_update') def test_migrate_instance_finish(self, floating_update, fixed_get): called = {'count': 0} @@ -3443,13 +3443,13 @@ class FloatingIPTestCase(test.TestCase): self.context, mock.sentinel.address)) mock_get.assert_called_once_with(self.context, mock.sentinel.address) - @mock.patch('nova.db.floating_ip_get_pools') + @mock.patch('nova.db.api.floating_ip_get_pools') def test_floating_ip_pool_exists(self, floating_ip_get_pools): floating_ip_get_pools.return_value = [{'name': 'public'}] self.assertTrue(self.network._floating_ip_pool_exists(self.context, 'public')) - @mock.patch('nova.db.floating_ip_get_pools') + @mock.patch('nova.db.api.floating_ip_get_pools') def test_floating_ip_pool_does_not_exist(self, floating_ip_get_pools): floating_ip_get_pools.return_value = [] self.assertFalse(self.network._floating_ip_pool_exists(self.context, diff --git a/nova/tests/unit/notifications/objects/test_notification.py b/nova/tests/unit/notifications/objects/test_notification.py index 26a890f759..6172bcf8d6 100644 --- a/nova/tests/unit/notifications/objects/test_notification.py +++ b/nova/tests/unit/notifications/objects/test_notification.py @@ -136,7 +136,8 @@ class TestNotificationBase(test.NoDBTestCase): def setUp(self): super(TestNotificationBase, self).setUp() - with mock.patch('nova.db.service_update') as mock_db_service_update: + with mock.patch( + 'nova.db.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 c228a8674a..c681163874 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.service_update') + @mock.patch('nova.db.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.service_update') + @mock.patch('nova.db.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.service_create') + @mock.patch('nova.db.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.service_destroy') + @mock.patch('nova.db.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_agent.py b/nova/tests/unit/objects/test_agent.py index 87ff38f92c..352dbba2a8 100644 --- a/nova/tests/unit/objects/test_agent.py +++ b/nova/tests/unit/objects/test_agent.py @@ -40,21 +40,21 @@ class _TestAgent(object): for field, value in db.items(): test.assertEqual(db[field], getattr(obj, field)) - @mock.patch('nova.db.agent_build_get_by_triple') + @mock.patch('nova.db.api.agent_build_get_by_triple') def test_get_by_triple(self, mock_get): mock_get.return_value = fake_agent agent = agent_obj.Agent.get_by_triple(self.context, 'novavm', 'linux', 'DISC') self._compare(self, fake_agent, agent) - @mock.patch('nova.db.agent_build_get_by_triple') + @mock.patch('nova.db.api.agent_build_get_by_triple') def test_get_by_triple_none(self, mock_get): mock_get.return_value = None agent = agent_obj.Agent.get_by_triple(self.context, 'novavm', 'linux', 'DISC') self.assertIsNone(agent) - @mock.patch('nova.db.agent_build_create') + @mock.patch('nova.db.api.agent_build_create') def test_create(self, mock_create): mock_create.return_value = fake_agent agent = agent_obj.Agent(context=self.context) @@ -64,19 +64,19 @@ class _TestAgent(object): {'hypervisor': 'novavm'}) self._compare(self, fake_agent, agent) - @mock.patch('nova.db.agent_build_create') + @mock.patch('nova.db.api.agent_build_create') def test_create_with_id(self, mock_create): agent = agent_obj.Agent(context=self.context, id=123) self.assertRaises(exception.ObjectActionError, agent.create) self.assertFalse(mock_create.called) - @mock.patch('nova.db.agent_build_destroy') + @mock.patch('nova.db.api.agent_build_destroy') def test_destroy(self, mock_destroy): agent = agent_obj.Agent(context=self.context, id=123) agent.destroy() mock_destroy.assert_called_once_with(self.context, 123) - @mock.patch('nova.db.agent_build_update') + @mock.patch('nova.db.api.agent_build_update') def test_save(self, mock_update): mock_update.return_value = fake_agent agent = agent_obj.Agent(context=self.context, id=123) @@ -86,7 +86,7 @@ class _TestAgent(object): mock_update.assert_called_once_with(self.context, 123, {'hypervisor': 'novavm'}) - @mock.patch('nova.db.agent_build_get_all') + @mock.patch('nova.db.api.agent_build_get_all') def test_get_all(self, mock_get_all): mock_get_all.return_value = [fake_agent] agents = agent_obj.AgentList.get_all(self.context, hypervisor='novavm') diff --git a/nova/tests/unit/objects/test_bandwidth_usage.py b/nova/tests/unit/objects/test_bandwidth_usage.py index 44030d42bf..cde7dcdaaa 100644 --- a/nova/tests/unit/objects/test_bandwidth_usage.py +++ b/nova/tests/unit/objects/test_bandwidth_usage.py @@ -17,7 +17,7 @@ import mock from oslo_utils import timeutils from nova import context -from nova import db +from nova.db 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 961ae01509..32e35068fd 100644 --- a/nova/tests/unit/objects/test_block_device.py +++ b/nova/tests/unit/objects/test_block_device.py @@ -16,7 +16,7 @@ import mock from nova.cells import rpcapi as cells_rpcapi from nova import context -from nova import db +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 import exception diff --git a/nova/tests/unit/objects/test_compute_node.py b/nova/tests/unit/objects/test_compute_node.py index 7dedb67dba..51a7b72bf5 100644 --- a/nova/tests/unit/objects/test_compute_node.py +++ b/nova/tests/unit/objects/test_compute_node.py @@ -21,7 +21,7 @@ from oslo_utils import timeutils from oslo_versionedobjects import base as ovo_base from oslo_versionedobjects import exception as ovo_exc -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import base @@ -235,7 +235,7 @@ class _TestComputeNodeObject(object): subs=self.subs(), comparators=self.comparators()) - @mock.patch('nova.db.compute_node_get_all_by_host') + @mock.patch('nova.db.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() @@ -262,7 +262,7 @@ class _TestComputeNodeObject(object): self.context, 'fake') @mock.patch.object(db, 'compute_node_create') - @mock.patch('nova.db.compute_node_get', return_value=fake_compute_node) + @mock.patch('nova.db.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) @@ -287,9 +287,9 @@ class _TestComputeNodeObject(object): } mock_create.assert_called_once_with(self.context, param_dict) - @mock.patch('nova.db.compute_node_create') + @mock.patch('nova.db.api.compute_node_create') @mock.patch('oslo_utils.uuidutils.generate_uuid') - @mock.patch('nova.db.compute_node_get', return_value=fake_compute_node) + @mock.patch('nova.db.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'] @@ -299,8 +299,8 @@ class _TestComputeNodeObject(object): mock_create.assert_called_once_with( self.context, {'uuid': fake_compute_node['uuid']}) - @mock.patch('nova.db.compute_node_create') - @mock.patch('nova.db.compute_node_get', return_value=fake_compute_node) + @mock.patch('nova.db.api.compute_node_create') + @mock.patch('nova.db.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) @@ -313,7 +313,7 @@ class _TestComputeNodeObject(object): mock_create.assert_called_once_with(self.context, param_dict) @mock.patch.object(db, 'compute_node_update') - @mock.patch('nova.db.compute_node_get', return_value=fake_compute_node) + @mock.patch('nova.db.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) @@ -337,7 +337,7 @@ class _TestComputeNodeObject(object): } mock_update.assert_called_once_with(self.context, 123, param_dict) - @mock.patch('nova.db.compute_node_update') + @mock.patch('nova.db.api.compute_node_update') def test_save_pci_device_pools_empty(self, mock_update): fake_pci = jsonutils.dumps( objects.PciDevicePoolList(objects=[]).obj_to_primitive()) @@ -356,7 +356,7 @@ class _TestComputeNodeObject(object): mock_update.assert_called_once_with( self.context, 123, {'pci_stats': fake_pci}) - @mock.patch('nova.db.compute_node_update') + @mock.patch('nova.db.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 @@ -412,7 +412,7 @@ class _TestComputeNodeObject(object): comparators=self.comparators()) mock_search.assert_called_once_with(self.context, 'hyper') - @mock.patch('nova.db.compute_node_get_all_by_pagination', + @mock.patch('nova.db.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( @@ -422,7 +422,7 @@ class _TestComputeNodeObject(object): subs=self.subs(), comparators=self.comparators()) - @mock.patch('nova.db.compute_nodes_get_by_service_id') + @mock.patch('nova.db.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, @@ -432,7 +432,7 @@ class _TestComputeNodeObject(object): subs=self.subs(), comparators=self.comparators()) - @mock.patch('nova.db.compute_node_get_all_by_host') + @mock.patch('nova.db.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, diff --git a/nova/tests/unit/objects/test_console_auth_token.py b/nova/tests/unit/objects/test_console_auth_token.py index b92399a5f4..f566dadbb4 100644 --- a/nova/tests/unit/objects/test_console_auth_token.py +++ b/nova/tests/unit/objects/test_console_auth_token.py @@ -28,7 +28,7 @@ from nova.tests import uuidsentinel class _TestConsoleAuthToken(object): - @mock.patch('nova.db.console_auth_token_create') + @mock.patch('nova.db.api.console_auth_token_create') def test_authorize(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 @@ -75,7 +75,7 @@ class _TestConsoleAuthToken(object): fakes.fake_token) self.assertEqual(expected_url, url) - @mock.patch('nova.db.console_auth_token_create') + @mock.patch('nova.db.api.console_auth_token_create') def test_authorize_duplicate_token(self, mock_create): mock_create.side_effect = DBDuplicateEntry() @@ -93,7 +93,7 @@ class _TestConsoleAuthToken(object): obj.authorize, 100) - @mock.patch('nova.db.console_auth_token_create') + @mock.patch('nova.db.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']) @@ -112,7 +112,7 @@ class _TestConsoleAuthToken(object): obj.authorize, 100) - @mock.patch('nova.db.console_auth_token_create') + @mock.patch('nova.db.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 @@ -140,14 +140,14 @@ class _TestConsoleAuthToken(object): obj.authorize, 100) - @mock.patch('nova.db.console_auth_token_destroy_all_by_instance') + @mock.patch('nova.db.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.console_auth_token_destroy_expired_by_host') + @mock.patch('nova.db.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_dns_domain.py b/nova/tests/unit/objects/test_dns_domain.py index 71ea5979d1..fc2810fbed 100644 --- a/nova/tests/unit/objects/test_dns_domain.py +++ b/nova/tests/unit/objects/test_dns_domain.py @@ -14,7 +14,7 @@ import mock -from nova import db +from nova.db import api as db from nova.objects import dns_domain from nova.tests.unit.objects import test_objects diff --git a/nova/tests/unit/objects/test_ec2.py b/nova/tests/unit/objects/test_ec2.py index a9d781785c..efd8630311 100644 --- a/nova/tests/unit/objects/test_ec2.py +++ b/nova/tests/unit/objects/test_ec2.py @@ -14,7 +14,7 @@ import mock -from nova import db +from nova.db 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_fixed_ip.py b/nova/tests/unit/objects/test_fixed_ip.py index 922550a8f1..8d59251b59 100644 --- a/nova/tests/unit/objects/test_fixed_ip.py +++ b/nova/tests/unit/objects/test_fixed_ip.py @@ -67,15 +67,15 @@ class _TestFixedIPObject(object): obj_val = str(obj_val) self.assertEqual(db_val, obj_val) - @mock.patch('nova.db.fixed_ip_get') + @mock.patch('nova.db.api.fixed_ip_get') def test_get_by_id(self, get): get.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP.get_by_id(self.context, 123) get.assert_called_once_with(self.context, 123, get_network=False) self._compare(fixedip, fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_get') - @mock.patch('nova.db.network_get') + @mock.patch('nova.db.api.fixed_ip_get') + @mock.patch('nova.db.api.network_get') def test_get_by_id_with_extras(self, network_get, fixed_get): db_fixed = dict(fake_fixed_ip, network=test_network.fake_network) @@ -87,7 +87,7 @@ class _TestFixedIPObject(object): self.assertEqual(db_fixed['network']['uuid'], fixedip.network.uuid) self.assertFalse(network_get.called) - @mock.patch('nova.db.fixed_ip_get_by_address') + @mock.patch('nova.db.api.fixed_ip_get_by_address') def test_get_by_address(self, get): get.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP.get_by_address(self.context, '1.2.3.4') @@ -95,9 +95,9 @@ class _TestFixedIPObject(object): columns_to_join=[]) self._compare(fixedip, fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_get_by_address') - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.instance_get') + @mock.patch('nova.db.api.fixed_ip_get_by_address') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.instance_get') def test_get_by_address_with_extras(self, instance_get, network_get, fixed_get): db_fixed = dict(fake_fixed_ip, network=test_network.fake_network, @@ -115,9 +115,9 @@ class _TestFixedIPObject(object): self.assertFalse(network_get.called) self.assertFalse(instance_get.called) - @mock.patch('nova.db.fixed_ip_get_by_address') - @mock.patch('nova.db.network_get') - @mock.patch('nova.db.instance_get') + @mock.patch('nova.db.api.fixed_ip_get_by_address') + @mock.patch('nova.db.api.network_get') + @mock.patch('nova.db.api.instance_get') def test_get_by_address_with_extras_deleted_instance(self, instance_get, network_get, fixed_get): @@ -136,7 +136,7 @@ class _TestFixedIPObject(object): self.assertFalse(network_get.called) self.assertFalse(instance_get.called) - @mock.patch('nova.db.fixed_ip_get_by_floating_address') + @mock.patch('nova.db.api.fixed_ip_get_by_floating_address') def test_get_by_floating_address(self, get): get.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP.get_by_floating_address(self.context, @@ -144,7 +144,7 @@ class _TestFixedIPObject(object): get.assert_called_once_with(self.context, '1.2.3.4') self._compare(fixedip, fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_get_by_floating_address') + @mock.patch('nova.db.api.fixed_ip_get_by_floating_address') def test_get_by_floating_address_none(self, get): get.return_value = None fixedip = fixed_ip.FixedIP.get_by_floating_address(self.context, @@ -152,7 +152,7 @@ class _TestFixedIPObject(object): get.assert_called_once_with(self.context, '1.2.3.4') self.assertIsNone(fixedip) - @mock.patch('nova.db.fixed_ip_get_by_network_host') + @mock.patch('nova.db.api.fixed_ip_get_by_network_host') def test_get_by_network_and_host(self, get): get.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP.get_by_network_and_host(self.context, @@ -160,7 +160,7 @@ class _TestFixedIPObject(object): get.assert_called_once_with(self.context, 123, 'host') self._compare(fixedip, fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_associate') + @mock.patch('nova.db.api.fixed_ip_associate') def test_associate(self, associate): associate.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP.associate(self.context, '1.2.3.4', @@ -170,7 +170,7 @@ class _TestFixedIPObject(object): virtual_interface_id=None) self._compare(fixedip, fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_associate') + @mock.patch('nova.db.api.fixed_ip_associate') def test_associate_with_vif(self, associate): associate.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP.associate(self.context, '1.2.3.4', @@ -182,7 +182,7 @@ class _TestFixedIPObject(object): virtual_interface_id=0) self._compare(fixedip, fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_associate_pool') + @mock.patch('nova.db.api.fixed_ip_associate_pool') def test_associate_pool(self, associate): associate.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP.associate_pool(self.context, 123, @@ -192,7 +192,7 @@ class _TestFixedIPObject(object): host='host', virtual_interface_id=None) self._compare(fixedip, fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_associate_pool') + @mock.patch('nova.db.api.fixed_ip_associate_pool') def test_associate_pool_with_vif(self, associate): associate.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP.associate_pool(self.context, 123, @@ -203,12 +203,12 @@ class _TestFixedIPObject(object): host='host', virtual_interface_id=0) self._compare(fixedip, fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_disassociate') + @mock.patch('nova.db.api.fixed_ip_disassociate') def test_disassociate_by_address(self, disassociate): fixed_ip.FixedIP.disassociate_by_address(self.context, '1.2.3.4') disassociate.assert_called_with(self.context, '1.2.3.4') - @mock.patch('nova.db.fixed_ip_disassociate_all_by_timeout') + @mock.patch('nova.db.api.fixed_ip_disassociate_all_by_timeout') def test_disassociate_all_by_timeout(self, disassociate): now = timeutils.utcnow() now_tz = timeutils.parse_isotime( @@ -224,7 +224,7 @@ class _TestFixedIPObject(object): self.assertEqual((self.context, 'host'), args[:2]) self.assertEqual({}, kwargs) - @mock.patch('nova.db.fixed_ip_create') + @mock.patch('nova.db.api.fixed_ip_create') def test_create(self, create): create.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP(context=self.context, address='1.2.3.4') @@ -233,7 +233,7 @@ class _TestFixedIPObject(object): self.context, {'address': '1.2.3.4'}) self._compare(fixedip, fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_update') + @mock.patch('nova.db.api.fixed_ip_update') def test_save(self, update): update.return_value = fake_fixed_ip fixedip = fixed_ip.FixedIP(context=self.context, address='1.2.3.4', @@ -244,7 +244,7 @@ class _TestFixedIPObject(object): update.assert_called_once_with(self.context, '1.2.3.4', {'instance_uuid': uuids.instance}) - @mock.patch('nova.db.fixed_ip_disassociate') + @mock.patch('nova.db.api.fixed_ip_disassociate') def test_disassociate(self, disassociate): fixedip = fixed_ip.FixedIP(context=self.context, address='1.2.3.4', instance_uuid=uuids.instance) @@ -253,7 +253,7 @@ class _TestFixedIPObject(object): disassociate.assert_called_once_with(self.context, '1.2.3.4') self.assertIsNone(fixedip.instance_uuid) - @mock.patch('nova.db.fixed_ip_get_all') + @mock.patch('nova.db.api.fixed_ip_get_all') def test_get_all(self, get_all): get_all.return_value = [fake_fixed_ip] fixedips = fixed_ip.FixedIPList.get_all(self.context) @@ -261,7 +261,7 @@ class _TestFixedIPObject(object): get_all.assert_called_once_with(self.context) self._compare(fixedips[0], fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_get_by_instance') + @mock.patch('nova.db.api.fixed_ip_get_by_instance') def test_get_by_instance(self, get): get.return_value = [fake_fixed_ip] fixedips = fixed_ip.FixedIPList.get_by_instance_uuid(self.context, @@ -270,7 +270,7 @@ class _TestFixedIPObject(object): get.assert_called_once_with(self.context, uuids.instance) self._compare(fixedips[0], fake_fixed_ip) - @mock.patch('nova.db.fixed_ip_get_by_host') + @mock.patch('nova.db.api.fixed_ip_get_by_host') def test_get_by_host(self, get): get.return_value = [fake_fixed_ip] fixedips = fixed_ip.FixedIPList.get_by_host(self.context, 'host') @@ -278,7 +278,7 @@ class _TestFixedIPObject(object): get.assert_called_once_with(self.context, 'host') self._compare(fixedips[0], fake_fixed_ip) - @mock.patch('nova.db.fixed_ips_by_virtual_interface') + @mock.patch('nova.db.api.fixed_ips_by_virtual_interface') def test_get_by_virtual_interface_id(self, get): get.return_value = [fake_fixed_ip] fixedips = fixed_ip.FixedIPList.get_by_virtual_interface_id( @@ -291,7 +291,7 @@ class _TestFixedIPObject(object): fixedip = fixed_ip.FixedIP() self.assertRaises(NotImplementedError, lambda: fixedip.floating_ips) - @mock.patch('nova.db.fixed_ip_bulk_create') + @mock.patch('nova.db.api.fixed_ip_bulk_create') def test_bulk_create(self, bulk): fixed_ips = [fixed_ip.FixedIP(address='192.168.1.1'), fixed_ip.FixedIP(address='192.168.1.2')] @@ -300,7 +300,7 @@ class _TestFixedIPObject(object): [{'address': '192.168.1.1'}, {'address': '192.168.1.2'}]) - @mock.patch('nova.db.network_get_associated_fixed_ips') + @mock.patch('nova.db.api.network_get_associated_fixed_ips') def test_get_by_network(self, get): info = {'address': '1.2.3.4', 'instance_uuid': uuids.instance, @@ -333,7 +333,7 @@ class _TestFixedIPObject(object): self.assertEqual(1, fip.virtual_interface.id) self.assertEqual(info['vif_address'], fip.virtual_interface.address) - @mock.patch('nova.db.network_get_associated_fixed_ips') + @mock.patch('nova.db.api.network_get_associated_fixed_ips') def test_backport_default_route(self, mock_get): info = {'address': '1.2.3.4', 'instance_uuid': uuids.instance, diff --git a/nova/tests/unit/objects/test_floating_ip.py b/nova/tests/unit/objects/test_floating_ip.py index 5b691747e2..94291807a5 100644 --- a/nova/tests/unit/objects/test_floating_ip.py +++ b/nova/tests/unit/objects/test_floating_ip.py @@ -58,7 +58,7 @@ class _TestFloatingIPObject(object): obj_val = str(obj_val) self.assertEqual(db_val, obj_val) - @mock.patch('nova.db.floating_ip_get') + @mock.patch('nova.db.api.floating_ip_get') def test_get_by_id(self, get): db_floatingip = dict(fake_floating_ip, fixed_ip=test_fixed_ip.fake_fixed_ip) @@ -67,7 +67,7 @@ class _TestFloatingIPObject(object): get.assert_called_once_with(self.context, 123) self._compare(floatingip, db_floatingip) - @mock.patch('nova.db.floating_ip_get_by_address') + @mock.patch('nova.db.api.floating_ip_get_by_address') def test_get_by_address(self, get): get.return_value = fake_floating_ip floatingip = floating_ip.FloatingIP.get_by_address(self.context, @@ -75,13 +75,13 @@ class _TestFloatingIPObject(object): get.assert_called_once_with(self.context, '1.2.3.4') self._compare(floatingip, fake_floating_ip) - @mock.patch('nova.db.floating_ip_get_pools') + @mock.patch('nova.db.api.floating_ip_get_pools') def test_get_pool_names(self, get): get.return_value = [{'name': 'a'}, {'name': 'b'}] self.assertEqual(['a', 'b'], floating_ip.FloatingIP.get_pool_names(self.context)) - @mock.patch('nova.db.floating_ip_allocate_address') + @mock.patch('nova.db.api.floating_ip_allocate_address') def test_allocate_address(self, allocate): allocate.return_value = '1.2.3.4' self.assertEqual('1.2.3.4', @@ -91,7 +91,7 @@ class _TestFloatingIPObject(object): allocate.assert_called_with(self.context, 'project', 'pool', auto_assigned=False) - @mock.patch('nova.db.floating_ip_fixed_ip_associate') + @mock.patch('nova.db.api.floating_ip_fixed_ip_associate') def test_associate(self, associate): db_fixed = dict(test_fixed_ip.fake_fixed_ip, network=test_network.fake_network) @@ -106,17 +106,17 @@ class _TestFloatingIPObject(object): self.assertEqual('172.17.0.1', str(floatingip.address)) self.assertEqual('host', floatingip.host) - @mock.patch('nova.db.floating_ip_deallocate') + @mock.patch('nova.db.api.floating_ip_deallocate') def test_deallocate(self, deallocate): floating_ip.FloatingIP.deallocate(self.context, '1.2.3.4') deallocate.assert_called_with(self.context, '1.2.3.4') - @mock.patch('nova.db.floating_ip_destroy') + @mock.patch('nova.db.api.floating_ip_destroy') def test_destroy(self, destroy): floating_ip.FloatingIP.destroy(self.context, '1.2.3.4') destroy.assert_called_with(self.context, '1.2.3.4') - @mock.patch('nova.db.floating_ip_disassociate') + @mock.patch('nova.db.api.floating_ip_disassociate') def test_disassociate(self, disassociate): db_fixed = dict(test_fixed_ip.fake_fixed_ip, network=test_network.fake_network) @@ -127,7 +127,7 @@ class _TestFloatingIPObject(object): self.assertEqual(db_fixed['id'], floatingip.fixed_ip.id) self.assertEqual('1.2.3.4', str(floatingip.address)) - @mock.patch('nova.db.floating_ip_update') + @mock.patch('nova.db.api.floating_ip_update') def test_save(self, update): update.return_value = fake_floating_ip floatingip = floating_ip.FloatingIP(context=self.context, @@ -150,7 +150,7 @@ class _TestFloatingIPObject(object): floatingip.fixed_ip_id = 1 self.assertRaises(exception.ObjectActionError, floatingip.save) - @mock.patch('nova.db.floating_ip_update') + @mock.patch('nova.db.api.floating_ip_update') def test_save_no_fixedip(self, update): update.return_value = fake_floating_ip floatingip = floating_ip.FloatingIP(context=self.context, @@ -159,7 +159,7 @@ class _TestFloatingIPObject(object): id=456) self.assertNotIn('fixed_ip', update.calls[1]) - @mock.patch('nova.db.floating_ip_get_all') + @mock.patch('nova.db.api.floating_ip_get_all') def test_get_all(self, get): get.return_value = [fake_floating_ip] floatingips = floating_ip.FloatingIPList.get_all(self.context) @@ -167,7 +167,7 @@ class _TestFloatingIPObject(object): self._compare(floatingips[0], fake_floating_ip) get.assert_called_with(self.context) - @mock.patch('nova.db.floating_ip_get_all_by_host') + @mock.patch('nova.db.api.floating_ip_get_all_by_host') def test_get_by_host(self, get): get.return_value = [fake_floating_ip] floatingips = floating_ip.FloatingIPList.get_by_host(self.context, @@ -176,7 +176,7 @@ class _TestFloatingIPObject(object): self._compare(floatingips[0], fake_floating_ip) get.assert_called_with(self.context, 'host') - @mock.patch('nova.db.floating_ip_get_all_by_project') + @mock.patch('nova.db.api.floating_ip_get_all_by_project') def test_get_by_project(self, get): get.return_value = [fake_floating_ip] floatingips = floating_ip.FloatingIPList.get_by_project(self.context, @@ -185,7 +185,7 @@ class _TestFloatingIPObject(object): self._compare(floatingips[0], fake_floating_ip) get.assert_called_with(self.context, 'project') - @mock.patch('nova.db.floating_ip_get_by_fixed_address') + @mock.patch('nova.db.api.floating_ip_get_by_fixed_address') def test_get_by_fixed_address(self, get): get.return_value = [fake_floating_ip] floatingips = floating_ip.FloatingIPList.get_by_fixed_address( @@ -194,7 +194,7 @@ class _TestFloatingIPObject(object): self._compare(floatingips[0], fake_floating_ip) get.assert_called_with(self.context, '1.2.3.4') - @mock.patch('nova.db.floating_ip_get_by_fixed_ip_id') + @mock.patch('nova.db.api.floating_ip_get_by_fixed_ip_id') def test_get_by_fixed_ip_id(self, get): get.return_value = [fake_floating_ip] floatingips = floating_ip.FloatingIPList.get_by_fixed_ip_id( @@ -203,7 +203,7 @@ class _TestFloatingIPObject(object): self._compare(floatingips[0], fake_floating_ip) get.assert_called_with(self.context, 123) - @mock.patch('nova.db.instance_floating_address_get_all') + @mock.patch('nova.db.api.instance_floating_address_get_all') def test_get_addresses_by_instance(self, get_all): expected = ['1.2.3.4', '4.5.6.7'] get_all.return_value = list(expected) @@ -218,7 +218,7 @@ class _TestFloatingIPObject(object): 'interface': 'eth0'}, result) - @mock.patch('nova.db.floating_ip_bulk_create') + @mock.patch('nova.db.api.floating_ip_bulk_create') def test_bulk_create(self, create_mock): def fake_create(ctxt, ip_info, want_result=False): return [{'id': 1, 'address': ip['address'], 'fixed_ip_id': 1, @@ -238,7 +238,7 @@ class _TestFloatingIPObject(object): self.assertEqual('1.1.1.1', str(result[0].address)) self.assertEqual('1.1.1.2', str(result[1].address)) - @mock.patch('nova.db.floating_ip_bulk_destroy') + @mock.patch('nova.db.api.floating_ip_bulk_destroy') def test_bulk_destroy(self, destroy_mock): ips = [{'address': '1.2.3.4'}, {'address': '4.5.6.7'}] objects.FloatingIPList.destroy(None, ips) diff --git a/nova/tests/unit/objects/test_instance.py b/nova/tests/unit/objects/test_instance.py index d22064159f..7d7abcb133 100644 --- a/nova/tests/unit/objects/test_instance.py +++ b/nova/tests/unit/objects/test_instance.py @@ -24,7 +24,7 @@ from nova.cells import rpcapi as cells_rpcapi from nova.compute import flavors from nova.compute import task_states from nova.compute import vm_states -from nova import db +from nova.db import api as db from nova import exception from nova.network import model as network_model from nova import notifications @@ -545,7 +545,7 @@ class _TestInstanceObject(object): 'system_metadata']) mock_send.assert_called_once_with(self.context, mock.ANY, mock.ANY) - @mock.patch('nova.db.instance_extra_update_by_uuid') + @mock.patch('nova.db.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, "spec": [{"vendor_id": "8086",' @@ -576,7 +576,7 @@ class _TestInstanceObject(object): inst.save() self.assertFalse(mock_instance_extra_update.called) - @mock.patch('nova.db.instance_update_and_get_original') + @mock.patch('nova.db.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 +592,8 @@ class _TestInstanceObject(object): self.assertNotIn('pci_devices', mock_fdo.call_args_list[0][1]['expected_attrs']) - @mock.patch('nova.db.instance_extra_update_by_uuid') - @mock.patch('nova.db.instance_update_and_get_original') + @mock.patch('nova.db.api.instance_extra_update_by_uuid') + @mock.patch('nova.db.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): @@ -627,7 +627,7 @@ class _TestInstanceObject(object): mock_extra_update.assert_called_once_with( self.context, inst.uuid, {'numa_topology': None}) - @mock.patch('nova.db.instance_extra_update_by_uuid') + @mock.patch('nova.db.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 @@ -647,7 +647,7 @@ class _TestInstanceObject(object): mock_update.assert_called_once_with( self.context, inst.uuid, {'vcpu_model': None}) - @mock.patch('nova.db.instance_extra_update_by_uuid') + @mock.patch('nova.db.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( @@ -673,11 +673,12 @@ class _TestInstanceObject(object): inst = objects.Instance(context=self.context, flavor=objects.Flavor()) inst.obj_reset_changes() - with mock.patch('nova.db.instance_extra_update_by_uuid') as mock_upd: + with mock.patch( + 'nova.db.api.instance_extra_update_by_uuid') as mock_upd: inst.save() self.assertFalse(mock_upd.called) - @mock.patch('nova.db.instance_extra_update_by_uuid') + @mock.patch('nova.db.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 @@ -995,7 +996,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.instance_get_by_uuid') + @mock.patch('nova.db.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'] @@ -1009,7 +1010,7 @@ class _TestInstanceObject(object): self.assertEqual(fake_ec2_ids.instance_id, inst.ec2_ids.instance_id) - @mock.patch('nova.db.instance_get_by_uuid') + @mock.patch('nova.db.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 @@ -1311,7 +1312,7 @@ class _TestInstanceObject(object): expected_attrs=['security_groups']) self.assertEqual([], inst.security_groups.objects) - @mock.patch('nova.db.instance_extra_get_by_instance_uuid', + @mock.patch('nova.db.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() @@ -1449,7 +1450,7 @@ class _TestInstanceObject(object): inst.migration_context.instance_uuid = inst.uuid inst.migration_context.id = 7 with mock.patch( - 'nova.db.instance_extra_update_by_uuid') as update_extra: + 'nova.db.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, @@ -1531,7 +1532,7 @@ class _TestInstanceObject(object): uuid=uuids.instance, expected_attrs=['vm_state']) - @mock.patch('nova.db.instance_fault_get_by_instance_uuids') + @mock.patch('nova.db.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]} @@ -1807,7 +1808,7 @@ class _TestInstanceListObject(object): type_id='bar') @mock.patch('nova.objects.instance._expected_cols') - @mock.patch('nova.db.instance_get_all') + @mock.patch('nova.db.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 @@ -1985,7 +1986,7 @@ class _TestInstanceListObject(object): self.assertEqual(2, len(instances)) self.assertEqual([1, 2], [x.id for x in instances]) - @mock.patch('nova.db.instance_get_all_uuids_by_host') + @mock.patch('nova.db.api.instance_get_all_uuids_by_host') def test_get_uuids_by_host(self, mock_get_all): fake_instances = [uuids.inst1, uuids.inst2] mock_get_all.return_value = fake_instances diff --git a/nova/tests/unit/objects/test_instance_action.py b/nova/tests/unit/objects/test_instance_action.py index 5958845055..be344093b6 100644 --- a/nova/tests/unit/objects/test_instance_action.py +++ b/nova/tests/unit/objects/test_instance_action.py @@ -19,7 +19,7 @@ from oslo_utils import fixture as utils_fixture from oslo_utils import timeutils import six -from nova import db +from nova.db import api as db from nova.objects import instance_action from nova import test from nova.tests.unit.objects import test_objects diff --git a/nova/tests/unit/objects/test_instance_device_metadata.py b/nova/tests/unit/objects/test_instance_device_metadata.py index 336b88388c..ee9266479a 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.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.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 f4b451dced..38cef458d3 100644 --- a/nova/tests/unit/objects/test_instance_fault.py +++ b/nova/tests/unit/objects/test_instance_fault.py @@ -14,7 +14,7 @@ import mock -from nova import db +from nova.db import api as db from nova import exception from nova.objects import instance_fault from nova.tests.unit.objects import test_objects @@ -73,7 +73,7 @@ class _TestInstanceFault(object): get_mock.assert_called_once_with(self.context, ['fake-uuid']) @mock.patch('nova.cells.rpcapi.CellsAPI.instance_fault_create_at_top') - @mock.patch('nova.db.instance_fault_create') + @mock.patch('nova.db.api.instance_fault_create') def _test_create(self, update_cells, mock_create, cells_fault_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 7659e9ec4a..227f0ffc33 100644 --- a/nova/tests/unit/objects/test_instance_info_cache.py +++ b/nova/tests/unit/objects/test_instance_info_cache.py @@ -19,7 +19,7 @@ from oslo_utils import timeutils from nova.cells import opts as cells_opts from nova.cells import rpcapi as cells_rpcapi -from nova import db +from nova.db 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_topology.py b/nova/tests/unit/objects/test_instance_numa_topology.py index 16b33ac4c6..188baaf17a 100644 --- a/nova/tests/unit/objects/test_instance_numa_topology.py +++ b/nova/tests/unit/objects/test_instance_numa_topology.py @@ -50,7 +50,7 @@ def get_fake_obj_numa_topology(context): class _TestInstanceNUMATopology(object): - @mock.patch('nova.db.instance_extra_update_by_uuid') + @mock.patch('nova.db.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'] @@ -70,12 +70,12 @@ class _TestInstanceNUMATopology(object): self.assertEqual(topo_cell.memory, obj_cell.memory) self.assertEqual(topo_cell.pagesize, obj_cell.pagesize) - @mock.patch('nova.db.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.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.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.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 6d568fa1c1..933846bafe 100644 --- a/nova/tests/unit/objects/test_instance_pci_requests.py +++ b/nova/tests/unit/objects/test_instance_pci_requests.py @@ -54,7 +54,7 @@ fake_legacy_pci_requests = [ class _TestInstancePCIRequests(object): - @mock.patch('nova.db.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.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 a252003f22..a0a33efce1 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.key_pair_get') + @mock.patch('nova.db.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.key_pair_get_all_by_user') - @mock.patch('nova.db.key_pair_count_by_user') + @mock.patch('nova.db.api.key_pair_get_all_by_user') + @mock.patch('nova.db.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.key_pair_get_all_by_user') + @mock.patch('nova.db.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.key_pair_get_all_by_user') + @mock.patch('nova.db.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.key_pair_get_all_by_user') + @mock.patch('nova.db.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.key_pair_get_all_by_user') + @mock.patch('nova.db.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.key_pair_get_all_by_user') + @mock.patch('nova.db.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 bda9a5c8db..a841837c81 100644 --- a/nova/tests/unit/objects/test_migration.py +++ b/nova/tests/unit/objects/test_migration.py @@ -16,7 +16,7 @@ import mock from oslo_utils import timeutils from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import migration @@ -82,7 +82,7 @@ class _TestMigrationObject(object): fake_migration['id'], 'migrating') - @mock.patch('nova.db.migration_get_in_progress_by_instance') + @mock.patch('nova.db.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() @@ -221,7 +221,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.migration_get') as fake_get: + with mock.patch('nova.db.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')) @@ -231,7 +231,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.migration_get') as fake_get: + with mock.patch('nova.db.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')) @@ -249,7 +249,7 @@ class _TestMigrationObject(object): self.assertEqual('migration', mig.migration_type) self.assertTrue(mig.obj_attr_is_set('migration_type')) - @mock.patch('nova.db.migration_get_by_id_and_instance') + @mock.patch('nova.db.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() diff --git a/nova/tests/unit/objects/test_migration_context.py b/nova/tests/unit/objects/test_migration_context.py index b1c2d7bd72..1f1a854843 100644 --- a/nova/tests/unit/objects/test_migration_context.py +++ b/nova/tests/unit/objects/test_migration_context.py @@ -82,19 +82,19 @@ class _TestMigrationContext(object): else: self.assertIsNone(mig_context) - @mock.patch('nova.db.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.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.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.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.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.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_network.py b/nova/tests/unit/objects/test_network.py index bcc45fd6ff..f964510211 100644 --- a/nova/tests/unit/objects/test_network.py +++ b/nova/tests/unit/objects/test_network.py @@ -70,7 +70,7 @@ class _TestNetworkObject(object): db_val = str(netaddr.IPNetwork('1::/%i' % db_val).netmask) self.assertEqual(db_val, obj_val) - @mock.patch('nova.db.network_get') + @mock.patch('nova.db.api.network_get') def test_get_by_id(self, get): get.return_value = fake_network network = network_obj.Network.get_by_id(self.context, 'foo') @@ -78,14 +78,14 @@ class _TestNetworkObject(object): get.assert_called_once_with(self.context, 'foo', project_only='allow_none') - @mock.patch('nova.db.network_get_by_uuid') + @mock.patch('nova.db.api.network_get_by_uuid') def test_get_by_uuid(self, get): get.return_value = fake_network network = network_obj.Network.get_by_uuid(self.context, 'foo') self._compare(network, fake_network) get.assert_called_once_with(self.context, 'foo') - @mock.patch('nova.db.network_get_by_cidr') + @mock.patch('nova.db.api.network_get_by_cidr') def test_get_by_cidr(self, get): get.return_value = fake_network network = network_obj.Network.get_by_cidr(self.context, @@ -93,8 +93,8 @@ class _TestNetworkObject(object): self._compare(network, fake_network) get.assert_called_once_with(self.context, '192.168.1.0/24') - @mock.patch('nova.db.network_update') - @mock.patch('nova.db.network_set_host') + @mock.patch('nova.db.api.network_update') + @mock.patch('nova.db.api.network_set_host') def test_save(self, set_host, update): result = dict(fake_network, injected=True) network = network_obj.Network._from_db_object(self.context, @@ -110,9 +110,9 @@ class _TestNetworkObject(object): self.assertFalse(set_host.called) self._compare(network, result) - @mock.patch('nova.db.network_update') - @mock.patch('nova.db.network_set_host') - @mock.patch('nova.db.network_get') + @mock.patch('nova.db.api.network_update') + @mock.patch('nova.db.api.network_set_host') + @mock.patch('nova.db.api.network_get') def test_save_with_host(self, get, set_host, update): result = dict(fake_network, injected=True) network = network_obj.Network._from_db_object(self.context, @@ -126,8 +126,8 @@ class _TestNetworkObject(object): self.assertFalse(update.called) self._compare(network, result) - @mock.patch('nova.db.network_update') - @mock.patch('nova.db.network_set_host') + @mock.patch('nova.db.api.network_update') + @mock.patch('nova.db.api.network_set_host') def test_save_with_host_and_other(self, set_host, update): result = dict(fake_network, injected=True) network = network_obj.Network._from_db_object(self.context, @@ -143,20 +143,20 @@ class _TestNetworkObject(object): {'label': 'bar'}) self._compare(network, result) - @mock.patch('nova.db.network_associate') + @mock.patch('nova.db.api.network_associate') def test_associate(self, associate): network_obj.Network.associate(self.context, 'project', network_id=123) associate.assert_called_once_with(self.context, 'project', network_id=123, force=False) - @mock.patch('nova.db.network_disassociate') + @mock.patch('nova.db.api.network_disassociate') def test_disassociate(self, disassociate): network_obj.Network.disassociate(self.context, 123, host=True, project=True) disassociate.assert_called_once_with(self.context, 123, True, True) - @mock.patch('nova.db.network_create_safe') + @mock.patch('nova.db.api.network_create_safe') def test_create(self, create): create.return_value = fake_network network = network_obj.Network(context=self.context, label='foo') @@ -164,7 +164,7 @@ class _TestNetworkObject(object): create.assert_called_once_with(self.context, {'label': 'foo'}) self._compare(network, fake_network) - @mock.patch('nova.db.network_delete_safe') + @mock.patch('nova.db.api.network_delete_safe') def test_destroy(self, delete): network = network_obj.Network(context=self.context, id=123) network.destroy() @@ -172,7 +172,7 @@ class _TestNetworkObject(object): self.assertTrue(network.deleted) self.assertNotIn('deleted', network.obj_what_changed()) - @mock.patch('nova.db.network_get_all') + @mock.patch('nova.db.api.network_get_all') def test_get_all(self, get_all): get_all.return_value = [fake_network] networks = network_obj.NetworkList.get_all(self.context) @@ -180,7 +180,7 @@ class _TestNetworkObject(object): get_all.assert_called_once_with(self.context, 'allow_none') self._compare(networks[0], fake_network) - @mock.patch('nova.db.network_get_all_by_uuids') + @mock.patch('nova.db.api.network_get_all_by_uuids') def test_get_all_by_uuids(self, get_all): get_all.return_value = [fake_network] networks = network_obj.NetworkList.get_by_uuids(self.context, @@ -189,7 +189,7 @@ class _TestNetworkObject(object): get_all.assert_called_once_with(self.context, ['foo'], 'allow_none') self._compare(networks[0], fake_network) - @mock.patch('nova.db.network_get_all_by_host') + @mock.patch('nova.db.api.network_get_all_by_host') def test_get_all_by_host(self, get_all): get_all.return_value = [fake_network] networks = network_obj.NetworkList.get_by_host(self.context, 'host') @@ -197,14 +197,14 @@ class _TestNetworkObject(object): get_all.assert_called_once_with(self.context, 'host') self._compare(networks[0], fake_network) - @mock.patch('nova.db.network_in_use_on_host') + @mock.patch('nova.db.api.network_in_use_on_host') def test_in_use_on_host(self, in_use): in_use.return_value = True self.assertTrue(network_obj.Network.in_use_on_host(self.context, 123, 'foo')) in_use.assert_called_once_with(self.context, 123, 'foo') - @mock.patch('nova.db.project_get_networks') + @mock.patch('nova.db.api.project_get_networks') def test_get_all_by_project(self, get_nets): get_nets.return_value = [fake_network] networks = network_obj.NetworkList.get_by_project(self.context, 123) diff --git a/nova/tests/unit/objects/test_pci_device.py b/nova/tests/unit/objects/test_pci_device.py index 252452eae4..374894b9d1 100644 --- a/nova/tests/unit/objects/test_pci_device.py +++ b/nova/tests/unit/objects/test_pci_device.py @@ -20,7 +20,7 @@ from oslo_serialization import jsonutils from oslo_utils import timeutils from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import fields @@ -267,7 +267,7 @@ class _TestPciDeviceObject(object): return return_dev ctxt = context.get_admin_context() - self.stub_out('nova.db.pci_device_update', _fake_update) + self.stub_out('nova.db.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() @@ -289,8 +289,8 @@ class _TestPciDeviceObject(object): def _fake_update(ctxt, node_id, addr, updates): self.called = True - self.stub_out('nova.db.pci_device_destroy', _fake_destroy) - self.stub_out('nova.db.pci_device_update', _fake_update) + self.stub_out('nova.db.api.pci_device_destroy', _fake_destroy) + self.stub_out('nova.db.api.pci_device_update', _fake_update) self._create_fake_pci_device() self.pci_device.status = fields.PciDeviceStatus.DELETED self.called = False diff --git a/nova/tests/unit/objects/test_quotas.py b/nova/tests/unit/objects/test_quotas.py index c736a3738e..2131c2afb3 100644 --- a/nova/tests/unit/objects/test_quotas.py +++ b/nova/tests/unit/objects/test_quotas.py @@ -54,7 +54,7 @@ class _TestQuotasObject(object): self.instance = fake_instance.fake_db_instance( project_id='fake_proj2', user_id='fake_user2') - @mock.patch('nova.db.quota_get', side_effect=exception.QuotaNotFound) + @mock.patch('nova.db.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 +62,7 @@ class _TestQuotasObject(object): mock_create.assert_called_once_with(self.context, 'fake-project', 'foo', 10, user_id='user') - @mock.patch('nova.db.quota_get') + @mock.patch('nova.db.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 +203,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._update_limit_in_db', side_effect=exception.QuotaNotFound) - @mock.patch('nova.db.quota_update') + @mock.patch('nova.db.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 +223,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._get_from_db', side_effect=exception.QuotaNotFound) - @mock.patch('nova.db.quota_get') + @mock.patch('nova.db.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 +233,7 @@ class _TestQuotasObject(object): 'foo', user_id='user') @mock.patch('nova.objects.Quotas._get_all_from_db') - @mock.patch('nova.db.quota_get_all') + @mock.patch('nova.db.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 +243,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.quota_get_all_by_project') + @mock.patch('nova.db.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 +258,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.quota_get_all_by_project_and_user') + @mock.patch('nova.db.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 +285,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.quota_destroy_all_by_project') + @mock.patch('nova.db.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 +304,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.quota_destroy_all_by_project_and_user') + @mock.patch('nova.db.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 +323,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._get_class_from_db', side_effect=exception.QuotaClassNotFound(class_name='class')) - @mock.patch('nova.db.quota_class_get') + @mock.patch('nova.db.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 +340,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.quota_class_get_default') + @mock.patch('nova.db.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 +349,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.quota_class_get_all_by_name') + @mock.patch('nova.db.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 +363,7 @@ class _TestQuotasObject(object): 'fixed_ips': 10} self.assertEqual(expected, quotas_dict) - @mock.patch('nova.db.quota_class_get', + @mock.patch('nova.db.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 +372,7 @@ class _TestQuotasObject(object): mock_create.assert_called_once_with(self.context, 'class', 'resource', 'limit') - @mock.patch('nova.db.quota_class_get') + @mock.patch('nova.db.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 +388,7 @@ class _TestQuotasObject(object): @mock.patch('nova.objects.Quotas._update_class_in_db', side_effect=exception.QuotaClassNotFound(class_name='class')) - @mock.patch('nova.db.quota_class_update') + @mock.patch('nova.db.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_security_group.py b/nova/tests/unit/objects/test_security_group.py index 931a479ec1..55b9661033 100644 --- a/nova/tests/unit/objects/test_security_group.py +++ b/nova/tests/unit/objects/test_security_group.py @@ -15,7 +15,7 @@ import mock from oslo_versionedobjects import fixture as ovo_fixture -from nova import db +from nova.db 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_security_group_rule.py b/nova/tests/unit/objects/test_security_group_rule.py index 624d666861..1abc43c028 100644 --- a/nova/tests/unit/objects/test_security_group_rule.py +++ b/nova/tests/unit/objects/test_security_group_rule.py @@ -15,7 +15,7 @@ import mock from oslo_versionedobjects import exception as ovo_exc -from nova import db +from nova.db import api as db from nova import objects from nova.tests.unit.objects import test_objects from nova.tests.unit.objects import test_security_group @@ -104,7 +104,7 @@ fake_rules = [ class _TestSecurityGroupRuleListObject(object): - @mock.patch('nova.db.security_group_rule_get_by_instance') + @mock.patch('nova.db.api.security_group_rule_get_by_instance') def test_get_by_instance(self, mock_get): mock_get.return_value = fake_rules instance = objects.Instance(uuid=uuids.instance) diff --git a/nova/tests/unit/objects/test_service.py b/nova/tests/unit/objects/test_service.py index abf1ded76f..94f56e5af7 100644 --- a/nova/tests/unit/objects/test_service.py +++ b/nova/tests/unit/objects/test_service.py @@ -20,7 +20,7 @@ import six from nova.compute import manager as compute_manager from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import aggregate @@ -205,7 +205,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.service_get_all_by_binary') + @mock.patch('nova.db.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, @@ -215,7 +215,7 @@ class _TestServiceObject(object): 'fake-binary', include_disabled=False) - @mock.patch('nova.db.service_get_all_by_binary') + @mock.patch('nova.db.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, @@ -226,7 +226,7 @@ class _TestServiceObject(object): 'fake-binary', include_disabled=True) - @mock.patch('nova.db.service_get_all_by_binary') + @mock.patch('nova.db.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)] @@ -318,7 +318,7 @@ class _TestServiceObject(object): version_manifest=versions), fake_service_dict['compute_node']) - @mock.patch('nova.db.service_get_minimum_version') + @mock.patch('nova.db.api.service_get_minimum_version') def test_get_minimum_version_none(self, mock_get): mock_get.return_value = None self.assertEqual(0, @@ -326,7 +326,7 @@ class _TestServiceObject(object): 'nova-compute')) mock_get.assert_called_once_with(self.context, ['nova-compute']) - @mock.patch('nova.db.service_get_minimum_version') + @mock.patch('nova.db.api.service_get_minimum_version') def test_get_minimum_version(self, mock_get): mock_get.return_value = {'nova-compute': 123} self.assertEqual(123, @@ -334,7 +334,7 @@ class _TestServiceObject(object): 'nova-compute')) mock_get.assert_called_once_with(self.context, ['nova-compute']) - @mock.patch('nova.db.service_get_minimum_version') + @mock.patch('nova.db.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 @@ -348,7 +348,7 @@ class _TestServiceObject(object): 'compute') self.assertTrue(mock_log.warning.called) - @mock.patch('nova.db.service_get_minimum_version') + @mock.patch('nova.db.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} @@ -364,7 +364,7 @@ class _TestServiceObject(object): objects.Service._SERVICE_VERSION_CACHING = False objects.Service.clear_min_version_cache() - @mock.patch('nova.db.service_get_minimum_version') + @mock.patch('nova.db.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, @@ -376,7 +376,7 @@ class _TestServiceObject(object): binaries) self.assertEqual(0, minimum) - @mock.patch('nova.db.service_get_minimum_version') + @mock.patch('nova.db.api.service_get_minimum_version') def test_get_min_version_multiple(self, mock_gmv): mock_gmv.return_value = {'nova-api': 1, 'nova-scheduler': 2, @@ -389,7 +389,7 @@ class _TestServiceObject(object): self.assertEqual(1, minimum) @mock.patch('nova.objects.Service._send_notification') - @mock.patch('nova.db.service_get_minimum_version', + @mock.patch('nova.db.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', @@ -398,7 +398,7 @@ class _TestServiceObject(object): binary='nova-compute').create() @mock.patch('nova.objects.Service._send_notification') - @mock.patch('nova.db.service_get_minimum_version', + @mock.patch('nova.db.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', @@ -406,7 +406,7 @@ class _TestServiceObject(object): objects.Service(context=self.context, binary='nova-compute').create() - @mock.patch('nova.db.service_get_minimum_version', + @mock.patch('nova.db.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', @@ -428,14 +428,14 @@ class _TestServiceObject(object): return_value=uuidsentinel.service4) def test_from_db_object_without_uuid_generates_one(self, generate_uuid): values = _fake_service(uuid=None, id=None) - db_service = db.api.service_create(self.context, values) + db_service = db.service_create(self.context, values) s = service.Service() service.Service._from_db_object(self.context, s, db_service) self.assertEqual(uuidsentinel.service4, s.uuid) # Check the DB too - db_service2 = db.api.service_get(self.context, s.id) + db_service2 = db.service_get(self.context, s.id) self.assertEqual(s.uuid, db_service2['uuid']) diff --git a/nova/tests/unit/objects/test_tag.py b/nova/tests/unit/objects/test_tag.py index b1a0386827..e91f94bfd1 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.instance_tag_add') + @mock.patch('nova.db.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.instance_tag_delete') + @mock.patch('nova.db.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.instance_tag_exists') + @mock.patch('nova.db.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.instance_tag_get_by_instance_uuid') + @mock.patch('nova.db.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.instance_tag_set') + @mock.patch('nova.db.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.instance_tag_delete_all') + @mock.patch('nova.db.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 1773f50bec..fa15ab4e06 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.task_log_get', return_value=fake_task_log) + @mock.patch('nova.db.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.task_log_begin_task') + @mock.patch('nova.db.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.task_log_end_task') + @mock.patch('nova.db.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.task_log_get_all') + @mock.patch('nova.db.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 d056244a78..08166a886b 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.instance_extra_get_by_instance_uuid') + @mock.patch('nova.db.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 000e6dbdfb..ae332b4637 100644 --- a/nova/tests/unit/objects/test_virtual_interface.py +++ b/nova/tests/unit/objects/test_virtual_interface.py @@ -14,7 +14,7 @@ import mock -from nova import db +from nova.db import api as db from nova.objects import virtual_interface as vif_obj from nova.tests.unit.objects import test_objects from nova.tests import uuidsentinel as uuids diff --git a/nova/tests/unit/objects/test_volume_usage.py b/nova/tests/unit/objects/test_volume_usage.py index 418f2b7803..63e8352a72 100644 --- a/nova/tests/unit/objects/test_volume_usage.py +++ b/nova/tests/unit/objects/test_volume_usage.py @@ -45,7 +45,7 @@ fake_vol_usage = { class _TestVolumeUsage(object): - @mock.patch('nova.db.vol_usage_update', return_value=fake_vol_usage) + @mock.patch('nova.db.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 +63,7 @@ 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.vol_usage_update', return_value=fake_vol_usage) + @mock.patch('nova.db.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 d85e451726..5471bbc077 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.pci_device_get_all_by_node', + self.stub_out('nova.db.api.pci_device_get_all_by_node', self._fake_get_pci_devices) # The fake_pci_whitelist must be called before creating the fake # devices @@ -396,7 +396,7 @@ class PciDevTrackerTestCase(test.NoDBTestCase): return_value=False) def test_save(self, migrate_mock): self.stub_out( - 'nova.db.pci_device_update', + 'nova.db.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), @@ -408,10 +408,10 @@ class PciDevTrackerTestCase(test.NoDBTestCase): def test_save_removed(self): self.stub_out( - 'nova.db.pci_device_update', + 'nova.db.api.pci_device_update', self._fake_pci_device_update) self.stub_out( - 'nova.db.pci_device_destroy', + 'nova.db.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/scheduler/test_caching_scheduler.py b/nova/tests/unit/scheduler/test_caching_scheduler.py index 2760f92629..5a4a87ec8a 100644 --- a/nova/tests/unit/scheduler/test_caching_scheduler.py +++ b/nova/tests/unit/scheduler/test_caching_scheduler.py @@ -89,7 +89,7 @@ class CachingSchedulerTestCase(test_scheduler.SchedulerTestCase): self.context, spec_obj, [spec_obj.instance_uuid], {}, {}) - @mock.patch('nova.db.instance_extra_get_by_instance_uuid', + @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid', return_value={'numa_topology': None, 'pci_requests': None}) def test_select_destination_works(self, mock_get_extra): @@ -166,7 +166,7 @@ class CachingSchedulerTestCase(test_scheduler.SchedulerTestCase): host_state.failed_builds = 0 return host_state - @mock.patch('nova.db.instance_extra_get_by_instance_uuid', + @mock.patch('nova.db.api.instance_extra_get_by_instance_uuid', return_value={'numa_topology': None, 'pci_requests': None}) def test_performance_check_select_destination(self, mock_get_extra): diff --git a/nova/tests/unit/test_availability_zones.py b/nova/tests/unit/test_availability_zones.py index bc8262d518..e2b3096117 100644 --- a/nova/tests/unit/test_availability_zones.py +++ b/nova/tests/unit/test_availability_zones.py @@ -23,7 +23,7 @@ import six from nova import availability_zones as az import nova.conf from nova import context -from nova import db +from nova.db import api as db from nova import objects from nova import test from nova.tests import uuidsentinel diff --git a/nova/tests/unit/test_context.py b/nova/tests/unit/test_context.py index 012731911a..076dd2e2f4 100644 --- a/nova/tests/unit/test_context.py +++ b/nova/tests/unit/test_context.py @@ -240,7 +240,7 @@ class ContextTestCase(test.NoDBTestCase): mock.sentinel.target) @mock.patch('nova.rpc.create_transport') - @mock.patch('nova.db.create_context_manager') + @mock.patch('nova.db.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 @@ -260,7 +260,7 @@ class ContextTestCase(test.NoDBTestCase): self.assertEqual(mock.sentinel.mq_conn, ctxt.mq_connection) @mock.patch('nova.rpc.create_transport') - @mock.patch('nova.db.create_context_manager') + @mock.patch('nova.db.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. @@ -305,7 +305,7 @@ class ContextTestCase(test.NoDBTestCase): self.assertFalse(ctxt.is_admin) @mock.patch('nova.rpc.create_transport') - @mock.patch('nova.db.create_context_manager') + @mock.patch('nova.db.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_flavors.py b/nova/tests/unit/test_flavors.py index 14f21afc1a..6ce20a9ea4 100644 --- a/nova/tests/unit/test_flavors.py +++ b/nova/tests/unit/test_flavors.py @@ -15,7 +15,7 @@ Unit Tests for flavors code """ from nova.compute import flavors from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova import objects from nova.objects import base as obj_base diff --git a/nova/tests/unit/test_metadata.py b/nova/tests/unit/test_metadata.py index 641c7af89b..f55dfc92d2 100644 --- a/nova/tests/unit/test_metadata.py +++ b/nova/tests/unit/test_metadata.py @@ -357,7 +357,7 @@ class MetadataTestCase(test.TestCase): 'delete_on_termination': None, 'device_name': '/dev/sdb'})] - self.stub_out('nova.db.block_device_mapping_get_all_by_instance', + self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance', fake_bdm_get) expected = {'ami': 'sda1', diff --git a/nova/tests/unit/test_nova_manage.py b/nova/tests/unit/test_nova_manage.py index 37f37fa5e2..ff02b2ebeb 100644 --- a/nova/tests/unit/test_nova_manage.py +++ b/nova/tests/unit/test_nova_manage.py @@ -27,7 +27,7 @@ from six.moves import StringIO from nova.cmd import manage from nova import conf from nova import context -from nova import db +from nova.db import api as db from nova.db import migration from nova.db.sqlalchemy import migration as sqla_migration from nova import exception @@ -274,7 +274,7 @@ class NetworkCommandsTestCase(test.NoDBTestCase): def fake_network_get_all(context): return [db_fakes.FakeModel(self.net)] - self.stub_out('nova.db.network_get_all', fake_network_get_all) + self.stub_out('nova.db.api.network_get_all', fake_network_get_all) self.commands.list() result = self.output.getvalue() _fmt = "\t".join(["%(id)-5s", "%(cidr)-18s", "%(cidr_v6)-15s", @@ -305,35 +305,37 @@ class NetworkCommandsTestCase(test.NoDBTestCase): self.fake_net = self.net self.fake_net['project_id'] = None self.fake_net['host'] = None - self.stub_out('nova.db.network_get_by_uuid', + self.stub_out('nova.db.api.network_get_by_uuid', self.fake_network_get_by_uuid) def fake_network_delete_safe(context, network_id): self.assertTrue(context.to_dict()['is_admin']) self.assertEqual(network_id, self.fake_net['id']) - self.stub_out('nova.db.network_delete_safe', fake_network_delete_safe) + self.stub_out('nova.db.api.network_delete_safe', + fake_network_delete_safe) self.commands.delete(uuid=self.fake_net['uuid']) def test_delete_by_cidr(self): self.fake_net = self.net self.fake_net['project_id'] = None self.fake_net['host'] = None - self.stub_out('nova.db.network_get_by_cidr', + self.stub_out('nova.db.api.network_get_by_cidr', self.fake_network_get_by_cidr) def fake_network_delete_safe(context, network_id): self.assertTrue(context.to_dict()['is_admin']) self.assertEqual(network_id, self.fake_net['id']) - self.stub_out('nova.db.network_delete_safe', fake_network_delete_safe) + self.stub_out('nova.db.api.network_delete_safe', + fake_network_delete_safe) self.commands.delete(fixed_range=self.fake_net['cidr']) def _test_modify_base(self, update_value, project, host, dis_project=None, dis_host=None): self.fake_net = self.net self.fake_update_value = update_value - self.stub_out('nova.db.network_get_by_cidr', + self.stub_out('nova.db.api.network_get_by_cidr', self.fake_network_get_by_cidr) - self.stub_out('nova.db.network_update', self.fake_network_update) + self.stub_out('nova.db.api.network_update', self.fake_network_update) self.commands.modify(self.fake_net['cidr'], project=project, host=host, dis_project=dis_project, dis_host=dis_host) diff --git a/nova/tests/unit/test_quota.py b/nova/tests/unit/test_quota.py index bcb4b7cdbe..7b179eb499 100644 --- a/nova/tests/unit/test_quota.py +++ b/nova/tests/unit/test_quota.py @@ -22,7 +22,7 @@ from nova import compute from nova.compute import flavors import nova.conf from nova import context -from nova import db +from nova.db import api as db from nova.db.sqlalchemy import models as sqa_models from nova import exception from nova import objects @@ -862,9 +862,9 @@ class DbQuotaDriverTestCase(test.TestCase): 'injected_file_path_bytes': 127, } - self.stub_out('nova.db.quota_get_all_by_project_and_user', + self.stub_out('nova.db.api.quota_get_all_by_project_and_user', fake_qgabpau) - self.stub_out('nova.db.quota_get_all_by_project', fake_qgabp) + self.stub_out('nova.db.api.quota_get_all_by_project', fake_qgabp) self._stub_quota_class_get_all_by_name() @@ -1035,7 +1035,7 @@ class DbQuotaDriverTestCase(test.TestCase): return dict( test_resource=dict(in_use=20), ) - self.stub_out('nova.db.quota_get', fake_quota_get) + self.stub_out('nova.db.api.quota_get', fake_quota_get) def test_get_by_project_and_user(self): self._stub_get_by_project_and_user_specific() @@ -1066,8 +1066,8 @@ class DbQuotaDriverTestCase(test.TestCase): sqa_models.ProjectUserQuota(resource='cores', hard_limit=2)] - self.stub_out('nova.db.quota_get_all_by_project', fake_qgabp) - self.stub_out('nova.db.quota_get_all', fake_quota_get_all) + 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_quota_class_get_all_by_name() self._stub_quota_class_get_default() @@ -1767,13 +1767,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.quota_get_all_by_project', + self.stub_out('nova.db.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.quota_get_all_by_project_and_user', + self.stub_out('nova.db.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 594e3c2ed4..6f5a3349ea 100644 --- a/nova/tests/unit/test_test_utils.py +++ b/nova/tests/unit/test_test_utils.py @@ -18,7 +18,7 @@ import tempfile import fixtures -from nova import db +from nova.db 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 28d36159f5..ae64faf7c5 100644 --- a/nova/tests/unit/utils.py +++ b/nova/tests/unit/utils.py @@ -23,7 +23,7 @@ from six.moves import range from nova.compute import flavors import nova.conf import nova.context -import nova.db +from nova.db import api as db from nova import exception from nova.image import glance from nova.network import minidns @@ -100,7 +100,7 @@ def get_test_instance(context=None, flavor=None, obj=False): instance.create() else: flavors.save_flavor_info(test_instance['system_metadata'], flavor, '') - instance = nova.db.instance_create(context, test_instance) + instance = db.instance_create(context, test_instance) return instance FAKE_NETWORK_VLAN = 100 diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 188572e85a..e482e02914 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -65,7 +65,7 @@ from nova.compute import task_states from nova.compute import vm_states import nova.conf from nova import context -from nova import db +from nova.db import api as db from nova import exception from nova.network import model as network_model from nova import objects diff --git a/nova/tests/unit/virt/xenapi/test_xenapi.py b/nova/tests/unit/virt/xenapi/test_xenapi.py index 39baa8cb75..33f355ce38 100644 --- a/nova/tests/unit/virt/xenapi/test_xenapi.py +++ b/nova/tests/unit/virt/xenapi/test_xenapi.py @@ -43,7 +43,7 @@ from nova.compute import vm_states import nova.conf from nova import context from nova import crypto -from nova import db +from nova.db import api as db from nova import exception from nova.network import model as network_model from nova import objects @@ -1254,7 +1254,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase, self.check_vm_params_for_linux() self.assertEqual(actual_injected_files, injected_files) - @mock.patch('nova.db.agent_build_get_by_triple') + @mock.patch('nova.db.api.agent_build_get_by_triple') def test_spawn_agent_upgrade(self, mock_get): self.flags(use_agent_default=True, group='xenserver') @@ -1269,7 +1269,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase, self._test_spawn(IMAGE_VHD, None, None, os_type="linux", architecture="x86-64") - @mock.patch('nova.db.agent_build_get_by_triple') + @mock.patch('nova.db.api.agent_build_get_by_triple') def test_spawn_agent_upgrade_fails_silently(self, mock_get): mock_get.return_value = {"version": "1.1.0", "architecture": "x86-64", "hypervisor": "xen", "os": "windows",