summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorChris Behrens <cbehrens@codestud.com>2013-01-14 02:06:39 +0000
committerChris Behrens <cbehrens@codestud.com>2013-01-14 18:28:37 +0000
commit7e7bcc4f080c824c94c41485e29e365473661fa3 (patch)
tree40659e8a41af38e7304234f5a03b7639a2a04226 /nova/tests
parentca4b1303804e94f10f0e4e6c4a9e09c049efd1ee (diff)
Fix uses of service_get_all_compute_by_host
There should never be more than 1 service entry for the same topic and host, however this method returns a list of services. All callers of this method except for 1 already account for there being only 1 service entry for a particular 'compute' host and only use the first entry in the return list. This patch renames the DB API call to be 'service_get_by_compute_host' and returns a single entry. All uses of the old method are adjusted accordingly. Change-Id: I0e0ef62f5d2e71efe756940d9fdd98aa02fef216
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/compute/test_host_api.py24
-rw-r--r--nova/tests/compute/test_resource_tracker.py16
-rw-r--r--nova/tests/conductor/test_conductor.py34
-rw-r--r--nova/tests/integrated/test_api_samples.py4
-rw-r--r--nova/tests/scheduler/test_scheduler.py113
5 files changed, 98 insertions, 93 deletions
diff --git a/nova/tests/compute/test_host_api.py b/nova/tests/compute/test_host_api.py
index f00245d1e..0af1d6766 100644
--- a/nova/tests/compute/test_host_api.py
+++ b/nova/tests/compute/test_host_api.py
@@ -57,19 +57,19 @@ class HostApiTestCase(test.TestCase):
given our fake input.
"""
ctx = context.get_admin_context()
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
host_name = 'host_c1'
- db.service_get_all_compute_by_host(ctx, host_name).AndReturn(
- [{'host': 'fake_host',
- 'compute_node': [
- {'vcpus': 4,
- 'vcpus_used': 1,
- 'memory_mb': 8192,
- 'memory_mb_used': 2048,
- 'local_gb': 1024,
- 'local_gb_used': 648}
- ]
- }])
+ db.service_get_by_compute_host(ctx, host_name).AndReturn(
+ {'host': 'fake_host',
+ 'compute_node': [
+ {'vcpus': 4,
+ 'vcpus_used': 1,
+ 'memory_mb': 8192,
+ 'memory_mb_used': 2048,
+ 'local_gb': 1024,
+ 'local_gb_used': 648}
+ ]
+ })
self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
db.instance_get_all_by_host(ctx, 'fake_host').AndReturn(
[{'project_id': 42,
diff --git a/nova/tests/compute/test_resource_tracker.py b/nova/tests/compute/test_resource_tracker.py
index 3bfd51461..53d92a13f 100644
--- a/nova/tests/compute/test_resource_tracker.py
+++ b/nova/tests/compute/test_resource_tracker.py
@@ -297,8 +297,8 @@ class MissingComputeNodeTestCase(BaseTestCase):
super(MissingComputeNodeTestCase, self).setUp()
self.tracker = self._tracker()
- self.stubs.Set(db, 'service_get_all_compute_by_host',
- self._fake_service_get_all_compute_by_host)
+ self.stubs.Set(db, 'service_get_by_compute_host',
+ self._fake_service_get_by_compute_host)
self.stubs.Set(db, 'compute_node_create',
self._fake_create_compute_node)
@@ -306,10 +306,10 @@ class MissingComputeNodeTestCase(BaseTestCase):
self.created = True
return self._create_compute_node()
- def _fake_service_get_all_compute_by_host(self, ctx, host):
+ def _fake_service_get_by_compute_host(self, ctx, host):
# return a service with no joined compute
service = self._create_service()
- return [service]
+ return service
def test_create_compute_node(self):
self.tracker.update_available_resource(self.context)
@@ -330,8 +330,8 @@ class BaseTrackerTestCase(BaseTestCase):
self.tracker = self._tracker()
self._migrations = {}
- self.stubs.Set(db, 'service_get_all_compute_by_host',
- self._fake_service_get_all_compute_by_host)
+ self.stubs.Set(db, 'service_get_by_compute_host',
+ self._fake_service_get_by_compute_host)
self.stubs.Set(db, 'compute_node_update',
self._fake_compute_node_update)
self.stubs.Set(db, 'migration_update',
@@ -342,10 +342,10 @@ class BaseTrackerTestCase(BaseTestCase):
self.tracker.update_available_resource(self.context)
self.limits = self._limits()
- def _fake_service_get_all_compute_by_host(self, ctx, host):
+ def _fake_service_get_by_compute_host(self, ctx, host):
self.compute = self._create_compute_node()
self.service = self._create_service(host, compute=self.compute)
- return [self.service]
+ return self.service
def _fake_compute_node_update(self, ctx, compute_node_id, values,
prune_stats=False):
diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py
index 46fadf4f0..cc3dbfcc0 100644
--- a/nova/tests/conductor/test_conductor.py
+++ b/nova/tests/conductor/test_conductor.py
@@ -451,12 +451,16 @@ class ConductorTestCase(_BaseTestCase, test.TestCase):
self.conductor.instance_get_all_by_filters(self.context, filters,
'fake-key', 'fake-sort')
- def _test_stubbed(self, name, dbargs, condargs):
+ def _test_stubbed(self, name, dbargs, condargs,
+ db_result_listified=False):
self.mox.StubOutWithMock(db, name)
getattr(db, name)(self.context, *dbargs).AndReturn('fake-result')
self.mox.ReplayAll()
result = self.conductor.service_get_all_by(self.context, **condargs)
- self.assertEqual(result, 'fake-result')
+ if db_result_listified:
+ self.assertEqual(['fake-result'], result)
+ else:
+ self.assertEqual('fake-result', result)
def test_service_get_all(self):
self._test_stubbed('service_get_all', (), {})
@@ -476,10 +480,11 @@ class ConductorTestCase(_BaseTestCase, test.TestCase):
('host',),
dict(host='host'))
- def test_service_get_all_compute_by_host(self):
- self._test_stubbed('service_get_all_compute_by_host',
+ def test_service_get_by_compute_host(self):
+ self._test_stubbed('service_get_by_compute_host',
('host',),
- dict(topic='compute', host='host'))
+ dict(topic='compute', host='host'),
+ db_result_listified=True)
def test_service_get_by_args(self):
self._test_stubbed('service_get_by_args',
@@ -547,12 +552,16 @@ class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase):
self.conductor.instance_get_all_by_filters(self.context, filters,
'fake-key', 'fake-sort')
- def _test_stubbed(self, name, dbargs, condargs):
+ def _test_stubbed(self, name, dbargs, condargs,
+ db_result_listified=False):
self.mox.StubOutWithMock(db, name)
getattr(db, name)(self.context, *dbargs).AndReturn('fake-result')
self.mox.ReplayAll()
result = self.conductor.service_get_all_by(self.context, **condargs)
- self.assertEqual(result, 'fake-result')
+ if db_result_listified:
+ self.assertEqual(['fake-result'], result)
+ else:
+ self.assertEqual('fake-result', result)
def test_service_get_all(self):
self._test_stubbed('service_get_all', (), {})
@@ -572,10 +581,11 @@ class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase):
('host',),
dict(host='host'))
- def test_service_get_all_compute_by_host(self):
- self._test_stubbed('service_get_all_compute_by_host',
+ def test_service_get_by_compute_host(self):
+ self._test_stubbed('service_get_by_compute_host',
('host',),
- dict(topic='compute', host='host'))
+ dict(topic='compute', host='host'),
+ db_result_listified=True)
class ConductorAPITestCase(_BaseTestCase, test.TestCase):
@@ -681,8 +691,8 @@ class ConductorAPITestCase(_BaseTestCase, test.TestCase):
def test_service_get_all_by_host(self):
self._test_stubbed('service_get_all_by_host', 'host')
- def test_service_get_all_compute_by_host(self):
- self._test_stubbed('service_get_all_compute_by_host', 'host')
+ def test_service_get_by_compute_host(self):
+ self._test_stubbed('service_get_by_compute_host', 'host')
def test_service_create(self):
self._test_stubbed('service_create', {})
diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py
index 5bdaa977a..0fb0e9107 100644
--- a/nova/tests/integrated/test_api_samples.py
+++ b/nova/tests/integrated/test_api_samples.py
@@ -2091,8 +2091,8 @@ class AdminActionsSamplesJsonTest(ServersSampleBase):
hypervisor_type='bar',
hypervisor_version='1',
disabled=False)
- return [{'compute_node': [service]}]
- self.stubs.Set(db, "service_get_all_compute_by_host", fake_get_compute)
+ return {'compute_node': [service]}
+ self.stubs.Set(db, "service_get_by_compute_host", fake_get_compute)
response = self._do_post('servers/%s/action' % self.uuid,
'admin-actions-live-migrate',
diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py
index ceea74e70..dd5b0ae32 100644
--- a/nova/tests/scheduler/test_scheduler.py
+++ b/nova/tests/scheduler/test_scheduler.py
@@ -111,13 +111,13 @@ class SchedulerManagerTestCase(test.TestCase):
def test_show_host_resources(self):
host = 'fake_host'
- computes = [{'host': host,
- 'compute_node': [{'vcpus': 4,
- 'vcpus_used': 2,
- 'memory_mb': 1024,
- 'memory_mb_used': 512,
- 'local_gb': 1024,
- 'local_gb_used': 512}]}]
+ compute_node = {'host': host,
+ 'compute_node': [{'vcpus': 4,
+ 'vcpus_used': 2,
+ 'memory_mb': 1024,
+ 'memory_mb_used': 512,
+ 'local_gb': 1024,
+ 'local_gb_used': 512}]}
instances = [{'project_id': 'project1',
'vcpus': 1,
'memory_mb': 128,
@@ -134,11 +134,11 @@ class SchedulerManagerTestCase(test.TestCase):
'root_gb': 256,
'ephemeral_gb': 0}]
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
- db.service_get_all_compute_by_host(self.context, host).AndReturn(
- computes)
+ db.service_get_by_compute_host(self.context, host).AndReturn(
+ compute_node)
db.instance_get_all_by_host(self.context, host).AndReturn(instances)
self.mox.ReplayAll()
@@ -338,8 +338,6 @@ class SchedulerTestCase(test.TestCase):
block_migration = False
disk_over_commit = False
instance = jsonutils.to_primitive(self._live_migration_instance())
- instance_id = instance['id']
- instance_uuid = instance['uuid']
self.driver._live_migration_src_check(self.context, instance)
self.driver._live_migration_dest_check(self.context, instance, dest)
@@ -362,7 +360,7 @@ class SchedulerTestCase(test.TestCase):
# Test live migration when all checks pass.
self.mox.StubOutWithMock(servicegroup.API, 'service_is_up')
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
self.mox.StubOutWithMock(rpc, 'call')
self.mox.StubOutWithMock(rpc, 'cast')
@@ -373,34 +371,32 @@ class SchedulerTestCase(test.TestCase):
block_migration = True
disk_over_commit = True
instance = jsonutils.to_primitive(self._live_migration_instance())
- instance_id = instance['id']
- instance_uuid = instance['uuid']
# Source checks
- db.service_get_all_compute_by_host(self.context,
- instance['host']).AndReturn(['fake_service2'])
+ db.service_get_by_compute_host(self.context,
+ instance['host']).AndReturn('fake_service2')
self.servicegroup_api.service_is_up('fake_service2').AndReturn(True)
# Destination checks (compute is up, enough memory, disk)
- db.service_get_all_compute_by_host(self.context,
- dest).AndReturn(['fake_service3'])
+ db.service_get_by_compute_host(self.context,
+ dest).AndReturn('fake_service3')
self.servicegroup_api.service_is_up('fake_service3').AndReturn(True)
# assert_compute_node_has_enough_memory()
- db.service_get_all_compute_by_host(self.context, dest).AndReturn(
- [{'compute_node': [{'memory_mb': 2048,
- 'hypervisor_version': 1}]}])
+ db.service_get_by_compute_host(self.context, dest).AndReturn(
+ {'compute_node': [{'memory_mb': 2048,
+ 'hypervisor_version': 1}]})
db.instance_get_all_by_host(self.context, dest).AndReturn(
[dict(memory_mb=256), dict(memory_mb=512)])
# Common checks (same hypervisor, etc)
- db.service_get_all_compute_by_host(self.context, dest).AndReturn(
- [{'compute_node': [{'hypervisor_type': 'xen',
- 'hypervisor_version': 1}]}])
- db.service_get_all_compute_by_host(self.context,
+ db.service_get_by_compute_host(self.context, dest).AndReturn(
+ {'compute_node': [{'hypervisor_type': 'xen',
+ 'hypervisor_version': 1}]})
+ db.service_get_by_compute_host(self.context,
instance['host']).AndReturn(
- [{'compute_node': [{'hypervisor_type': 'xen',
- 'hypervisor_version': 1,
- 'cpu_info': 'fake_cpu_info'}]}])
+ {'compute_node': [{'hypervisor_type': 'xen',
+ 'hypervisor_version': 1,
+ 'cpu_info': 'fake_cpu_info'}]})
rpc.call(self.context, "compute.fake_host2",
{"method": 'check_can_live_migrate_destination',
@@ -440,7 +436,7 @@ class SchedulerTestCase(test.TestCase):
# Raise exception when src compute node is does not exist.
self.mox.StubOutWithMock(servicegroup.API, 'service_is_up')
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
dest = 'fake_host2'
block_migration = False
@@ -448,9 +444,9 @@ class SchedulerTestCase(test.TestCase):
instance = self._live_migration_instance()
# Compute down
- db.service_get_all_compute_by_host(self.context,
+ db.service_get_by_compute_host(self.context,
instance['host']).AndRaise(
- exception.NotFound())
+ exception.ComputeHostNotFound(host='fake'))
self.mox.ReplayAll()
self.assertRaises(exception.ComputeServiceUnavailable,
@@ -463,7 +459,7 @@ class SchedulerTestCase(test.TestCase):
# Raise exception when src compute node is not alive.
self.mox.StubOutWithMock(servicegroup.API, 'service_is_up')
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
dest = 'fake_host2'
block_migration = False
@@ -471,8 +467,8 @@ class SchedulerTestCase(test.TestCase):
instance = self._live_migration_instance()
# Compute down
- db.service_get_all_compute_by_host(self.context,
- instance['host']).AndReturn(['fake_service2'])
+ db.service_get_by_compute_host(self.context,
+ instance['host']).AndReturn('fake_service2')
self.servicegroup_api.service_is_up('fake_service2').AndReturn(False)
self.mox.ReplayAll()
@@ -486,7 +482,7 @@ class SchedulerTestCase(test.TestCase):
# Raise exception when dest compute node is not alive.
self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
self.mox.StubOutWithMock(servicegroup.API, 'service_is_up')
dest = 'fake_host2'
@@ -495,8 +491,8 @@ class SchedulerTestCase(test.TestCase):
instance = self._live_migration_instance()
self.driver._live_migration_src_check(self.context, instance)
- db.service_get_all_compute_by_host(self.context,
- dest).AndReturn(['fake_service3'])
+ db.service_get_by_compute_host(self.context,
+ dest).AndReturn('fake_service3')
# Compute is down
self.servicegroup_api.service_is_up('fake_service3').AndReturn(False)
@@ -511,17 +507,16 @@ class SchedulerTestCase(test.TestCase):
# Confirms exception raises in case dest and src is same host.
self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
self.mox.StubOutWithMock(servicegroup.API, 'service_is_up')
block_migration = False
- disk_over_commit = False
instance = self._live_migration_instance()
# make dest same as src
dest = instance['host']
self.driver._live_migration_src_check(self.context, instance)
- db.service_get_all_compute_by_host(self.context,
- dest).AndReturn(['fake_service3'])
+ db.service_get_by_compute_host(self.context,
+ dest).AndReturn('fake_service3')
self.servicegroup_api.service_is_up('fake_service3').AndReturn(True)
self.mox.ReplayAll()
@@ -535,7 +530,7 @@ class SchedulerTestCase(test.TestCase):
# Confirms exception raises when dest doesn't have enough memory.
self.mox.StubOutWithMock(self.driver, '_live_migration_src_check')
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
self.mox.StubOutWithMock(servicegroup.API, 'service_is_up')
self.mox.StubOutWithMock(self.driver, '_get_compute_info')
self.mox.StubOutWithMock(db, 'instance_get_all_by_host')
@@ -546,8 +541,8 @@ class SchedulerTestCase(test.TestCase):
instance = self._live_migration_instance()
self.driver._live_migration_src_check(self.context, instance)
- db.service_get_all_compute_by_host(self.context,
- dest).AndReturn(['fake_service3'])
+ db.service_get_by_compute_host(self.context,
+ dest).AndReturn('fake_service3')
self.servicegroup_api.service_is_up('fake_service3').AndReturn(True)
self.driver._get_compute_info(self.context, dest).AndReturn(
@@ -569,7 +564,7 @@ class SchedulerTestCase(test.TestCase):
self.mox.StubOutWithMock(rpc, 'queue_get_for')
self.mox.StubOutWithMock(rpc, 'call')
self.mox.StubOutWithMock(rpc, 'cast')
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
dest = 'fake_host2'
block_migration = False
@@ -579,13 +574,13 @@ class SchedulerTestCase(test.TestCase):
self.driver._live_migration_src_check(self.context, instance)
self.driver._live_migration_dest_check(self.context, instance, dest)
- db.service_get_all_compute_by_host(self.context, dest).AndReturn(
- [{'compute_node': [{'hypervisor_type': 'xen',
- 'hypervisor_version': 1}]}])
- db.service_get_all_compute_by_host(self.context,
+ db.service_get_by_compute_host(self.context, dest).AndReturn(
+ {'compute_node': [{'hypervisor_type': 'xen',
+ 'hypervisor_version': 1}]})
+ db.service_get_by_compute_host(self.context,
instance['host']).AndReturn(
- [{'compute_node': [{'hypervisor_type': 'not-xen',
- 'hypervisor_version': 1}]}])
+ {'compute_node': [{'hypervisor_type': 'not-xen',
+ 'hypervisor_version': 1}]})
self.mox.ReplayAll()
self.assertRaises(exception.InvalidHypervisorType,
@@ -601,7 +596,7 @@ class SchedulerTestCase(test.TestCase):
self.mox.StubOutWithMock(rpc, 'queue_get_for')
self.mox.StubOutWithMock(rpc, 'call')
self.mox.StubOutWithMock(rpc, 'cast')
- self.mox.StubOutWithMock(db, 'service_get_all_compute_by_host')
+ self.mox.StubOutWithMock(db, 'service_get_by_compute_host')
dest = 'fake_host2'
block_migration = False
@@ -611,13 +606,13 @@ class SchedulerTestCase(test.TestCase):
self.driver._live_migration_src_check(self.context, instance)
self.driver._live_migration_dest_check(self.context, instance, dest)
- db.service_get_all_compute_by_host(self.context, dest).AndReturn(
- [{'compute_node': [{'hypervisor_type': 'xen',
- 'hypervisor_version': 1}]}])
- db.service_get_all_compute_by_host(self.context,
+ db.service_get_by_compute_host(self.context, dest).AndReturn(
+ {'compute_node': [{'hypervisor_type': 'xen',
+ 'hypervisor_version': 1}]})
+ db.service_get_by_compute_host(self.context,
instance['host']).AndReturn(
- [{'compute_node': [{'hypervisor_type': 'xen',
- 'hypervisor_version': 2}]}])
+ {'compute_node': [{'hypervisor_type': 'xen',
+ 'hypervisor_version': 2}]})
self.mox.ReplayAll()
self.assertRaises(exception.DestinationHypervisorTooOld,
self.driver.schedule_live_migration, self.context,