diff options
author | Andrew Laski <andrew.laski@rackspace.com> | 2013-06-17 10:36:46 -0400 |
---|---|---|
committer | Andrew Laski <andrew.laski@rackspace.com> | 2013-06-28 09:48:14 -0400 |
commit | 4f3c5411d92d488b78f06212912fc7ae6d225b79 (patch) | |
tree | 2265977f9567fec74f96b34ec965a1666df57259 /nova/tests/scheduler/test_chance_scheduler.py | |
parent | 7a241e5f8be927ff87c6ee6a478a7757a4a55813 (diff) | |
download | nova-4f3c5411d92d488b78f06212912fc7ae6d225b79.tar.gz nova-4f3c5411d92d488b78f06212912fc7ae6d225b79.tar.xz nova-4f3c5411d92d488b78f06212912fc7ae6d225b79.zip |
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
Diffstat (limited to 'nova/tests/scheduler/test_chance_scheduler.py')
-rw-r--r-- | nova/tests/scheduler/test_chance_scheduler.py | 45 |
1 files changed, 45 insertions, 0 deletions
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, {}) |