From cb49e5407cc1db0cd3533b57a12ec99a7179abd7 Mon Sep 17 00:00:00 2001 From: Tiago Mello Date: Wed, 5 Jun 2013 20:52:07 -0300 Subject: Refactors scheduler.chance.select_hosts to raise NoValidHost This change is intended to refactor the method to be consistent with the filter_scheduler.select_hosts implementation. This method is called by scheduler.manager and it is exposed through the scheduler.rpcapi. Thus, both implementations should behave the same. This change is needed by others that will move cold migration to conductor. Partially implements bp cold-migrations-to-conductor Change-Id: I0f6fef43324cf829cdb26633874c537572423f77 --- nova/scheduler/chance.py | 5 ++++- nova/tests/scheduler/test_chance_scheduler.py | 9 +++++++++ nova/tests/scheduler/test_filter_scheduler.py | 9 +++++++++ nova/tests/scheduler/test_scheduler.py | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/nova/scheduler/chance.py b/nova/scheduler/chance.py index 6e9688d81..0f8f3c45a 100644 --- a/nova/scheduler/chance.py +++ b/nova/scheduler/chance.py @@ -60,9 +60,12 @@ class ChanceScheduler(driver.Scheduler): def select_hosts(self, context, request_spec, filter_properties): """Selects a set of random hosts.""" - return [self._schedule(context, CONF.compute_topic, + hosts = [self._schedule(context, CONF.compute_topic, request_spec, filter_properties) for instance_uuid in request_spec.get('instance_uuids', [])] + if not hosts: + raise exception.NoValidHost(reason="") + return hosts def schedule_run_instance(self, context, request_spec, admin_password, injected_files, diff --git a/nova/tests/scheduler/test_chance_scheduler.py b/nova/tests/scheduler/test_chance_scheduler.py index a589000cd..8a281073a 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -194,3 +194,12 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): self.mox.ReplayAll() hosts = self.driver.select_hosts(ctxt, request_spec, {}) self.assertEquals(['host3', 'host1'], hosts) + + def test_select_hosts_no_valid_host(self): + + def _return_no_host(*args, **kwargs): + return [] + + self.stubs.Set(self.driver, '_schedule', _return_no_host) + self.assertRaises(exception.NoValidHost, + self.driver.select_hosts, self.context, {}, {}) diff --git a/nova/tests/scheduler/test_filter_scheduler.py b/nova/tests/scheduler/test_filter_scheduler.py index 80680dda8..a4aba4207 100644 --- a/nova/tests/scheduler/test_filter_scheduler.py +++ b/nova/tests/scheduler/test_filter_scheduler.py @@ -707,3 +707,12 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): hosts = sched.select_hosts(fake_context, request_spec, {}) self.assertEquals(len(hosts), 10) self.assertEquals(hosts, selected_hosts) + + def test_select_hosts_no_valid_host(self): + + def _return_no_host(*args, **kwargs): + return [] + + self.stubs.Set(self.driver, '_schedule', _return_no_host) + self.assertRaises(exception.NoValidHost, + self.driver.select_hosts, self.context, {}, {}) diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index f4f607647..fc5c4787b 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -951,6 +951,10 @@ class SchedulerDriverBaseTestCase(SchedulerTestCase): self.context, {}, fake_request_spec, {}, {}, {}, None) + def test_unimplemented_select_hosts(self): + self.assertRaises(NotImplementedError, + self.driver.select_hosts, self.context, {}, {}) + class SchedulerDriverModuleTestCase(test.TestCase): """Test case for scheduler driver module methods.""" -- cgit