Browse Source

Use nova.db.api directly

nova/db/__init__.py was importing * from nova.db.api. This meant that
any time any code anywhere within the nova.db package was imported
then nova.db.api was too, leading to a cascade of imports that may
not have been desired. Also, in general, code in __init__.py is a pain.

Therefore, this change adjusts code that so that either:

* nova.db.api is used directly
* nova.db.api is imported as 'db'

In either case, the functionality remains the same.

The primary goal of this change was to make it possible to import the
model files without having to import the db api. Moving the model files
to a different place in the directory hierarchy was considered, but
given that "code in __init__.py is a pain" this mode was chosen.

This looks like a very large change, but it is essentially adjusting
package names, many in mocks.

Change-Id: Ic1fd7c87ceda05eeb96735da2a415ef37060bb1a
changes/62/543262/31
Chris Dent 4 years ago
committed by Eric Fried
parent
commit
def4b17934
  1. 2
      nova/api/openstack/compute/schemas/flavor_manage.py
  2. 2
      nova/api/openstack/compute/schemas/quota_sets.py
  3. 2
      nova/api/validation/parameter_types.py
  4. 2
      nova/cmd/manage.py
  5. 2
      nova/cmd/policy.py
  6. 2
      nova/compute/flavors.py
  7. 2
      nova/compute/instance_list.py
  8. 2
      nova/compute/migration_list.py
  9. 2
      nova/console/xvp.py
  10. 2
      nova/context.py
  11. 11
      nova/db/__init__.py
  12. 4
      nova/db/base.py
  13. 4
      nova/hacking/checks.py
  14. 2
      nova/objects/agent.py
  15. 2
      nova/objects/bandwidth_usage.py
  16. 2
      nova/objects/block_device.py
  17. 2
      nova/objects/compute_node.py
  18. 2
      nova/objects/console_auth_token.py
  19. 2
      nova/objects/dns_domain.py
  20. 2
      nova/objects/ec2.py
  21. 2
      nova/objects/fixed_ip.py
  22. 2
      nova/objects/floating_ip.py
  23. 2
      nova/objects/instance.py
  24. 2
      nova/objects/instance_action.py
  25. 2
      nova/objects/instance_fault.py
  26. 2
      nova/objects/instance_info_cache.py
  27. 2
      nova/objects/instance_numa_topology.py
  28. 2
      nova/objects/instance_pci_requests.py
  29. 2
      nova/objects/keypair.py
  30. 2
      nova/objects/migration.py
  31. 2
      nova/objects/migration_context.py
  32. 2
      nova/objects/network.py
  33. 2
      nova/objects/pci_device.py
  34. 2
      nova/objects/quotas.py
  35. 2
      nova/objects/security_group.py
  36. 2
      nova/objects/security_group_rule.py
  37. 2
      nova/objects/service.py
  38. 2
      nova/objects/tag.py
  39. 2
      nova/objects/task_log.py
  40. 2
      nova/objects/trusted_certs.py
  41. 2
      nova/objects/vcpu_model.py
  42. 2
      nova/objects/virt_device_metadata.py
  43. 2
      nova/objects/virtual_interface.py
  44. 2
      nova/objects/volume_usage.py
  45. 2
      nova/quota.py
  46. 2
      nova/test.py
  47. 12
      nova/tests/functional/api_sample_tests/test_agents.py
  48. 2
      nova/tests/functional/api_sample_tests/test_cells.py
  49. 3
      nova/tests/functional/api_sample_tests/test_migrate_server.py
  50. 2
      nova/tests/functional/api_sample_tests/test_server_migrations.py
  51. 10
      nova/tests/functional/api_sample_tests/test_servers.py
  52. 11
      nova/tests/functional/api_sample_tests/test_services.py
  53. 2
      nova/tests/functional/api_sample_tests/test_volumes.py
  54. 2
      nova/tests/functional/compute/test_instance_list.py
  55. 2
      nova/tests/functional/db/test_archive.py
  56. 2
      nova/tests/functional/db/test_instance.py
  57. 2
      nova/tests/functional/integrated_helpers.py
  58. 7
      nova/tests/functional/notification_sample_tests/test_service.py
  59. 2
      nova/tests/functional/regressions/test_bug_1746509.py
  60. 2
      nova/tests/functional/test_server_group.py
  61. 2
      nova/tests/unit/api/openstack/compute/test_access_ips.py
  62. 16
      nova/tests/unit/api/openstack/compute/test_agents.py
  63. 4
      nova/tests/unit/api/openstack/compute/test_availability_zone.py
  64. 2
      nova/tests/unit/api/openstack/compute/test_block_device_mapping_v1.py
  65. 4
      nova/tests/unit/api/openstack/compute/test_config_drive.py
  66. 4
      nova/tests/unit/api/openstack/compute/test_consoles.py
  67. 18
      nova/tests/unit/api/openstack/compute/test_disk_config.py
  68. 2
      nova/tests/unit/api/openstack/compute/test_extended_availability_zone.py
  69. 2
      nova/tests/unit/api/openstack/compute/test_extended_server_attributes.py
  70. 2
      nova/tests/unit/api/openstack/compute/test_extended_status.py
  71. 7
      nova/tests/unit/api/openstack/compute/test_extended_volumes.py
  72. 2
      nova/tests/unit/api/openstack/compute/test_flavor_manage.py
  73. 2
      nova/tests/unit/api/openstack/compute/test_floating_ip_dns.py
  74. 6
      nova/tests/unit/api/openstack/compute/test_floating_ips.py
  75. 2
      nova/tests/unit/api/openstack/compute/test_hide_server_addresses.py
  76. 8
      nova/tests/unit/api/openstack/compute/test_hosts.py
  77. 2
      nova/tests/unit/api/openstack/compute/test_hypervisors.py
  78. 12
      nova/tests/unit/api/openstack/compute/test_instance_actions.py
  79. 4
      nova/tests/unit/api/openstack/compute/test_instance_usage_audit_log.py
  80. 20
      nova/tests/unit/api/openstack/compute/test_keypairs.py
  81. 13
      nova/tests/unit/api/openstack/compute/test_multiple_create.py
  82. 20
      nova/tests/unit/api/openstack/compute/test_neutron_security_groups.py
  83. 2
      nova/tests/unit/api/openstack/compute/test_quotas.py
  84. 17
      nova/tests/unit/api/openstack/compute/test_security_group_default_rules.py
  85. 112
      nova/tests/unit/api/openstack/compute/test_security_groups.py
  86. 38
      nova/tests/unit/api/openstack/compute/test_server_actions.py
  87. 88
      nova/tests/unit/api/openstack/compute/test_server_metadata.py
  88. 6
      nova/tests/unit/api/openstack/compute/test_server_start_stop.py
  89. 28
      nova/tests/unit/api/openstack/compute/test_server_tags.py
  90. 2
      nova/tests/unit/api/openstack/compute/test_server_usage.py
  91. 40
      nova/tests/unit/api/openstack/compute/test_serversV21.py
  92. 6
      nova/tests/unit/api/openstack/compute/test_services.py
  93. 6
      nova/tests/unit/api/openstack/fakes.py
  94. 4
      nova/tests/unit/cells/fakes.py
  95. 2
      nova/tests/unit/cells/test_cells_messaging.py
  96. 2
      nova/tests/unit/cells/test_cells_scheduler.py
  97. 4
      nova/tests/unit/cells/test_cells_state_manager.py
  98. 10
      nova/tests/unit/cmd/test_cmd_db_blocks.py
  99. 2
      nova/tests/unit/cmd/test_policy.py
  100. 4
      nova/tests/unit/compute/test_claims.py

2
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',

2
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'],

2
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

2
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

2
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

2
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

2
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

2
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

2
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 _

2
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.

11
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."""

4
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

4
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):

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

2
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

12
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.

2
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):

3
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',

2
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

10
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 = {}

11
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',

2
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(

2
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

2
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

2
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

2
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

7
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'}

2
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

2
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

2
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)

16
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',

4
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',

2
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

4
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

4
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

18
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()

2
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)

2
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)

2
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')

7
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()

2
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

2
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

6
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()

2
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):

8
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,

2
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):

12
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)

4
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('')

20
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)