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
This commit is contained in:
Chris Dent 2018-02-11 21:58:04 +00:00 committed by Eric Fried
parent 8469fa70da
commit def4b17934
162 changed files with 715 additions and 692 deletions

View File

@ -15,7 +15,7 @@
import copy import copy
from nova.api.validation import parameter_types from nova.api.validation import parameter_types
from nova import db from nova.db import api as db
create = { create = {
'type': 'object', 'type': 'object',

View File

@ -15,7 +15,7 @@
import copy import copy
from nova.api.validation import parameter_types from nova.api.validation import parameter_types
from nova import db from nova.db import api as db
common_quota = { common_quota = {
'type': ['integer', 'string'], 'type': ['integer', 'string'],

View File

@ -21,7 +21,7 @@ import unicodedata
import six import six
from nova import db from nova.db import api as db
from nova.i18n import _ from nova.i18n import _
from nova.objects import tag from nova.objects import tag

View File

@ -50,7 +50,7 @@ from nova.cmd import common as cmd_common
import nova.conf import nova.conf
from nova import config from nova import config
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova.db import migration from nova.db import migration
from nova.db.sqlalchemy import api as sa_db from nova.db.sqlalchemy import api as sa_db
from nova import exception from nova import exception

View File

@ -27,7 +27,7 @@ from nova.cmd import common as cmd_common
import nova.conf import nova.conf
from nova import config from nova import config
from nova import context as nova_context 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 exception
from nova.i18n import _ from nova.i18n import _
from nova import policies from nova import policies

View File

@ -27,7 +27,7 @@ import six
from nova.api.validation import parameter_types from nova.api.validation import parameter_types
import nova.conf import nova.conf
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova.i18n import _ from nova.i18n import _
from nova import objects from nova import objects

View File

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

View File

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

View File

@ -25,7 +25,7 @@ from oslo_utils import excutils
import nova.conf import nova.conf
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova.i18n import _ from nova.i18n import _

View File

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

View File

@ -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 # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at
@ -13,8 +9,5 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
""" """Use nova.db.api instead. In the past this file imported * from there,
DB abstraction for Nova which led to unwanted imports."""
"""
from nova.db.api import * # noqa

View File

@ -16,7 +16,7 @@
"""Base class for classes that need database access.""" """Base class for classes that need database access."""
import nova.db import nova.db.api
class Base(object): class Base(object):
@ -24,4 +24,4 @@ class Base(object):
def __init__(self): def __init__(self):
super(Base, self).__init__() super(Base, self).__init__()
self.db = nova.db self.db = nova.db.api

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@ from oslo_utils import versionutils
from nova import block_device from nova import block_device
from nova.cells import opts as cells_opts from nova.cells import opts as cells_opts
from nova.cells import rpcapi as cells_rpcapi 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 api as db_api
from nova.db.sqlalchemy import models as db_models from nova.db.sqlalchemy import models as db_models
from nova import exception from nova import exception

View File

@ -18,7 +18,7 @@ from oslo_utils import uuidutils
from oslo_utils import versionutils from oslo_utils import versionutils
import nova.conf import nova.conf
from nova import db from nova.db import api as db
from nova.db.sqlalchemy import models from nova.db.sqlalchemy import models
from nova import exception from nova import exception
from nova import objects from nova import objects

View File

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

View File

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

View File

@ -13,7 +13,7 @@
# under the License. # under the License.
from nova.api.ec2 import ec2utils from nova.api.ec2 import ec2utils
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova.objects import base from nova.objects import base
from nova.objects import fields from nova.objects import fields

View File

@ -15,7 +15,7 @@
from oslo_utils import timeutils from oslo_utils import timeutils
from oslo_utils import versionutils 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 as db_api
from nova.db.sqlalchemy import models from nova.db.sqlalchemy import models
from nova import exception from nova import exception

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # 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 api as db_api
from nova.db.sqlalchemy import models from nova.db.sqlalchemy import models
from nova import exception from nova import exception

View File

@ -30,7 +30,7 @@ from nova.cells import rpcapi as cells_rpcapi
from nova.cells import utils as cells_utils from nova.cells import utils as cells_utils
from nova.compute import task_states from nova.compute import task_states
from nova.compute import vm_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 api as db_api
from nova.db.sqlalchemy import models from nova.db.sqlalchemy import models
from nova import exception from nova import exception

View File

@ -15,7 +15,7 @@
from oslo_utils import timeutils from oslo_utils import timeutils
from oslo_utils import versionutils from oslo_utils import versionutils
from nova import db from nova.db import api as db
from nova import objects from nova import objects
from nova.objects import base from nova.objects import base
from nova.objects import fields from nova.objects import fields

View File

@ -18,7 +18,7 @@ from oslo_log import log as logging
from nova.cells import opts as cells_opts from nova.cells import opts as cells_opts
from nova.cells import rpcapi as cells_rpcapi 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 exception
from nova import objects from nova import objects
from nova.objects import base from nova.objects import base

View File

@ -16,7 +16,7 @@ from oslo_log import log as logging
from nova.cells import opts as cells_opts from nova.cells import opts as cells_opts
from nova.cells import rpcapi as cells_rpcapi 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 exception
from nova.objects import base from nova.objects import base
from nova.objects import fields from nova.objects import fields

View File

@ -15,7 +15,7 @@
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import versionutils from oslo_utils import versionutils
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova.objects import base from nova.objects import base
from nova.objects import fields as obj_fields from nova.objects import fields as obj_fields

View File

@ -13,7 +13,7 @@
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import versionutils 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 base
from nova.objects import fields from nova.objects import fields

View File

@ -17,7 +17,7 @@ from oslo_db.sqlalchemy import utils as sqlalchemyutils
from oslo_log import log as logging from oslo_log import log as logging
from oslo_utils import versionutils 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 as db_api
from nova.db.sqlalchemy import api_models from nova.db.sqlalchemy import api_models
from nova.db.sqlalchemy import models as main_models from nova.db.sqlalchemy import models as main_models

View File

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

View File

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

View File

@ -16,7 +16,7 @@ import netaddr
from oslo_utils import versionutils from oslo_utils import versionutils
import nova.conf import nova.conf
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova.i18n import _ from nova.i18n import _
from nova import objects from nova import objects

View File

@ -21,7 +21,7 @@ from oslo_utils import uuidutils
from oslo_utils import versionutils from oslo_utils import versionutils
import six import six
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import objects from nova import objects
from nova.objects import base from nova.objects import base

View File

@ -16,7 +16,7 @@ import collections
from oslo_db import exception as db_exc 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 as db_api
from nova.db.sqlalchemy import api_models from nova.db.sqlalchemy import api_models
from nova.db.sqlalchemy import models as main_models from nova.db.sqlalchemy import models as main_models

View File

@ -15,7 +15,7 @@
from oslo_utils import uuidutils from oslo_utils import uuidutils
from oslo_utils import versionutils 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 as db_api
from nova.db.sqlalchemy import models from nova.db.sqlalchemy import models
from nova import objects from nova import objects

View File

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

View File

@ -18,7 +18,7 @@ from oslo_utils import versionutils
from nova import availability_zones from nova import availability_zones
from nova import context as nova_context 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 exception
from nova.notifications.objects import base as notification from nova.notifications.objects import base as notification
from nova.notifications.objects import service as service_notification from nova.notifications.objects import service as service_notification

View File

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

View File

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

View File

@ -12,7 +12,7 @@
from oslo_serialization import jsonutils 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 base
from nova.objects import fields from nova.objects import fields

View File

@ -12,7 +12,7 @@
from oslo_serialization import jsonutils 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 base
from nova.objects import fields from nova.objects import fields

View File

@ -15,7 +15,7 @@
from oslo_serialization import jsonutils from oslo_serialization import jsonutils
from oslo_utils import versionutils 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 base
from nova.objects import fields from nova.objects import fields

View File

@ -14,7 +14,7 @@
from oslo_utils import versionutils from oslo_utils import versionutils
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import objects from nova import objects
from nova.objects import base from nova.objects import base

View File

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

View File

@ -23,7 +23,7 @@ from oslo_utils import importutils
import nova.conf import nova.conf
from nova import context as nova_context 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 exception
from nova import objects from nova import objects
from nova import utils from nova import utils

View File

@ -52,7 +52,7 @@ import testtools
from nova.api.openstack.placement.objects import resource_provider from nova.api.openstack.placement.objects import resource_provider
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova.network import manager as network_manager from nova.network import manager as network_manager
from nova.network.security_group import openstack_driver from nova.network.security_group import openstack_driver

View File

@ -54,10 +54,14 @@ class AgentsJsonTest(api_sample_base.ApiSampleTestBaseV21):
def fake_agent_build_destroy(context, agent_update_id): def fake_agent_build_destroy(context, agent_update_id):
pass pass
self.stub_out("nova.db.agent_build_create", fake_agent_build_create) self.stub_out("nova.db.api.agent_build_create",
self.stub_out("nova.db.agent_build_get_all", fake_agent_build_get_all) fake_agent_build_create)
self.stub_out("nova.db.agent_build_update", fake_agent_build_update) self.stub_out("nova.db.api.agent_build_get_all",
self.stub_out("nova.db.agent_build_destroy", fake_agent_build_destroy) 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): def test_agent_create(self):
# Creates a new agent build. # Creates a new agent build.

View File

@ -56,7 +56,7 @@ class CellsSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
'is_parent': our_id % 2 == 0}) 'is_parent': our_id % 2 == 0})
self.cell_list.append(cell) 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) self.stub_out('nova.cells.rpcapi.CellsAPI.cell_get', _fake_cell_get)
def test_cells_empty_list(self): def test_cells_empty_list(self):

View File

@ -65,7 +65,8 @@ class MigrateServerSamplesJsonTest(test_servers.ServersSampleBase):
versionutils.convert_version_to_int('1.0')), versionutils.convert_version_to_int('1.0')),
disabled=False) disabled=False)
return {'compute_node': [service]} 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, response = self._do_post('servers/%s/action' % self.uuid,
'live-migrate-server', 'live-migrate-server',

View File

@ -19,7 +19,7 @@ import mock
from nova.conductor import manager as conductor_manager from nova.conductor import manager as conductor_manager
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import objects from nova import objects
from nova.tests.functional.api_sample_tests import test_servers from nova.tests.functional.api_sample_tests import test_servers
from nova.tests.unit import fake_instance from nova.tests.unit import fake_instance

View File

@ -99,8 +99,9 @@ class ServersSampleJsonTest(ServersSampleBase):
use_common_server_api_samples=self.use_common_server_post) use_common_server_api_samples=self.use_common_server_post)
def test_servers_get(self): def test_servers_get(self):
self.stub_out('nova.db.block_device_mapping_get_all_by_instance_uuids', self.stub_out(
fakes.stub_bdm_get_all_by_instance_uuids) 'nova.db.api.block_device_mapping_get_all_by_instance_uuids',
fakes.stub_bdm_get_all_by_instance_uuids)
uuid = self.test_servers_post() uuid = self.test_servers_post()
response = self._do_get('servers/%s' % uuid) response = self._do_get('servers/%s' % uuid)
subs = {} subs = {}
@ -125,8 +126,9 @@ class ServersSampleJsonTest(ServersSampleBase):
self._verify_response('servers-list-resp', subs, response, 200) self._verify_response('servers-list-resp', subs, response, 200)
def test_servers_details(self): def test_servers_details(self):
self.stub_out('nova.db.block_device_mapping_get_all_by_instance_uuids', self.stub_out(
fakes.stub_bdm_get_all_by_instance_uuids) 'nova.db.api.block_device_mapping_get_all_by_instance_uuids',
fakes.stub_bdm_get_all_by_instance_uuids)
uuid = self.test_servers_post() uuid = self.test_servers_post()
response = self._do_get('servers/detail?limit=1') response = self._do_get('servers/detail?limit=1')
subs = {} subs = {}

