db: Unify 'nova.db.api', 'nova.db.sqlalchemy.api'
Merge these, removing an unnecessary layer of abstraction, and place them in the new 'nova.db.main' directory. The resulting change is huge, but it's mainly the result of 's/sqlalchemy import api/main import api/' and 's/nova.db.api/nova.db.main.api/' with some necessary cleanup. We also need to rework how we do the blocking of API calls since we no longer have a 'DBAPI' object that we can monkey patch as we were doing before. This is now done via a global variable that is set by the 'main' function of 'nova.cmd.compute'. The main impact of this change is that it's no longer possible to set '[database] use_db_reconnect' and have all APIs automatically wrapped in a DB retry. Seeing as this behavior is experimental, isn't applied to any of the API DB methods (which don't use oslo.db's 'DBAPI' helper), and is used explicitly in what would appear to be the critical cases (via the explicit 'oslo_db.api.wrap_db_retry' decorator), this doesn't seem like a huge loss. Change-Id: Iad2e4da4546b80a016e477577d23accb2606a6e4 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
84b6179076
commit
100b9dc62c
@ -9,7 +9,6 @@ namespace = oslo.policy
|
|||||||
namespace = oslo.privsep
|
namespace = oslo.privsep
|
||||||
namespace = oslo.service.periodic_task
|
namespace = oslo.service.periodic_task
|
||||||
namespace = oslo.service.service
|
namespace = oslo.service.service
|
||||||
namespace = oslo.db
|
|
||||||
namespace = oslo.middleware
|
namespace = oslo.middleware
|
||||||
namespace = oslo.concurrency
|
namespace = oslo.concurrency
|
||||||
namespace = keystonemiddleware.auth_token
|
namespace = keystonemiddleware.auth_token
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import inspect
|
import inspect
|
||||||
import traceback
|
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
import nova.conf
|
import nova.conf
|
||||||
import nova.db.api
|
import nova.db.main.api
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
|
|
||||||
@ -32,23 +31,6 @@ CONF = nova.conf.CONF
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def block_db_access(service_name):
|
|
||||||
"""Blocks Nova DB access."""
|
|
||||||
|
|
||||||
class NoDB(object):
|
|
||||||
def __getattr__(self, attr):
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
|
||||||
stacktrace = "".join(traceback.format_stack())
|
|
||||||
LOG.error('No db access allowed in %(service_name)s: '
|
|
||||||
'%(stacktrace)s',
|
|
||||||
dict(service_name=service_name, stacktrace=stacktrace))
|
|
||||||
raise exception.DBNotAllowed(binary=service_name)
|
|
||||||
|
|
||||||
nova.db.api.IMPL = NoDB()
|
|
||||||
|
|
||||||
|
|
||||||
def validate_args(fn, *args, **kwargs):
|
def validate_args(fn, *args, **kwargs):
|
||||||
"""Check that the supplied args are sufficient for calling a function.
|
"""Check that the supplied args are sufficient for calling a function.
|
||||||
|
|
||||||
|
@ -25,12 +25,12 @@ from oslo_privsep import priv_context
|
|||||||
from oslo_reports import guru_meditation_report as gmr
|
from oslo_reports import guru_meditation_report as gmr
|
||||||
from oslo_reports import opts as gmr_opts
|
from oslo_reports import opts as gmr_opts
|
||||||
|
|
||||||
from nova.cmd import common as cmd_common
|
|
||||||
from nova.compute import rpcapi as compute_rpcapi
|
from nova.compute import rpcapi as compute_rpcapi
|
||||||
from nova.conductor import rpcapi as conductor_rpcapi
|
from nova.conductor import rpcapi as conductor_rpcapi
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova.conf import remote_debug
|
from nova.conf import remote_debug
|
||||||
from nova import config
|
from nova import config
|
||||||
|
import nova.db.main.api
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import base as objects_base
|
from nova.objects import base as objects_base
|
||||||
from nova import service
|
from nova import service
|
||||||
@ -52,7 +52,8 @@ def main():
|
|||||||
|
|
||||||
gmr.TextGuruMeditation.setup_autorun(version, conf=CONF)
|
gmr.TextGuruMeditation.setup_autorun(version, conf=CONF)
|
||||||
|
|
||||||
cmd_common.block_db_access('nova-compute')
|
# disable database access for this service
|
||||||
|
nova.db.main.api.DISABLE_DB_ACCESS = True
|
||||||
objects_base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI()
|
objects_base.NovaObject.indirection_api = conductor_rpcapi.ConductorAPI()
|
||||||
objects.Service.enable_min_version_cache()
|
objects.Service.enable_min_version_cache()
|
||||||
server = service.Service.create(binary='nova-compute',
|
server = service.Service.create(binary='nova-compute',
|
||||||
|
@ -47,10 +47,9 @@ from nova.compute import api as compute_api
|
|||||||
import nova.conf
|
import nova.conf
|
||||||
from nova import config
|
from nova import config
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db import api as db
|
|
||||||
from nova.db import constants as db_const
|
from nova.db import constants as db_const
|
||||||
|
from nova.db.main 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 import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
from nova.network import constants
|
from nova.network import constants
|
||||||
@ -121,7 +120,7 @@ class DbCommands(object):
|
|||||||
# Added in Pike
|
# Added in Pike
|
||||||
quotas_obj.migrate_quota_classes_to_api_db,
|
quotas_obj.migrate_quota_classes_to_api_db,
|
||||||
# Added in Queens
|
# Added in Queens
|
||||||
sa_db.migration_migrate_to_uuid,
|
db.migration_migrate_to_uuid,
|
||||||
# Added in Queens
|
# Added in Queens
|
||||||
block_device_obj.BlockDeviceMapping.populate_uuids,
|
block_device_obj.BlockDeviceMapping.populate_uuids,
|
||||||
# Added in Rocky
|
# Added in Rocky
|
||||||
@ -461,13 +460,12 @@ Error: %s""") % str(e))
|
|||||||
for cell in cells:
|
for cell in cells:
|
||||||
identity = _('Cell %s') % cell.identity
|
identity = _('Cell %s') % cell.identity
|
||||||
with context.target_cell(admin_ctxt, cell) as cctxt:
|
with context.target_cell(admin_ctxt, cell) as cctxt:
|
||||||
deleted += sa_db.purge_shadow_tables(cctxt,
|
deleted += db.purge_shadow_tables(
|
||||||
before_date,
|
cctxt, before_date, status_fn=status)
|
||||||
status_fn=status)
|
|
||||||
else:
|
else:
|
||||||
identity = _('DB')
|
identity = _('DB')
|
||||||
deleted = sa_db.purge_shadow_tables(admin_ctxt,
|
deleted = db.purge_shadow_tables(
|
||||||
before_date, status_fn=status)
|
admin_ctxt, before_date, status_fn=status)
|
||||||
if deleted:
|
if deleted:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
|
@ -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.db import api as db
|
from nova.db.main 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
|
||||||
|
@ -32,7 +32,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.db.sqlalchemy import api as db_session
|
from nova.db.main import api as db_session
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
from nova.objects import cell_mapping as cell_mapping_obj
|
from nova.objects import cell_mapping as cell_mapping_obj
|
||||||
|
@ -53,8 +53,7 @@ from nova import conductor
|
|||||||
import nova.conf
|
import nova.conf
|
||||||
from nova import context as nova_context
|
from nova import context as nova_context
|
||||||
from nova import crypto
|
from nova import crypto
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db_api
|
||||||
from nova.db.sqlalchemy import api as db_api
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import exception_wrapper
|
from nova import exception_wrapper
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
@ -5083,7 +5082,7 @@ class API:
|
|||||||
|
|
||||||
def get_instance_metadata(self, context, instance):
|
def get_instance_metadata(self, context, instance):
|
||||||
"""Get all metadata associated with an instance."""
|
"""Get all metadata associated with an instance."""
|
||||||
return db.instance_metadata_get(context, instance.uuid)
|
return db_api.instance_metadata_get(context, instance.uuid)
|
||||||
|
|
||||||
@check_instance_lock
|
@check_instance_lock
|
||||||
@check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.PAUSED,
|
@check_instance_state(vm_state=[vm_states.ACTIVE, vm_states.PAUSED,
|
||||||
@ -5963,7 +5962,7 @@ class HostAPI:
|
|||||||
"""Return the task logs within a given range, optionally
|
"""Return the task logs within a given range, optionally
|
||||||
filtering by host and/or state.
|
filtering by host and/or state.
|
||||||
"""
|
"""
|
||||||
return db.task_log_get_all(
|
return db_api.task_log_get_all(
|
||||||
context, task_name, period_beginning, period_ending, host=host,
|
context, task_name, period_beginning, period_ending, host=host,
|
||||||
state=state)
|
state=state)
|
||||||
|
|
||||||
@ -6056,7 +6055,7 @@ class HostAPI:
|
|||||||
if cell.uuid == objects.CellMapping.CELL0_UUID:
|
if cell.uuid == objects.CellMapping.CELL0_UUID:
|
||||||
continue
|
continue
|
||||||
with nova_context.target_cell(context, cell) as cctxt:
|
with nova_context.target_cell(context, cell) as cctxt:
|
||||||
cell_stats.append(db.compute_node_statistics(cctxt))
|
cell_stats.append(db_api.compute_node_statistics(cctxt))
|
||||||
|
|
||||||
if cell_stats:
|
if cell_stats:
|
||||||
keys = cell_stats[0].keys()
|
keys = cell_stats[0].keys()
|
||||||
|
@ -97,7 +97,8 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
|
|||||||
|
|
||||||
for key, value in flavor_attributes.items():
|
for key, value in flavor_attributes.items():
|
||||||
kwargs[key] = utils.validate_integer(
|
kwargs[key] = utils.validate_integer(
|
||||||
kwargs[key], value[0], value[1], db_const.MAX_INT)
|
kwargs[key], value[0], value[1], db_const.MAX_INT,
|
||||||
|
)
|
||||||
|
|
||||||
# rxtx_factor should be a positive float
|
# rxtx_factor should be a positive float
|
||||||
try:
|
try:
|
||||||
|
@ -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.db import api as db
|
from nova.db.main 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
|
||||||
|
@ -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.db import api as db
|
from nova.db.main 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
|
||||||
|
@ -49,16 +49,12 @@ api_db_opts = copy.deepcopy(oslo_db_opts.database_opts)
|
|||||||
|
|
||||||
|
|
||||||
def register_opts(conf):
|
def register_opts(conf):
|
||||||
# TODO(stephenfin): Enable this once we drop use of
|
conf.register_opts(copy.deepcopy(main_db_opts), group=main_db_group)
|
||||||
# 'oslo_db.api.DBAPI.from_config'
|
|
||||||
# conf.register_opts(copy.deepcopy(main_db_opts), group=main_db_group)
|
|
||||||
conf.register_opts(copy.deepcopy(api_db_opts), group=api_db_group)
|
conf.register_opts(copy.deepcopy(api_db_opts), group=api_db_group)
|
||||||
|
|
||||||
|
|
||||||
def list_opts():
|
def list_opts():
|
||||||
return {
|
return {
|
||||||
# TODO(stephenfin): Enable this once we drop use of
|
main_db_group: main_db_opts,
|
||||||
# 'oslo_db.api.DBAPI.from_config'
|
|
||||||
# main_db_group: main_db_opts,
|
|
||||||
api_db_group: api_db_opts,
|
api_db_group: api_db_opts,
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ from oslo_policy import opts as policy_opts
|
|||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova.db.sqlalchemy import api as sqlalchemy_api
|
from nova.db.main import api as db_api
|
||||||
from nova import middleware
|
from nova import middleware
|
||||||
from nova import policy
|
from nova import policy
|
||||||
from nova import rpc
|
from nova import rpc
|
||||||
@ -100,4 +100,4 @@ def parse_args(argv, default_config_files=None, configure_db=True,
|
|||||||
rpc.init(CONF)
|
rpc.init(CONF)
|
||||||
|
|
||||||
if configure_db:
|
if configure_db:
|
||||||
sqlalchemy_api.configure(CONF)
|
db_api.configure(CONF)
|
||||||
|
@ -339,7 +339,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.db import api as db
|
from nova.db.main 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.
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
"""Use nova.db.api instead. In the past this file imported * from there,
|
|
||||||
which led to unwanted imports."""
|
|
1463
nova/db/api.py
1463
nova/db/api.py
File diff suppressed because it is too large
Load Diff
0
nova/db/main/__init__.py
Normal file
0
nova/db/main/__init__.py
Normal file
@ -23,6 +23,7 @@ import datetime
|
|||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
from oslo_db import api as oslo_db_api
|
from oslo_db import api as oslo_db_api
|
||||||
from oslo_db import exception as db_exc
|
from oslo_db import exception as db_exc
|
||||||
@ -47,7 +48,7 @@ from nova.compute import task_states
|
|||||||
from nova.compute import vm_states
|
from nova.compute import vm_states
|
||||||
import nova.conf
|
import nova.conf
|
||||||
import nova.context
|
import nova.context
|
||||||
from nova.db.sqlalchemy import models
|
from nova.db.main import models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
from nova import safe_utils
|
from nova import safe_utils
|
||||||
@ -55,10 +56,10 @@ from nova import safe_utils
|
|||||||
profiler_sqlalchemy = importutils.try_import('osprofiler.sqlalchemy')
|
profiler_sqlalchemy = importutils.try_import('osprofiler.sqlalchemy')
|
||||||
|
|
||||||
CONF = nova.conf.CONF
|
CONF = nova.conf.CONF
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DISABLE_DB_ACCESS = False
|
||||||
|
|
||||||
main_context_manager = enginefacade.transaction_context()
|
main_context_manager = enginefacade.transaction_context()
|
||||||
api_context_manager = enginefacade.transaction_context()
|
api_context_manager = enginefacade.transaction_context()
|
||||||
|
|
||||||
@ -193,6 +194,17 @@ def select_db_reader_mode(f):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def _check_db_access():
|
||||||
|
# disable all database access if required
|
||||||
|
if DISABLE_DB_ACCESS:
|
||||||
|
service_name = 'nova-compute'
|
||||||
|
stacktrace = ''.join(traceback.format_stack())
|
||||||
|
LOG.error(
|
||||||
|
'No DB access allowed in %(service_name)s: %(stacktrace)s',
|
||||||
|
{'service_name': service_name, 'stacktrace': stacktrace})
|
||||||
|
raise exception.DBNotAllowed(binary=service_name)
|
||||||
|
|
||||||
|
|
||||||
def pick_context_manager_writer(f):
|
def pick_context_manager_writer(f):
|
||||||
"""Decorator to use a writer db context manager.
|
"""Decorator to use a writer db context manager.
|
||||||
|
|
||||||
@ -202,6 +214,7 @@ def pick_context_manager_writer(f):
|
|||||||
"""
|
"""
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
def wrapper(context, *args, **kwargs):
|
def wrapper(context, *args, **kwargs):
|
||||||
|
_check_db_access()
|
||||||
ctxt_mgr = get_context_manager(context)
|
ctxt_mgr = get_context_manager(context)
|
||||||
with ctxt_mgr.writer.using(context):
|
with ctxt_mgr.writer.using(context):
|
||||||
return f(context, *args, **kwargs)
|
return f(context, *args, **kwargs)
|
||||||
@ -218,6 +231,7 @@ def pick_context_manager_reader(f):
|
|||||||
"""
|
"""
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
def wrapper(context, *args, **kwargs):
|
def wrapper(context, *args, **kwargs):
|
||||||
|
_check_db_access()
|
||||||
ctxt_mgr = get_context_manager(context)
|
ctxt_mgr = get_context_manager(context)
|
||||||
with ctxt_mgr.reader.using(context):
|
with ctxt_mgr.reader.using(context):
|
||||||
return f(context, *args, **kwargs)
|
return f(context, *args, **kwargs)
|
||||||
@ -234,6 +248,7 @@ def pick_context_manager_reader_allow_async(f):
|
|||||||
"""
|
"""
|
||||||
@functools.wraps(f)
|
@functools.wraps(f)
|
||||||
def wrapper(context, *args, **kwargs):
|
def wrapper(context, *args, **kwargs):
|
||||||
|
_check_db_access()
|
||||||
ctxt_mgr = get_context_manager(context)
|
ctxt_mgr = get_context_manager(context)
|
||||||
with ctxt_mgr.reader.allow_async.using(context):
|
with ctxt_mgr.reader.allow_async.using(context):
|
||||||
return f(context, *args, **kwargs)
|
return f(context, *args, **kwargs)
|
@ -22,7 +22,7 @@ from migrate.versioning.repository import Repository
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
|
|
||||||
from nova.db.sqlalchemy import api as db_session
|
from nova.db.main import api as db_session
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
|
|
||||||
|
@ -184,8 +184,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.db import api"):
|
if logical_line.startswith("from nova.db.main import api"):
|
||||||
yield (0, "N307: nova.db.api import not allowed in nova/virt/*")
|
yield (0, "N307: nova.db.* import not allowed in nova/virt/*")
|
||||||
|
|
||||||
|
|
||||||
@core.flake8ext
|
@core.flake8ext
|
||||||
|
@ -54,7 +54,7 @@ This module provides Manager, a base class for managers.
|
|||||||
from oslo_service import periodic_task
|
from oslo_service import periodic_task
|
||||||
|
|
||||||
import nova.conf
|
import nova.conf
|
||||||
import nova.db.api
|
import nova.db.main.api
|
||||||
from nova import profiler
|
from nova import profiler
|
||||||
from nova import rpc
|
from nova import rpc
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ from oslo_utils import uuidutils
|
|||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
from nova.compute import utils as compute_utils
|
from nova.compute import utils as compute_utils
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
|
@ -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.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
|
||||||
|
@ -19,9 +19,8 @@ from oslo_utils import uuidutils
|
|||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
|
|
||||||
from nova import block_device
|
from nova import block_device
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import models as db_models
|
||||||
from nova.db.sqlalchemy import models as db_models
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
from nova import objects
|
from nova import objects
|
||||||
@ -109,7 +108,7 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def populate_uuids(cls, context, count):
|
def populate_uuids(cls, context, count):
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def get_bdms_no_uuid(context):
|
def get_bdms_no_uuid(context):
|
||||||
return context.session.query(db_models.BlockDeviceMapping).\
|
return context.session.query(db_models.BlockDeviceMapping).\
|
||||||
filter_by(uuid=None).limit(count).all()
|
filter_by(uuid=None).limit(count).all()
|
||||||
@ -145,7 +144,7 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
|
|||||||
# normally a read operation. Forcing everything (transitively)
|
# normally a read operation. Forcing everything (transitively)
|
||||||
# which reads a BDM to be in a write transaction for a narrow
|
# which reads a BDM to be in a write transaction for a narrow
|
||||||
# temporary edge case is undesirable.
|
# temporary edge case is undesirable.
|
||||||
tctxt = db_api.get_context_manager(context).writer.independent
|
tctxt = db.get_context_manager(context).writer.independent
|
||||||
with tctxt.using(context):
|
with tctxt.using(context):
|
||||||
query = context.session.query(db_models.BlockDeviceMapping).\
|
query = context.session.query(db_models.BlockDeviceMapping).\
|
||||||
filter_by(id=bdm_id)
|
filter_by(id=bdm_id)
|
||||||
|
@ -18,7 +18,7 @@ from oslo_serialization import jsonutils
|
|||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
from oslo_versionedobjects import exception as ovoo_exc
|
from oslo_versionedobjects import exception as ovoo_exc
|
||||||
|
|
||||||
from nova.db.sqlalchemy import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
|
@ -18,7 +18,7 @@ from sqlalchemy import sql
|
|||||||
from sqlalchemy.sql import expression
|
from sqlalchemy.sql import expression
|
||||||
|
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
|
@ -19,9 +19,8 @@ import sqlalchemy as sa
|
|||||||
from sqlalchemy import sql
|
from sqlalchemy import sql
|
||||||
|
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as sa_api
|
from nova.db.main import models
|
||||||
from nova.db.sqlalchemy import models
|
|
||||||
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
|
||||||
@ -469,7 +468,7 @@ class ComputeNodeList(base.ObjectListBase, base.NovaObject):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
@db.select_db_reader_mode
|
@db.select_db_reader_mode
|
||||||
def _db_compute_node_get_all_by_uuids(context, compute_uuids):
|
def _db_compute_node_get_all_by_uuids(context, compute_uuids):
|
||||||
db_computes = sa_api.model_query(context, models.ComputeNode).filter(
|
db_computes = db.model_query(context, models.ComputeNode).filter(
|
||||||
models.ComputeNode.uuid.in_(compute_uuids)).all()
|
models.ComputeNode.uuid.in_(compute_uuids)).all()
|
||||||
return db_computes
|
return db_computes
|
||||||
|
|
||||||
@ -509,7 +508,7 @@ def _get_node_empty_ratio(context, max_count):
|
|||||||
)).filter(models.ComputeNode.deleted == 0).limit(max_count).all()
|
)).filter(models.ComputeNode.deleted == 0).limit(max_count).all()
|
||||||
|
|
||||||
|
|
||||||
@sa_api.pick_context_manager_writer
|
@db.pick_context_manager_writer
|
||||||
def migrate_empty_ratio(context, max_count):
|
def migrate_empty_ratio(context, max_count):
|
||||||
cns = _get_node_empty_ratio(context, max_count)
|
cns = _get_node_empty_ratio(context, max_count)
|
||||||
|
|
||||||
|
@ -21,7 +21,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.db import api as db
|
from nova.db.main 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
|
||||||
|
@ -17,7 +17,7 @@ import functools
|
|||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
|
|
||||||
from nova import cache_utils
|
from nova import cache_utils
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
@ -21,8 +21,7 @@ from sqlalchemy import sql
|
|||||||
from sqlalchemy.sql import expression
|
from sqlalchemy.sql import expression
|
||||||
|
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova.db.sqlalchemy.api import require_context
|
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.notifications.objects import base as notification
|
from nova.notifications.objects import base as notification
|
||||||
@ -282,7 +281,7 @@ class Flavor(base.NovaPersistentObject, base.NovaObject,
|
|||||||
return query
|
return query
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@require_context
|
@db_api.require_context
|
||||||
def _flavor_get_from_db(context, id):
|
def _flavor_get_from_db(context, id):
|
||||||
"""Returns a dict describing specific flavor."""
|
"""Returns a dict describing specific flavor."""
|
||||||
result = Flavor._flavor_get_query_from_db(context).\
|
result = Flavor._flavor_get_query_from_db(context).\
|
||||||
@ -293,7 +292,7 @@ class Flavor(base.NovaPersistentObject, base.NovaObject,
|
|||||||
return _dict_with_extra_specs(result)
|
return _dict_with_extra_specs(result)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@require_context
|
@db_api.require_context
|
||||||
def _flavor_get_by_name_from_db(context, name):
|
def _flavor_get_by_name_from_db(context, name):
|
||||||
"""Returns a dict describing specific flavor."""
|
"""Returns a dict describing specific flavor."""
|
||||||
result = Flavor._flavor_get_query_from_db(context).\
|
result = Flavor._flavor_get_query_from_db(context).\
|
||||||
@ -304,7 +303,7 @@ class Flavor(base.NovaPersistentObject, base.NovaObject,
|
|||||||
return _dict_with_extra_specs(result)
|
return _dict_with_extra_specs(result)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@require_context
|
@db_api.require_context
|
||||||
def _flavor_get_by_flavor_id_from_db(context, flavor_id):
|
def _flavor_get_by_flavor_id_from_db(context, flavor_id):
|
||||||
"""Returns a dict describing specific flavor_id."""
|
"""Returns a dict describing specific flavor_id."""
|
||||||
result = Flavor._flavor_get_query_from_db(context).\
|
result = Flavor._flavor_get_query_from_db(context).\
|
||||||
|
@ -14,7 +14,7 @@ from oslo_db import exception as db_exc
|
|||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
|
@ -27,9 +27,8 @@ from sqlalchemy.sql import func
|
|||||||
from nova import availability_zones as avail_zone
|
from nova import availability_zones as avail_zone
|
||||||
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.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import models
|
||||||
from nova.db.sqlalchemy import models
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
from nova.network import model as network_model
|
from nova.network import model as network_model
|
||||||
@ -1254,7 +1253,7 @@ def _make_instance_list(context, inst_list, db_inst_list, expected_attrs):
|
|||||||
return inst_list
|
return inst_list
|
||||||
|
|
||||||
|
|
||||||
@db_api.pick_context_manager_writer
|
@db.pick_context_manager_writer
|
||||||
def populate_missing_availability_zones(context, count):
|
def populate_missing_availability_zones(context, count):
|
||||||
# instances without host have no reasonable AZ to set
|
# instances without host have no reasonable AZ to set
|
||||||
not_empty_host = models.Instance.host != None # noqa E711
|
not_empty_host = models.Instance.host != None # noqa E711
|
||||||
@ -1344,7 +1343,7 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
|
|||||||
expected_attrs)
|
expected_attrs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def _get_uuids_by_host_and_node(context, host, node):
|
def _get_uuids_by_host_and_node(context, host, node):
|
||||||
return context.session.query(
|
return context.session.query(
|
||||||
models.Instance.uuid).filter_by(
|
models.Instance.uuid).filter_by(
|
||||||
@ -1495,7 +1494,7 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
|
|||||||
return db.instance_get_all_uuids_by_hosts(context, hosts)
|
return db.instance_get_all_uuids_by_hosts(context, hosts)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def _get_count_by_vm_state_in_db(context, project_id, user_id, vm_state):
|
def _get_count_by_vm_state_in_db(context, project_id, user_id, vm_state):
|
||||||
return context.session.query(models.Instance.id).\
|
return context.session.query(models.Instance.id).\
|
||||||
filter_by(deleted=0).\
|
filter_by(deleted=0).\
|
||||||
@ -1510,9 +1509,9 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
|
|||||||
vm_state)
|
vm_state)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def _get_counts_in_db(context, project_id, user_id=None):
|
def _get_counts_in_db(context, project_id, user_id=None):
|
||||||
# NOTE(melwitt): Copied from nova/db/sqlalchemy/api.py:
|
# NOTE(melwitt): Copied from nova/db/main/api.py:
|
||||||
# It would be better to have vm_state not be nullable
|
# It would be better to have vm_state not be nullable
|
||||||
# but until then we test it explicitly as a workaround.
|
# but until then we test it explicitly as a workaround.
|
||||||
not_soft_deleted = sa.or_(
|
not_soft_deleted = sa.or_(
|
||||||
@ -1567,7 +1566,7 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
|
|||||||
return cls._get_counts_in_db(context, project_id, user_id=user_id)
|
return cls._get_counts_in_db(context, project_id, user_id=user_id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def _get_count_by_hosts(context, hosts):
|
def _get_count_by_hosts(context, hosts):
|
||||||
return context.session.query(models.Instance).\
|
return context.session.query(models.Instance).\
|
||||||
filter_by(deleted=0).\
|
filter_by(deleted=0).\
|
||||||
|
@ -16,7 +16,7 @@ from oslo_utils import timeutils
|
|||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
|
|
||||||
from nova.compute import utils as compute_utils
|
from nova.compute import utils as compute_utils
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
|
@ -16,7 +16,7 @@ import itertools
|
|||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
|
@ -22,7 +22,7 @@ from oslo_utils import versionutils
|
|||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
from nova.compute import utils as compute_utils
|
from nova.compute import utils as compute_utils
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
@ -20,7 +20,7 @@ from sqlalchemy import sql
|
|||||||
from sqlalchemy.sql import func
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
from nova import context as nova_context
|
from nova import context as nova_context
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
|
@ -17,7 +17,7 @@ import itertools
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
|
@ -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.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
|
||||||
|
@ -17,8 +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.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as db_api
|
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
@ -30,7 +29,7 @@ KEYPAIR_TYPE_X509 = 'x509'
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@db_api.api_context_manager.reader
|
@db.api_context_manager.reader
|
||||||
def _get_from_db(context, user_id, name=None, limit=None, marker=None):
|
def _get_from_db(context, user_id, name=None, limit=None, marker=None):
|
||||||
query = context.session.query(api_models.KeyPair).\
|
query = context.session.query(api_models.KeyPair).\
|
||||||
filter(api_models.KeyPair.user_id == user_id)
|
filter(api_models.KeyPair.user_id == user_id)
|
||||||
@ -55,14 +54,14 @@ def _get_from_db(context, user_id, name=None, limit=None, marker=None):
|
|||||||
return query.all()
|
return query.all()
|
||||||
|
|
||||||
|
|
||||||
@db_api.api_context_manager.reader
|
@db.api_context_manager.reader
|
||||||
def _get_count_from_db(context, user_id):
|
def _get_count_from_db(context, user_id):
|
||||||
return context.session.query(api_models.KeyPair).\
|
return context.session.query(api_models.KeyPair).\
|
||||||
filter(api_models.KeyPair.user_id == user_id).\
|
filter(api_models.KeyPair.user_id == user_id).\
|
||||||
count()
|
count()
|
||||||
|
|
||||||
|
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _create_in_db(context, values):
|
def _create_in_db(context, values):
|
||||||
kp = api_models.KeyPair()
|
kp = api_models.KeyPair()
|
||||||
kp.update(values)
|
kp.update(values)
|
||||||
@ -73,7 +72,7 @@ def _create_in_db(context, values):
|
|||||||
return kp
|
return kp
|
||||||
|
|
||||||
|
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _destroy_in_db(context, user_id, name):
|
def _destroy_in_db(context, user_id, name):
|
||||||
result = context.session.query(api_models.KeyPair).\
|
result = context.session.query(api_models.KeyPair).\
|
||||||
filter_by(user_id=user_id).\
|
filter_by(user_id=user_id).\
|
||||||
|
@ -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.db import api as db
|
from nova.db.main 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
|
||||||
|
@ -16,7 +16,7 @@ from oslo_log import log as logging
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
|
@ -22,9 +22,8 @@ from oslo_serialization import jsonutils
|
|||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import models as db_models
|
||||||
from nova.db.sqlalchemy import models as db_models
|
|
||||||
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
|
||||||
@ -208,7 +207,7 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def populate_dev_uuids(cls, context, count):
|
def populate_dev_uuids(cls, context, count):
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def get_devs_no_uuid(context):
|
def get_devs_no_uuid(context):
|
||||||
return context.session.query(db_models.PciDevice).\
|
return context.session.query(db_models.PciDevice).\
|
||||||
filter_by(uuid=None).limit(count).all()
|
filter_by(uuid=None).limit(count).all()
|
||||||
@ -264,7 +263,7 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject):
|
|||||||
# normally a read operation. Forcing everything (transitively) which
|
# normally a read operation. Forcing everything (transitively) which
|
||||||
# reads a PCI device to be in a write transaction for a narrow
|
# reads a PCI device to be in a write transaction for a narrow
|
||||||
# temporary edge case is undesirable.
|
# temporary edge case is undesirable.
|
||||||
tctxt = db_api.get_context_manager(context).writer.independent
|
tctxt = db.get_context_manager(context).writer.independent
|
||||||
with tctxt.using(context):
|
with tctxt.using(context):
|
||||||
query = context.session.query(db_models.PciDevice).\
|
query = context.session.query(db_models.PciDevice).\
|
||||||
filter_by(id=dev_id)
|
filter_by(id=dev_id)
|
||||||
|
@ -16,10 +16,9 @@ import collections
|
|||||||
|
|
||||||
from oslo_db import exception as db_exc
|
from oslo_db import exception as db_exc
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import models as main_models
|
||||||
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 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
|
||||||
@ -83,7 +82,7 @@ class Quotas(base.NovaObject):
|
|||||||
self.obj_reset_changes(fields=[attr])
|
self.obj_reset_changes(fields=[attr])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.reader
|
@db.api_context_manager.reader
|
||||||
def _get_from_db(context, project_id, resource, user_id=None):
|
def _get_from_db(context, project_id, resource, user_id=None):
|
||||||
model = api_models.ProjectUserQuota if user_id else api_models.Quota
|
model = api_models.ProjectUserQuota if user_id else api_models.Quota
|
||||||
query = context.session.query(model).\
|
query = context.session.query(model).\
|
||||||
@ -101,14 +100,14 @@ class Quotas(base.NovaObject):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.reader
|
@db.api_context_manager.reader
|
||||||
def _get_all_from_db(context, project_id):
|
def _get_all_from_db(context, project_id):
|
||||||
return context.session.query(api_models.ProjectUserQuota).\
|
return context.session.query(api_models.ProjectUserQuota).\
|
||||||
filter_by(project_id=project_id).\
|
filter_by(project_id=project_id).\
|
||||||
all()
|
all()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.reader
|
@db.api_context_manager.reader
|
||||||
def _get_all_from_db_by_project(context, project_id):
|
def _get_all_from_db_by_project(context, project_id):
|
||||||
# by_project refers to the returned dict that has a 'project_id' key
|
# by_project refers to the returned dict that has a 'project_id' key
|
||||||
rows = context.session.query(api_models.Quota).\
|
rows = context.session.query(api_models.Quota).\
|
||||||
@ -120,7 +119,7 @@ class Quotas(base.NovaObject):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.reader
|
@db.api_context_manager.reader
|
||||||
def _get_all_from_db_by_project_and_user(context, project_id, user_id):
|
def _get_all_from_db_by_project_and_user(context, project_id, user_id):
|
||||||
# by_project_and_user refers to the returned dict that has
|
# by_project_and_user refers to the returned dict that has
|
||||||
# 'project_id' and 'user_id' keys
|
# 'project_id' and 'user_id' keys
|
||||||
@ -136,7 +135,7 @@ class Quotas(base.NovaObject):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _destroy_all_in_db_by_project(context, project_id):
|
def _destroy_all_in_db_by_project(context, project_id):
|
||||||
per_project = context.session.query(api_models.Quota).\
|
per_project = context.session.query(api_models.Quota).\
|
||||||
filter_by(project_id=project_id).\
|
filter_by(project_id=project_id).\
|
||||||
@ -148,7 +147,7 @@ class Quotas(base.NovaObject):
|
|||||||
raise exception.ProjectQuotaNotFound(project_id=project_id)
|
raise exception.ProjectQuotaNotFound(project_id=project_id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _destroy_all_in_db_by_project_and_user(context, project_id, user_id):
|
def _destroy_all_in_db_by_project_and_user(context, project_id, user_id):
|
||||||
result = context.session.query(api_models.ProjectUserQuota).\
|
result = context.session.query(api_models.ProjectUserQuota).\
|
||||||
filter_by(project_id=project_id).\
|
filter_by(project_id=project_id).\
|
||||||
@ -159,7 +158,7 @@ class Quotas(base.NovaObject):
|
|||||||
user_id=user_id)
|
user_id=user_id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.reader
|
@db.api_context_manager.reader
|
||||||
def _get_class_from_db(context, class_name, resource):
|
def _get_class_from_db(context, class_name, resource):
|
||||||
result = context.session.query(api_models.QuotaClass).\
|
result = context.session.query(api_models.QuotaClass).\
|
||||||
filter_by(class_name=class_name).\
|
filter_by(class_name=class_name).\
|
||||||
@ -170,7 +169,7 @@ class Quotas(base.NovaObject):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.reader
|
@db.api_context_manager.reader
|
||||||
def _get_all_class_from_db_by_name(context, class_name):
|
def _get_all_class_from_db_by_name(context, class_name):
|
||||||
# by_name refers to the returned dict that has a 'class_name' key
|
# by_name refers to the returned dict that has a 'class_name' key
|
||||||
rows = context.session.query(api_models.QuotaClass).\
|
rows = context.session.query(api_models.QuotaClass).\
|
||||||
@ -182,14 +181,14 @@ class Quotas(base.NovaObject):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _create_limit_in_db(context, project_id, resource, limit,
|
def _create_limit_in_db(context, project_id, resource, limit,
|
||||||
user_id=None):
|
user_id=None):
|
||||||
# TODO(melwitt): We won't have per project resources after nova-network
|
# TODO(melwitt): We won't have per project resources after nova-network
|
||||||
# is removed.
|
# is removed.
|
||||||
# TODO(stephenfin): We need to do something here now...but what?
|
# TODO(stephenfin): We need to do something here now...but what?
|
||||||
per_user = (user_id and
|
per_user = (user_id and
|
||||||
resource not in db_api.quota_get_per_project_resources())
|
resource not in db.quota_get_per_project_resources())
|
||||||
quota_ref = (api_models.ProjectUserQuota() if per_user
|
quota_ref = (api_models.ProjectUserQuota() if per_user
|
||||||
else api_models.Quota())
|
else api_models.Quota())
|
||||||
if per_user:
|
if per_user:
|
||||||
@ -205,14 +204,14 @@ class Quotas(base.NovaObject):
|
|||||||
return quota_ref
|
return quota_ref
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _update_limit_in_db(context, project_id, resource, limit,
|
def _update_limit_in_db(context, project_id, resource, limit,
|
||||||
user_id=None):
|
user_id=None):
|
||||||
# TODO(melwitt): We won't have per project resources after nova-network
|
# TODO(melwitt): We won't have per project resources after nova-network
|
||||||
# is removed.
|
# is removed.
|
||||||
# TODO(stephenfin): We need to do something here now...but what?
|
# TODO(stephenfin): We need to do something here now...but what?
|
||||||
per_user = (user_id and
|
per_user = (user_id and
|
||||||
resource not in db_api.quota_get_per_project_resources())
|
resource not in db.quota_get_per_project_resources())
|
||||||
model = api_models.ProjectUserQuota if per_user else api_models.Quota
|
model = api_models.ProjectUserQuota if per_user else api_models.Quota
|
||||||
query = context.session.query(model).\
|
query = context.session.query(model).\
|
||||||
filter_by(project_id=project_id).\
|
filter_by(project_id=project_id).\
|
||||||
@ -229,7 +228,7 @@ class Quotas(base.NovaObject):
|
|||||||
raise exception.ProjectQuotaNotFound(project_id=project_id)
|
raise exception.ProjectQuotaNotFound(project_id=project_id)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _create_class_in_db(context, class_name, resource, limit):
|
def _create_class_in_db(context, class_name, resource, limit):
|
||||||
# NOTE(melwitt): There's no unique constraint on the QuotaClass model,
|
# NOTE(melwitt): There's no unique constraint on the QuotaClass model,
|
||||||
# so check for duplicate manually.
|
# so check for duplicate manually.
|
||||||
@ -248,7 +247,7 @@ class Quotas(base.NovaObject):
|
|||||||
return quota_class_ref
|
return quota_class_ref
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _update_class_in_db(context, class_name, resource, limit):
|
def _update_class_in_db(context, class_name, resource, limit):
|
||||||
result = context.session.query(api_models.QuotaClass).\
|
result = context.session.query(api_models.QuotaClass).\
|
||||||
filter_by(class_name=class_name).\
|
filter_by(class_name=class_name).\
|
||||||
@ -467,7 +466,7 @@ class Quotas(base.NovaObject):
|
|||||||
def get_default_class(cls, context):
|
def get_default_class(cls, context):
|
||||||
try:
|
try:
|
||||||
qclass = cls._get_all_class_from_db_by_name(
|
qclass = cls._get_all_class_from_db_by_name(
|
||||||
context, db_api._DEFAULT_QUOTA_NAME)
|
context, db._DEFAULT_QUOTA_NAME)
|
||||||
except exception.QuotaClassNotFound:
|
except exception.QuotaClassNotFound:
|
||||||
qclass = db.quota_class_get_default(context)
|
qclass = db.quota_class_get_default(context)
|
||||||
return qclass
|
return qclass
|
||||||
@ -502,8 +501,8 @@ class QuotasNoOp(Quotas):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@db_api.require_context
|
@db.require_context
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def _get_main_per_project_limits(context, limit):
|
def _get_main_per_project_limits(context, limit):
|
||||||
return context.session.query(main_models.Quota).\
|
return context.session.query(main_models.Quota).\
|
||||||
filter_by(deleted=0).\
|
filter_by(deleted=0).\
|
||||||
@ -511,8 +510,8 @@ def _get_main_per_project_limits(context, limit):
|
|||||||
all()
|
all()
|
||||||
|
|
||||||
|
|
||||||
@db_api.require_context
|
@db.require_context
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def _get_main_per_user_limits(context, limit):
|
def _get_main_per_user_limits(context, limit):
|
||||||
return context.session.query(main_models.ProjectUserQuota).\
|
return context.session.query(main_models.ProjectUserQuota).\
|
||||||
filter_by(deleted=0).\
|
filter_by(deleted=0).\
|
||||||
@ -520,8 +519,8 @@ def _get_main_per_user_limits(context, limit):
|
|||||||
all()
|
all()
|
||||||
|
|
||||||
|
|
||||||
@db_api.require_context
|
@db.require_context
|
||||||
@db_api.pick_context_manager_writer
|
@db.pick_context_manager_writer
|
||||||
def _destroy_main_per_project_limits(context, project_id, resource):
|
def _destroy_main_per_project_limits(context, project_id, resource):
|
||||||
context.session.query(main_models.Quota).\
|
context.session.query(main_models.Quota).\
|
||||||
filter_by(deleted=0).\
|
filter_by(deleted=0).\
|
||||||
@ -530,8 +529,8 @@ def _destroy_main_per_project_limits(context, project_id, resource):
|
|||||||
soft_delete(synchronize_session=False)
|
soft_delete(synchronize_session=False)
|
||||||
|
|
||||||
|
|
||||||
@db_api.require_context
|
@db.require_context
|
||||||
@db_api.pick_context_manager_writer
|
@db.pick_context_manager_writer
|
||||||
def _destroy_main_per_user_limits(context, project_id, resource, user_id):
|
def _destroy_main_per_user_limits(context, project_id, resource, user_id):
|
||||||
context.session.query(main_models.ProjectUserQuota).\
|
context.session.query(main_models.ProjectUserQuota).\
|
||||||
filter_by(deleted=0).\
|
filter_by(deleted=0).\
|
||||||
@ -541,7 +540,7 @@ def _destroy_main_per_user_limits(context, project_id, resource, user_id):
|
|||||||
soft_delete(synchronize_session=False)
|
soft_delete(synchronize_session=False)
|
||||||
|
|
||||||
|
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _create_limits_in_api_db(context, db_limits, per_user=False):
|
def _create_limits_in_api_db(context, db_limits, per_user=False):
|
||||||
for db_limit in db_limits:
|
for db_limit in db_limits:
|
||||||
user_id = db_limit.user_id if per_user else None
|
user_id = db_limit.user_id if per_user else None
|
||||||
@ -588,8 +587,8 @@ def migrate_quota_limits_to_api_db(context, count):
|
|||||||
return len(main_per_project_limits) + len(main_per_user_limits), done
|
return len(main_per_project_limits) + len(main_per_user_limits), done
|
||||||
|
|
||||||
|
|
||||||
@db_api.require_context
|
@db.require_context
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def _get_main_quota_classes(context, limit):
|
def _get_main_quota_classes(context, limit):
|
||||||
return context.session.query(main_models.QuotaClass).\
|
return context.session.query(main_models.QuotaClass).\
|
||||||
filter_by(deleted=0).\
|
filter_by(deleted=0).\
|
||||||
@ -597,7 +596,7 @@ def _get_main_quota_classes(context, limit):
|
|||||||
all()
|
all()
|
||||||
|
|
||||||
|
|
||||||
@db_api.pick_context_manager_writer
|
@db.pick_context_manager_writer
|
||||||
def _destroy_main_quota_classes(context, db_classes):
|
def _destroy_main_quota_classes(context, db_classes):
|
||||||
for db_class in db_classes:
|
for db_class in db_classes:
|
||||||
context.session.query(main_models.QuotaClass).\
|
context.session.query(main_models.QuotaClass).\
|
||||||
@ -606,7 +605,7 @@ def _destroy_main_quota_classes(context, db_classes):
|
|||||||
soft_delete(synchronize_session=False)
|
soft_delete(synchronize_session=False)
|
||||||
|
|
||||||
|
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def _create_classes_in_api_db(context, db_classes):
|
def _create_classes_in_api_db(context, db_classes):
|
||||||
for db_class in db_classes:
|
for db_class in db_classes:
|
||||||
Quotas._create_class_in_db(context, db_class.class_name,
|
Quotas._create_class_in_db(context, db_class.class_name,
|
||||||
|
@ -20,7 +20,7 @@ from oslo_log import log as logging
|
|||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
|
|
||||||
from nova.db.sqlalchemy import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
|
||||||
|
@ -18,9 +18,8 @@
|
|||||||
from oslo_utils import uuidutils
|
from oslo_utils import uuidutils
|
||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import models
|
||||||
from nova.db.sqlalchemy import models
|
|
||||||
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
|
||||||
@ -115,7 +114,7 @@ class SecurityGroupList(base.ObjectListBase, base.NovaObject):
|
|||||||
self.obj_reset_changes()
|
self.obj_reset_changes()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def _get_counts_from_db(context, project_id, user_id=None):
|
def _get_counts_from_db(context, project_id, user_id=None):
|
||||||
query = context.session.query(models.SecurityGroup.id).\
|
query = context.session.query(models.SecurityGroup.id).\
|
||||||
filter_by(deleted=0).\
|
filter_by(deleted=0).\
|
||||||
|
@ -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.db import api as db
|
from nova.db.main 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
|
||||||
|
@ -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.db import api as db
|
from nova.db.main 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
|
||||||
|
@ -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.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
|
||||||
|
@ -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.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
|
||||||
|
@ -16,9 +16,8 @@ from oslo_log import log as logging
|
|||||||
from oslo_utils import versionutils
|
from oslo_utils import versionutils
|
||||||
|
|
||||||
from nova import context as nova_context
|
from nova import context as nova_context
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import models
|
||||||
from nova.db.sqlalchemy import models
|
|
||||||
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
|
||||||
@ -150,7 +149,7 @@ class VirtualInterfaceList(base.ObjectListBase, base.NovaObject):
|
|||||||
objects.VirtualInterface, db_vifs)
|
objects.VirtualInterface, db_vifs)
|
||||||
|
|
||||||
|
|
||||||
@db_api.api_context_manager.writer
|
@db.api_context_manager.writer
|
||||||
def fill_virtual_interface_list(context, max_count):
|
def fill_virtual_interface_list(context, max_count):
|
||||||
"""This fills missing VirtualInterface Objects in Nova DB"""
|
"""This fills missing VirtualInterface Objects in Nova DB"""
|
||||||
count_hit = 0
|
count_hit = 0
|
||||||
@ -288,7 +287,7 @@ def fill_virtual_interface_list(context, max_count):
|
|||||||
# we checked.
|
# we checked.
|
||||||
# Please notice that because of virtual_interfaces_instance_uuid_fkey
|
# Please notice that because of virtual_interfaces_instance_uuid_fkey
|
||||||
# we need to have FAKE_UUID instance object, even deleted one.
|
# we need to have FAKE_UUID instance object, even deleted one.
|
||||||
@db_api.pick_context_manager_writer
|
@db.pick_context_manager_writer
|
||||||
def _set_or_delete_marker_for_migrate_instances(context, marker=None):
|
def _set_or_delete_marker_for_migrate_instances(context, marker=None):
|
||||||
context.session.query(models.VirtualInterface).filter_by(
|
context.session.query(models.VirtualInterface).filter_by(
|
||||||
instance_uuid=FAKE_UUID).delete()
|
instance_uuid=FAKE_UUID).delete()
|
||||||
@ -317,7 +316,7 @@ def _set_or_delete_marker_for_migrate_instances(context, marker=None):
|
|||||||
db_mapping.create()
|
db_mapping.create()
|
||||||
|
|
||||||
|
|
||||||
@db_api.pick_context_manager_reader
|
@db.pick_context_manager_reader
|
||||||
def _get_marker_for_migrate_instances(context):
|
def _get_marker_for_migrate_instances(context):
|
||||||
vif = (context.session.query(models.VirtualInterface).filter_by(
|
vif = (context.session.query(models.VirtualInterface).filter_by(
|
||||||
instance_uuid=FAKE_UUID)).first()
|
instance_uuid=FAKE_UUID)).first()
|
||||||
|
@ -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.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
from nova.objects import fields
|
from nova.objects import fields
|
||||||
|
|
||||||
|
@ -24,8 +24,7 @@ from sqlalchemy import sql
|
|||||||
|
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova import context as nova_context
|
from nova import context as nova_context
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as db_api
|
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
@ -1046,7 +1045,7 @@ class QuotaEngine(object):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
@db_api.api_context_manager.reader
|
@db.api_context_manager.reader
|
||||||
def _user_id_queued_for_delete_populated(context, project_id=None):
|
def _user_id_queued_for_delete_populated(context, project_id=None):
|
||||||
"""Determine whether user_id and queued_for_delete are set.
|
"""Determine whether user_id and queued_for_delete are set.
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ import testtools
|
|||||||
from nova.api.openstack import wsgi_app
|
from nova.api.openstack import wsgi_app
|
||||||
from nova.compute import rpcapi as compute_rpcapi
|
from nova.compute import rpcapi as compute_rpcapi
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db.sqlalchemy import api as sqlalchemy_api
|
from nova.db.main import api as db_api
|
||||||
from nova import exception
|
from nova import 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
|
||||||
@ -382,7 +382,7 @@ class TestCase(base.BaseTestCase):
|
|||||||
|
|
||||||
def enforce_fk_constraints(self, engine=None):
|
def enforce_fk_constraints(self, engine=None):
|
||||||
if engine is None:
|
if engine is None:
|
||||||
engine = sqlalchemy_api.get_engine()
|
engine = db_api.get_engine()
|
||||||
dialect = engine.url.get_dialect()
|
dialect = engine.url.get_dialect()
|
||||||
if dialect == sqlite.dialect:
|
if dialect == sqlite.dialect:
|
||||||
engine.connect().execute("PRAGMA foreign_keys = ON")
|
engine.connect().execute("PRAGMA foreign_keys = ON")
|
||||||
|
11
nova/tests/fixtures/nova.py
vendored
11
nova/tests/fixtures/nova.py
vendored
@ -43,8 +43,8 @@ from nova.api import wsgi
|
|||||||
from nova.compute import multi_cell_list
|
from nova.compute import multi_cell_list
|
||||||
from nova.compute import rpcapi as compute_rpcapi
|
from nova.compute import rpcapi as compute_rpcapi
|
||||||
from nova import context
|
from nova import context
|
||||||
|
from nova.db.main import api as session
|
||||||
from nova.db import migration
|
from nova.db import migration
|
||||||
from nova.db.sqlalchemy import api as session
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import base as obj_base
|
from nova.objects import base as obj_base
|
||||||
@ -554,8 +554,9 @@ class CellDatabases(fixtures.Fixture):
|
|||||||
# a new database created with the schema we need and the
|
# a new database created with the schema we need and the
|
||||||
# context manager for it stashed.
|
# context manager for it stashed.
|
||||||
with fixtures.MonkeyPatch(
|
with fixtures.MonkeyPatch(
|
||||||
'nova.db.sqlalchemy.api.get_context_manager',
|
'nova.db.main.api.get_context_manager',
|
||||||
get_context_manager):
|
get_context_manager,
|
||||||
|
):
|
||||||
engine = ctxt_mgr.writer.get_engine()
|
engine = ctxt_mgr.writer.get_engine()
|
||||||
engine.dispose()
|
engine.dispose()
|
||||||
self._cache_schema(connection_str)
|
self._cache_schema(connection_str)
|
||||||
@ -571,10 +572,10 @@ class CellDatabases(fixtures.Fixture):
|
|||||||
# duration of the test (unlike the temporary ones above) and
|
# duration of the test (unlike the temporary ones above) and
|
||||||
# provide the actual "runtime" switching of connections for us.
|
# provide the actual "runtime" switching of connections for us.
|
||||||
self.useFixture(fixtures.MonkeyPatch(
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
'nova.db.sqlalchemy.api.create_context_manager',
|
'nova.db.main.api.create_context_manager',
|
||||||
self._wrap_create_context_manager))
|
self._wrap_create_context_manager))
|
||||||
self.useFixture(fixtures.MonkeyPatch(
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
'nova.db.sqlalchemy.api.get_context_manager',
|
'nova.db.main.api.get_context_manager',
|
||||||
self._wrap_get_context_manager))
|
self._wrap_get_context_manager))
|
||||||
self.useFixture(fixtures.MonkeyPatch(
|
self.useFixture(fixtures.MonkeyPatch(
|
||||||
'nova.context.target_cell',
|
'nova.context.target_cell',
|
||||||
|
@ -71,7 +71,7 @@ class MigrateServerSamplesJsonTest(test_servers.ServersSampleBase):
|
|||||||
'nova.conductor.manager.ComputeTaskManager._live_migrate',
|
'nova.conductor.manager.ComputeTaskManager._live_migrate',
|
||||||
fake_live_migrate)
|
fake_live_migrate)
|
||||||
self.stub_out(
|
self.stub_out(
|
||||||
'nova.db.api.service_get_by_compute_host',
|
'nova.db.main.api.service_get_by_compute_host',
|
||||||
fake_get_compute)
|
fake_get_compute)
|
||||||
|
|
||||||
response = self._do_post('servers/%s/action' % self.uuid,
|
response = self._do_post('servers/%s/action' % self.uuid,
|
||||||
@ -218,7 +218,7 @@ class MigrateServerSamplesJsonTestV268(test_servers.ServersSampleBase):
|
|||||||
'nova.conductor.manager.ComputeTaskManager._live_migrate',
|
'nova.conductor.manager.ComputeTaskManager._live_migrate',
|
||||||
fake_live_migrate)
|
fake_live_migrate)
|
||||||
self.stub_out(
|
self.stub_out(
|
||||||
'nova.db.api.service_get_by_compute_host',
|
'nova.db.main.api.service_get_by_compute_host',
|
||||||
fake_get_compute)
|
fake_get_compute)
|
||||||
|
|
||||||
response = self._do_post('servers/%s/action' % self.uuid,
|
response = self._do_post('servers/%s/action' % self.uuid,
|
||||||
|
@ -20,7 +20,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.db import api as db
|
from nova.db.main 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
|
||||||
|
@ -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.db.sqlalchemy import models
|
from nova.db.main import models
|
||||||
from nova.tests.functional.api_sample_tests import test_servers
|
from nova.tests.functional.api_sample_tests import test_servers
|
||||||
|
|
||||||
TAG1 = 'tag1'
|
TAG1 = 'tag1'
|
||||||
|
@ -116,7 +116,7 @@ class ServersSampleJsonTest(ServersSampleBase):
|
|||||||
|
|
||||||
def test_servers_get(self):
|
def test_servers_get(self):
|
||||||
self.stub_out(
|
self.stub_out(
|
||||||
'nova.db.api.block_device_mapping_get_all_by_instance_uuids',
|
'nova.db.main.api.block_device_mapping_get_all_by_instance_uuids',
|
||||||
fakes.stub_bdm_get_all_by_instance_uuids)
|
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)
|
||||||
@ -142,7 +142,7 @@ class ServersSampleJsonTest(ServersSampleBase):
|
|||||||
|
|
||||||
def test_servers_details(self):
|
def test_servers_details(self):
|
||||||
self.stub_out(
|
self.stub_out(
|
||||||
'nova.db.api.block_device_mapping_get_all_by_instance_uuids',
|
'nova.db.main.api.block_device_mapping_get_all_by_instance_uuids',
|
||||||
fakes.stub_bdm_get_all_by_instance_uuids)
|
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')
|
||||||
|
@ -31,11 +31,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.api.service_get_all",
|
self.stub_out("nova.db.main.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.api.service_get_by_host_and_binary",
|
self.stub_out("nova.db.main.api.service_get_by_host_and_binary",
|
||||||
test_services.fake_service_get_by_host_binary)
|
test_services.fake_service_get_by_host_binary)
|
||||||
self.stub_out("nova.db.api.service_update",
|
self.stub_out("nova.db.main.api.service_update",
|
||||||
test_services.fake_service_update)
|
test_services.fake_service_update)
|
||||||
# If we are not using real services, we need to stub out
|
# If we are not using real services, we need to stub out
|
||||||
# HostAPI._update_compute_provider_status so we don't actually
|
# HostAPI._update_compute_provider_status so we don't actually
|
||||||
@ -154,9 +154,9 @@ class ServicesV253JsonTest(ServicesV211JsonTest):
|
|||||||
def fake_get_provider_uuids_in_tree(context, compute_node_id):
|
def fake_get_provider_uuids_in_tree(context, compute_node_id):
|
||||||
return [compute_node_id]
|
return [compute_node_id]
|
||||||
|
|
||||||
self.stub_out('nova.db.api.service_get_by_uuid',
|
self.stub_out('nova.db.main.api.service_get_by_uuid',
|
||||||
db_service_get_by_uuid)
|
db_service_get_by_uuid)
|
||||||
self.stub_out('nova.db.api.compute_node_get_all_by_host',
|
self.stub_out('nova.db.main.api.compute_node_get_all_by_host',
|
||||||
fake_cn_get_all_by_host)
|
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',
|
||||||
|
@ -16,7 +16,7 @@ from oslo_utils.fixture import uuidsentinel as uuids
|
|||||||
|
|
||||||
from nova.compute import instance_list
|
from nova.compute import instance_list
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova import test
|
from nova import test
|
||||||
|
@ -18,7 +18,7 @@ from oslo_utils.fixture import uuidsentinel
|
|||||||
from oslo_utils import timeutils
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
import nova.objects.aggregate as aggregate_obj
|
import nova.objects.aggregate as aggregate_obj
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
# 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.db.main import models
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova.db.sqlalchemy import models
|
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,8 +22,7 @@ import sqlalchemy as sa
|
|||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import api as sqlalchemy_api
|
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.tests.functional import integrated_helpers
|
from nova.tests.functional import integrated_helpers
|
||||||
from nova import utils as nova_utils
|
from nova import utils as nova_utils
|
||||||
@ -176,11 +175,11 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase):
|
|||||||
self.assertFalse(exceptions)
|
self.assertFalse(exceptions)
|
||||||
|
|
||||||
def _get_table_counts(self):
|
def _get_table_counts(self):
|
||||||
engine = sqlalchemy_api.get_engine()
|
engine = db.get_engine()
|
||||||
conn = engine.connect()
|
conn = engine.connect()
|
||||||
meta = sa.MetaData(engine)
|
meta = sa.MetaData(engine)
|
||||||
meta.reflect()
|
meta.reflect()
|
||||||
shadow_tables = sqlalchemy_api._purgeable_tables(meta)
|
shadow_tables = db._purgeable_tables(meta)
|
||||||
results = {}
|
results = {}
|
||||||
for table in shadow_tables:
|
for table in shadow_tables:
|
||||||
r = conn.execute(
|
r = conn.execute(
|
||||||
@ -222,8 +221,7 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase):
|
|||||||
def status(msg):
|
def status(msg):
|
||||||
lines.append(msg)
|
lines.append(msg)
|
||||||
|
|
||||||
deleted = sqlalchemy_api.purge_shadow_tables(admin_context,
|
deleted = db.purge_shadow_tables(admin_context, None, status_fn=status)
|
||||||
None, status_fn=status)
|
|
||||||
self.assertNotEqual(0, deleted)
|
self.assertNotEqual(0, deleted)
|
||||||
self.assertNotEqual(0, len(lines))
|
self.assertNotEqual(0, len(lines))
|
||||||
self.assertEqual(sum(results.values()), archived)
|
self.assertEqual(sum(results.values()), archived)
|
||||||
@ -277,8 +275,7 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase):
|
|||||||
# Make sure we didn't delete anything if the marker is before
|
# Make sure we didn't delete anything if the marker is before
|
||||||
# we started
|
# we started
|
||||||
past = timeutils.utcnow() - datetime.timedelta(days=31)
|
past = timeutils.utcnow() - datetime.timedelta(days=31)
|
||||||
deleted = sqlalchemy_api.purge_shadow_tables(admin_context,
|
deleted = db.purge_shadow_tables(admin_context, past)
|
||||||
past)
|
|
||||||
self.assertEqual(0, deleted)
|
self.assertEqual(0, deleted)
|
||||||
|
|
||||||
# Nothing should be changed if we didn't purge anything
|
# Nothing should be changed if we didn't purge anything
|
||||||
@ -288,7 +285,7 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase):
|
|||||||
# Make sure we deleted things when the marker is after
|
# Make sure we deleted things when the marker is after
|
||||||
# we started
|
# we started
|
||||||
future = timeutils.utcnow() + datetime.timedelta(hours=1)
|
future = timeutils.utcnow() + datetime.timedelta(hours=1)
|
||||||
deleted = sqlalchemy_api.purge_shadow_tables(admin_context, future)
|
deleted = db.purge_shadow_tables(admin_context, future)
|
||||||
self.assertNotEqual(0, deleted)
|
self.assertNotEqual(0, deleted)
|
||||||
|
|
||||||
# There should be no rows in any table if we purged everything
|
# There should be no rows in any table if we purged everything
|
||||||
@ -306,6 +303,6 @@ class TestDatabaseArchive(integrated_helpers._IntegratedTestBase):
|
|||||||
self.assertEqual([server_id], deleted_ids)
|
self.assertEqual([server_id], deleted_ids)
|
||||||
date = dateutil_parser.parse('oct 21 2015', fuzzy=True)
|
date = dateutil_parser.parse('oct 21 2015', fuzzy=True)
|
||||||
admin_context = context.get_admin_context()
|
admin_context = context.get_admin_context()
|
||||||
deleted = sqlalchemy_api.purge_shadow_tables(admin_context, date)
|
deleted = db.purge_shadow_tables(admin_context, date)
|
||||||
self.assertEqual(0, deleted)
|
self.assertEqual(0, deleted)
|
||||||
self.assertEqual(sum(results.values()), archived)
|
self.assertEqual(sum(results.values()), archived)
|
||||||
|
@ -15,7 +15,7 @@ from oslo_utils.fixture import uuidsentinel
|
|||||||
|
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import compute_node
|
from nova.objects import compute_node
|
||||||
from nova.objects import fields as obj_fields
|
from nova.objects import fields as obj_fields
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
# 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.db.main import models
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova.db.sqlalchemy import models
|
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,7 +15,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.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import keypair
|
from nova.objects import keypair
|
||||||
|
@ -10,8 +10,8 @@
|
|||||||
# 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.db.main import models
|
||||||
from nova.db.sqlalchemy import api_models
|
from nova.db.sqlalchemy import api_models
|
||||||
from nova.db.sqlalchemy import models
|
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.objects import quotas
|
from nova.objects import quotas
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests.unit.db import test_db_api
|
from nova.tests.unit.db.main import test_api as test_db_api
|
||||||
|
|
||||||
|
|
||||||
class QuotasObjectTestCase(test.TestCase,
|
class QuotasObjectTestCase(test.TestCase,
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ from nova.compute import rpcapi as compute_rpcapi
|
|||||||
from nova.compute import utils as compute_utils
|
from nova.compute import utils as compute_utils
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
import nova.image.glance
|
import nova.image.glance
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import base as objects_base
|
from nova.objects import base as objects_base
|
||||||
|
@ -44,9 +44,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.api.service_get_by_host_and_binary",
|
self.stub_out("nova.db.main.api.service_get_by_host_and_binary",
|
||||||
test_services.fake_service_get_by_host_binary)
|
test_services.fake_service_get_by_host_binary)
|
||||||
self.stub_out("nova.db.api.service_update",
|
self.stub_out("nova.db.main.api.service_update",
|
||||||
test_services.fake_service_update)
|
test_services.fake_service_update)
|
||||||
# NOTE(gibi): enable / disable a compute service tries to call
|
# NOTE(gibi): enable / disable a compute service tries to call
|
||||||
# the compute service via RPC to update placement. However in these
|
# the compute service via RPC to update placement. However in these
|
||||||
@ -111,7 +111,7 @@ 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.api.service_get_by_uuid',
|
self.stub_out('nova.db.main.api.service_get_by_uuid',
|
||||||
db_service_get_by_uuid)
|
db_service_get_by_uuid)
|
||||||
|
|
||||||
def test_service_enable(self):
|
def test_service_enable(self):
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import context as nova_context
|
from nova import context as nova_context
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fixtures as nova_fixtures
|
from nova.tests import fixtures as nova_fixtures
|
||||||
from nova.tests.functional import fixtures as func_fixtures
|
from nova.tests.functional import fixtures as func_fixtures
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import nova.context
|
import nova.context
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from nova import context as nova_context
|
from nova import context as nova_context
|
||||||
from nova.db import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova.objects import virtual_interface
|
from nova.objects import virtual_interface
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fixtures as nova_fixtures
|
from nova.tests import fixtures as nova_fixtures
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fixtures as nova_fixtures
|
from nova.tests import fixtures as nova_fixtures
|
||||||
|
@ -21,7 +21,7 @@ from oslo_utils import timeutils
|
|||||||
from nova.compute import instance_actions
|
from nova.compute import instance_actions
|
||||||
from nova import conf
|
from nova import conf
|
||||||
from nova import context as nova_context
|
from nova import context as nova_context
|
||||||
from nova.db import api as db_api
|
from nova.db.main import api as db_api
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.policies import base as base_policies
|
from nova.policies import base as base_policies
|
||||||
|
@ -18,8 +18,7 @@ from oslo_config import cfg
|
|||||||
|
|
||||||
from nova.compute import instance_actions
|
from nova.compute import instance_actions
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
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
|
||||||
from nova.tests.functional.api import client
|
from nova.tests.functional.api import client
|
||||||
@ -261,9 +260,9 @@ class ServerGroupTestV21(ServerGroupTestBase):
|
|||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
servers = db.instance_get_all(ctxt)
|
servers = db.instance_get_all(ctxt)
|
||||||
self.assertEqual(1, len(servers))
|
self.assertEqual(1, len(servers))
|
||||||
ctxt_mgr = db_api.get_context_manager(ctxt)
|
ctxt_mgr = db.get_context_manager(ctxt)
|
||||||
with ctxt_mgr.reader.using(ctxt):
|
with ctxt_mgr.reader.using(ctxt):
|
||||||
bdms = db_api._block_device_mapping_get_query(ctxt).all()
|
bdms = db._block_device_mapping_get_query(ctxt).all()
|
||||||
self.assertEqual(1, len(bdms))
|
self.assertEqual(1, len(bdms))
|
||||||
self.assertEqual(servers[0]['uuid'], bdms[0]['instance_uuid'])
|
self.assertEqual(servers[0]['uuid'], bdms[0]['instance_uuid'])
|
||||||
|
|
||||||
|
@ -24,7 +24,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.db import api as db
|
from nova.db.main 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
|
||||||
|
@ -88,7 +88,7 @@ class DiskConfigTestCaseV21(test.TestCase):
|
|||||||
|
|
||||||
return inst
|
return inst
|
||||||
|
|
||||||
self.stub_out('nova.db.api.instance_create', fake_instance_create)
|
self.stub_out('nova.db.main.api.instance_create', fake_instance_create)
|
||||||
|
|
||||||
def _set_up_app(self):
|
def _set_up_app(self):
|
||||||
self.app = compute.APIRouterV21()
|
self.app = compute.APIRouterV21()
|
||||||
|
@ -22,7 +22,7 @@ from nova.api.openstack.compute import hosts as os_hosts_v21
|
|||||||
from nova.compute import power_state
|
from nova.compute import 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.db import api as db
|
from nova.db.main 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
|
||||||
@ -135,10 +135,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.api.service_get_all',
|
self.stub_out('nova.db.main.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.api.service_get_by_host_and_binary',
|
self.stub_out('nova.db.main.api.service_get_by_host_and_binary',
|
||||||
stub_service_get_by_host_and_binary)
|
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',
|
||||||
@ -233,7 +233,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.api.service_get_all',
|
self.stub_out('nova.db.main.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,
|
||||||
|
@ -250,7 +250,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.api.compute_node_statistics',
|
self.stub_out('nova.db.main.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):
|
||||||
|
@ -25,7 +25,7 @@ from webob import exc
|
|||||||
from nova.api.openstack.compute import instance_actions as instance_actions_v21
|
from nova.api.openstack.compute import instance_actions as instance_actions_v21
|
||||||
from nova.api.openstack import wsgi as os_wsgi
|
from nova.api.openstack import wsgi as os_wsgi
|
||||||
from nova.compute import api as compute_api
|
from nova.compute import api as compute_api
|
||||||
from nova.db.sqlalchemy import models
|
from nova.db.main import models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova import policy
|
from nova import policy
|
||||||
@ -134,7 +134,7 @@ class InstanceActionsTestV21(test.NoDBTestCase):
|
|||||||
actions.append(action)
|
actions.append(action)
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
self.stub_out('nova.db.api.actions_get', fake_get_actions)
|
self.stub_out('nova.db.main.api.actions_get', fake_get_actions)
|
||||||
req = self._get_http_req('os-instance-actions')
|
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']:
|
||||||
@ -155,8 +155,9 @@ class InstanceActionsTestV21(test.NoDBTestCase):
|
|||||||
events.append(event)
|
events.append(event)
|
||||||
return events
|
return events
|
||||||
|
|
||||||
self.stub_out('nova.db.api.action_get_by_request_id', fake_get_action)
|
self.stub_out(
|
||||||
self.stub_out('nova.db.api.action_events_get', fake_get_events)
|
'nova.db.main.api.action_get_by_request_id', fake_get_action)
|
||||||
|
self.stub_out('nova.db.main.api.action_events_get', fake_get_events)
|
||||||
req = self._get_http_req('os-instance-actions/1',
|
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)
|
||||||
@ -177,8 +178,9 @@ 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.api.action_get_by_request_id', fake_get_action)
|
self.stub_out(
|
||||||
self.stub_out('nova.db.api.action_events_get', fake_get_events)
|
'nova.db.main.api.action_get_by_request_id', fake_get_action)
|
||||||
|
self.stub_out('nova.db.main.api.action_events_get', fake_get_events)
|
||||||
|
|
||||||
self._set_policy_rules()
|
self._set_policy_rules()
|
||||||
req = self._get_http_req('os-instance-actions/1')
|
req = self._get_http_req('os-instance-actions/1')
|
||||||
@ -202,7 +204,8 @@ class InstanceActionsTestV21(test.NoDBTestCase):
|
|||||||
def fake_no_action(context, uuid, action_id):
|
def fake_no_action(context, uuid, action_id):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
self.stub_out('nova.db.api.action_get_by_request_id', fake_no_action)
|
self.stub_out(
|
||||||
|
'nova.db.main.api.action_get_by_request_id', fake_no_action)
|
||||||
req = self._get_http_req('os-instance-actions/1')
|
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)
|
||||||
@ -431,8 +434,9 @@ class InstanceActionsTestV284(InstanceActionsTestV266):
|
|||||||
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.api.action_get_by_request_id', fake_get_action)
|
self.stub_out(
|
||||||
self.stub_out('nova.db.api.action_events_get', fake_get_events)
|
'nova.db.main.api.action_get_by_request_id', fake_get_action)
|
||||||
|
self.stub_out('nova.db.main.api.action_events_get', fake_get_events)
|
||||||
|
|
||||||
self._set_policy_rules(overwrite=False)
|
self._set_policy_rules(overwrite=False)
|
||||||
req = self._get_http_req('os-instance-actions/1')
|
req = self._get_http_req('os-instance-actions/1')
|
||||||
@ -448,8 +452,9 @@ class InstanceActionsTestV284(InstanceActionsTestV266):
|
|||||||
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.api.action_get_by_request_id', fake_get_action)
|
self.stub_out(
|
||||||
self.stub_out('nova.db.api.action_events_get', fake_get_events)
|
'nova.db.main.api.action_get_by_request_id', fake_get_action)
|
||||||
|
self.stub_out('nova.db.main.api.action_events_get', fake_get_events)
|
||||||
|
|
||||||
req = self._get_http_req_with_version('os-instance-actions/1',
|
req = self._get_http_req_with_version('os-instance-actions/1',
|
||||||
version="2.83")
|
version="2.83")
|
||||||
|
@ -119,10 +119,12 @@ class InstanceUsageAuditLogTestV21(test.NoDBTestCase):
|
|||||||
self.assertIsNone(disabled)
|
self.assertIsNone(disabled)
|
||||||
return TEST_COMPUTE_SERVICES
|
return TEST_COMPUTE_SERVICES
|
||||||
|
|
||||||
self.stub_out('nova.utils.last_completed_audit_period',
|
self.stub_out(
|
||||||
fake_last_completed_audit_period)
|
'nova.utils.last_completed_audit_period',
|
||||||
self.stub_out('nova.db.api.service_get_all', fake_service_get_all)
|
fake_last_completed_audit_period)
|
||||||
self.stub_out('nova.db.api.task_log_get_all', fake_task_log_get_all)
|
self.stub_out('nova.db.main.api.service_get_all', fake_service_get_all)
|
||||||
|
self.stub_out(
|
||||||
|
'nova.db.main.api.task_log_get_all', fake_task_log_get_all)
|
||||||
|
|
||||||
self.req = fakes.HTTPRequest.blank('')
|
self.req = fakes.HTTPRequest.blank('')
|
||||||
|
|
||||||
|
@ -74,11 +74,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.api.key_pair_get_all_by_user",
|
self.stub_out("nova.db.main.api.key_pair_get_all_by_user",
|
||||||
db_key_pair_get_all_by_user)
|
db_key_pair_get_all_by_user)
|
||||||
self.stub_out("nova.db.api.key_pair_create",
|
self.stub_out("nova.db.main.api.key_pair_create",
|
||||||
db_key_pair_create)
|
db_key_pair_create)
|
||||||
self.stub_out("nova.db.api.key_pair_destroy",
|
self.stub_out("nova.db.main.api.key_pair_destroy",
|
||||||
db_key_pair_destroy)
|
db_key_pair_destroy)
|
||||||
self._setup_app_and_controller()
|
self._setup_app_and_controller()
|
||||||
|
|
||||||
@ -282,7 +282,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.api.key_pair_destroy",
|
self.stub_out("nova.db.main.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')
|
||||||
@ -294,7 +294,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.api.key_pair_get", _db_key_pair_get)
|
self.stub_out("nova.db.main.api.key_pair_get", _db_key_pair_get)
|
||||||
|
|
||||||
res_dict = self.controller.show(self.req, 'FAKE')
|
res_dict = self.controller.show(self.req, 'FAKE')
|
||||||
self.assertEqual('foo', res_dict['keypair']['name'])
|
self.assertEqual('foo', res_dict['keypair']['name'])
|
||||||
@ -307,7 +307,7 @@ 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.api.key_pair_get", _db_key_pair_get)
|
self.stub_out("nova.db.main.api.key_pair_get", _db_key_pair_get)
|
||||||
|
|
||||||
self.assertRaises(webob.exc.HTTPNotFound,
|
self.assertRaises(webob.exc.HTTPNotFound,
|
||||||
self.controller.show, self.req, 'FAKE')
|
self.controller.show, self.req, 'FAKE')
|
||||||
@ -432,7 +432,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.api.key_pair_get_all_by_user")
|
@mock.patch("nova.db.main.api.key_pair_get_all_by_user")
|
||||||
def test_keypair_list_limit_and_marker(self, mock_kp_get):
|
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
|
||||||
|
|
||||||
@ -467,7 +467,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.api.key_pair_get_all_by_user")
|
@mock.patch("nova.db.main.api.key_pair_get_all_by_user")
|
||||||
def test_keypair_list_limit_and_marker_invalid_in_old_microversion(
|
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
|
||||||
@ -488,7 +488,7 @@ class KeypairsTestV275(test.TestCase):
|
|||||||
super(KeypairsTestV275, self).setUp()
|
super(KeypairsTestV275, self).setUp()
|
||||||
self.controller = keypairs_v21.KeypairController()
|
self.controller = keypairs_v21.KeypairController()
|
||||||
|
|
||||||
@mock.patch("nova.db.api.key_pair_get_all_by_user")
|
@mock.patch("nova.db.main.api.key_pair_get_all_by_user")
|
||||||
@mock.patch('nova.objects.KeyPair.get_by_name')
|
@mock.patch('nova.objects.KeyPair.get_by_name')
|
||||||
def test_keypair_list_additional_param_old_version(self, mock_get_by_name,
|
def test_keypair_list_additional_param_old_version(self, mock_get_by_name,
|
||||||
mock_kp_get):
|
mock_kp_get):
|
||||||
|
@ -24,7 +24,7 @@ import webob
|
|||||||
|
|
||||||
from nova.api.openstack.compute import security_groups as secgroups_v21
|
from nova.api.openstack.compute import security_groups as secgroups_v21
|
||||||
from nova import context as context_maker
|
from nova import context as context_maker
|
||||||
import nova.db.api
|
import nova.db.main.api
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.network import model
|
from nova.network import model
|
||||||
from nova.network import neutron as neutron_api
|
from nova.network import neutron as neutron_api
|
||||||
@ -636,7 +636,7 @@ class TestSecurityGroupsV21(test.TestCase):
|
|||||||
_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.api, 'instance_get_by_uuid',
|
with mock.patch.object(nova.db.main.api, 'instance_get_by_uuid',
|
||||||
return_value=db_inst):
|
return_value=db_inst):
|
||||||
neutron.allocate_for_instance(_context, instance, None,
|
neutron.allocate_for_instance(_context, instance, None,
|
||||||
security_groups=[sg['id']])
|
security_groups=[sg['id']])
|
||||||
|
@ -1038,8 +1038,9 @@ class ServerActionsControllerTestV21(test.TestCase):
|
|||||||
'delete_on_termination': False,
|
'delete_on_termination': False,
|
||||||
'no_device': None})]
|
'no_device': None})]
|
||||||
|
|
||||||
self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance',
|
self.stub_out(
|
||||||
fake_block_device_mapping_get_all_by_instance)
|
'nova.db.main.api.block_device_mapping_get_all_by_instance',
|
||||||
|
fake_block_device_mapping_get_all_by_instance)
|
||||||
|
|
||||||
system_metadata = dict(image_kernel_id=_fake_id('b'),
|
system_metadata = dict(image_kernel_id=_fake_id('b'),
|
||||||
image_ramdisk_id=_fake_id('c'),
|
image_ramdisk_id=_fake_id('c'),
|
||||||
@ -1150,8 +1151,9 @@ class ServerActionsControllerTestV21(test.TestCase):
|
|||||||
'delete_on_termination': False,
|
'delete_on_termination': False,
|
||||||
'no_device': None})]
|
'no_device': None})]
|
||||||
|
|
||||||
self.stub_out('nova.db.api.block_device_mapping_get_all_by_instance',
|
self.stub_out(
|
||||||
fake_block_device_mapping_get_all_by_instance)
|
'nova.db.main.api.block_device_mapping_get_all_by_instance',
|
||||||
|
fake_block_device_mapping_get_all_by_instance)
|
||||||
|
|
||||||
instance = fakes.fake_compute_get(
|
instance = fakes.fake_compute_get(
|
||||||
project_id=fakes.FAKE_PROJECT_ID,
|
project_id=fakes.FAKE_PROJECT_ID,
|
||||||
|
@ -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.api
|
import nova.db.main.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
|
||||||
@ -96,7 +96,7 @@ class ServerMetaDataTestV21(test.TestCase):
|
|||||||
'vm_state': vm_states.ACTIVE,
|
'vm_state': vm_states.ACTIVE,
|
||||||
'metadata': metadata}))
|
'metadata': metadata}))
|
||||||
|
|
||||||
self.stub_out('nova.db.api.instance_metadata_get',
|
self.stub_out('nova.db.main.api.instance_metadata_get',
|
||||||
return_server_metadata)
|
return_server_metadata)
|
||||||
|
|
||||||
self._set_up_resources()
|
self._set_up_resources()
|
||||||
@ -124,14 +124,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.api.instance_metadata_get',
|
self.stub_out('nova.db.main.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.api.instance_metadata_get',
|
self.stub_out('nova.db.main.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)
|
||||||
@ -145,23 +145,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.api.instance_metadata_get',
|
self.stub_out('nova.db.main.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.api.instance_metadata_get',
|
self.stub_out('nova.db.main.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.api.instance_metadata_get',
|
self.stub_out('nova.db.main.api.instance_metadata_get',
|
||||||
return_server_metadata)
|
return_server_metadata)
|
||||||
self.stub_out('nova.db.api.instance_metadata_delete',
|
self.stub_out('nova.db.main.api.instance_metadata_delete',
|
||||||
delete_server_metadata)
|
delete_server_metadata)
|
||||||
req = self._get_request('/key2')
|
req = self._get_request('/key2')
|
||||||
req.method = 'DELETE'
|
req.method = 'DELETE'
|
||||||
@ -179,7 +179,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.api.instance_metadata_get',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -203,7 +203,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -213,7 +213,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -225,7 +225,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -237,7 +237,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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):
|
|||||||
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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -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_malformed_data(self):
|
def test_create_malformed_data(self):
|
||||||
self.stub_out('nova.db.api.instance_metadata_update',
|
self.stub_out('nova.db.main.api.instance_metadata_update',
|
||||||
return_create_instance_metadata)
|
return_create_instance_metadata)
|
||||||
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
req = fakes.HTTPRequest.blank(self.url + '/key1')
|
||||||
req.method = 'PUT'
|
req.method = 'PUT'
|
||||||
@ -329,7 +329,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -340,7 +340,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -353,7 +353,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -366,7 +366,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -392,7 +392,7 @@ class ServerMetaDataTestV21(test.TestCase):
|
|||||||
body=body)
|
body=body)
|
||||||
|
|
||||||
def test_update_all_non_dict(self):
|
def test_update_all_non_dict(self):
|
||||||
self.stub_out('nova.db.api.instance_metadata_update',
|
self.stub_out('nova.db.main.api.instance_metadata_update',
|
||||||
return_create_instance_metadata)
|
return_create_instance_metadata)
|
||||||
req = self._get_request()
|
req = self._get_request()
|
||||||
req.method = 'PUT'
|
req.method = 'PUT'
|
||||||
@ -428,7 +428,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -439,7 +439,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -452,7 +452,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -465,7 +465,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -478,7 +478,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -491,7 +491,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -504,7 +504,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -517,7 +517,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -530,7 +530,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -556,7 +556,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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):
|
||||||
@ -570,7 +570,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
@ -595,7 +595,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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):
|
||||||
@ -609,7 +609,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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):
|
||||||
@ -645,14 +645,14 @@ class BadStateServerMetaDataTestV21(test.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BadStateServerMetaDataTestV21, self).setUp()
|
super(BadStateServerMetaDataTestV21, self).setUp()
|
||||||
self.stub_out('nova.db.api.instance_metadata_get',
|
self.stub_out('nova.db.main.api.instance_metadata_get',
|
||||||
return_server_metadata)
|
return_server_metadata)
|
||||||
self.stub_out('nova.compute.api.API.get',
|
self.stub_out('nova.compute.api.API.get',
|
||||||
fakes.fake_compute_get(
|
fakes.fake_compute_get(
|
||||||
**{'uuid': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
|
**{'uuid': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
|
||||||
'name': 'fake',
|
'name': 'fake',
|
||||||
'vm_state': vm_states.BUILDING}))
|
'vm_state': vm_states.BUILDING}))
|
||||||
self.stub_out('nova.db.api.instance_metadata_delete',
|
self.stub_out('nova.db.main.api.instance_metadata_delete',
|
||||||
delete_server_metadata)
|
delete_server_metadata)
|
||||||
self._set_up_resources()
|
self._set_up_resources()
|
||||||
|
|
||||||
@ -672,7 +672,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.api.instance_metadata_update',
|
self.stub_out('nova.db.main.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'
|
||||||
|
@ -18,7 +18,7 @@ import webob
|
|||||||
|
|
||||||
from nova.api.openstack.compute import servers
|
from nova.api.openstack.compute import servers
|
||||||
from nova.compute import api as compute_api
|
from nova.compute import api as compute_api
|
||||||
from nova.db import api as db
|
from nova.db.main import api as db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import fixtures as nova_fixtures
|
from nova.tests import fixtures as nova_fixtures
|
||||||
@ -32,7 +32,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.api.instance_get_by_uuid',
|
self.stub_out('nova.db.main.api.instance_get_by_uuid',
|
||||||
fakes.fake_instance_get(
|
fakes.fake_instance_get(
|
||||||
project_id=fakes.FAKE_PROJECT_ID))
|
project_id=fakes.FAKE_PROJECT_ID))
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from nova.api.openstack.compute import server_tags
|
|||||||
from nova.api.openstack.compute import servers
|
from nova.api.openstack.compute import servers
|
||||||
from nova.compute import vm_states
|
from nova.compute import vm_states
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db.sqlalchemy import models
|
from nova.db.main import models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import instance
|
from nova.objects import instance
|
||||||
@ -68,7 +68,7 @@ class ServerTagsTest(test.TestCase):
|
|||||||
request.method = method
|
request.method = method
|
||||||
return request
|
return request
|
||||||
|
|
||||||
@mock.patch('nova.db.api.instance_tag_exists')
|
@mock.patch('nova.db.main.api.instance_tag_exists')
|
||||||
def test_show(self, mock_exists):
|
def test_show(self, mock_exists):
|
||||||
mock_exists.return_value = True
|
mock_exists.return_value = True
|
||||||
req = self._get_request(
|
req = self._get_request(
|
||||||
@ -78,7 +78,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.api.instance_tag_get_by_instance_uuid')
|
@mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid')
|
||||||
def test_index(self, mock_db_get_inst_tags):
|
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
|
||||||
@ -91,7 +91,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.api.instance_tag_set')
|
@mock.patch('nova.db.main.api.instance_tag_set')
|
||||||
def test_update_all(self, mock_db_set_inst_tags, mock_notify):
|
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]
|
||||||
@ -162,7 +162,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.api.instance_tag_exists')
|
@mock.patch('nova.db.main.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(
|
||||||
@ -172,8 +172,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.api.instance_tag_add')
|
@mock.patch('nova.db.main.api.instance_tag_add')
|
||||||
@mock.patch('nova.db.api.instance_tag_get_by_instance_uuid')
|
@mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid')
|
||||||
def test_update(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)
|
||||||
@ -192,7 +192,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.api.instance_tag_get_by_instance_uuid')
|
@mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid')
|
||||||
def test_update_existing_tag(self, mock_db_get_inst_tags):
|
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)]
|
||||||
@ -206,7 +206,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.api.instance_tag_get_by_instance_uuid')
|
@mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid')
|
||||||
def test_update_tag_limit_exceed(self, mock_db_get_inst_tags):
|
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))
|
||||||
@ -219,7 +219,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.api.instance_tag_get_by_instance_uuid')
|
@mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid')
|
||||||
def test_update_too_long_tag(self, mock_db_get_inst_tags):
|
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 = []
|
||||||
@ -231,7 +231,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.api.instance_tag_get_by_instance_uuid')
|
@mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid')
|
||||||
def test_update_forbidden_characters(self, mock_db_get_inst_tags):
|
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 = []
|
||||||
@ -251,9 +251,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.api.instance_tag_get_by_instance_uuid')
|
@mock.patch('nova.db.main.api.instance_tag_get_by_instance_uuid')
|
||||||
@mock.patch('nova.notifications.base.send_instance_update_notification')
|
@mock.patch('nova.notifications.base.send_instance_update_notification')
|
||||||
@mock.patch('nova.db.api.instance_tag_delete')
|
@mock.patch('nova.db.main.api.instance_tag_delete')
|
||||||
def test_delete(self, mock_db_delete_inst_tags, mock_notify,
|
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)
|
||||||
@ -265,7 +265,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.api.instance_tag_delete')
|
@mock.patch('nova.db.main.api.instance_tag_delete')
|
||||||
def test_delete_non_existing_tag(self, mock_db_delete_inst_tags):
|
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)
|
||||||
|
|
||||||
@ -291,7 +291,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.api.instance_tag_delete_all')
|
@mock.patch('nova.db.main.api.instance_tag_delete_all')
|
||||||
def test_delete_all(self, mock_db_delete_inst_tags, mock_notify):
|
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/%s/servers/%s/tags' % (
|
req = self._get_request('/v2/%s/servers/%s/tags' % (
|
||||||
|
@ -52,8 +52,8 @@ from nova.compute import vm_states
|
|||||||
import nova.conf
|
import nova.conf
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db import constants as db_const
|
from nova.db import constants as db_const
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.main import api as db
|
||||||
from nova.db.sqlalchemy import models
|
from nova.db.main import models
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.image import glance
|
from nova.image import glance
|
||||||
from nova import objects
|
from nova import objects
|
||||||
@ -241,9 +241,9 @@ 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.api.instance_update_and_get_original',
|
self.stub_out('nova.db.main.api.instance_update_and_get_original',
|
||||||
instance_update_and_get_original)
|
instance_update_and_get_original)
|
||||||
self.stub_out('nova.db.api.'
|
self.stub_out('nova.db.main.api.'
|
||||||
'block_device_mapping_get_all_by_instance_uuids',
|
'block_device_mapping_get_all_by_instance_uuids',
|
||||||
fake_bdms_get_all_by_instance_uuids)
|
fake_bdms_get_all_by_instance_uuids)
|
||||||
self.stub_out('nova.objects.InstanceMappingList.'
|
self.stub_out('nova.objects.InstanceMappingList.'
|
||||||
@ -2923,7 +2923,8 @@ 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.api.instance_destroy', instance_destroy_mock)
|
self.stub_out(
|
||||||
|
'nova.db.main.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,
|
||||||
@ -3258,7 +3259,7 @@ 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.api.instance_get_by_uuid',
|
'nova.db.main.api.instance_get_by_uuid',
|
||||||
fake_instance_get_by_uuid_not_found)
|
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(self.path_action % 'test_inst')
|
req = fakes.HTTPRequestV21.blank(self.path_action % 'test_inst')
|
||||||
@ -3267,7 +3268,7 @@ 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.api.instance_get_by_uuid',
|
'nova.db.main.api.instance_get_by_uuid',
|
||||||
fake_instance_get_by_uuid_not_found)
|
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(self.path_action % 'test_inst')
|
req = fakes.HTTPRequestV21.blank(self.path_action % 'test_inst')
|
||||||
@ -3336,7 +3337,7 @@ class ServersControllerRebuildTestV254(ServersControllerRebuildInstanceTest):
|
|||||||
def test_rebuild_user_has_no_key_pair(self):
|
def 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.api.key_pair_get', no_key_pair)
|
self.stub_out('nova.db.main.api.key_pair_get', no_key_pair)
|
||||||
fake_get = fakes.fake_compute_get(vm_state=vm_states.ACTIVE,
|
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,
|
||||||
@ -3478,7 +3479,7 @@ class ServersControllerRebuildTestV257(ServersControllerRebuildTestV254):
|
|||||||
self.assertIn('user_data', str(ex))
|
self.assertIn('user_data', str(ex))
|
||||||
|
|
||||||
@mock.patch.object(context.RequestContext, 'can')
|
@mock.patch.object(context.RequestContext, 'can')
|
||||||
@mock.patch('nova.db.api.instance_update_and_get_original')
|
@mock.patch('nova.db.main.api.instance_update_and_get_original')
|
||||||
def test_rebuild_reset_user_data(self, mock_update, mock_policy):
|
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.
|
||||||
@ -3806,7 +3807,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.api.instance_get',
|
self.stub_out('nova.db.main.api.instance_get',
|
||||||
fakes.fake_instance_get(name='server_test'))
|
fakes.fake_instance_get(name='server_test'))
|
||||||
req = fakes.HTTPRequest.blank(self.path_with_id % FAKE_UUID)
|
req = fakes.HTTPRequest.blank(self.path_with_id % FAKE_UUID)
|
||||||
req.method = 'PUT'
|
req.method = 'PUT'
|
||||||
@ -3822,7 +3823,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.api.instance_get',
|
self.stub_out('nova.db.main.api.instance_get',
|
||||||
fakes.fake_instance_get(name='server_test'))
|
fakes.fake_instance_get(name='server_test'))
|
||||||
req = fakes.HTTPRequest.blank(self.path_with_id % FAKE_UUID)
|
req = fakes.HTTPRequest.blank(self.path_with_id % FAKE_UUID)
|
||||||
req.method = 'PUT'
|
req.method = 'PUT'
|
||||||
@ -5494,7 +5495,7 @@ class ServersControllerCreateTest(test.TestCase):
|
|||||||
mock_get_all_p.return_value = {'project_id': fakes.FAKE_PROJECT_ID}
|
mock_get_all_p.return_value = {'project_id': fakes.FAKE_PROJECT_ID}
|
||||||
mock_get_all_pu.return_value = {'project_id': fakes.FAKE_PROJECT_ID,
|
mock_get_all_pu.return_value = {'project_id': fakes.FAKE_PROJECT_ID,
|
||||||
'user_id': 'fake_user'}
|
'user_id': 'fake_user'}
|
||||||
if resource in db_api.PER_PROJECT_QUOTAS:
|
if resource in db.PER_PROJECT_QUOTAS:
|
||||||
mock_get_all_p.return_value[resource] = quota
|
mock_get_all_p.return_value[resource] = quota
|
||||||
else:
|
else:
|
||||||
mock_get_all_pu.return_value[resource] = quota
|
mock_get_all_pu.return_value[resource] = quota
|
||||||
@ -5550,7 +5551,8 @@ 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.api.instance_destroy', fake_instance_destroy)
|
self.stub_out(
|
||||||
|
'nova.db.main.api.instance_destroy', fake_instance_destroy)
|
||||||
self.body['os:scheduler_hints'] = {'group': fake_group.uuid}
|
self.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"
|
||||||
@ -5573,7 +5575,8 @@ 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.api.instance_destroy', fake_instance_destroy)
|
self.stub_out(
|
||||||
|
'nova.db.main.api.instance_destroy', fake_instance_destroy)
|
||||||
self.body['os:scheduler_hints'] = {'group': test_group.uuid}
|
self.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']
|
||||||
@ -5613,7 +5616,8 @@ 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.api.instance_destroy', fake_instance_destroy)
|
self.stub_out(
|
||||||
|
'nova.db.main.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)
|
||||||
@ -7102,7 +7106,7 @@ class ServersViewBuilderTest(test.TestCase):
|
|||||||
fakes.stub_out_secgroup_api(
|
fakes.stub_out_secgroup_api(
|
||||||
self, security_groups=[{'name': 'default'}])
|
self, security_groups=[{'name': 'default'}])
|
||||||
|
|
||||||
self.stub_out('nova.db.api.'
|
self.stub_out('nova.db.main.api.'
|
||||||
'block_device_mapping_get_all_by_instance_uuids',
|
'block_device_mapping_get_all_by_instance_uuids',
|
||||||
fake_bdms_get_all_by_instance_uuids)
|
fake_bdms_get_all_by_instance_uuids)
|
||||||
self.stub_out('nova.objects.InstanceMappingList.'
|
self.stub_out('nova.objects.InstanceMappingList.'
|
||||||
|
@ -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.api.service_get_by_host_and_binary',
|
self.stub_out('nova.db.main.api.service_get_by_host_and_binary',
|
||||||
fake_db_service_get_by_host_binary(fake_services_list))
|
fake_db_service_get_by_host_binary(fake_services_list))
|
||||||
self.stub_out('nova.db.api.service_update',
|
self.stub_out('nova.db.main.api.service_update',
|
||||||
fake_db_service_update(fake_services_list))
|
fake_db_service_update(fake_services_list))
|
||||||
|
|
||||||
# NOTE(gibi): enable / disable a compute service tries to call
|
# NOTE(gibi): enable / disable a compute service tries to call
|
||||||
@ -595,7 +595,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.api.service_update', _service_update)
|
self.stub_out('nova.db.main.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)
|
||||||
|
@ -33,7 +33,7 @@ from nova.compute import flavors
|
|||||||
from nova.compute import vm_states
|
from nova.compute import vm_states
|
||||||
import nova.conf
|
import nova.conf
|
||||||
from nova import context
|
from nova import context
|
||||||
from nova.db.sqlalchemy import models
|
from nova.db.main import models
|
||||||
from nova import exception as exc
|
from nova import exception as exc
|
||||||
from nova import objects
|
from nova import objects
|
||||||
from nova.objects import base
|
from nova.objects import base
|
||||||
@ -105,10 +105,12 @@ 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.api.key_pair_get_all_by_user', key_pair)
|
testcase.stub_out(
|
||||||
testcase.stub_out('nova.db.api.key_pair_get', one_key_pair)
|
'nova.db.main.api.key_pair_get_all_by_user', key_pair)
|
||||||
|
testcase.stub_out('nova.db.main.api.key_pair_get', one_key_pair)
|
||||||
else:
|
else:
|
||||||
testcase.stub_out('nova.db.api.key_pair_get_all_by_user', no_key_pair)
|
testcase.stub_out(
|
||||||
|
'nova.db.main.api.key_pair_get_all_by_user', no_key_pair)
|
||||||
|
|
||||||
|
|
||||||
def stub_out_trusted_certs(test, certs=None):
|
def stub_out_trusted_certs(test, certs=None):
|
||||||
|
@ -46,7 +46,7 @@ document_root = /tmp
|
|||||||
self.useFixture(config_fixture.Config())
|
self.useFixture(config_fixture.Config())
|
||||||
|
|
||||||
@mock.patch('sys.argv', return_value=mock.sentinel.argv)
|
@mock.patch('sys.argv', return_value=mock.sentinel.argv)
|
||||||
@mock.patch('nova.db.sqlalchemy.api.configure')
|
@mock.patch('nova.db.main.api.configure')
|
||||||
@mock.patch('nova.api.openstack.wsgi_app._setup_service')
|
@mock.patch('nova.api.openstack.wsgi_app._setup_service')
|
||||||
@mock.patch('nova.api.openstack.wsgi_app._get_config_files')
|
@mock.patch('nova.api.openstack.wsgi_app._get_config_files')
|
||||||
def test_init_application_called_twice(self, mock_get_files, mock_setup,
|
def test_init_application_called_twice(self, mock_get_files, mock_setup,
|
||||||
|
@ -24,23 +24,12 @@ import fixtures
|
|||||||
import mock
|
import mock
|
||||||
|
|
||||||
from nova.cmd import common as cmd_common
|
from nova.cmd import common as cmd_common
|
||||||
from nova.db import api
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import test
|
from nova import test
|
||||||
|
|
||||||
|
|
||||||
class TestCmdCommon(test.NoDBTestCase):
|
class TestCmdCommon(test.NoDBTestCase):
|
||||||
|
|
||||||
@mock.patch.object(cmd_common, 'LOG')
|
|
||||||
@mock.patch.object(api, 'IMPL')
|
|
||||||
def test_block_db_access(self, mock_db_IMPL, mock_LOG):
|
|
||||||
cmd_common.block_db_access('unit-tests')
|
|
||||||
|
|
||||||
self.assertEqual(api.IMPL, api.IMPL.foo)
|
|
||||||
self.assertRaises(exception.DBNotAllowed, api.IMPL)
|
|
||||||
self.assertEqual('unit-tests',
|
|
||||||
mock_LOG.error.call_args[0][1]['service_name'])
|
|
||||||
|
|
||||||
def test_args_decorator(self):
|
def test_args_decorator(self):
|
||||||
@cmd_common.args(bar='<bar>')
|
@cmd_common.args(bar='<bar>')
|
||||||
@cmd_common.args('foo')
|
@cmd_common.args('foo')
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user