summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-01-23 19:33:11 +0000
committerGerrit Code Review <review@openstack.org>2012-01-23 19:33:11 +0000
commit152da40a0651bfbdeb748c249e771c10e716c79c (patch)
tree1f6cf4ec149c3c257d2af1b0ea5b10704b69f5d4
parentba5a60bdaf6697ac52d80b40b763da6c75b6efc7 (diff)
parenta6cae3ce38e763d190e0f9d9680d44c1ecd11711 (diff)
downloadnova-152da40a0651bfbdeb748c249e771c10e716c79c.tar.gz
nova-152da40a0651bfbdeb748c249e771c10e716c79c.tar.xz
nova-152da40a0651bfbdeb748c249e771c10e716c79c.zip
Merge "Add context and request spec to filter_properties"
-rw-r--r--nova/scheduler/distributed_scheduler.py21
-rw-r--r--nova/tests/scheduler/fakes.py12
-rw-r--r--nova/tests/scheduler/test_distributed_scheduler.py19
3 files changed, 28 insertions, 24 deletions
diff --git a/nova/scheduler/distributed_scheduler.py b/nova/scheduler/distributed_scheduler.py
index 172a7f88d..2e54461b8 100644
--- a/nova/scheduler/distributed_scheduler.py
+++ b/nova/scheduler/distributed_scheduler.py
@@ -92,7 +92,7 @@ class DistributedScheduler(driver.Scheduler):
weighted_hosts.append(self._make_weighted_host_from_blob(blob))
else:
# No plan ... better make one.
- weighted_hosts = self._schedule(elevated, "compute", request_spec,
+ weighted_hosts = self._schedule(context, "compute", request_spec,
*args, **kwargs)
if not weighted_hosts:
@@ -135,7 +135,7 @@ class DistributedScheduler(driver.Scheduler):
instance_type = db.instance_type_get(elevated, instance_type_id)
# Now let's grab a possibility
- hosts = self._schedule(elevated, 'compute', request_spec,
+ hosts = self._schedule(context, 'compute', request_spec,
*args, **kwargs)
if not hosts:
raise exception.NoValidHost(reason=_(""))
@@ -151,8 +151,7 @@ class DistributedScheduler(driver.Scheduler):
internal zone information will be encrypted so as not to reveal
anything about our inner layout.
"""
- elevated = context.elevated()
- weighted_hosts = self._schedule(elevated, "compute", request_spec,
+ weighted_hosts = self._schedule(context, "compute", request_spec,
*args, **kwargs)
return [weighted_host.to_dict() for weighted_host in weighted_hosts]
@@ -284,10 +283,11 @@ class DistributedScheduler(driver.Scheduler):
"""
pass
- def _schedule(self, elevated, topic, request_spec, *args, **kwargs):
+ def _schedule(self, context, topic, request_spec, *args, **kwargs):
"""Returns a list of hosts that meet the required specs,
ordered by their fitness.
"""
+ elevated = context.elevated()
if topic != "compute":
msg = _("Scheduler only understands Compute nodes (for now)")
raise NotImplementedError(msg)
@@ -300,17 +300,16 @@ class DistributedScheduler(driver.Scheduler):
raise NotImplementedError(msg)
cost_functions = self.get_cost_functions()
-
- ram_requirement_mb = instance_type['memory_mb']
- disk_requirement_gb = instance_type['local_gb']
-
config_options = self._get_configuration_options()
filter_properties = kwargs.get('filter_properties', {})
- filter_properties.update({'config_options': config_options,
+ filter_properties.update({'context': context,
+ 'request_spec': request_spec,
+ 'config_options': config_options,
'instance_type': instance_type})
- self.populate_filter_properties(request_spec, filter_properties)
+ self.populate_filter_properties(request_spec,
+ filter_properties)
# Find our local list of acceptable hosts by repeatedly
# filtering and weighing our options. Each time we choose a
diff --git a/nova/tests/scheduler/fakes.py b/nova/tests/scheduler/fakes.py
index db50193a9..8abf68e52 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 ca498f7aa..8e586ac8b 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):