View File

@ -30,11 +30,11 @@ class ServicesJsonTest(api_sample_base.ApiSampleTestBaseV21):
def setUp(self): def setUp(self):
super(ServicesJsonTest, self).setUp() super(ServicesJsonTest, self).setUp()
self.api.microversion = self.microversion 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) 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) 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) test_services.fake_service_update)
self.useFixture(utils_fixture.TimeFixture(test_services.fake_utcnow())) self.useFixture(utils_fixture.TimeFixture(test_services.fake_utcnow()))
@ -136,8 +136,9 @@ class ServicesV253JsonTest(ServicesV211JsonTest):
def fake_hm_destroy(context, host): def fake_hm_destroy(context, host):
return 1 return 1
self.stub_out('nova.db.service_get_by_uuid', db_service_get_by_uuid) self.stub_out('nova.db.api.service_get_by_uuid',
self.stub_out('nova.db.compute_node_get_all_by_host', db_service_get_by_uuid)
self.stub_out('nova.db.api.compute_node_get_all_by_host',
fake_cn_get_all_by_host) fake_cn_get_all_by_host)
self.stub_out( self.stub_out(
'nova.objects.host_mapping.HostMapping._get_by_host_from_db', 'nova.objects.host_mapping.HostMapping._get_by_host_from_db',

View File

@ -220,7 +220,7 @@ class VolumeAttachmentsSample(test_servers.ServersSampleBase):
] ]
return bdms 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) fake_bdms_get_all_by_instance)
def fake_bdm_get_by_volume_and_instance( def fake_bdm_get_by_volume_and_instance(

View File

@ -14,7 +14,7 @@ import datetime
from nova.compute import instance_list from nova.compute import instance_list
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import objects from nova import objects
from nova import test from nova import test

View File

@ -23,7 +23,7 @@ from sqlalchemy import MetaData
from sqlalchemy import select from sqlalchemy import select
from nova import context 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 api as sqlalchemy_api
from nova.tests.functional import test_servers from nova.tests.functional import test_servers
from nova.tests.unit import fake_network from nova.tests.unit import fake_network

View File

@ -14,7 +14,7 @@ from oslo_utils import uuidutils
from nova.compute import vm_states from nova.compute import vm_states
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import objects from nova import objects
from nova import test from nova import test

View File

@ -25,7 +25,7 @@ from oslo_log import log as logging
import nova.conf import nova.conf
from nova import context from nova import context
from nova import db from nova.db import api as db
import nova.image.glance import nova.image.glance
from nova import test from nova import test
from nova.tests import fixtures as nova_fixtures from nova.tests import fixtures as nova_fixtures

View File

@ -45,9 +45,9 @@ class TestServiceUpdateNotificationSamplev2_52(TestServiceNotificationBase):
def setUp(self): def setUp(self):
super(TestServiceUpdateNotificationSamplev2_52, self).setUp() 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) 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) test_services.fake_service_update)
self.useFixture(utils_fixture.TimeFixture(test_services.fake_utcnow())) self.useFixture(utils_fixture.TimeFixture(test_services.fake_utcnow()))
self.useFixture(fixtures.SingleCellSimple()) self.useFixture(fixtures.SingleCellSimple())
@ -105,7 +105,8 @@ class TestServiceUpdateNotificationSampleLatest(
if svc['uuid'] == service_uuid: if svc['uuid'] == service_uuid:
return svc return svc
raise exception.ServiceNotFound(service_id=service_uuid) 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): def test_service_enable(self):
body = {'status': 'enabled'} body = {'status': 'enabled'}

View File

@ -11,7 +11,7 @@
# under the License. # under the License.
import nova.context import nova.context
from nova import db from nova.db import api as db
from nova import objects from nova import objects
from nova import test from nova import test

View File

@ -19,7 +19,7 @@ import mock
from oslo_config import cfg from oslo_config import cfg
from nova import context 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 as db_api
from nova import test from nova import test
from nova.tests import fixtures as nova_fixtures from nova.tests import fixtures as nova_fixtures

View File

@ -37,7 +37,7 @@ class AccessIPsAPIValidationTestV21(test.TestCase):
fakes.stub_out_nw_api(self) fakes.stub_out_nw_api(self)
self._set_up_controller() self._set_up_controller()
fake.stub_out_image_service(self) 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()) fakes.fake_instance_get())
self.stub_out('nova.objects.instance.Instance.save', fake_save) self.stub_out('nova.objects.instance.Instance.save', fake_save)
self.stub_out('nova.compute.api.API.rebuild', fake_rebuild) self.stub_out('nova.compute.api.API.rebuild', fake_rebuild)

View File

@ -16,7 +16,7 @@ import mock
import webob.exc import webob.exc
from nova.api.openstack.compute import agents as agents_v21 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.db.sqlalchemy import models
from nova import exception from nova import exception
from nova import test from nova import test
@ -82,10 +82,14 @@ class AgentsTestV21(test.NoDBTestCase):
def setUp(self): def setUp(self):
super(AgentsTestV21, self).setUp() super(AgentsTestV21, self).setUp()
self.stub_out("nova.db.agent_build_get_all", fake_agent_build_get_all) self.stub_out("nova.db.api.agent_build_get_all",
self.stub_out("nova.db.agent_build_update", fake_agent_build_update) fake_agent_build_get_all)
self.stub_out("nova.db.agent_build_destroy", fake_agent_build_destroy) self.stub_out("nova.db.api.agent_build_update",
self.stub_out("nova.db.agent_build_create", fake_agent_build_create) 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() self.req = self._get_http_request()
def _get_http_request(self): def _get_http_request(self):
@ -151,7 +155,7 @@ class AgentsTestV21(test.NoDBTestCase):
def fake_agent_build_create_with_exited_agent(context, values): def fake_agent_build_create_with_exited_agent(context, values):
raise exception.AgentBuildExists(**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) fake_agent_build_create_with_exited_agent)
body = {'agent': {'hypervisor': 'kvm', body = {'agent': {'hypervisor': 'kvm',
'os': 'win', 'os': 'win',

View File

@ -22,7 +22,7 @@ from nova.api.openstack.compute import servers as servers_v21
from nova import availability_zones from nova import availability_zones
from nova.compute import api as compute_api from nova.compute import api as compute_api
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import objects from nova import objects
from nova import test from nova import test
@ -83,7 +83,7 @@ class AvailabilityZoneApiTestV21(test.NoDBTestCase):
super(AvailabilityZoneApiTestV21, self).setUp() super(AvailabilityZoneApiTestV21, self).setUp()
availability_zones.reset_cache() availability_zones.reset_cache()
fakes.stub_out_nw_api(self) 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', self.stub_out('nova.availability_zones.set_availability_zones',
lambda c, services: services) lambda c, services: services)
self.stub_out('nova.servicegroup.API.service_is_up', self.stub_out('nova.servicegroup.API.service_is_up',

View File

@ -19,7 +19,7 @@ from webob import exc
from nova.api.openstack.compute import servers as servers_v21 from nova.api.openstack.compute import servers as servers_v21
from nova.compute import api as compute_api 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 exception
from nova import objects from nova import objects
from nova import test from nova import test

View File

@ -40,9 +40,9 @@ class ConfigDriveTestV21(test.TestCase):
self._setup_wsgi() self._setup_wsgi()
def test_show(self): def test_show(self):
self.stub_out('nova.db.instance_get', self.stub_out('nova.db.api.instance_get',
fakes.fake_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()) fakes.fake_instance_get())
# NOTE(sdague): because of the way extensions work, we have to # NOTE(sdague): because of the way extensions work, we have to
# also stub out the Request compute cache with a real compute # also stub out the Request compute cache with a real compute

View File

@ -124,9 +124,9 @@ class ConsolesControllerTestV21(test.NoDBTestCase):
def setUp(self): def setUp(self):
super(ConsolesControllerTestV21, self).setUp() super(ConsolesControllerTestV21, self).setUp()
self.instance_db = FakeInstanceDB() 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.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.instance_db.return_server_by_uuid)
self.uuid = uuids.fake self.uuid = uuids.fake
self.url = '/v2/fake/servers/%s/consoles' % self.uuid self.url = '/v2/fake/servers/%s/consoles' % self.uuid

View File

@ -63,7 +63,7 @@ class DiskConfigTestCaseV21(test.TestCase):
if id_ == instance['id']: if id_ == instance['id']:
return instance 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, def fake_instance_get_by_uuid(context, uuid,
columns_to_join=None, use_slave=False): columns_to_join=None, use_slave=False):
@ -71,14 +71,14 @@ class DiskConfigTestCaseV21(test.TestCase):
if uuid == instance['uuid']: if uuid == instance['uuid']:
return instance 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) fake_instance_get_by_uuid)
def fake_instance_get_all(context, *args, **kwargs): def fake_instance_get_all(context, *args, **kwargs):
return FAKE_INSTANCES return FAKE_INSTANCES
self.stub_out('nova.db.instance_get_all', fake_instance_get_all) self.stub_out('nova.db.api.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_by_filters',
fake_instance_get_all) fake_instance_get_all)
self.stub_out('nova.objects.Instance.save', 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): def fake_instance_get_for_create(context, id_, *args, **kwargs):
return (inst, inst) 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) fake_instance_get_for_create)
def fake_instance_get_all_for_create(context, *args, **kwargs): def fake_instance_get_all_for_create(context, *args, **kwargs):
return [inst] 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) 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) fake_instance_get_all_for_create)
def fake_instance_add_security_group(context, instance_id, def fake_instance_add_security_group(context, instance_id,
security_group_id): security_group_id):
pass 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) fake_instance_add_security_group)
return inst 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): def _set_up_app(self):
self.app = compute.APIRouterV21() self.app = compute.APIRouterV21()

View File

@ -84,7 +84,7 @@ class ExtendedAvailabilityZoneTestV21(test.TestCase):
self.stub_out('nova.availability_zones.get_host_availability_zone', self.stub_out('nova.availability_zones.get_host_availability_zone',
fake_get_host_availability_zone) fake_get_host_availability_zone)
return_server = fakes.fake_instance_get() 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): def _make_request(self, url):
req = fakes.HTTPRequest.blank(url) req = fakes.HTTPRequest.blank(url)

