db: Remove 'nova.db.base' module
This made sense back in the day where the ORM was configurable and we were making lots of direct calls to the database. Now, in a world where most things happen via o.vo, it's just noise. Remove it. Change-Id: I216cabcde5311abd46fdad9c95bb72c31b414010 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
5819fe46a9
commit
7ab2947720
@ -53,7 +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 base
|
from nova.db import api as db
|
||||||
from nova.db.sqlalchemy import api as db_api
|
from nova.db.sqlalchemy import api as db_api
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import exception_wrapper
|
from nova import exception_wrapper
|
||||||
@ -334,11 +334,10 @@ def block_accelerators(until_service=None):
|
|||||||
|
|
||||||
|
|
||||||
@profiler.trace_cls("compute_api")
|
@profiler.trace_cls("compute_api")
|
||||||
class API(base.Base):
|
class API:
|
||||||
"""API for interacting with the compute manager."""
|
"""API for interacting with the compute manager."""
|
||||||
|
|
||||||
def __init__(self, image_api=None, network_api=None, volume_api=None,
|
def __init__(self, image_api=None, network_api=None, volume_api=None):
|
||||||
**kwargs):
|
|
||||||
self.image_api = image_api or glance.API()
|
self.image_api = image_api or glance.API()
|
||||||
self.network_api = network_api or neutron.API()
|
self.network_api = network_api or neutron.API()
|
||||||
self.volume_api = volume_api or cinder.API()
|
self.volume_api = volume_api or cinder.API()
|
||||||
@ -352,7 +351,6 @@ class API(base.Base):
|
|||||||
self.key_manager = key_manager.API()
|
self.key_manager = key_manager.API()
|
||||||
# Help us to record host in EventReporter
|
# Help us to record host in EventReporter
|
||||||
self.host = CONF.host
|
self.host = CONF.host
|
||||||
super(API, self).__init__(**kwargs)
|
|
||||||
|
|
||||||
def _record_action_start(self, context, instance, action):
|
def _record_action_start(self, context, instance, action):
|
||||||
objects.InstanceAction.action_start(context, instance.uuid,
|
objects.InstanceAction.action_start(context, instance.uuid,
|
||||||
@ -5087,7 +5085,7 @@ class API(base.Base):
|
|||||||
|
|
||||||
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 self.db.instance_metadata_get(context, instance.uuid)
|
return db.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,
|
||||||
@ -5718,13 +5716,12 @@ def _find_service_in_cell(context, service_id=None, service_host=None):
|
|||||||
raise exception.NotFound()
|
raise exception.NotFound()
|
||||||
|
|
||||||
|
|
||||||
class HostAPI(base.Base):
|
class HostAPI:
|
||||||
"""Sub-set of the Compute Manager API for managing host operations."""
|
"""Sub-set of the Compute Manager API for managing host operations."""
|
||||||
|
|
||||||
def __init__(self, rpcapi=None, servicegroup_api=None):
|
def __init__(self, rpcapi=None, servicegroup_api=None):
|
||||||
self.rpcapi = rpcapi or compute_rpcapi.ComputeAPI()
|
self.rpcapi = rpcapi or compute_rpcapi.ComputeAPI()
|
||||||
self.servicegroup_api = servicegroup_api or servicegroup.API()
|
self.servicegroup_api = servicegroup_api or servicegroup.API()
|
||||||
super(HostAPI, self).__init__()
|
|
||||||
|
|
||||||
def _assert_host_exists(self, context, host_name, must_be_up=False):
|
def _assert_host_exists(self, context, host_name, must_be_up=False):
|
||||||
"""Raise HostNotFound if compute host doesn't exist."""
|
"""Raise HostNotFound if compute host doesn't exist."""
|
||||||
@ -5968,11 +5965,9 @@ class HostAPI(base.Base):
|
|||||||
"""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 self.db.task_log_get_all(context, task_name,
|
return db.task_log_get_all(
|
||||||
period_beginning,
|
context, task_name, period_beginning, period_ending, host=host,
|
||||||
period_ending,
|
state=state)
|
||||||
host=host,
|
|
||||||
state=state)
|
|
||||||
|
|
||||||
def compute_node_get(self, context, compute_id):
|
def compute_node_get(self, context, compute_id):
|
||||||
"""Return compute node entry for particular integer ID or UUID."""
|
"""Return compute node entry for particular integer ID or UUID."""
|
||||||
@ -6063,7 +6058,7 @@ class HostAPI(base.Base):
|
|||||||
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(self.db.compute_node_statistics(cctxt))
|
cell_stats.append(db.compute_node_statistics(cctxt))
|
||||||
|
|
||||||
if cell_stats:
|
if cell_stats:
|
||||||
keys = cell_stats[0].keys()
|
keys = cell_stats[0].keys()
|
||||||
@ -6073,7 +6068,7 @@ class HostAPI(base.Base):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
class InstanceActionAPI(base.Base):
|
class InstanceActionAPI:
|
||||||
"""Sub-set of the Compute Manager API for managing instance actions."""
|
"""Sub-set of the Compute Manager API for managing instance actions."""
|
||||||
|
|
||||||
def actions_get(self, context, instance, limit=None, marker=None,
|
def actions_get(self, context, instance, limit=None, marker=None,
|
||||||
@ -6090,13 +6085,13 @@ class InstanceActionAPI(base.Base):
|
|||||||
context, action_id)
|
context, action_id)
|
||||||
|
|
||||||
|
|
||||||
class AggregateAPI(base.Base):
|
class AggregateAPI:
|
||||||
"""Sub-set of the Compute Manager API for managing host aggregates."""
|
"""Sub-set of the Compute Manager API for managing host aggregates."""
|
||||||
def __init__(self, **kwargs):
|
|
||||||
|
def __init__(self):
|
||||||
self.compute_rpcapi = compute_rpcapi.ComputeAPI()
|
self.compute_rpcapi = compute_rpcapi.ComputeAPI()
|
||||||
self.query_client = query.SchedulerQueryClient()
|
self.query_client = query.SchedulerQueryClient()
|
||||||
self._placement_client = None # Lazy-load on first access.
|
self._placement_client = None # Lazy-load on first access.
|
||||||
super(AggregateAPI, self).__init__(**kwargs)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def placement_client(self):
|
def placement_client(self):
|
||||||
@ -6380,14 +6375,13 @@ class AggregateAPI(base.Base):
|
|||||||
return aggregate
|
return aggregate
|
||||||
|
|
||||||
|
|
||||||
class KeypairAPI(base.Base):
|
class KeypairAPI:
|
||||||
"""Subset of the Compute Manager API for managing key pairs."""
|
"""Subset of the Compute Manager API for managing key pairs."""
|
||||||
|
|
||||||
wrap_exception = functools.partial(
|
wrap_exception = functools.partial(
|
||||||
exception_wrapper.wrap_exception, service='api', binary='nova-api')
|
exception_wrapper.wrap_exception, service='api', binary='nova-api')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
|
||||||
self.notifier = rpc.get_notifier('api')
|
self.notifier = rpc.get_notifier('api')
|
||||||
|
|
||||||
def _notify(self, context, event_suffix, keypair_name):
|
def _notify(self, context, event_suffix, keypair_name):
|
||||||
|
@ -42,7 +42,6 @@ from nova.conductor.tasks import cross_cell_migrate
|
|||||||
from nova.conductor.tasks import live_migrate
|
from nova.conductor.tasks import live_migrate
|
||||||
from nova.conductor.tasks import migrate
|
from nova.conductor.tasks import migrate
|
||||||
from nova import context as nova_context
|
from nova import context as nova_context
|
||||||
from nova.db import base
|
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova.i18n import _
|
from nova.i18n import _
|
||||||
from nova.image import glance
|
from nova.image import glance
|
||||||
@ -224,7 +223,7 @@ def obj_target_cell(obj, cell):
|
|||||||
|
|
||||||
|
|
||||||
@profiler.trace_cls("rpc")
|
@profiler.trace_cls("rpc")
|
||||||
class ComputeTaskManager(base.Base):
|
class ComputeTaskManager:
|
||||||
"""Namespace for compute methods.
|
"""Namespace for compute methods.
|
||||||
|
|
||||||
This class presents an rpc API for nova-conductor under the 'compute_task'
|
This class presents an rpc API for nova-conductor under the 'compute_task'
|
||||||
@ -236,7 +235,6 @@ class ComputeTaskManager(base.Base):
|
|||||||
target = messaging.Target(namespace='compute_task', version='1.23')
|
target = messaging.Target(namespace='compute_task', version='1.23')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ComputeTaskManager, self).__init__()
|
|
||||||
self.compute_rpcapi = compute_rpcapi.ComputeAPI()
|
self.compute_rpcapi = compute_rpcapi.ComputeAPI()
|
||||||
self.volume_api = cinder.API()
|
self.volume_api = cinder.API()
|
||||||
self.image_api = glance.API()
|
self.image_api = glance.API()
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
# Copyright 2010 United States Government as represented by the
|
|
||||||
# Administrator of the National Aeronautics and Space Administration.
|
|
||||||
# All Rights Reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
||||||
# not use this file except in compliance with the License. You may obtain
|
|
||||||
# a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
# License for the specific language governing permissions and limitations
|
|
||||||
# under the License.
|
|
||||||
|
|
||||||
"""Base class for classes that need database access."""
|
|
||||||
|
|
||||||
import nova.db.api
|
|
||||||
|
|
||||||
|
|
||||||
class Base(object):
|
|
||||||
"""DB driver is injected in the init method."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
super(Base, self).__init__()
|
|
||||||
self.db = nova.db.api
|
|
@ -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
|
||||||
from nova.db import base
|
import nova.db.api
|
||||||
from nova import profiler
|
from nova import profiler
|
||||||
from nova import rpc
|
from nova import rpc
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ class ManagerMeta(profiler.get_traced_meta(), type(PeriodicTasks)):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Manager(base.Base, PeriodicTasks, metaclass=ManagerMeta):
|
class Manager(PeriodicTasks, metaclass=ManagerMeta):
|
||||||
__trace_args__ = {"name": "rpc"}
|
__trace_args__ = {"name": "rpc"}
|
||||||
|
|
||||||
def __init__(self, host=None, service_name='undefined'):
|
def __init__(self, host=None, service_name='undefined'):
|
||||||
|
@ -36,7 +36,6 @@ from oslo_utils import uuidutils
|
|||||||
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 as nova_context
|
from nova import context as nova_context
|
||||||
from nova.db import base
|
|
||||||
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
|
||||||
@ -299,11 +298,10 @@ def _ensure_no_port_binding_failure(port):
|
|||||||
raise exception.PortBindingFailed(port_id=port['id'])
|
raise exception.PortBindingFailed(port_id=port['id'])
|
||||||
|
|
||||||
|
|
||||||
class API(base.Base):
|
class API:
|
||||||
"""API for interacting with the neutron 2.x API."""
|
"""API for interacting with the neutron 2.x API."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(API, self).__init__()
|
|
||||||
self.last_neutron_extension_sync = None
|
self.last_neutron_extension_sync = None
|
||||||
self.extensions = {}
|
self.extensions = {}
|
||||||
self.pci_whitelist = pci_whitelist.Whitelist(
|
self.pci_whitelist = pci_whitelist.Whitelist(
|
||||||
|
@ -102,18 +102,21 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
|
|
||||||
_do_test()
|
_do_test()
|
||||||
|
|
||||||
def test_get_host_uptime_service_down(self):
|
@mock.patch('nova.db.api.service_get_by_compute_host')
|
||||||
@mock.patch.object(self.host_api.db, 'service_get_by_compute_host',
|
def test_get_host_uptime_service_down(
|
||||||
return_value=dict(test_service.fake_service, id=1))
|
self, mock_get_service_get_by_compute_host,
|
||||||
@mock.patch.object(self.host_api.servicegroup_api, 'service_is_up',
|
):
|
||||||
return_value=False)
|
mock_get_service_get_by_compute_host.return_value = dict(
|
||||||
def _do_test(mock_service_is_up, mock_service_get_by_compute_host):
|
test_service.fake_service, id=1)
|
||||||
|
|
||||||
|
with mock.patch.object(
|
||||||
|
self.host_api.servicegroup_api, 'service_is_up',
|
||||||
|
return_value=False,
|
||||||
|
):
|
||||||
self.assertRaises(exception.ComputeServiceUnavailable,
|
self.assertRaises(exception.ComputeServiceUnavailable,
|
||||||
self.host_api.get_host_uptime, self.ctxt,
|
self.host_api.get_host_uptime, self.ctxt,
|
||||||
'fake_host')
|
'fake_host')
|
||||||
|
|
||||||
_do_test()
|
|
||||||
|
|
||||||
def test_host_power_action(self):
|
def test_host_power_action(self):
|
||||||
|
|
||||||
@mock.patch.object(self.host_api.rpcapi, 'host_power_action',
|
@mock.patch.object(self.host_api.rpcapi, 'host_power_action',
|
||||||
@ -226,39 +229,37 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
None, set_zones=False)
|
None, set_zones=False)
|
||||||
mock_get_hm.assert_called_once_with(self.ctxt, cells[1].id)
|
mock_get_hm.assert_called_once_with(self.ctxt, cells[1].id)
|
||||||
|
|
||||||
def test_service_get_all_no_zones(self):
|
@mock.patch('nova.db.api.service_get_all')
|
||||||
|
def test_service_get_all_no_zones(self, mock_service_get_all):
|
||||||
services = [dict(test_service.fake_service,
|
services = [dict(test_service.fake_service,
|
||||||
id=1, topic='compute', host='host1'),
|
id=1, topic='compute', host='host1'),
|
||||||
dict(test_service.fake_service,
|
dict(test_service.fake_service,
|
||||||
topic='compute', host='host2')]
|
topic='compute', host='host2')]
|
||||||
|
|
||||||
@mock.patch.object(self.host_api.db, 'service_get_all')
|
mock_service_get_all.return_value = services
|
||||||
def _do_test(mock_service_get_all):
|
# Test no filters
|
||||||
mock_service_get_all.return_value = services
|
result = self.host_api.service_get_all(self.ctxt)
|
||||||
# Test no filters
|
mock_service_get_all.assert_called_once_with(self.ctxt,
|
||||||
result = self.host_api.service_get_all(self.ctxt)
|
disabled=None)
|
||||||
mock_service_get_all.assert_called_once_with(self.ctxt,
|
self._compare_objs(result, services)
|
||||||
disabled=None)
|
|
||||||
self._compare_objs(result, services)
|
|
||||||
|
|
||||||
# Test no filters #2
|
# Test no filters #2
|
||||||
mock_service_get_all.reset_mock()
|
mock_service_get_all.reset_mock()
|
||||||
result = self.host_api.service_get_all(self.ctxt, filters={})
|
result = self.host_api.service_get_all(self.ctxt, filters={})
|
||||||
mock_service_get_all.assert_called_once_with(self.ctxt,
|
mock_service_get_all.assert_called_once_with(self.ctxt,
|
||||||
disabled=None)
|
disabled=None)
|
||||||
self._compare_objs(result, services)
|
self._compare_objs(result, services)
|
||||||
|
|
||||||
# Test w/ filter
|
# Test w/ filter
|
||||||
mock_service_get_all.reset_mock()
|
mock_service_get_all.reset_mock()
|
||||||
result = self.host_api.service_get_all(self.ctxt,
|
result = self.host_api.service_get_all(self.ctxt,
|
||||||
filters=dict(host='host2'))
|
filters=dict(host='host2'))
|
||||||
mock_service_get_all.assert_called_once_with(self.ctxt,
|
mock_service_get_all.assert_called_once_with(self.ctxt,
|
||||||
disabled=None)
|
disabled=None)
|
||||||
self._compare_objs(result, [services[1]])
|
self._compare_objs(result, [services[1]])
|
||||||
|
|
||||||
_do_test()
|
@mock.patch('nova.db.api.service_get_all')
|
||||||
|
def test_service_get_all(self, mock_service_get_all):
|
||||||
def test_service_get_all(self):
|
|
||||||
services = [dict(test_service.fake_service,
|
services = [dict(test_service.fake_service,
|
||||||
topic='compute', host='host1'),
|
topic='compute', host='host1'),
|
||||||
dict(test_service.fake_service,
|
dict(test_service.fake_service,
|
||||||
@ -269,77 +270,74 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
exp_service.update(availability_zone='nova', **service)
|
exp_service.update(availability_zone='nova', **service)
|
||||||
exp_services.append(exp_service)
|
exp_services.append(exp_service)
|
||||||
|
|
||||||
@mock.patch.object(self.host_api.db, 'service_get_all')
|
mock_service_get_all.return_value = services
|
||||||
def _do_test(mock_service_get_all):
|
|
||||||
mock_service_get_all.return_value = services
|
|
||||||
|
|
||||||
# Test no filters
|
# Test no filters
|
||||||
result = self.host_api.service_get_all(self.ctxt, set_zones=True)
|
result = self.host_api.service_get_all(self.ctxt, set_zones=True)
|
||||||
mock_service_get_all.assert_called_once_with(self.ctxt,
|
mock_service_get_all.assert_called_once_with(self.ctxt,
|
||||||
disabled=None)
|
disabled=None)
|
||||||
self._compare_objs(result, exp_services)
|
self._compare_objs(result, exp_services)
|
||||||
|
|
||||||
# Test no filters #2
|
# Test no filters #2
|
||||||
mock_service_get_all.reset_mock()
|
mock_service_get_all.reset_mock()
|
||||||
result = self.host_api.service_get_all(self.ctxt, filters={},
|
result = self.host_api.service_get_all(self.ctxt, filters={},
|
||||||
set_zones=True)
|
set_zones=True)
|
||||||
mock_service_get_all.assert_called_once_with(self.ctxt,
|
mock_service_get_all.assert_called_once_with(self.ctxt,
|
||||||
disabled=None)
|
disabled=None)
|
||||||
self._compare_objs(result, exp_services)
|
self._compare_objs(result, exp_services)
|
||||||
|
|
||||||
# Test w/ filter
|
# Test w/ filter
|
||||||
mock_service_get_all.reset_mock()
|
mock_service_get_all.reset_mock()
|
||||||
result = self.host_api.service_get_all(self.ctxt,
|
result = self.host_api.service_get_all(self.ctxt,
|
||||||
filters=dict(host='host2'),
|
filters=dict(host='host2'),
|
||||||
set_zones=True)
|
set_zones=True)
|
||||||
mock_service_get_all.assert_called_once_with(self.ctxt,
|
mock_service_get_all.assert_called_once_with(self.ctxt,
|
||||||
disabled=None)
|
disabled=None)
|
||||||
self._compare_objs(result, [exp_services[1]])
|
self._compare_objs(result, [exp_services[1]])
|
||||||
|
|
||||||
# Test w/ zone filter but no set_zones arg.
|
# Test w/ zone filter but no set_zones arg.
|
||||||
mock_service_get_all.reset_mock()
|
mock_service_get_all.reset_mock()
|
||||||
filters = {'availability_zone': 'nova'}
|
filters = {'availability_zone': 'nova'}
|
||||||
result = self.host_api.service_get_all(self.ctxt,
|
result = self.host_api.service_get_all(self.ctxt,
|
||||||
filters=filters)
|
filters=filters)
|
||||||
mock_service_get_all.assert_called_once_with(self.ctxt,
|
mock_service_get_all.assert_called_once_with(self.ctxt,
|
||||||
disabled=None)
|
disabled=None)
|
||||||
self._compare_objs(result, exp_services)
|
self._compare_objs(result, exp_services)
|
||||||
|
|
||||||
_do_test()
|
@mock.patch(
|
||||||
|
'nova.db.api.service_get_by_compute_host',
|
||||||
|
return_value=test_service.fake_service)
|
||||||
|
def test_service_get_by_compute_host(
|
||||||
|
self, mock_service_get_by_compute_host,
|
||||||
|
):
|
||||||
|
result = self.host_api.service_get_by_compute_host(
|
||||||
|
self.ctxt, 'fake-host')
|
||||||
|
self.assertEqual(test_service.fake_service['id'], result.id)
|
||||||
|
|
||||||
def test_service_get_by_compute_host(self):
|
@mock.patch('nova.db.api.service_get_by_host_and_binary')
|
||||||
@mock.patch.object(self.host_api.db, 'service_get_by_compute_host',
|
@mock.patch('nova.db.api.service_update')
|
||||||
return_value=test_service.fake_service)
|
def test_service_update_by_host_and_binary(
|
||||||
def _do_test(mock_service_get_by_compute_host):
|
self, mock_service_update, mock_service_get_by_host_and_binary,
|
||||||
result = self.host_api.service_get_by_compute_host(self.ctxt,
|
):
|
||||||
'fake-host')
|
|
||||||
self.assertEqual(test_service.fake_service['id'], result.id)
|
|
||||||
|
|
||||||
_do_test()
|
|
||||||
|
|
||||||
def test_service_update_by_host_and_binary(self):
|
|
||||||
host_name = 'fake-host'
|
host_name = 'fake-host'
|
||||||
binary = 'nova-compute'
|
binary = 'nova-compute'
|
||||||
params_to_update = dict(disabled=True)
|
params_to_update = dict(disabled=True)
|
||||||
service_id = 42
|
service_id = 42
|
||||||
expected_result = dict(test_service.fake_service, id=service_id)
|
expected_result = dict(test_service.fake_service, id=service_id)
|
||||||
|
|
||||||
@mock.patch.object(self.host_api, '_update_compute_provider_status')
|
mock_service_get_by_host_and_binary.return_value = expected_result
|
||||||
@mock.patch.object(self.host_api.db, 'service_get_by_host_and_binary')
|
mock_service_update.return_value = expected_result
|
||||||
@mock.patch.object(self.host_api.db, 'service_update')
|
|
||||||
def _do_test(mock_service_update, mock_service_get_by_host_and_binary,
|
|
||||||
mock_update_compute_provider_status):
|
|
||||||
mock_service_get_by_host_and_binary.return_value = expected_result
|
|
||||||
mock_service_update.return_value = expected_result
|
|
||||||
|
|
||||||
|
with mock.patch.object(
|
||||||
|
self.host_api, '_update_compute_provider_status',
|
||||||
|
) as mock_update_compute_provider_status:
|
||||||
result = self.host_api.service_update_by_host_and_binary(
|
result = self.host_api.service_update_by_host_and_binary(
|
||||||
self.ctxt, host_name, binary, params_to_update)
|
self.ctxt, host_name, binary, params_to_update)
|
||||||
|
|
||||||
self._compare_obj(result, expected_result)
|
self._compare_obj(result, expected_result)
|
||||||
mock_update_compute_provider_status.assert_called_once_with(
|
mock_update_compute_provider_status.assert_called_once_with(
|
||||||
self.ctxt, test.MatchType(objects.Service))
|
self.ctxt, test.MatchType(objects.Service))
|
||||||
|
|
||||||
_do_test()
|
|
||||||
|
|
||||||
@mock.patch('nova.compute.api.HostAPI._update_compute_provider_status',
|
@mock.patch('nova.compute.api.HostAPI._update_compute_provider_status',
|
||||||
new_callable=mock.NonCallableMock)
|
new_callable=mock.NonCallableMock)
|
||||||
def test_service_update_no_update_provider_status(self, mock_ucps):
|
def test_service_update_no_update_provider_status(self, mock_ucps):
|
||||||
@ -399,17 +397,13 @@ class ComputeHostAPITestCase(test.TestCase):
|
|||||||
'fake-host')
|
'fake-host')
|
||||||
self.assertEqual(['fake-responses'], result)
|
self.assertEqual(['fake-responses'], result)
|
||||||
|
|
||||||
def test_task_log_get_all(self):
|
@mock.patch('nova.db.api.task_log_get_all', return_value='fake-response')
|
||||||
@mock.patch.object(self.host_api.db, 'task_log_get_all',
|
def test_task_log_get_all(self, mock_task_log_get_all):
|
||||||
return_value='fake-response')
|
result = self.host_api.task_log_get_all(self.ctxt, 'fake-name',
|
||||||
def _do_test(mock_task_log_get_all):
|
'fake-begin', 'fake-end',
|
||||||
result = self.host_api.task_log_get_all(self.ctxt, 'fake-name',
|
host='fake-host',
|
||||||
'fake-begin', 'fake-end',
|
state='fake-state')
|
||||||
host='fake-host',
|
self.assertEqual('fake-response', result)
|
||||||
state='fake-state')
|
|
||||||
self.assertEqual('fake-response', result)
|
|
||||||
|
|
||||||
_do_test()
|
|
||||||
|
|
||||||
@mock.patch.object(objects.CellMappingList, 'get_all',
|
@mock.patch.object(objects.CellMappingList, 'get_all',
|
||||||
return_value=objects.CellMappingList(objects=[
|
return_value=objects.CellMappingList(objects=[
|
||||||
|
@ -81,7 +81,6 @@ class FakeVirtAPITest(VirtAPIBaseTest):
|
|||||||
class FakeCompute(object):
|
class FakeCompute(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.conductor_api = mock.MagicMock()
|
self.conductor_api = mock.MagicMock()
|
||||||
self.db = mock.MagicMock()
|
|
||||||
self._events = []
|
self._events = []
|
||||||
self.instance_events = mock.MagicMock()
|
self.instance_events = mock.MagicMock()
|
||||||
self.instance_events.prepare_for_instance_event.side_effect = \
|
self.instance_events.prepare_for_instance_event.side_effect = \
|
||||||
|
Loading…
Reference in New Issue
Block a user