From 53a7538a84ea2612cd86e6e98887cab7723dcbb2 Mon Sep 17 00:00:00 2001 From: David Scannell Date: Wed, 13 Feb 2013 11:18:04 -0500 Subject: 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 --- nova/tests/scheduler/test_chance_scheduler.py | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'nova/tests/scheduler/test_chance_scheduler.py') 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) -- cgit