View File

@ -85,7 +85,7 @@ class ExtendedServerAttributesTestV21(test.TestCase):
fakes.stub_out_secgroup_api(self) 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', fake_compute_get)
self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all) 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): def _make_request(self, url):
req = fakes.HTTPRequest.blank(url) req = fakes.HTTPRequest.blank(url)

View File

@ -69,7 +69,7 @@ class ExtendedStatusTestV21(test.TestCase):
self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all) self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all)
self._set_flags() self._set_flags()
return_server = fakes.fake_instance_get() 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): def _get_server(self, body):
return jsonutils.loads(body).get('server') return jsonutils.loads(body).get('server')

View File

@ -94,12 +94,13 @@ class ExtendedVolumesTestV21(test.TestCase):
fakes.stub_out_secgroup_api(self) 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', fake_compute_get)
self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all) 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', self.stub_out(
fake_bdms_get_all_by_instance_uuids) 'nova.db.api.block_device_mapping_get_all_by_instance_uuids',
fake_bdms_get_all_by_instance_uuids)
self._setUp() self._setUp()
self.app = self._setup_app() self.app = self._setup_app()
return_server = fakes.fake_instance_get() 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): def _setup_app(self):
return fakes.wsgi_app_v21() return fakes.wsgi_app_v21()

View File

@ -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_access as flavor_access_v21
from nova.api.openstack.compute import flavor_manage as flavormanage_v21 from nova.api.openstack.compute import flavor_manage as flavormanage_v21
from nova.compute import flavors from nova.compute import flavors
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import objects from nova import objects
from nova import policy from nova import policy

View File

@ -21,7 +21,7 @@ import webob
from nova.api.openstack.compute import floating_ip_dns \ from nova.api.openstack.compute import floating_ip_dns \
as fipdns_v21 as fipdns_v21
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import network from nova import network
from nova import test from nova import test

View File

@ -21,7 +21,7 @@ import webob
from nova.api.openstack.compute import floating_ips as fips_v21 from nova.api.openstack.compute import floating_ips as fips_v21
from nova import compute from nova import compute
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import network from nova import network
from nova import objects from nova import objects
@ -238,7 +238,7 @@ class FloatingIpTestV21(test.TestCase):
stub_nw_info(self)) stub_nw_info(self))
fake_network.stub_out_nw_api_get_instance_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) fake_instance_get)
self.context = context.get_admin_context() self.context = context.get_admin_context()
@ -942,7 +942,7 @@ class ExtendedFloatingIpTestV21(test.TestCase):
stub_nw_info(self)) stub_nw_info(self))
fake_network.stub_out_nw_api_get_instance_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) fake_instance_get)
self.context = context.get_admin_context() self.context = context.get_admin_context()

View File

@ -47,7 +47,7 @@ class HideServerAddressesTestV21(test.TestCase):
fakes.stub_out_nw_api(self) fakes.stub_out_nw_api(self)
fakes.stub_out_secgroup_api(self) fakes.stub_out_secgroup_api(self)
return_server = fakes.fake_instance_get() 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() self._setup_wsgi()
def _make_request(self, url): def _make_request(self, url):

View File

@ -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 power_state
from nova.compute import vm_states from nova.compute import vm_states
from nova import context as context_maker 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 exception
from nova import test from nova import test
from nova.tests import fixtures from nova.tests import fixtures
@ -136,10 +136,10 @@ class HostTestCaseV21(test.TestCase):
def _setup_stubs(self): def _setup_stubs(self):
# Pretend we have fake_hosts.HOST_LIST in the DB # 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) stub_service_get_all)
# Only hosts in our fake DB exist # 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) stub_service_get_by_host_and_binary)
# 'host_c1' always succeeds, and 'host_c2' # 'host_c1' always succeeds, and 'host_c2'
self.stub_out('nova.compute.api.HostAPI.set_host_enabled', 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): def stub_service_get_all_notimpl(self, req):
return [{'host': 'notimplemented', 'topic': None, return [{'host': 'notimplemented', 'topic': None,
'availability_zone': 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) stub_service_get_all_notimpl)
body = {key: val} body = {key: val}
self.assertRaises(webob.exc.HTTPNotImplemented, self.assertRaises(webob.exc.HTTPNotImplemented,

View File

@ -248,7 +248,7 @@ class HypervisorsTestV21(test.NoDBTestCase):
host_api.compute_node_get = mock.MagicMock( host_api.compute_node_get = mock.MagicMock(
side_effect=fake_compute_node_get) 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) fake_compute_node_statistics)
def test_view_hypervisor_nodetail_noservers(self): def test_view_hypervisor_nodetail_noservers(self):

View File

@ -160,7 +160,7 @@ class InstanceActionsTestV21(test.NoDBTestCase):
actions.append(action) actions.append(action)
return actions 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') req = self._get_http_req('os-instance-actions')
res_dict = self.controller.index(req, FAKE_UUID) res_dict = self.controller.index(req, FAKE_UUID)
for res in res_dict['instanceActions']: for res in res_dict['instanceActions']:
@ -181,8 +181,8 @@ class InstanceActionsTestV21(test.NoDBTestCase):
events.append(event) events.append(event)
return events return events
self.stub_out('nova.db.action_get_by_request_id', fake_get_action) self.stub_out('nova.db.api.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_events_get', fake_get_events)
req = self._get_http_req('os-instance-actions/1', req = self._get_http_req('os-instance-actions/1',
use_admin_context=True) use_admin_context=True)
res_dict = self.controller.show(req, FAKE_UUID, FAKE_REQUEST_ID) 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): def fake_get_events(context, action_id):
return self.fake_events[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.api.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_events_get', fake_get_events)
self._set_policy_rules() self._set_policy_rules()
req = self._get_http_req('os-instance-actions/1') 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): def fake_no_action(context, uuid, action_id):
return None 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') req = self._get_http_req('os-instance-actions/1')
self.assertRaises(exc.HTTPNotFound, self.controller.show, req, self.assertRaises(exc.HTTPNotFound, self.controller.show, req,
FAKE_UUID, FAKE_REQUEST_ID) FAKE_UUID, FAKE_REQUEST_ID)

View File

@ -122,8 +122,8 @@ class InstanceUsageAuditLogTestV21(test.NoDBTestCase):
self.stub_out('nova.utils.last_completed_audit_period', self.stub_out('nova.utils.last_completed_audit_period',
fake_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.api.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.task_log_get_all', fake_task_log_get_all)
self.req = fakes.HTTPRequest.blank('') self.req = fakes.HTTPRequest.blank('')

View File

@ -79,11 +79,11 @@ class KeypairsTestV21(test.TestCase):
fakes.stub_out_networking(self) fakes.stub_out_networking(self)
fakes.stub_out_secgroup_api(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) 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) 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) db_key_pair_destroy)
self._setup_app_and_controller() self._setup_app_and_controller()
@ -287,7 +287,7 @@ class KeypairsTestV21(test.TestCase):
def db_key_pair_get_not_found(context, user_id, name): def db_key_pair_get_not_found(context, user_id, name):
raise exception.KeypairNotFound(user_id=user_id, name=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) db_key_pair_get_not_found)
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.delete, self.req, 'FAKE') self.controller.delete, self.req, 'FAKE')
@ -299,7 +299,7 @@ class KeypairsTestV21(test.TestCase):
name='foo', public_key='XXX', fingerprint='YYY', name='foo', public_key='XXX', fingerprint='YYY',
type='ssh') 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') res_dict = self.controller.show(self.req, 'FAKE')
self.assertEqual('foo', res_dict['keypair']['name']) self.assertEqual('foo', res_dict['keypair']['name'])
@ -312,15 +312,15 @@ class KeypairsTestV21(test.TestCase):
def _db_key_pair_get(context, user_id, name): def _db_key_pair_get(context, user_id, name):
raise exception.KeypairNotFound(user_id=user_id, name=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.assertRaises(webob.exc.HTTPNotFound,
self.controller.show, self.req, 'FAKE') self.controller.show, self.req, 'FAKE')
def test_show_server(self): def test_show_server(self):
self.stub_out('nova.db.instance_get', self.stub_out('nova.db.api.instance_get',
fakes.fake_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()) fakes.fake_instance_get())
# NOTE(sdague): because of the way extensions work, we have to # NOTE(sdague): because of the way extensions work, we have to
# also stub out the Request compute cache with a real compute # also stub out the Request compute cache with a real compute
@ -626,7 +626,7 @@ class KeypairsTestV235(test.TestCase):
super(KeypairsTestV235, self).setUp() super(KeypairsTestV235, self).setUp()
self._setup_app_and_controller() 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): def test_keypair_list_limit_and_marker(self, mock_kp_get):
mock_kp_get.side_effect = db_key_pair_get_all_by_user 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, self.assertRaises(exception.ValidationError, self.controller.index,
req) 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( def test_keypair_list_limit_and_marker_invalid_in_old_microversion(
self, mock_kp_get): self, mock_kp_get):
mock_kp_get.side_effect = db_key_pair_get_all_by_user mock_kp_get.side_effect = db_key_pair_get_all_by_user

View File

@ -80,15 +80,16 @@ class MultiCreateExtensionTestV21(test.TestCase):
fakes.stub_out_key_pair_funcs(self) fakes.stub_out_key_pair_funcs(self)
fake.stub_out_image_service(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) 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', self.stub_out('nova.compute.api.API.create_db_entry_for_new_instance',
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.api.instance_system_metadata_update',
self.stub_out('nova.db.instance_get', instance_get) fake_method)
self.stub_out('nova.db.instance_update', instance_update) self.stub_out('nova.db.api.instance_get', instance_get)
self.stub_out('nova.db.instance_update_and_get_original', self.stub_out('nova.db.api.instance_update', instance_update)
self.stub_out('nova.db.api.instance_update_and_get_original',
server_update) server_update)
self.stub_out('nova.network.manager.VlanManager.allocate_fixed_ip', self.stub_out('nova.network.manager.VlanManager.allocate_fixed_ip',
fake_method) fake_method)

View File

