diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2012-01-20 19:49:04 -0800 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2012-01-20 20:05:00 -0800 |
| commit | 15af999fbd7b3532b92f4cba54bdd25e89677eb6 (patch) | |
| tree | b36f3038a023ed231f995674db8733227c7dc4d7 /nova | |
| parent | 16ea348a1623f055809d0d9b7fe9f046515b5dd1 (diff) | |
Forgot to update chance scheduler for ignore_hosts change
Change-Id: If67416e30b8cfe12de6fdc5c151899fd0a56225c
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/scheduler/chance.py | 15 | ||||
| -rw-r--r-- | nova/tests/scheduler/test_chance_scheduler.py | 16 |
2 files changed, 14 insertions, 17 deletions
diff --git a/nova/scheduler/chance.py b/nova/scheduler/chance.py index 079c1cfc3..587c11af9 100644 --- a/nova/scheduler/chance.py +++ b/nova/scheduler/chance.py @@ -30,17 +30,12 @@ from nova.scheduler import driver class ChanceScheduler(driver.Scheduler): """Implements Scheduler as a random node selector.""" - def _filter_hosts(self, request_spec, hosts): + def _filter_hosts(self, request_spec, hosts, **kwargs): """Filter a list of hosts based on request_spec.""" - # Filter out excluded host - try: - if request_spec['avoid_original_host']: - original_host = request_spec['instance_properties']['host'] - hosts = [host for host in hosts if host != original_host] - except (KeyError, TypeError): - pass - + filter_properties = kwargs.get('filter_properties', {}) + ignore_hosts = filter_properties.get('ignore_hosts', []) + hosts = [host for host in hosts if host not in ignore_hosts] return hosts def _schedule(self, context, topic, request_spec, **kwargs): @@ -52,7 +47,7 @@ class ChanceScheduler(driver.Scheduler): msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg) - hosts = self._filter_hosts(request_spec, hosts) + hosts = self._filter_hosts(request_spec, hosts, **kwargs) if not hosts: msg = _("Could not find another compute") raise exception.NoValidHost(reason=msg) diff --git a/nova/tests/scheduler/test_chance_scheduler.py b/nova/tests/scheduler/test_chance_scheduler.py index 0bb3927a2..b6a91cdf5 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -23,17 +23,18 @@ from nova.scheduler import chance class ChanceSchedulerTestCase(test.TestCase): """Test case for Chance Scheduler.""" - def test_filter_hosts_avoid(self): + def test_filter_hosts_avoid_matches(self): """Test to make sure _filter_hosts() filters original hosts if avoid_original_host is True.""" sched = chance.ChanceScheduler() hosts = ['host1', 'host2', 'host3'] - request_spec = dict(instance_properties=dict(host='host2'), - avoid_original_host=True) + request_spec = dict(instance_properties=dict(host='host2')) + filter_properties = {'ignore_hosts': ['host2']} - filtered = sched._filter_hosts(request_spec, hosts) + filtered = sched._filter_hosts(request_spec, hosts, + filter_properties=filter_properties) self.assertEqual(filtered, ['host1', 'host3']) def test_filter_hosts_no_avoid(self): @@ -43,8 +44,9 @@ class ChanceSchedulerTestCase(test.TestCase): sched = chance.ChanceScheduler() hosts = ['host1', 'host2', 'host3'] - request_spec = dict(instance_properties=dict(host='host2'), - avoid_original_host=False) + request_spec = dict(instance_properties=dict(host='host2')) + filter_properties = {'ignore_hosts': []} - filtered = sched._filter_hosts(request_spec, hosts) + filtered = sched._filter_hosts(request_spec, hosts, + filter_properties=filter_properties) self.assertEqual(filtered, hosts) |
