Add context and request spec to filter_properties

Change-Id: Iebece7fac9c980ef32e37a8b01b505340e5d12b0
This commit is contained in:
Vishvananda Ishaya
2012-01-20 15:46:33 -08:00
parent 2fdb334091
commit 5d612effc6
3 changed files with 28 additions and 24 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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):