@ -24,7 +24,7 @@ import webob
from nova.api.openstack.compute import security_groups from nova.api.openstack.compute import security_groups
from nova import context from nova import context
import nova.db import nova.db.api
from nova import exception from nova import exception
from nova.network import model from nova.network import model
from nova.network.neutronv2 import api as neutron_api from nova.network.neutronv2 import api as neutron_api
@ -164,7 +164,7 @@ class TestNeutronSecurityGroupsV21(
device_id=test_security_groups.FAKE_UUID1) device_id=test_security_groups.FAKE_UUID1)
expected = [{'rules': [], 'tenant_id': 'fake', 'id': sg['id'], expected = [{'rules': [], 'tenant_id': 'fake', 'id': sg['id'],
'name': 'test', 'description': 'test-description'}] '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) test_security_groups.return_server_by_uuid)
req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/os-security-groups' req = fakes.HTTPRequest.blank('/v2/fake/servers/%s/os-security-groups'
% test_security_groups.FAKE_UUID1) % test_security_groups.FAKE_UUID1)
@ -202,7 +202,7 @@ class TestNeutronSecurityGroupsV21(
_context, instance_obj.Instance(), db_inst, _context, instance_obj.Instance(), db_inst,
expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS) expected_attrs=instance_obj.INSTANCE_DEFAULT_FIELDS)
neutron = neutron_api.API() 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): return_value=db_inst):
neutron.allocate_for_instance(_context, instance, False, None, neutron.allocate_for_instance(_context, instance, False, None,
security_groups=[sg['id']]) security_groups=[sg['id']])
@ -231,7 +231,7 @@ class TestNeutronSecurityGroupsV21(
network_id=net['network']['id'], security_groups=[sg['id']], network_id=net['network']['id'], security_groups=[sg['id']],
device_id=UUID_SERVER) 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) test_security_groups.return_server)
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
@ -249,7 +249,7 @@ class TestNeutronSecurityGroupsV21(
network_id=net['network']['id'], security_groups=[sg1['id']], network_id=net['network']['id'], security_groups=[sg1['id']],
device_id=UUID_SERVER) 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) test_security_groups.return_server)
body = dict(addSecurityGroup=dict(name="sg1")) body = dict(addSecurityGroup=dict(name="sg1"))
@ -267,7 +267,7 @@ class TestNeutronSecurityGroupsV21(
port_security_enabled=True, port_security_enabled=True,
device_id=UUID_SERVER) 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) test_security_groups.return_server)
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
@ -282,7 +282,7 @@ class TestNeutronSecurityGroupsV21(
network_id=net['network']['id'], port_security_enabled=False, network_id=net['network']['id'], port_security_enabled=False,
device_id=UUID_SERVER) 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) test_security_groups.return_server)
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
@ -300,7 +300,7 @@ class TestNeutronSecurityGroupsV21(
port_security_enabled=True, ip_allocation='deferred', port_security_enabled=True, ip_allocation='deferred',
device_id=UUID_SERVER) 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) test_security_groups.return_server)
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
@ -309,7 +309,7 @@ class TestNeutronSecurityGroupsV21(
self.manager._addSecurityGroup(req, UUID_SERVER, body) self.manager._addSecurityGroup(req, UUID_SERVER, body)
def test_disassociate_by_non_existing_security_group_name(self): 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) test_security_groups.return_server)
body = dict(removeSecurityGroup=dict(name='non-existing')) body = dict(removeSecurityGroup=dict(name='non-existing'))
@ -338,7 +338,7 @@ class TestNeutronSecurityGroupsV21(
network_id=net['network']['id'], security_groups=[sg['id']], network_id=net['network']['id'], security_groups=[sg['id']],
device_id=UUID_SERVER) 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) test_security_groups.return_server)
body = dict(removeSecurityGroup=dict(name="test")) body = dict(removeSecurityGroup=dict(name="test"))

View File

@ -18,7 +18,7 @@ import mock
import webob import webob
from nova.api.openstack.compute import quota_sets as quotas_v21 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 exception
from nova import quota from nova import quota
from nova import test from nova import test

View File

@ -18,7 +18,7 @@ import webob
from nova.api.openstack.compute import \ from nova.api.openstack.compute import \
security_group_default_rules as security_group_default_rules_v21 security_group_default_rules as security_group_default_rules_v21
from nova import context from nova import context
import nova.db import nova.db.api
from nova import exception from nova import exception
from nova import test from nova import test
from nova.tests.unit.api.openstack import fakes from nova.tests.unit.api.openstack import fakes
@ -226,7 +226,7 @@ class TestSecurityGroupDefaultRulesV21(test.TestCase):
res_dict = self.controller.index(self.req) res_dict = self.controller.index(self.req)
self.assertEqual(res_dict, expected) 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. side_effect=(exception.
SecurityGroupDefaultRuleNotFound("Rule Not Found"))) SecurityGroupDefaultRuleNotFound("Rule Not Found")))
def test_non_existing_security_group_default_rules_list(self, 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'], self.assertEqual(security_group_default_rule['ip_range']['cidr'],
sgr['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. side_effect=(exception.
SecurityGroupDefaultRuleNotFound("Rule Not Found"))) SecurityGroupDefaultRuleNotFound("Rule Not Found")))
def test_non_existing_security_group_default_rule_show(self, def test_non_existing_security_group_default_rule_show(self,
@ -274,16 +274,16 @@ class TestSecurityGroupDefaultRulesV21(test.TestCase):
self.assertEqual(sgr['id'], id) self.assertEqual(sgr['id'], id)
return security_group_default_rule_db(sgr) 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) 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) return_security_group_default_rule)
self.controller.delete(self.req, '1') self.controller.delete(self.req, '1')
self.assertTrue(self.called) 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. side_effect=(exception.
SecurityGroupDefaultRuleNotFound("Rule Not Found"))) SecurityGroupDefaultRuleNotFound("Rule Not Found")))
def test_non_existing_security_group_default_rule_delete( def test_non_existing_security_group_default_rule_delete(
@ -299,8 +299,9 @@ class TestSecurityGroupDefaultRulesV21(test.TestCase):
setattr(ctxt, 'project_id', 'new_project_id') setattr(ctxt, 'project_id', 'new_project_id')
sg = nova.db.security_group_ensure_default(ctxt) sg = nova.db.api.security_group_ensure_default(ctxt)
rules = nova.db.security_group_rule_get_by_security_group(ctxt, sg.id) rules = nova.db.api.security_group_rule_get_by_security_group(
ctxt, sg.id)
security_group_rule = rules[0] security_group_rule = rules[0]
self.assertEqual(sgr['id'], security_group_rule.id) self.assertEqual(sgr['id'], security_group_rule.id)
self.assertEqual(sgr['ip_protocol'], security_group_rule.protocol) self.assertEqual(sgr['ip_protocol'], security_group_rule.protocol)

View File

@ -25,7 +25,7 @@ from nova.api.openstack import wsgi
from nova import compute from nova import compute
from nova.compute import power_state from nova.compute import power_state
from nova import context as context_maker from nova import context as context_maker
import nova.db import nova.db.api
from nova import exception from nova import exception
from nova import objects from nova import objects
from nova import test from nova import test
@ -335,7 +335,7 @@ class TestSecurityGroupsV21(test.TestCase):
def return_security_groups(context, project_id): def return_security_groups(context, project_id):
return [security_group_db(sg) for sg in groups] 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) return_security_groups)
path = '/v2/fake/os-security-groups' path = '/v2/fake/os-security-groups'
@ -407,13 +407,13 @@ class TestSecurityGroupsV21(test.TestCase):
def return_all_security_groups(context): def return_all_security_groups(context):
return [security_group_db(sg) for sg in all_groups] 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) return_all_security_groups)
def return_tenant_security_groups(context, project_id): def return_tenant_security_groups(context, project_id):
return [security_group_db(sg) for sg in tenant_groups] 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) return_tenant_security_groups)
path = '/v2/fake/os-security-groups' path = '/v2/fake/os-security-groups'
@ -469,14 +469,14 @@ class TestSecurityGroupsV21(test.TestCase):
self.assertEqual(server_id, FAKE_UUID1) self.assertEqual(server_id, FAKE_UUID1)
return return_server_by_uuid(context, server_id) 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) return_instance)
def return_security_groups(context, instance_uuid): def return_security_groups(context, instance_uuid):
self.assertEqual(instance_uuid, FAKE_UUID1) self.assertEqual(instance_uuid, FAKE_UUID1)
return [security_group_db(sg) for sg in groups] 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) return_security_groups)
# Stub out the security group API get() method to assert that we only # 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) self.assertEqual(expected, res_dict)
@mock.patch('nova.db.instance_get_by_uuid') @mock.patch('nova.db.api.instance_get_by_uuid')
@mock.patch('nova.db.security_group_get_by_instance', return_value=[]) @mock.patch('nova.db.api.security_group_get_by_instance', return_value=[])
def test_get_security_group_empty_for_instance(self, mock_sec_group, def test_get_security_group_empty_for_instance(self, mock_sec_group,
mock_db_get_ins): mock_db_get_ins):
expected = {'security_groups': []} expected = {'security_groups': []}
@ -515,8 +515,8 @@ class TestSecurityGroupsV21(test.TestCase):
self.req.environ['nova.context'], FAKE_UUID1) self.req.environ['nova.context'], FAKE_UUID1)
def test_get_security_group_by_instance_non_existing(self): 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.api.instance_get', return_server_nonexistent)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
return_server_nonexistent) return_server_nonexistent)
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.server_controller.index, self.req, '1') self.server_controller.index, self.req, '1')
@ -532,7 +532,7 @@ class TestSecurityGroupsV21(test.TestCase):
self.assertEqual(sg['id'], group_id) self.assertEqual(sg['id'], group_id)
return security_group_db(sg) 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) return_security_group)
res_dict = self.controller.show(self.req, '2') res_dict = self.controller.show(self.req, '2')
@ -564,9 +564,9 @@ class TestSecurityGroupsV21(test.TestCase):
self.assertEqual(sg_update['description'], values['description']) self.assertEqual(sg_update['description'], values['description'])
return security_group_db(sg_update) 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) return_update_security_group)
self.stub_out('nova.db.security_group_get', self.stub_out('nova.db.api.security_group_get',
return_security_group) return_security_group)
res_dict = self.controller.update(self.req, '2', res_dict = self.controller.update(self.req, '2',
@ -582,7 +582,7 @@ class TestSecurityGroupsV21(test.TestCase):
self.assertEqual(sg['id'], group_id) self.assertEqual(sg['id'], group_id)
return security_group_db(sg) 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) return_security_group)
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update,
@ -607,9 +607,9 @@ class TestSecurityGroupsV21(test.TestCase):
self.assertEqual(sg['id'], group_id) self.assertEqual(sg['id'], group_id)
return security_group_db(sg) 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) security_group_destroy)
self.stub_out('nova.db.security_group_get', self.stub_out('nova.db.api.security_group_get',
return_security_group) return_security_group)
self.controller.delete(self.req, '1') self.controller.delete(self.req, '1')
@ -651,9 +651,9 @@ class TestSecurityGroupsV21(test.TestCase):
self.assertEqual(sg['id'], group_id) self.assertEqual(sg['id'], group_id)
return security_group_db(sg) 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) security_group_in_use)
self.stub_out('nova.db.security_group_get', self.stub_out('nova.db.api.security_group_get',
return_security_group) return_security_group)
self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete, self.assertRaises(webob.exc.HTTPBadRequest, self.controller.delete,
@ -720,9 +720,9 @@ class TestSecurityGroupsV21(test.TestCase):
self.controller.index(req) self.controller.index(req)
def test_associate_by_non_existing_security_group_name(self): 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'), 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')) body = dict(addSecurityGroup=dict(name='non-existing'))
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
@ -736,29 +736,29 @@ class TestSecurityGroupsV21(test.TestCase):
'invalid', body) 'invalid', body)
def test_associate_without_body(self): 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) body = dict(addSecurityGroup=None)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.manager._addSecurityGroup, self.req, '1', body) self.manager._addSecurityGroup, self.req, '1', body)
def test_associate_no_security_group_name(self): 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()) body = dict(addSecurityGroup=dict())
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.manager._addSecurityGroup, self.req, '1', body) self.manager._addSecurityGroup, self.req, '1', body)
def test_associate_security_group_name_with_whitespaces(self): 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=" ")) body = dict(addSecurityGroup=dict(name=" "))
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
self.manager._addSecurityGroup, self.req, '1', body) self.manager._addSecurityGroup, self.req, '1', body)
def test_associate_non_existing_instance(self): def test_associate_non_existing_instance(self):
self.stub_out('nova.db.instance_get', return_server_nonexistent) self.stub_out('nova.db.api.instance_get', return_server_nonexistent)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
return_server_nonexistent) return_server_nonexistent)
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
@ -766,20 +766,20 @@ class TestSecurityGroupsV21(test.TestCase):
self.manager._addSecurityGroup, self.req, '1', body) self.manager._addSecurityGroup, self.req, '1', body)
def test_associate_non_running_instance(self): def test_associate_non_running_instance(self):
self.stub_out('nova.db.instance_get', return_non_running_server) self.stub_out('nova.db.api.instance_get', return_non_running_server)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
return_non_running_server) 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) return_security_group_without_instances)
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
self.manager._addSecurityGroup(self.req, UUID_SERVER, body) self.manager._addSecurityGroup(self.req, UUID_SERVER, body)
def test_associate_already_associated_security_group_to_instance(self): def test_associate_already_associated_security_group_to_instance(self):
self.stub_out('nova.db.instance_get', return_server) self.stub_out('nova.db.api.instance_get', return_server)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
return_server_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) return_security_group_by_name)
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
@ -787,13 +787,13 @@ class TestSecurityGroupsV21(test.TestCase):
self.manager._addSecurityGroup, self.req, self.manager._addSecurityGroup, self.req,
UUID_SERVER, body) 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): def test_associate(self, mock_add_security_group):
self.stub_out('nova.db.instance_get', return_server) self.stub_out('nova.db.api.instance_get', return_server)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
return_server_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) return_security_group_without_instances)
body = dict(addSecurityGroup=dict(name="test")) body = dict(addSecurityGroup=dict(name="test"))
@ -804,9 +804,9 @@ class TestSecurityGroupsV21(test.TestCase):
mock.ANY) mock.ANY)
def test_disassociate_by_non_existing_security_group_name(self): 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'), 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')) body = dict(removeSecurityGroup=dict(name='non-existing'))
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
@ -814,7 +814,7 @@ class TestSecurityGroupsV21(test.TestCase):
UUID_SERVER, body) UUID_SERVER, body)
def test_disassociate_by_invalid_server_id(self): 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) return_security_group_by_name)
body = dict(removeSecurityGroup=dict(name='test')) body = dict(removeSecurityGroup=dict(name='test'))
@ -823,7 +823,7 @@ class TestSecurityGroupsV21(test.TestCase):
'invalid', body) 'invalid', body)
def test_disassociate_without_body(self): 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) body = dict(removeSecurityGroup=None)
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
@ -831,7 +831,7 @@ class TestSecurityGroupsV21(test.TestCase):
'1', body) '1', body)
def test_disassociate_no_security_group_name(self): 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()) body = dict(removeSecurityGroup=dict())
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
@ -839,7 +839,7 @@ class TestSecurityGroupsV21(test.TestCase):
'1', body) '1', body)
def test_disassociate_security_group_name_with_whitespaces(self): 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=" ")) body = dict(removeSecurityGroup=dict(name=" "))
self.assertRaises(webob.exc.HTTPBadRequest, self.assertRaises(webob.exc.HTTPBadRequest,
@ -847,8 +847,8 @@ class TestSecurityGroupsV21(test.TestCase):
'1', body) '1', body)
def test_disassociate_non_existing_instance(self): def test_disassociate_non_existing_instance(self):
self.stub_out('nova.db.instance_get', return_server_nonexistent) self.stub_out('nova.db.api.instance_get', return_server_nonexistent)
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) return_security_group_by_name)
body = dict(removeSecurityGroup=dict(name="test")) body = dict(removeSecurityGroup=dict(name="test"))
@ -857,20 +857,20 @@ class TestSecurityGroupsV21(test.TestCase):
self.req, '1', body) self.req, '1', body)
def test_disassociate_non_running_instance(self): def test_disassociate_non_running_instance(self):
self.stub_out('nova.db.instance_get', return_non_running_server) self.stub_out('nova.db.api.instance_get', return_non_running_server)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
return_non_running_server) 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) return_security_group_by_name)
body = dict(removeSecurityGroup=dict(name="test")) body = dict(removeSecurityGroup=dict(name="test"))
self.manager._removeSecurityGroup(self.req, UUID_SERVER, body) self.manager._removeSecurityGroup(self.req, UUID_SERVER, body)
def test_disassociate_already_associated_security_group_to_instance(self): def test_disassociate_already_associated_security_group_to_instance(self):
self.stub_out('nova.db.instance_get', return_server) self.stub_out('nova.db.api.instance_get', return_server)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
return_server_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) return_security_group_without_instances)
body = dict(removeSecurityGroup=dict(name="test")) body = dict(removeSecurityGroup=dict(name="test"))
@ -878,12 +878,12 @@ class TestSecurityGroupsV21(test.TestCase):
self.manager._removeSecurityGroup, self.req, self.manager._removeSecurityGroup, self.req,
UUID_SERVER, body) 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): def test_disassociate(self, mock_remove_sec_group):
self.stub_out('nova.db.instance_get', return_server) self.stub_out('nova.db.api.instance_get', return_server)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
return_server_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) return_security_group_by_name)
body = dict(removeSecurityGroup=dict(name="test")) body = dict(removeSecurityGroup=dict(name="test"))
@ -929,7 +929,7 @@ class TestSecurityGroupRulesV21(test.TestCase):
return db2 return db2
raise exception.SecurityGroupNotFound(security_group_id=group_id) 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) return_security_group)
self.parent_security_group = db2 self.parent_security_group = db2
@ -1294,9 +1294,9 @@ class TestSecurityGroupRulesV21(test.TestCase):
def security_group_rule_destroy(context, id): def security_group_rule_destroy(context, id):
pass pass
self.stub_out('nova.db.security_group_rule_get', self.stub_out('nova.db.api.security_group_rule_get',
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) security_group_rule_destroy)
self.controller.delete(self.req, self.sg2['id']) self.controller.delete(self.req, self.sg2['id'])

