diff --git a/nova/conf/scheduler.py b/nova/conf/scheduler.py index 4bf76888ae8e..d7173b088506 100644 --- a/nova/conf/scheduler.py +++ b/nova/conf/scheduler.py @@ -206,6 +206,7 @@ metrics_weight_opts = [ scheduler_max_att_opt = cfg.IntOpt("scheduler_max_attempts", default=3, + min=1, help="Maximum number of attempts to schedule an instance") soft_affinity_weight_opt = cfg.FloatOpt('soft_affinity_weight_multiplier', diff --git a/nova/scheduler/utils.py b/nova/scheduler/utils.py index c5bd432ddd87..1a094df591fb 100644 --- a/nova/scheduler/utils.py +++ b/nova/scheduler/utils.py @@ -139,7 +139,7 @@ def populate_filter_properties(filter_properties, host_state): def populate_retry(filter_properties, instance_uuid): - max_attempts = _max_attempts() + max_attempts = CONF.scheduler_max_attempts force_hosts = filter_properties.get('force_hosts', []) force_nodes = filter_properties.get('force_nodes', []) @@ -193,14 +193,6 @@ def _log_compute_error(instance_uuid, retry): instance_uuid=instance_uuid) -def _max_attempts(): - max_attempts = CONF.scheduler_max_attempts - if max_attempts < 1: - raise exception.NovaException(_("Invalid value for " - "'scheduler_max_attempts', must be >= 1")) - return max_attempts - - def _add_retry_host(filter_properties, host, node): """Add a retry entry for the selected compute node. In the event that the request gets re-scheduled, this entry will signal that the given @@ -377,4 +369,4 @@ def retry_on_timeout(retries=1): return wrapped return outer -retry_select_destinations = retry_on_timeout(_max_attempts() - 1) +retry_select_destinations = retry_on_timeout(CONF.scheduler_max_attempts - 1) diff --git a/nova/tests/unit/scheduler/test_filter_scheduler.py b/nova/tests/unit/scheduler/test_filter_scheduler.py index 760b013efae6..2c93762361a3 100644 --- a/nova/tests/unit/scheduler/test_filter_scheduler.py +++ b/nova/tests/unit/scheduler/test_filter_scheduler.py @@ -82,15 +82,6 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): for weighed_host in weighed_hosts: self.assertIsNotNone(weighed_host.obj) - def test_max_attempts(self): - self.flags(scheduler_max_attempts=4) - self.assertEqual(4, scheduler_utils._max_attempts()) - - def test_invalid_max_attempts(self): - self.flags(scheduler_max_attempts=0) - self.assertRaises(exception.NovaException, - scheduler_utils._max_attempts) - def test_add_retry_host(self): retry = dict(num_attempts=1, hosts=[]) filter_properties = dict(retry=retry) diff --git a/nova/tests/unit/scheduler/test_scheduler_utils.py b/nova/tests/unit/scheduler/test_scheduler_utils.py index a9437de445b7..27ef76c5466d 100644 --- a/nova/tests/unit/scheduler/test_scheduler_utils.py +++ b/nova/tests/unit/scheduler/test_scheduler_utils.py @@ -187,9 +187,8 @@ class SchedulerUtilsTestCase(test.NoDBTestCase): self._test_populate_filter_props(force_nodes=['force-node1', 'force-node2']) - @mock.patch.object(scheduler_utils, '_max_attempts') - def test_populate_retry_exception_at_max_attempts(self, _max_attempts): - _max_attempts.return_value = 2 + def test_populate_retry_exception_at_max_attempts(self): + self.flags(scheduler_max_attempts=2) msg = 'The exception text was preserved!' filter_properties = dict(retry=dict(num_attempts=2, hosts=[], exc_reason=[msg]))