summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormelanie witt <melwittt@gmail.com>2020-09-30 17:26:21 +0000
committerStephen Finucane <stephenfin@redhat.com>2021-01-29 09:36:04 +0000
commit8e12b81839e1fb364b3598699fecf57c78f81df3 (patch)
tree574122040964e3d6da30221e0e802d58bd2acf8f
parent795aa6c25d85b05f6dfc7252f14bdc058bab9419 (diff)
downloadnova-8e12b81839e1fb364b3598699fecf57c78f81df3.tar.gz
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 25a632a4e1daa1941a6297ddb51088972f23ce6d)
-rw-r--r--nova/compute/manager.py7
-rw-r--r--nova/conf/compute.py8
-rw-r--r--nova/tests/unit/compute/test_compute_mgr.py5
3 files changed, 19 insertions, 1 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 409bf3ab25..88ede440af 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1411,6 +1411,13 @@ class ComputeManager(manager.Manager):
eventlet.semaphore.BoundedSemaphore(
CONF.compute.max_concurrent_disk_ops)
+ if CONF.compute.max_disk_devices_to_attach == 0:
+ msg = _('[compute]max_disk_devices_to_attach has been set to 0, '
+ 'which will prevent instances from being able to boot. '
+ 'Set -1 for unlimited or set >= 1 to limit the maximum '
+ 'number of disk devices.')
+ raise exception.InvalidConfiguration(msg)
+
self.driver.init_host(host=self.host)
context = nova.context.get_admin_context()
instances = objects.InstanceList.get_by_host(
diff --git a/nova/conf/compute.py b/nova/conf/compute.py
index dbdd051d9f..92b5ab7918 100644
--- a/nova/conf/compute.py
+++ b/nova/conf/compute.py
@@ -962,10 +962,16 @@ on compute host B.
The configured maximum is not enforced on shelved offloaded servers, as they
have no compute host.
+.. warning:: If this option is set to 0, the ``nova-compute`` service will fail
+ to start, as 0 disk devices is an invalid configuration that would
+ prevent instances from being able to boot.
+
Possible values:
* -1 means unlimited
-* Any integer >= 0 represents the maximum allowed
+* Any integer >= 1 represents the maximum allowed. A value of 0 will cause the
+ ``nova-compute`` service to fail to start, as 0 disk devices is an invalid
+ configuration that would prevent instances from being able to boot.
"""),
cfg.StrOpt('provider_config_location',
default='/etc/nova/provider_config/',
diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py
index 305e72d38f..167a4060d7 100644
--- a/nova/tests/unit/compute/test_compute_mgr.py
+++ b/nova/tests/unit/compute/test_compute_mgr.py
@@ -1111,6 +1111,11 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase,
"time this service is starting on this host, then you can ignore "
"this warning.", 'fake-node1')
+ def test_init_host_disk_devices_configuration_failure(self):
+ self.flags(max_disk_devices_to_attach=0, group='compute')
+ self.assertRaises(exception.InvalidConfiguration,
+ self.compute.init_host)
+
@mock.patch.object(objects.InstanceList, 'get_by_host',
new=mock.Mock())
@mock.patch('nova.compute.manager.ComputeManager.'