Merge "Cleanup: validate option at config read level"

This commit is contained in:
Jenkins 2016-08-09 19:37:10 +00:00 committed by Gerrit Code Review
commit 0da6c64611
4 changed files with 7 additions and 33 deletions

View File

@ -1382,11 +1382,6 @@ class ComputeManager(manager.Manager):
LOG.debug("Allocating IP information in the background.",
instance=instance)
retries = CONF.network_allocate_retries
if retries < 0:
LOG.warning(_LW("Treating negative config value (%(retries)s) for "
"'network_allocate_retries' as 0."),
{'retries': retries})
retries = 0
attempts = retries + 1
retry_time = 1
bind_host_id = self.driver.network_binding_host_id(context, instance)

View File

@ -226,7 +226,8 @@ compute_manager_opts = [
'host rebooted'),
cfg.IntOpt('network_allocate_retries',
default=0,
help="Number of times to retry network allocation on failures"),
help="Number of times to retry network allocation on failures",
min=0),
cfg.IntOpt('max_concurrent_builds',
default=10,
help='Maximum number of instance builds to run concurrently'),

View File

@ -425,33 +425,6 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
dhcp_options=dhcp_options,
bind_host_id=instance.get('host'))
@mock.patch.object(network_api.API, 'allocate_for_instance')
def test_allocate_network_neg_conf_value_treated_as_zero(self,
mock_allocate):
self.flags(network_allocate_retries=-1)
mock_allocate.side_effect = test.TestingException
instance = {}
is_vpn = 'fake-is-vpn'
req_networks = objects.NetworkRequestList(
objects=[objects.NetworkRequest(network_id='fake')])
macs = 'fake-macs'
sec_groups = 'fake-sec-groups'
dhcp_options = None
self.assertRaises(test.TestingException,
self.compute._allocate_network_async,
self.context, instance, req_networks, macs,
sec_groups, is_vpn, dhcp_options)
mock_allocate.assert_called_once_with(
self.context, instance, vpn=is_vpn,
requested_networks=req_networks, macs = macs,
security_groups=sec_groups,
dhcp_options=dhcp_options,
bind_host_id=instance.get('host'))
@mock.patch.object(network_api.API, 'allocate_for_instance')
@mock.patch.object(manager.ComputeManager, '_instance_update')
@mock.patch.object(time, 'sleep')

View File

@ -0,0 +1,5 @@
---
other:
- |
network_allocate_retries config param now allows only
positive integer values or 0.