From 883bae38c329abe4a54fba88b642c20a11529193 Mon Sep 17 00:00:00 2001 From: Andrey Volkov Date: Fri, 22 Jul 2016 09:33:04 +0300 Subject: [PATCH] Cleanup: validate option at config read level It's not necessary to make validation for negative retries in code if we have IntOpt min option. Change-Id: I3d42472604d86ba2e5e9b674e8ec2017849aa15a --- nova/compute/manager.py | 5 ---- nova/conf/compute.py | 3 ++- nova/tests/unit/compute/test_compute_mgr.py | 27 ------------------- ...allocate-retries-min-a5288476b11bfe55.yaml | 5 ++++ 4 files changed, 7 insertions(+), 33 deletions(-) create mode 100644 releasenotes/notes/network-allocate-retries-min-a5288476b11bfe55.yaml diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 189a1fed9b2f..298784d71c86 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1370,11 +1370,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) diff --git a/nova/conf/compute.py b/nova/conf/compute.py index 1bb4b25c55d2..bb8addfba49f 100644 --- a/nova/conf/compute.py +++ b/nova/conf/compute.py @@ -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'), diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index dce24554d5c4..5af5542f69fb 100755 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -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') diff --git a/releasenotes/notes/network-allocate-retries-min-a5288476b11bfe55.yaml b/releasenotes/notes/network-allocate-retries-min-a5288476b11bfe55.yaml new file mode 100644 index 000000000000..3ab756fb488f --- /dev/null +++ b/releasenotes/notes/network-allocate-retries-min-a5288476b11bfe55.yaml @@ -0,0 +1,5 @@ +--- +other: + - | + network_allocate_retries config param now allows only + positive integer values or 0. \ No newline at end of file