diff options
author | David Scannell <dscannell@gridcentric.com> | 2013-02-13 11:18:04 -0500 |
---|---|---|
committer | Hans Lindgren <hanlind@kth.se> | 2013-02-18 15:00:18 +0100 |
commit | 53a7538a84ea2612cd86e6e98887cab7723dcbb2 (patch) | |
tree | 70d4f21d6b944ec8295dc786b7d3925ca9314db8 /nova/tests/scheduler/test_chance_scheduler.py | |
parent | 931515378cfb893a8d15d06b25216fe9242f53b6 (diff) | |
download | nova-53a7538a84ea2612cd86e6e98887cab7723dcbb2.tar.gz nova-53a7538a84ea2612cd86e6e98887cab7723dcbb2.tar.xz nova-53a7538a84ea2612cd86e6e98887cab7723dcbb2.zip |
Add select_hosts to scheduler manager rpc
This adds a select_hosts(...) method to the scheduler manager
rpc that allows other services to query it for the best suited
host instead of relying on it to proxy its messages.
This can be used by extensions that need the scheduler to determine
the best-fit host but want to prepare and send their own messages
to that host.
Change-Id: I5b4760114dfcdb0464fac8ea81f46f7532ac0580
Diffstat (limited to 'nova/tests/scheduler/test_chance_scheduler.py')
-rw-r--r-- | nova/tests/scheduler/test_chance_scheduler.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/nova/tests/scheduler/test_chance_scheduler.py b/nova/tests/scheduler/test_chance_scheduler.py index dcbe86f75..0ee617044 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -165,3 +165,33 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): self.driver.schedule_prep_resize(fake_context, {}, {}, {}, instance, {}, None) self.assertEqual(info['called'], 0) + + def test_select_hosts(self): + ctxt = context.RequestContext('fake', 'fake', False) + ctxt_elevated = 'fake-context-elevated' + fake_args = (1, 2, 3) + instance_opts = {'fake_opt1': 'meow', 'launch_index': -1} + instance1 = {'uuid': 'fake-uuid1'} + instance2 = {'uuid': 'fake-uuid2'} + request_spec = {'instance_uuids': ['fake-uuid1', 'fake-uuid2'], + 'instance_properties': instance_opts} + + self.mox.StubOutWithMock(ctxt, 'elevated') + self.mox.StubOutWithMock(self.driver, 'hosts_up') + self.mox.StubOutWithMock(random, 'random') + + ctxt.elevated().AndReturn(ctxt_elevated) + # instance 1 + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( + ['host1', 'host2', 'host3', 'host4']) + random.random().AndReturn(.5) + + # instance 2 + ctxt.elevated().AndReturn(ctxt_elevated) + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( + ['host1', 'host2', 'host3', 'host4']) + random.random().AndReturn(.2) + + self.mox.ReplayAll() + hosts = self.driver.select_hosts(ctxt, request_spec, {}) + self.assertEquals(['host3', 'host1'], hosts) |