diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 4677a16e61b3..837474a28a69 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -490,11 +490,6 @@ class ComputeManager(manager.Manager): target = messaging.Target(version='5.0') - # How long to wait in seconds before re-issuing a shutdown - # signal to an instance during power off. The overall - # time to wait is set by CONF.shutdown_timeout. - SHUTDOWN_RETRY_INTERVAL = 10 - def __init__(self, compute_driver=None, *args, **kwargs): """Load configuration options and connect to the hypervisor.""" self.virtapi = ComputeVirtAPI(self) @@ -2310,7 +2305,7 @@ class ComputeManager(manager.Manager): timeout = compute_utils.get_value_from_system_metadata(instance, key='image_os_shutdown_timeout', type=int, default=CONF.shutdown_timeout) - retry_interval = self.SHUTDOWN_RETRY_INTERVAL + retry_interval = CONF.compute.shutdown_retry_interval else: timeout = 0 retry_interval = 0 diff --git a/nova/conf/compute.py b/nova/conf/compute.py index 1b63a12e1190..b2b455602b74 100644 --- a/nova/conf/compute.py +++ b/nova/conf/compute.py @@ -643,6 +643,23 @@ Possible values: * Any positive integer representing a build failure count. * Zero to never auto-disable. """), + cfg.IntOpt("shutdown_retry_interval", + default=10, + min=1, + help=""" +Time to wait in seconds before resending an ACPI shutdown signal to +instances. + +The overall time to wait is set by ``shutdown_timeout``. + +Possible values: + +* Any integer greater than 0 in seconds + +Related options: + +* ``shutdown_timeout`` +""") ] interval_opts = [ diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index 64487cb7efab..be8be39957fe 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -1253,6 +1253,24 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase): mock_instance_save.assert_called_once_with() self.assertIsNone(instance.task_state) + @mock.patch('nova.virt.fake.FakeDriver.power_off') + @mock.patch.object(compute_utils, 'get_value_from_system_metadata', + return_value=CONF.shutdown_timeout) + def test_power_off_values(self, mock_get_metadata, mock_power_off): + self.flags(shutdown_retry_interval=20, group='compute') + instance = fake_instance.fake_instance_obj( + self.context, + uuid=uuids.instance, + vm_state=vm_states.ACTIVE, + task_state=task_states.POWERING_OFF) + self.compute._power_off_instance( + self.context, instance, + clean_shutdown=True) + mock_power_off.assert_called_once_with( + instance, + CONF.shutdown_timeout, + 20) + @mock.patch('nova.context.RequestContext.elevated') @mock.patch('nova.objects.Instance.get_network_info') @mock.patch( diff --git a/nova/tests/unit/compute/test_shelve.py b/nova/tests/unit/compute/test_shelve.py index ca757d3218a7..e97ffbd30ae6 100644 --- a/nova/tests/unit/compute/test_shelve.py +++ b/nova/tests/unit/compute/test_shelve.py @@ -141,7 +141,7 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase): if clean_shutdown: mock_power_off_call_list.append( mock.call(instance, CONF.shutdown_timeout, - self.compute.SHUTDOWN_RETRY_INTERVAL)) + CONF.compute.shutdown_retry_interval)) else: mock_power_off_call_list.append(mock.call(instance, 0, 0)) @@ -183,7 +183,7 @@ class ShelveComputeManagerTestCase(test_compute.BaseTestCase): def test_shelve_offload(self, mock_power_off): instance = self._shelve_offload() mock_power_off.assert_called_once_with(instance, - CONF.shutdown_timeout, self.compute.SHUTDOWN_RETRY_INTERVAL) + CONF.shutdown_timeout, CONF.compute.shutdown_retry_interval) @mock.patch.object(nova.virt.fake.SmallFakeDriver, 'power_off') def test_shelve_offload_forced_shutdown(self, mock_power_off): diff --git a/releasenotes/notes/expose-shutdown-retry-interval-d83724ade1b44e62.yaml b/releasenotes/notes/expose-shutdown-retry-interval-d83724ade1b44e62.yaml new file mode 100644 index 000000000000..46cce8a5221c --- /dev/null +++ b/releasenotes/notes/expose-shutdown-retry-interval-d83724ade1b44e62.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The shutdown retry interval in powering off instances can now be set using + the configuration setting ``shutdown_retry_interval``, in the + compute configuration group.