View File

@ -77,10 +77,10 @@ class ServerActionsControllerTestV21(test.TestCase):
def setUp(self): def setUp(self):
super(ServerActionsControllerTestV21, self).setUp() super(ServerActionsControllerTestV21, self).setUp()
self.flags(group='glance', api_servers=['http://localhost:9292']) 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, fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
host='fake_host')) 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) instance_update_and_get_original)
fakes.stub_out_nw_api(self) fakes.stub_out_nw_api(self)
@ -195,7 +195,7 @@ class ServerActionsControllerTestV21(test.TestCase):
self.req, FAKE_UUID, body=body) self.req, FAKE_UUID, body=body)
def test_reboot_not_found(self): 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) return_server_not_found)
body = dict(reboot=dict(type="HARD")) 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): def test_reboot_soft_with_soft_in_progress_raises_conflict(self):
body = dict(reboot=dict(type="SOFT")) 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, fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
task_state=task_states.REBOOTING)) task_state=task_states.REBOOTING))
self.assertRaises(webob.exc.HTTPConflict, 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): def test_reboot_hard_with_soft_in_progress_does_not_raise(self):
body = dict(reboot=dict(type="HARD")) 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, fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
task_state=task_states.REBOOTING)) task_state=task_states.REBOOTING))
self.controller._action_reboot(self.req, FAKE_UUID, body=body) self.controller._action_reboot(self.req, FAKE_UUID, body=body)
def test_reboot_hard_with_hard_in_progress(self): def test_reboot_hard_with_hard_in_progress(self):
body = dict(reboot=dict(type="HARD")) 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, fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
task_state=task_states.REBOOTING_HARD)) task_state=task_states.REBOOTING_HARD))
self.controller._action_reboot(self.req, FAKE_UUID, body=body) self.controller._action_reboot(self.req, FAKE_UUID, body=body)
def test_reboot_soft_with_hard_in_progress_raises_conflict(self): def test_reboot_soft_with_hard_in_progress_raises_conflict(self):
body = dict(reboot=dict(type="SOFT")) 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, fakes.fake_instance_get(vm_state=vm_states.ACTIVE,
task_state=task_states.REBOOTING_HARD)) task_state=task_states.REBOOTING_HARD))
self.assertRaises(webob.exc.HTTPConflict, self.assertRaises(webob.exc.HTTPConflict,
@ -254,7 +254,7 @@ class ServerActionsControllerTestV21(test.TestCase):
return_server = fakes.fake_instance_get(image_ref='2', return_server = fakes.fake_instance_get(image_ref='2',
vm_state=vm_states.ACTIVE, vm_state=vm_states.ACTIVE,
host='fake_host') 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 = { body = {
"rebuild": { "rebuild": {
@ -286,7 +286,7 @@ class ServerActionsControllerTestV21(test.TestCase):
def test_rebuild_accepted_minimum(self): def test_rebuild_accepted_minimum(self):
return_server = fakes.fake_instance_get(image_ref='2', return_server = fakes.fake_instance_get(image_ref='2',
vm_state=vm_states.ACTIVE, host='fake_host') 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 self_href = 'http://localhost/v2/servers/%s' % FAKE_UUID
body = { body = {
@ -310,7 +310,7 @@ class ServerActionsControllerTestV21(test.TestCase):
def rebuild(self2, context, instance, image_href, *args, **kwargs): def rebuild(self2, context, instance, image_href, *args, **kwargs):
info['image_href_in_call'] = image_href 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)) fakes.fake_instance_get(vm_state=vm_states.ACTIVE))
self.stub_out('nova.compute.api.API.rebuild', rebuild) 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', return_server = fakes.fake_instance_get(image_ref='2',
vm_state=vm_states.ACTIVE, host='fake_host') 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 self_href = 'http://localhost/v2/servers/%s' % FAKE_UUID
body = { body = {
@ -383,7 +383,7 @@ class ServerActionsControllerTestV21(test.TestCase):
return_server = fakes.fake_instance_get(metadata=metadata, return_server = fakes.fake_instance_get(metadata=metadata,
vm_state=vm_states.ACTIVE, host='fake_host') 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 = { body = {
"rebuild": { "rebuild": {
@ -437,7 +437,7 @@ class ServerActionsControllerTestV21(test.TestCase):
def test_rebuild_admin_pass(self): def test_rebuild_admin_pass(self):
return_server = fakes.fake_instance_get(image_ref='2', return_server = fakes.fake_instance_get(image_ref='2',
vm_state=vm_states.ACTIVE, host='fake_host') 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 = { body = {
"rebuild": { "rebuild": {
@ -459,7 +459,7 @@ class ServerActionsControllerTestV21(test.TestCase):
return_server = fakes.fake_instance_get(image_ref='2', return_server = fakes.fake_instance_get(image_ref='2',
vm_state=vm_states.ACTIVE, host='fake_host') 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 = { body = {
"rebuild": { "rebuild": {
@ -478,7 +478,7 @@ class ServerActionsControllerTestV21(test.TestCase):
def server_not_found(self, instance_id, def server_not_found(self, instance_id,
columns_to_join=None, use_slave=False): columns_to_join=None, use_slave=False):
raise exception.InstanceNotFound(instance_id=instance_id) 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 = { body = {
"rebuild": { "rebuild": {
@ -958,7 +958,7 @@ class ServerActionsControllerTestV21(test.TestCase):
'delete_on_termination': False, 'delete_on_termination': False,
'no_device': None})] '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) fake_block_device_mapping_get_all_by_instance)
system_metadata = dict(image_kernel_id=_fake_id('b'), system_metadata = dict(image_kernel_id=_fake_id('b'),
@ -970,7 +970,7 @@ class ServerActionsControllerTestV21(test.TestCase):
vm_state=vm_states.ACTIVE, vm_state=vm_states.ACTIVE,
root_device_name='/dev/vda', root_device_name='/dev/vda',
system_metadata=system_metadata) 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'), volume = dict(id=_fake_id('a'),
size=1, size=1,
@ -1069,7 +1069,7 @@ class ServerActionsControllerTestV21(test.TestCase):
'delete_on_termination': False, 'delete_on_termination': False,
'no_device': None})] '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) fake_block_device_mapping_get_all_by_instance)
instance = fakes.fake_instance_get( instance = fakes.fake_instance_get(
@ -1078,7 +1078,7 @@ class ServerActionsControllerTestV21(test.TestCase):
root_device_name='/dev/vda', root_device_name='/dev/vda',
system_metadata={'image_test_key1': 'test_value1', system_metadata={'image_test_key1': 'test_value1',
'image_test_key2': 'test_value2'}) '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'), volume = dict(id=_fake_id('a'),
size=1, size=1,

View File

@ -23,7 +23,7 @@ import webob
from nova.api.openstack.compute import server_metadata \ from nova.api.openstack.compute import server_metadata \
as server_metadata_v21 as server_metadata_v21
from nova.compute import vm_states from nova.compute import vm_states
import nova.db import nova.db.api
from nova import exception from nova import exception
from nova import test from nova import test
from nova.tests.unit.api.openstack import fakes from nova.tests.unit.api.openstack import fakes
@ -116,11 +116,11 @@ class ServerMetaDataTestV21(test.TestCase):
def setUp(self): def setUp(self):
super(ServerMetaDataTestV21, self).setUp() super(ServerMetaDataTestV21, self).setUp()
fakes.stub_out_key_pair_funcs(self) fakes.stub_out_key_pair_funcs(self)
self.stub_out('nova.db.instance_get', return_server) self.stub_out('nova.db.api.instance_get', return_server)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
return_server_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) return_server_metadata)
self.stub_out( self.stub_out(
@ -150,14 +150,14 @@ class ServerMetaDataTestV21(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_index_nonexistent_server(self): 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) return_server_nonexistent)
req = self._get_request() req = self._get_request()
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.index, req, self.url) self.controller.index, req, self.url)
def test_index_no_data(self): 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) return_empty_server_metadata)
req = self._get_request() req = self._get_request()
res_dict = self.controller.index(req, self.uuid) res_dict = self.controller.index(req, self.uuid)
@ -171,23 +171,23 @@ class ServerMetaDataTestV21(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_show_nonexistent_server(self): 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) return_server_nonexistent)
req = self._get_request('/key2') req = self._get_request('/key2')
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.show, req, self.uuid, 'key2') self.controller.show, req, self.uuid, 'key2')
def test_show_meta_not_found(self): 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) return_empty_server_metadata)
req = self._get_request('/key6') req = self._get_request('/key6')
self.assertRaises(webob.exc.HTTPNotFound, self.assertRaises(webob.exc.HTTPNotFound,
self.controller.show, req, self.uuid, 'key6') self.controller.show, req, self.uuid, 'key6')
def test_delete(self): def test_delete(self):
self.stub_out('nova.db.instance_metadata_get', self.stub_out('nova.db.api.instance_metadata_get',
return_server_metadata) return_server_metadata)
self.stub_out('nova.db.instance_metadata_delete', self.stub_out('nova.db.api.instance_metadata_delete',
delete_server_metadata) delete_server_metadata)
req = self._get_request('/key2') req = self._get_request('/key2')
req.method = 'DELETE' req.method = 'DELETE'
@ -196,7 +196,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.assertIsNone(res) self.assertIsNone(res)
def test_delete_nonexistent_server(self): 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) return_server_nonexistent)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'DELETE' req.method = 'DELETE'
@ -204,7 +204,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.controller.delete, req, self.uuid, 'key1') self.controller.delete, req, self.uuid, 'key1')
def test_delete_meta_not_found(self): 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) return_empty_server_metadata)
req = self._get_request('/key6') req = self._get_request('/key6')
req.method = 'DELETE' req.method = 'DELETE'
@ -228,7 +228,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.assertEqual(body, res_dict) self.assertEqual(body, res_dict)
def test_create_empty_body(self): 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) return_create_instance_metadata)
req = self._get_request() req = self._get_request()
req.method = 'POST' req.method = 'POST'
@ -238,7 +238,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.controller.create, req, self.uuid, body=None) self.controller.create, req, self.uuid, body=None)
def test_create_item_empty_key(self): 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) return_create_instance_metadata)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'PUT' req.method = 'PUT'
@ -250,7 +250,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.controller.create, req, self.uuid, body=body) self.controller.create, req, self.uuid, body=body)
def test_create_item_non_dict(self): 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) return_create_instance_metadata)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'PUT' req.method = 'PUT'
@ -262,7 +262,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.controller.create, req, self.uuid, body=body) self.controller.create, req, self.uuid, body=body)
def test_create_item_key_too_long(self): 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) return_create_instance_metadata)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'PUT' req.method = 'PUT'
@ -275,7 +275,7 @@ class ServerMetaDataTestV21(test.TestCase):
req, self.uuid, body=body) req, self.uuid, body=body)
def test_create_malformed_container(self): 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) return_create_instance_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
@ -287,7 +287,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.controller.create, req, self.uuid, body=body) self.controller.create, req, self.uuid, body=body)
def test_create_malformed_data(self): 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) return_create_instance_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
@ -299,7 +299,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.controller.create, req, self.uuid, body=body) self.controller.create, req, self.uuid, body=body)
def test_create_nonexistent_server(self): 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) return_server_nonexistent)
req = self._get_request() req = self._get_request()
req.method = 'POST' req.method = 'POST'
@ -353,7 +353,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_update_all_empty_body_item(self): 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) return_create_instance_metadata)
req = fakes.HTTPRequest.blank(self.url + '/key1') req = fakes.HTTPRequest.blank(self.url + '/key1')
req.method = 'PUT' req.method = 'PUT'
@ -364,7 +364,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=None) body=None)
def test_update_all_with_non_dict_item(self): 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) return_create_instance_metadata)
req = fakes.HTTPRequest.blank(self.url + '/bad') req = fakes.HTTPRequest.blank(self.url + '/bad')
req.method = 'PUT' req.method = 'PUT'
@ -377,7 +377,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=body) body=body)
def test_update_all_malformed_container(self): 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) return_create_instance_metadata)
req = self._get_request() req = self._get_request()
req.method = 'PUT' req.method = 'PUT'
@ -390,7 +390,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=expected) body=expected)
def test_update_all_malformed_data(self): 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) return_create_instance_metadata)
req = self._get_request() req = self._get_request()
req.method = 'PUT' req.method = 'PUT'
@ -403,7 +403,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=expected) body=expected)
def test_update_all_nonexistent_server(self): 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 = self._get_request()
req.method = 'PUT' req.method = 'PUT'
req.content_type = "application/json" req.content_type = "application/json"
@ -414,7 +414,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.controller.update_all, req, '100', body=body) self.controller.update_all, req, '100', body=body)
def test_update_all_non_dict(self): 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) return_create_instance_metadata)
req = self._get_request() req = self._get_request()
req.method = 'PUT' req.method = 'PUT'
@ -437,7 +437,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.assertEqual(expected, res_dict) self.assertEqual(expected, res_dict)
def test_update_item_nonexistent_server(self): 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) return_server_nonexistent)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'PUT' req.method = 'PUT'
@ -450,7 +450,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=body) body=body)
def test_update_item_empty_body(self): 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) return_create_instance_metadata)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'PUT' req.method = 'PUT'
@ -461,7 +461,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=None) body=None)
def test_update_malformed_container(self): 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) return_create_instance_metadata)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT' req.method = 'PUT'
@ -474,7 +474,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=expected) body=expected)
def test_update_malformed_data(self): 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) return_create_instance_metadata)
req = fakes.HTTPRequest.blank(self.url) req = fakes.HTTPRequest.blank(self.url)
req.method = 'PUT' req.method = 'PUT'
@ -487,7 +487,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=expected) body=expected)
def test_update_item_empty_key(self): 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) return_create_instance_metadata)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'PUT' req.method = 'PUT'
@ -500,7 +500,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=body) body=body)
def test_update_item_key_too_long(self): 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) return_create_instance_metadata)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'PUT' req.method = 'PUT'
@ -513,7 +513,7 @@ class ServerMetaDataTestV21(test.TestCase):
req, self.uuid, ("a" * 260), body=body) req, self.uuid, ("a" * 260), body=body)
def test_update_item_value_too_long(self): 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) return_create_instance_metadata)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'PUT' req.method = 'PUT'
@ -526,7 +526,7 @@ class ServerMetaDataTestV21(test.TestCase):
req, self.uuid, "key1", body=body) req, self.uuid, "key1", body=body)
def test_update_item_too_many_keys(self): 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) return_create_instance_metadata)
req = self._get_request('/key1') req = self._get_request('/key1')
req.method = 'PUT' req.method = 'PUT'
@ -539,7 +539,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=body) body=body)
def test_update_item_body_uri_mismatch(self): 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) return_create_instance_metadata)
req = self._get_request('/bad') req = self._get_request('/bad')
req.method = 'PUT' req.method = 'PUT'
@ -552,7 +552,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=body) body=body)
def test_update_item_non_dict(self): 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) return_create_instance_metadata)
req = self._get_request('/bad') req = self._get_request('/bad')
req.method = 'PUT' req.method = 'PUT'
@ -578,7 +578,7 @@ class ServerMetaDataTestV21(test.TestCase):
body=expected) body=expected)
def test_too_many_metadata_items_on_create(self): 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) return_create_instance_metadata)
data = {"metadata": {}} data = {"metadata": {}}
for num in range(CONF.quota.metadata_items + 1): 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) self.controller.create, req, self.uuid, body=data)
def test_invalid_metadata_items_on_create(self): 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) return_create_instance_metadata)
req = self._get_request() req = self._get_request()
req.method = 'POST' req.method = 'POST'
@ -617,7 +617,7 @@ class ServerMetaDataTestV21(test.TestCase):
self.controller.create, req, self.uuid, body=data) self.controller.create, req, self.uuid, body=data)
def test_too_many_metadata_items_on_update_item(self): 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) return_create_instance_metadata)
data = {"metadata": {}} data = {"metadata": {}}
for num in range(CONF.quota.metadata_items + 1): for num in range(CONF.quota.metadata_items + 1):
@ -631,7 +631,7 @@ class ServerMetaDataTestV21(test.TestCase):
req, self.uuid, body=data) req, self.uuid, body=data)
def test_invalid_metadata_items_on_update_item(self): 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) return_create_instance_metadata)
data = {"metadata": {}} data = {"metadata": {}}
for num in range(CONF.quota.metadata_items + 1): for num in range(CONF.quota.metadata_items + 1):
@ -668,15 +668,15 @@ class BadStateServerMetaDataTestV21(test.TestCase):
def setUp(self): def setUp(self):
super(BadStateServerMetaDataTestV21, self).setUp() super(BadStateServerMetaDataTestV21, self).setUp()
fakes.stub_out_key_pair_funcs(self) 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) return_server_metadata)
self.stub_out( self.stub_out(
'nova.compute.rpcapi.ComputeAPI.change_instance_metadata', 'nova.compute.rpcapi.ComputeAPI.change_instance_metadata',
fake_change_instance_metadata) fake_change_instance_metadata)
self.stub_out('nova.db.instance_get', self._return_server_in_build) self.stub_out('nova.db.api.instance_get', self._return_server_in_build)
self.stub_out('nova.db.instance_get_by_uuid', self.stub_out('nova.db.api.instance_get_by_uuid',
self._return_server_in_build_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) delete_server_metadata)
self._set_up_resources() self._set_up_resources()
@ -695,7 +695,7 @@ class BadStateServerMetaDataTestV21(test.TestCase):
req, self.uuid, 'key2') req, self.uuid, 'key2')
def test_invalid_state_on_update_metadata(self): 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) return_create_instance_metadata)
req = self._get_request() req = self._get_request()
req.method = 'POST' req.method = 'POST'

