summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorDan Smith <danms@us.ibm.com>2013-01-03 09:17:17 -0800
committerDan Smith <danms@us.ibm.com>2013-01-04 08:37:13 -0800
commitd22b0ca2402d9625cea7460050e3fc77e7e2ea85 (patch)
tree67516c35b22edba479479afa2f0144e5cc665412 /nova/tests
parent269aa32a09af6200b4cafecf1cafb8ca34322b04 (diff)
Move instance_get_*() to conductor
This patch adds conductor support for instance_get_all_by_filters(), and supports the following APIs through that method: - instance_get_all() - instance_get_all_by_host() - instance_get_all_by_filters() Further, it adds support for the following APIs: - instance_get_all_hung_in_rebooting() - instance_get_active_by_window() It also makes compute/manager use conductor for these operations, with one exception. Currently, ComputeManager.init_host () lists all instances associated with the host, which may happen before a conductor service is available. This will be handled separately due to the sequencing concerns. Related to bp/no-db-compute-manager Change-Id: I0dd346fd632aa15cd301386bc392502b95709529
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/compute/test_compute.py17
-rw-r--r--nova/tests/conductor/test_conductor.py55
-rw-r--r--nova/tests/test_imagecache.py7
3 files changed, 62 insertions, 17 deletions
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index 3983dc8bb..b11add027 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -2720,10 +2720,10 @@ class ComputeTestCase(BaseTestCase):
self.flags(running_deleted_instance_timeout=3600,
running_deleted_instance_action='reap')
- self.mox.StubOutWithMock(self.compute.db, "instance_get_all_by_host")
- self.compute.db.instance_get_all_by_host(admin_context,
- self.compute.host
- ).AndReturn([instance])
+ self.mox.StubOutWithMock(self.compute.conductor_api,
+ "instance_get_all_by_host")
+ self.compute.conductor_api.instance_get_all_by_host(
+ admin_context, self.compute.host).AndReturn([instance])
bdms = []
@@ -2759,9 +2759,10 @@ class ComputeTestCase(BaseTestCase):
timeutils.is_older_than('sometimeago',
CONF.running_deleted_instance_timeout).AndReturn(True)
- self.mox.StubOutWithMock(self.compute.db, "instance_get_all_by_host")
- self.compute.db.instance_get_all_by_host('context',
- 'host').AndReturn(
+ self.mox.StubOutWithMock(self.compute.conductor_api,
+ "instance_get_all_by_host")
+ self.compute.conductor_api.instance_get_all_by_host('context',
+ 'host').AndReturn(
[instance1,
instance2])
self.mox.ReplayAll()
@@ -2802,7 +2803,7 @@ class ComputeTestCase(BaseTestCase):
self.assertEqual(instance, call_info['expected_instance'])
call_info['get_nw_info'] += 1
- self.stubs.Set(db, 'instance_get_all_by_host',
+ self.stubs.Set(self.compute.conductor_api, 'instance_get_all_by_host',
fake_instance_get_all_by_host)
self.stubs.Set(db, 'instance_get_by_uuid',
fake_instance_get_by_uuid)
diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py
index 23930770a..a7caa3ac9 100644
--- a/nova/tests/conductor/test_conductor.py
+++ b/nova/tests/conductor/test_conductor.py
@@ -116,13 +116,6 @@ class _BaseTestCase(object):
self.assertEqual(orig_instance['name'],
copy_instance['name'])
- def test_instance_get_all_by_host(self):
- orig_instance = jsonutils.to_primitive(self._create_fake_instance())
- all_instances = self.conductor.instance_get_all_by_host(
- self.context, orig_instance['host'])
- self.assertEqual(orig_instance['name'],
- all_instances[0]['name'])
-
def _setup_aggregate_with_host(self):
aggregate_ref = db.aggregate_create(self.context.elevated(),
{'name': 'foo', 'availability_zone': 'foo'})
@@ -279,6 +272,22 @@ class _BaseTestCase(object):
self.context, fake_inst)
self.assertEqual(result, 'fake-result')
+ def test_instance_get_all_hung_in_rebooting(self):
+ self.mox.StubOutWithMock(db, 'instance_get_all_hung_in_rebooting')
+ db.instance_get_all_hung_in_rebooting(self.context, 123)
+ self.mox.ReplayAll()
+ self.conductor.instance_get_all_hung_in_rebooting(self.context, 123)
+
+ def test_instance_get_active_by_window(self):
+ self.mox.StubOutWithMock(db, 'instance_get_active_by_window_joined')
+ db.instance_get_active_by_window_joined(self.context, 'fake-begin',
+ 'fake-end', 'fake-proj',
+ 'fake-host')
+ self.mox.ReplayAll()
+ self.conductor.instance_get_active_by_window(self.context,
+ 'fake-begin', 'fake-end',
+ 'fake-proj', 'fake-host')
+
class ConductorTestCase(_BaseTestCase, test.TestCase):
"""Conductor Manager Tests"""
@@ -333,6 +342,15 @@ class ConductorTestCase(_BaseTestCase, test.TestCase):
instance=fake_inst,
volume_id='fake-volume')
+ def test_instance_get_all_by_filters(self):
+ filters = {'foo': 'bar'}
+ self.mox.StubOutWithMock(db, 'instance_get_all_by_filters')
+ db.instance_get_all_by_filters(self.context, filters,
+ 'fake-key', 'fake-sort')
+ self.mox.ReplayAll()
+ self.conductor.instance_get_all_by_filters(self.context, filters,
+ 'fake-key', 'fake-sort')
+
class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase):
"""Conductor RPC API Tests"""
@@ -385,6 +403,15 @@ class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase):
instance=fake_inst,
volume_id='fake-volume')
+ def test_instance_get_all_by_filters(self):
+ filters = {'foo': 'bar'}
+ self.mox.StubOutWithMock(db, 'instance_get_all_by_filters')
+ db.instance_get_all_by_filters(self.context, filters,
+ 'fake-key', 'fake-sort')
+ self.mox.ReplayAll()
+ self.conductor.instance_get_all_by_filters(self.context, filters,
+ 'fake-key', 'fake-sort')
+
class ConductorAPITestCase(_BaseTestCase, test.TestCase):
"""Conductor API Tests"""
@@ -450,6 +477,20 @@ class ConductorAPITestCase(_BaseTestCase, test.TestCase):
self.conductor.block_device_mapping_destroy_by_instance_and_volume(
self.context, fake_inst, 'fake-volume')
+ def test_instance_get_all(self):
+ self.mox.StubOutWithMock(db, 'instance_get_all_by_filters')
+ db.instance_get_all_by_filters(self.context, {}, 'created_at', 'desc')
+ db.instance_get_all_by_filters(self.context, {'host': 'fake-host'},
+ 'created_at', 'desc')
+ db.instance_get_all_by_filters(self.context, {'name': 'fake-inst'},
+ 'updated_at', 'asc')
+ self.mox.ReplayAll()
+ self.conductor.instance_get_all(self.context)
+ self.conductor.instance_get_all_by_host(self.context, 'fake-host')
+ self.conductor.instance_get_all_by_filters(self.context,
+ {'name': 'fake-inst'},
+ 'updated_at', 'asc')
+
class ConductorLocalAPITestCase(ConductorAPITestCase):
"""Conductor LocalAPI Tests"""
diff --git a/nova/tests/test_imagecache.py b/nova/tests/test_imagecache.py
index bfa948ce5..e3f934b8b 100644
--- a/nova/tests/test_imagecache.py
+++ b/nova/tests/test_imagecache.py
@@ -28,6 +28,7 @@ from nova import test
from nova.compute import manager as compute_manager
from nova.compute import vm_states
+from nova import conductor
from nova import db
from nova.openstack.common import cfg
from nova.openstack.common import importutils
@@ -929,7 +930,7 @@ class ImageCacheManagerTestCase(test.TestCase):
def test_compute_manager(self):
was = {'called': False}
- def fake_get_all(context):
+ def fake_get_all(context, *args, **kwargs):
was['called'] = True
return [{'image_ref': '1',
'host': CONF.host,
@@ -947,7 +948,9 @@ class ImageCacheManagerTestCase(test.TestCase):
with utils.tempdir() as tmpdir:
self.flags(instances_path=tmpdir)
- self.stubs.Set(db, 'instance_get_all', fake_get_all)
+ self.stubs.Set(db, 'instance_get_all_by_filters', fake_get_all)
compute = importutils.import_object(CONF.compute_manager)
+ self.flags(use_local=True, group='conductor')
+ compute.conductor_api = conductor.API()
compute._run_image_cache_manager_pass(None)
self.assertTrue(was['called'])