From 4f3c5411d92d488b78f06212912fc7ae6d225b79 Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Mon, 17 Jun 2013 10:36:46 -0400 Subject: New select_destinations scheduler call select_destinations returns a list of (host, node) tuples that satisfy the request_spec and filter_properties passed to it. This will allow the conductor to get a list of destinations for workflows such as creating or resizing an instance and then handle the orchestration itself. part of bp query-scheduler Change-Id: I1a42cea64dbad67562d7efe8d759e6efb5ec8121 --- nova/tests/scheduler/test_chance_scheduler.py | 45 +++++++++++++++++++++++++++ 1 file changed, 45 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 ba1701e93..4e52464ec 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -197,3 +197,48 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): self.stubs.Set(self.driver, '_schedule', _return_no_host) self.assertRaises(exception.NoValidHost, self.driver.select_hosts, self.context, {}, {}) + + def test_select_destinations(self): + ctxt = context.RequestContext('fake', 'fake', False) + ctxt_elevated = 'fake-context-elevated' + request_spec = {'num_instances': 2} + + self.mox.StubOutWithMock(ctxt, 'elevated') + self.mox.StubOutWithMock(self.driver, 'hosts_up') + self.mox.StubOutWithMock(random, 'choice') + + hosts_full = ['host1', 'host2', 'host3', 'host4'] + + ctxt.elevated().AndReturn(ctxt_elevated) + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(hosts_full) + random.choice(hosts_full).AndReturn('host3') + + ctxt.elevated().AndReturn(ctxt_elevated) + self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn(hosts_full) + random.choice(hosts_full).AndReturn('host2') + + self.mox.ReplayAll() + dests = self.driver.select_destinations(ctxt, request_spec, {}) + self.assertEquals(2, len(dests)) + (host, node) = dests[0] + self.assertEquals('host3', host) + self.assertEquals(None, node) + (host, node) = dests[1] + self.assertEquals('host2', host) + self.assertEquals(None, node) + + def test_select_destinations_no_valid_host(self): + + def _return_no_host(*args, **kwargs): + return [] + + self.mox.StubOutWithMock(self.driver, 'hosts_up') + self.driver.hosts_up(mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn([1, 2]) + self.stubs.Set(self.driver, '_filter_hosts', _return_no_host) + self.mox.ReplayAll() + + request_spec = {'num_instances': 1} + self.assertRaises(exception.NoValidHost, + self.driver.select_destinations, self.context, + request_spec, {}) -- cgit