From a6cae3ce38e763d190e0f9d9680d44c1ecd11711 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 20 Jan 2012 15:46:33 -0800 Subject: Add context and request spec to filter_properties Change-Id: Iebece7fac9c980ef32e37a8b01b505340e5d12b0 --- nova/tests/scheduler/fakes.py | 12 +++++++----- nova/tests/scheduler/test_distributed_scheduler.py | 19 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/scheduler/fakes.py b/nova/tests/scheduler/fakes.py index f607b44fa..998f9a60b 100644 --- a/nova/tests/scheduler/fakes.py +++ b/nova/tests/scheduler/fakes.py @@ -16,6 +16,8 @@ Fakes For Scheduler tests. """ +import mox + from nova import db from nova.scheduler import distributed_scheduler from nova.scheduler import host_manager @@ -99,9 +101,9 @@ class FakeComputeAPI(object): pass -def mox_host_manager_db_calls(mox, context): - mox.StubOutWithMock(db, 'compute_node_get_all') - mox.StubOutWithMock(db, 'instance_get_all') +def mox_host_manager_db_calls(mock, context): + mock.StubOutWithMock(db, 'compute_node_get_all') + mock.StubOutWithMock(db, 'instance_get_all') - db.compute_node_get_all(context).AndReturn(COMPUTE_NODES) - db.instance_get_all(context).AndReturn(INSTANCES) + db.compute_node_get_all(mox.IgnoreArg()).AndReturn(COMPUTE_NODES) + db.instance_get_all(mox.IgnoreArg()).AndReturn(INSTANCES) diff --git a/nova/tests/scheduler/test_distributed_scheduler.py b/nova/tests/scheduler/test_distributed_scheduler.py index 3e909d005..86d57df80 100644 --- a/nova/tests/scheduler/test_distributed_scheduler.py +++ b/nova/tests/scheduler/test_distributed_scheduler.py @@ -18,7 +18,6 @@ Tests For Distributed Scheduler. import json -from nova.compute import api as compute_api from nova import context from nova import db from nova import exception @@ -165,32 +164,36 @@ class DistributedSchedulerTestCase(test.TestCase): a non-admin context. DB actions should work.""" self.was_admin = False - def fake_schedule(context, *args, **kwargs): + def fake_get(context, *args, **kwargs): # make sure this is called with admin context, even though # we're using user context below self.was_admin = context.is_admin - return [] + return {} sched = fakes.FakeDistributedScheduler() - self.stubs.Set(sched, '_schedule', fake_schedule) + self.stubs.Set(sched.host_manager, 'get_all_host_states', fake_get) fake_context = context.RequestContext('user', 'project') + request_spec = {'instance_type': {'memory_mb': 1, 'local_gb': 1}, + 'instance_properties': {'project_id': 1}} self.assertRaises(exception.NoValidHost, sched.schedule_run_instance, - fake_context, {}) + fake_context, request_spec) self.assertTrue(self.was_admin) def test_schedule_bad_topic(self): """Parameter checking.""" sched = fakes.FakeDistributedScheduler() - self.assertRaises(NotImplementedError, sched._schedule, None, "foo", - {}) + fake_context = context.RequestContext('user', 'project') + self.assertRaises(NotImplementedError, sched._schedule, fake_context, + "foo", {}) def test_schedule_no_instance_type(self): """Parameter checking.""" sched = fakes.FakeDistributedScheduler() request_spec = {'instance_properties': {}} - self.assertRaises(NotImplementedError, sched._schedule, None, + fake_context = context.RequestContext('user', 'project') + self.assertRaises(NotImplementedError, sched._schedule, fake_context, "compute", request_spec=request_spec) def test_schedule_happy_day(self): -- cgit