View File

@ -20,7 +20,7 @@ import webob
from nova.api.openstack.compute import servers \ from nova.api.openstack.compute import servers \
as server_v21 as server_v21
from nova.compute import api as compute_api 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 exception
from nova import policy from nova import policy
from nova import test from nova import test
@ -36,7 +36,7 @@ class ServerStartStopTestV21(test.TestCase):
self._setup_controller() self._setup_controller()
self.req = fakes.HTTPRequest.blank('') self.req = fakes.HTTPRequest.blank('')
self.useFixture(nova_fixtures.SingleCellSimple()) 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()) fakes.fake_instance_get())
def _setup_controller(self): def _setup_controller(self):
@ -131,7 +131,7 @@ class ServerStartStopPolicyEnforcementV21(test.TestCase):
self.req = fakes.HTTPRequest.blank('') self.req = fakes.HTTPRequest.blank('')
self.useFixture(nova_fixtures.SingleCellSimple()) self.useFixture(nova_fixtures.SingleCellSimple())
self.stub_out( self.stub_out(
'nova.db.instance_get_by_uuid', 'nova.db.api.instance_get_by_uuid',
fakes.fake_instance_get( fakes.fake_instance_get(
project_id=self.req.environ['nova.context'].project_id)) project_id=self.req.environ['nova.context'].project_id))

