Scheduler: enforce max attempts at service startup

The CFG module now supports min and max values. This is validated
when the configuration file is read. This change enables us to do
the validation of the 'scheduler_max_attempts' at init rather
than when an instance is being booted.

TrivialFix

Change-Id: Id44fa9299d509a61f586e843cac485a00f2af032
This commit is contained in:
Gary Kotton 2016-01-10 06:50:39 -08:00
parent f1da349a4f
commit 7954a7e1ce
4 changed files with 5 additions and 22 deletions

View File

@ -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',

View File

@ -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)

View File

@ -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)

View File

@ -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]))