Skip to content

Commit 8e12b81

Browse files
melwittstephenfin
authored andcommitted
Disallow CONF.compute.max_disk_devices_to_attach = 0
The CONF.compute.max_disk_devices_to_attach option controls the maximum number of disk devices allowed to attach to an instance. If it is set to 0, it will literally allow no disk device for instances, preventing them from being able to boot. This adds a note to the config option help to call this out and changes nova-compute to raise InvalidConfiguration during init_host if [compute]max_disk_devices_to_attach has been set to 0. The nova-compute service will fail to start if the option is set to 0. Note: there doesn't appear to be any way to disallow particular values in a oslo.config IntOpt other than the min/max values. Here we need the min value to be -1 to represent unlimited. There is a 'choices' kwarg available but that is only for enumerating valid values and we need to allow any integer >= 1 as well. Change-Id: I6e30468bc28f661ddc17937ab1de04a706f05063 Closes-Bug: #1897950 (cherry picked from commit 25a632a)
1 parent 795aa6c commit 8e12b81

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

nova/compute/manager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,13 @@ def init_host(self):
14111411
eventlet.semaphore.BoundedSemaphore(
14121412
CONF.compute.max_concurrent_disk_ops)
14131413

1414+
if CONF.compute.max_disk_devices_to_attach == 0:
1415+
msg = _('[compute]max_disk_devices_to_attach has been set to 0, '
1416+
'which will prevent instances from being able to boot. '
1417+
'Set -1 for unlimited or set >= 1 to limit the maximum '
1418+
'number of disk devices.')
1419+
raise exception.InvalidConfiguration(msg)
1420+
14141421
self.driver.init_host(host=self.host)
14151422
context = nova.context.get_admin_context()
14161423
instances = objects.InstanceList.get_by_host(

nova/conf/compute.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,10 +962,16 @@
962962
The configured maximum is not enforced on shelved offloaded servers, as they
963963
have no compute host.
964964
965+
.. warning:: If this option is set to 0, the ``nova-compute`` service will fail
966+
to start, as 0 disk devices is an invalid configuration that would
967+
prevent instances from being able to boot.
968+
965969
Possible values:
966970
967971
* -1 means unlimited
968-
* Any integer >= 0 represents the maximum allowed
972+
* Any integer >= 1 represents the maximum allowed. A value of 0 will cause the
973+
``nova-compute`` service to fail to start, as 0 disk devices is an invalid
974+
configuration that would prevent instances from being able to boot.
969975
"""),
970976
cfg.StrOpt('provider_config_location',
971977
default='/etc/nova/provider_config/',

nova/tests/unit/compute/test_compute_mgr.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,11 @@ def test_get_nodes_node_not_found(
11111111
"time this service is starting on this host, then you can ignore "
11121112
"this warning.", 'fake-node1')
11131113

1114+
def test_init_host_disk_devices_configuration_failure(self):
1115+
self.flags(max_disk_devices_to_attach=0, group='compute')
1116+
self.assertRaises(exception.InvalidConfiguration,
1117+
self.compute.init_host)
1118+
11141119
@mock.patch.object(objects.InstanceList, 'get_by_host',
11151120
new=mock.Mock())
11161121
@mock.patch('nova.compute.manager.ComputeManager.'

0 commit comments

Comments
 (0)