View File

@ -67,7 +67,7 @@ class ServerTagsTest(test.TestCase):
request.method = method request.method = method
return request return request
@mock.patch('nova.db.instance_tag_exists') @mock.patch('nova.db.api.instance_tag_exists')
def test_show(self, mock_exists): def test_show(self, mock_exists):
mock_exists.return_value = True mock_exists.return_value = True
req = self._get_request( req = self._get_request(
@ -76,7 +76,7 @@ class ServerTagsTest(test.TestCase):
self.controller.show(req, UUID, TAG1) self.controller.show(req, UUID, TAG1)
mock_exists.assert_called_once_with(mock.ANY, 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): def test_index(self, mock_db_get_inst_tags):
fake_tags = [self._get_tag(tag) for tag in TAGS] fake_tags = [self._get_tag(tag) for tag in TAGS]
mock_db_get_inst_tags.return_value = fake_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_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID)
@mock.patch('nova.notifications.base.send_instance_update_notification') @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): def test_update_all(self, mock_db_set_inst_tags, mock_notify):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
fake_tags = [self._get_tag(tag) for tag in TAGS] 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, self.assertRaises(exc.HTTPConflict, self.controller.update_all,
req, UUID, body={'tags': TAGS}) 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): def test_show_non_existing_tag(self, mock_exists):
mock_exists.return_value = False mock_exists.return_value = False
req = self._get_request( req = self._get_request(
@ -162,8 +162,8 @@ class ServerTagsTest(test.TestCase):
req, UUID, TAG1) req, UUID, TAG1)
@mock.patch('nova.notifications.base.send_instance_update_notification') @mock.patch('nova.notifications.base.send_instance_update_notification')
@mock.patch('nova.db.instance_tag_add') @mock.patch('nova.db.api.instance_tag_add')
@mock.patch('nova.db.instance_tag_get_by_instance_uuid') @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, def test_update(self, mock_db_get_inst_tags, mock_db_add_inst_tags,
mock_notify): mock_notify):
self.stub_out('nova.api.openstack.common.get_instance', return_server) 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(2, mock_db_get_inst_tags.call_count)
self.assertEqual(1, mock_notify.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): def test_update_existing_tag(self, mock_db_get_inst_tags):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
mock_db_get_inst_tags.return_value = [self._get_tag(TAG1)] 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)) self.assertEqual(0, len(res.body))
mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID) 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): def test_update_tag_limit_exceed(self, mock_db_get_inst_tags):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
fake_tags = [self._get_tag(str(i)) fake_tags = [self._get_tag(str(i))
@ -207,7 +207,7 @@ class ServerTagsTest(test.TestCase):
self.assertRaises(exc.HTTPBadRequest, self.controller.update, self.assertRaises(exc.HTTPBadRequest, self.controller.update,
req, UUID, TAG2, body=None) 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): def test_update_too_long_tag(self, mock_db_get_inst_tags):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
mock_db_get_inst_tags.return_value = [] mock_db_get_inst_tags.return_value = []
@ -218,7 +218,7 @@ class ServerTagsTest(test.TestCase):
self.assertRaises(exc.HTTPBadRequest, self.controller.update, self.assertRaises(exc.HTTPBadRequest, self.controller.update,
req, UUID, tag, body=None) 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): def test_update_forbidden_characters(self, mock_db_get_inst_tags):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
mock_db_get_inst_tags.return_value = [] mock_db_get_inst_tags.return_value = []
@ -236,9 +236,9 @@ class ServerTagsTest(test.TestCase):
self.assertRaises(exc.HTTPConflict, self.controller.update, req, UUID, self.assertRaises(exc.HTTPConflict, self.controller.update, req, UUID,
TAG1, body=None) 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.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, def test_delete(self, mock_db_delete_inst_tags, mock_notify,
mock_db_get_inst_tags): mock_db_get_inst_tags):
self.stub_out('nova.api.openstack.common.get_instance', return_server) 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) mock_db_get_inst_tags.assert_called_once_with(mock.ANY, UUID)
self.assertEqual(1, mock_notify.call_count) 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): def test_delete_non_existing_tag(self, mock_db_delete_inst_tags):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
@ -273,7 +273,7 @@ class ServerTagsTest(test.TestCase):
TAG1) TAG1)
@mock.patch('nova.notifications.base.send_instance_update_notification') @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): def test_delete_all(self, mock_db_delete_inst_tags, mock_notify):
self.stub_out('nova.api.openstack.common.get_instance', return_server) self.stub_out('nova.api.openstack.common.get_instance', return_server)
req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'DELETE') req = self._get_request('/v2/fake/servers/%s/tags' % UUID, 'DELETE')

View File

@ -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', fake_compute_get)
self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all) self.stub_out('nova.compute.api.API.get_all', fake_compute_get_all)
return_server = fakes.fake_instance_get() 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): def _make_request(self, url):
req = fakes.HTTPRequest.blank(url) req = fakes.HTTPRequest.blank(url)

View File

@ -159,7 +159,7 @@ class ControllerTest(test.TestCase):
compute_api.API, 'get_all', side_effect=return_servers)).mock compute_api.API, 'get_all', side_effect=return_servers)).mock
self.mock_get = self.useFixture(fixtures.MockPatchObject( self.mock_get = self.useFixture(fixtures.MockPatchObject(
compute_api.API, 'get', side_effect=return_server)).mock 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) instance_update_and_get_original)
self.flags(group='glance', api_servers=['http://localhost:9292']) self.flags(group='glance', api_servers=['http://localhost:9292'])
@ -1796,7 +1796,7 @@ class ServersControllerDeleteTest(ControllerTest):
self.server_delete_called = True self.server_delete_called = True
deleted_at = timeutils.utcnow() deleted_at = timeutils.utcnow()
return fake_instance.fake_db_instance(deleted_at=deleted_at) 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) self.controller.delete(req, FAKE_UUID)
# delete() should be called for instance which has never been active, # 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) self.controller._stop_server, req, FAKE_UUID, body)
@mock.patch( @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): def test_start_with_bogus_id(self):
req = fakes.HTTPRequestV21.blank('/fake/servers/test_inst/action') req = fakes.HTTPRequestV21.blank('/fake/servers/test_inst/action')
body = dict(start="") body = dict(start="")
@ -2116,7 +2117,8 @@ class ServersControllerRebuildInstanceTest(ControllerTest):
self.controller._start_server, req, 'test_inst', body) self.controller._start_server, req, 'test_inst', body)
@mock.patch( @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): def test_stop_with_bogus_id(self):
req = fakes.HTTPRequestV21.blank('/fake/servers/test_inst/action') req = fakes.HTTPRequestV21.blank('/fake/servers/test_inst/action')
body = dict(stop="") body = dict(stop="")
@ -2183,7 +2185,7 @@ class ServersControllerRebuildTestV254(ServersControllerRebuildInstanceTest):
def test_rebuild_user_has_no_key_pair(self): def test_rebuild_user_has_no_key_pair(self):
def no_key_pair(context, user_id, name): def no_key_pair(context, user_id, name):
raise exception.KeypairNotFound(user_id=user_id, name=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, fake_get = fakes.fake_compute_get(vm_state=vm_states.ACTIVE,
key_name=None, key_name=None,
project_id=self.req_project_id, project_id=self.req_project_id,
@ -2325,7 +2327,7 @@ class ServersControllerRebuildTestV257(ServersControllerRebuildTestV254):
self.assertIn('user_data', six.text_type(ex)) self.assertIn('user_data', six.text_type(ex))
@mock.patch.object(context.RequestContext, 'can') @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): def test_rebuild_reset_user_data(self, mock_update, mock_policy):
"""Tests that passing user_data=None resets the user_data on the """Tests that passing user_data=None resets the user_data on the
instance. instance.
@ -2638,7 +2640,7 @@ class ServersControllerUpdateTest(ControllerTest):
req, FAKE_UUID, body=body) req, FAKE_UUID, body=body)
def test_update_server_name_all_blank_spaces(self): 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')) fakes.fake_instance_get(name='server_test'))
req = fakes.HTTPRequest.blank('/fake/servers/%s' % FAKE_UUID) req = fakes.HTTPRequest.blank('/fake/servers/%s' % FAKE_UUID)
req.method = 'PUT' req.method = 'PUT'
@ -2654,7 +2656,7 @@ class ServersControllerUpdateTest(ControllerTest):
self.controller.update(req, FAKE_UUID, body=body) self.controller.update(req, FAKE_UUID, body=body)
def test_update_server_name_with_leading_trailing_spaces(self): 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')) fakes.fake_instance_get(name='server_test'))
req = fakes.HTTPRequest.blank('/fake/servers/%s' % FAKE_UUID) req = fakes.HTTPRequest.blank('/fake/servers/%s' % FAKE_UUID)
req.method = 'PUT' req.method = 'PUT'
@ -2872,7 +2874,7 @@ class ServerStatusTest(test.TestCase):
self.controller = servers.ServersController() self.controller = servers.ServersController()
def _get_with_state(self, vm_state, task_state=None): 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, fakes.fake_instance_get(vm_state=vm_state,
task_state=task_state)) task_state=task_state))
@ -3014,14 +3016,14 @@ class ServersControllerCreateTest(test.TestCase):
fakes.stub_out_key_pair_funcs(self) fakes.stub_out_key_pair_funcs(self)
fake.stub_out_image_service(self) fake.stub_out_image_service(self)
self.stub_out('uuid.uuid4', lambda: FAKE_UUID) 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')) lambda c, u: dict(id='1', host='localhost'))
self.stub_out('nova.db.instance_create', instance_create) self.stub_out('nova.db.api.instance_create', instance_create)
self.stub_out('nova.db.instance_system_metadata_update', self.stub_out('nova.db.api.instance_system_metadata_update',
lambda *a, **kw: None) lambda *a, **kw: None)
self.stub_out('nova.db.instance_get', instance_get) self.stub_out('nova.db.api.instance_get', instance_get)
self.stub_out('nova.db.instance_update', instance_update) self.stub_out('nova.db.api.instance_update', instance_update)
self.stub_out('nova.db.instance_update_and_get_original', self.stub_out('nova.db.api.instance_update_and_get_original',
server_update_and_get_original) server_update_and_get_original)
self.stub_out('nova.network.manager.VlanManager.allocate_fixed_ip', self.stub_out('nova.network.manager.VlanManager.allocate_fixed_ip',
lambda *a, **kw: None) lambda *a, **kw: None)
@ -3209,7 +3211,7 @@ class ServersControllerCreateTest(test.TestCase):
# self.assertEqual(kwargs['key_name'], key_name) # self.assertEqual(kwargs['key_name'], key_name)
# return old_create(*args, **kwargs) # 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.stubs.Set(compute_api.API, 'create', create)
# self._test_create_extra(params) # self._test_create_extra(params)
# #
@ -3681,7 +3683,7 @@ class ServersControllerCreateTest(test.TestCase):
return fakes.stub_instance(1) return fakes.stub_instance(1)
mock_limit_check.side_effect = fake_limit_check 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.body['os:scheduler_hints'] = {'group': fake_group.uuid}
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
expected_msg = "Quota exceeded, too many servers in group" expected_msg = "Quota exceeded, too many servers in group"
@ -3704,7 +3706,7 @@ class ServersControllerCreateTest(test.TestCase):
def fake_instance_destroy(context, uuid, constraint): def fake_instance_destroy(context, uuid, constraint):
return fakes.stub_instance(1) 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.body['os:scheduler_hints'] = {'group': test_group.uuid}
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)
server = self.controller.create(self.req, body=self.body).obj['server'] 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): def fake_instance_destroy(context, uuid, constraint):
return fakes.stub_instance(1) 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'] = { self.body['os:scheduler_hints'] = {
'group': '5b674f73-c8cf-40ef-9965-3b6fe4b304b1'} 'group': '5b674f73-c8cf-40ef-9965-3b6fe4b304b1'}
self.req.body = jsonutils.dump_as_bytes(self.body) self.req.body = jsonutils.dump_as_bytes(self.body)

View File

@ -191,9 +191,9 @@ class ServicesTestV21(test.TestCase):
mock.Mock(side_effect=fake_service_get_all(fake_services_list))) mock.Mock(side_effect=fake_service_get_all(fake_services_list)))
self.useFixture(utils_fixture.TimeFixture(fake_utcnow())) 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)) 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)) fake_db_service_update(fake_services_list))
self.req = fakes.HTTPRequest.blank('') self.req = fakes.HTTPRequest.blank('')
@ -585,7 +585,7 @@ class ServicesTestV21(test.TestCase):
self.assertIsNone(values['disabled_reason']) self.assertIsNone(values['disabled_reason'])
return dict(test_service.fake_service, id=service_id, **values) 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'} body = {'host': 'host1', 'binary': 'nova-compute'}
res_dict = self.controller.update(self.req, "enable", body=body) res_dict = self.controller.update(self.req, "enable", body=body)

View File

@ -99,10 +99,10 @@ def stub_out_key_pair_funcs(testcase, have_key_pair=True, **kwargs):
return [] return []
if have_key_pair: if have_key_pair:
testcase.stub_out('nova.db.key_pair_get_all_by_user', key_pair) testcase.stub_out('nova.db.api.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', one_key_pair)
else: 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): def stub_out_trusted_certs(test, certs=None):

View File

@ -21,7 +21,7 @@ from nova.cells import manager as cells_manager
from nova.cells import state as cells_state from nova.cells import state as cells_state
from nova.cells import utils as cells_utils from nova.cells import utils as cells_utils
import nova.conf import nova.conf
import nova.db import nova.db.api
from nova.db import base from nova.db import base
from nova import exception from nova import exception
from nova import objects from nova import objects
@ -52,7 +52,7 @@ class FakeDBApi(object):
self.cell_db_entries = cell_db_entries self.cell_db_entries = cell_db_entries
def __getattr__(self, key): def __getattr__(self, key):
return getattr(nova.db, key) return getattr(nova.db.api, key)
def cell_get_all(self, ctxt): def cell_get_all(self, ctxt):
return self.cell_db_entries return self.cell_db_entries

View File

@ -30,7 +30,7 @@ from nova.compute import instance_actions
from nova.compute import task_states from nova.compute import task_states
from nova.compute import vm_states from nova.compute import vm_states
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import objects from nova import objects
from nova.objects import base as objects_base from nova.objects import base as objects_base

View File

@ -25,7 +25,7 @@ from nova.cells import filters
from nova.cells import weights from nova.cells import weights
from nova.compute import vm_states from nova.compute import vm_states
from nova import context from nova import context
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import objects from nova import objects
from nova import test from nova import test

View File

@ -132,7 +132,7 @@ class TestCellsStateManager(test.NoDBTestCase):
_fake_service_get_all_by_binary) _fake_service_get_all_by_binary)
self.stub_out('nova.objects.FlavorList.get_all', self.stub_out('nova.objects.FlavorList.get_all',
_fake_instance_type_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): def test_cells_config_not_found(self):
self.flags(cells_config='no_such_file_exists.conf', group='cells') 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) _fake_service_get_all_by_binary_nodedown)
self.stub_out('nova.objects.FlavorList.get_all', self.stub_out('nova.objects.FlavorList.get_all',
_fake_instance_type_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): def test_capacity_no_reserve_nodedown(self):
cap = self._capacity(0.0) cap = self._capacity(0.0)

View File

@ -18,18 +18,18 @@ import mock
from nova.cmd import compute from nova.cmd import compute
from nova.cmd import network from nova.cmd import network
from nova import db from nova.db import api as db
from nova import exception from nova import exception
from nova import test from nova import test
@contextlib.contextmanager @contextlib.contextmanager
def restore_db(): def restore_db():
orig = db.api.IMPL orig = db.IMPL
try: try:
yield yield
finally: finally:
db.api.IMPL = orig db.IMPL = orig
class ComputeMainTest(test.NoDBTestCase): class ComputeMainTest(test.NoDBTestCase):
@ -47,11 +47,11 @@ class ComputeMainTest(test.NoDBTestCase):
with restore_db(): with restore_db():
self._call_main(compute) self._call_main(compute)
self.assertRaises(exception.DBNotAllowed, self.assertRaises(exception.DBNotAllowed,
db.api.instance_get, 1, 2) db.instance_get, 1, 2)
def test_network_main_blocks_db(self): def test_network_main_blocks_db(self):
self.flags(enable=True, group='cells') self.flags(enable=True, group='cells')
with restore_db(): with restore_db():
self._call_main(network) self._call_main(network)
self.assertRaises(exception.DBNotAllowed, self.assertRaises(exception.DBNotAllowed,
db.api.instance_get, 1, 2) db.instance_get, 1, 2)

View File

@ -24,7 +24,7 @@ from six.moves import StringIO
from nova.cmd import policy from nova.cmd import policy
import nova.conf import nova.conf
from nova import context as nova_context 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 exception
from nova.policies import base as base_policies from nova.policies import base as base_policies
from nova.policies import instance_actions as ia_policies from nova.policies import instance_actions as ia_policies

View File

@ -90,7 +90,7 @@ class ClaimTestCase(test.NoDBTestCase):
requests = requests or self.empty_requests 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) return_value=db_numa_topology)
def get_claim(mock_extra_get): def get_claim(mock_extra_get):
return claims.Claim(self.context, instance, _NODENAME, return claims.Claim(self.context, instance, _NODENAME,
@ -410,7 +410,7 @@ class MoveClaimTestCase(ClaimTestCase):
@mock.patch('nova.virt.hardware.numa_get_constraints', @mock.patch('nova.virt.hardware.numa_get_constraints',
return_value=numa_topology) 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) return_value=self.db_numa_topology)
def get_claim(mock_extra_get, mock_numa_get): def get_claim(mock_extra_get, mock_numa_get):
return claims.MoveClaim(self.context, self.instance, _NODENAME, return claims.MoveClaim(self.context, self.instance, _NODENAME,

Some files were not shown because too many files have changed in this diff Show More