From 0e9136fe1e2b360297b8b938faaed1e8d44ee843 Mon Sep 17 00:00:00 2001 From: Nobuto Murata Date: Wed, 8 Dec 2021 10:50:55 +0900 Subject: [PATCH] Expose max_local_block_devices as an explicit charm option It's useful to force instance creations to fail if ephemeral drives are requested when cloud admins want users to use persistent volumes always. Closes-Bug: #1953561 Change-Id: I1c958b4bcf79512c06de6d81fe55c681bb5f38a7 --- config.yaml | 9 +++++++++ hooks/nova_cc_context.py | 2 ++ templates/icehouse/nova.conf | 4 ++++ templates/juno/nova.conf | 4 ++++ templates/kilo/nova.conf | 4 ++++ templates/liberty/nova.conf | 4 ++++ templates/mitaka/nova.conf | 4 ++++ templates/newton/nova.conf | 4 ++++ templates/ocata/nova.conf | 4 ++++ templates/pike/nova.conf | 4 ++++ templates/rocky/nova.conf | 4 ++++ templates/train/nova.conf | 4 ++++ unit_tests/test_nova_cc_contexts.py | 2 ++ 13 files changed, 53 insertions(+) diff --git a/config.yaml b/config.yaml index 7bd31d16..fc5ad8c8 100644 --- a/config.yaml +++ b/config.yaml @@ -770,3 +770,12 @@ options: Allow resizing to the same host. Setting this option to True will add the source host to the destination options for consideration by the scheduler when resizing an instance. + max-local-block-devices: + type: int + default: + description: | + Maximum number of local devices which can be attached to an + instance. Possible values are 0: Creating a local disk is not + allowed and letting the request fail, Negative number: Allows + unlimited number of local devices, Positive number: Allows only + these many number of local devices. diff --git a/hooks/nova_cc_context.py b/hooks/nova_cc_context.py index 079fe5c3..82e65cd0 100644 --- a/hooks/nova_cc_context.py +++ b/hooks/nova_cc_context.py @@ -449,6 +449,8 @@ class NovaConfigContext(ch_context.WorkerConfigContext): 'placement-aggregate-required-for-tenants') ctxt['enable_isolated_aggregate_filtering'] = hookenv.config( 'enable-isolated-aggregate-filtering') + ctxt['max_local_block_devices'] = hookenv.config( + 'max-local-block-devices') return ctxt diff --git a/templates/icehouse/nova.conf b/templates/icehouse/nova.conf index 1b08e1a2..06d4b47d 100644 --- a/templates/icehouse/nova.conf +++ b/templates/icehouse/nova.conf @@ -93,6 +93,10 @@ keystone_ec2_url = {{ keystone_ec2_url }} glance_api_servers = {{ glance_api_servers }} {% endif -%} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/templates/juno/nova.conf b/templates/juno/nova.conf index 0238f262..c4b6ee91 100644 --- a/templates/juno/nova.conf +++ b/templates/juno/nova.conf @@ -99,6 +99,10 @@ keystone_ec2_url = {{ keystone_ec2_url }} glance_api_servers = {{ glance_api_servers }} {% endif -%} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/templates/kilo/nova.conf b/templates/kilo/nova.conf index 9d2c5a35..af25634e 100644 --- a/templates/kilo/nova.conf +++ b/templates/kilo/nova.conf @@ -99,6 +99,10 @@ memcached_servers = {{ memcached_servers }} keystone_ec2_url = {{ keystone_ec2_url }} {% endif -%} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/templates/liberty/nova.conf b/templates/liberty/nova.conf index efabdc80..a7a2a727 100644 --- a/templates/liberty/nova.conf +++ b/templates/liberty/nova.conf @@ -102,6 +102,10 @@ memcached_servers = {{ memcached_servers }} keystone_ec2_url = {{ keystone_ec2_url }} {% endif -%} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/templates/mitaka/nova.conf b/templates/mitaka/nova.conf index e451c6dc..cf834b50 100644 --- a/templates/mitaka/nova.conf +++ b/templates/mitaka/nova.conf @@ -87,6 +87,10 @@ quota_server_group_members = {{ quota_server_group_members }} {% include "parts/novnc" %} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/templates/newton/nova.conf b/templates/newton/nova.conf index 64b39ab3..743a9c1d 100644 --- a/templates/newton/nova.conf +++ b/templates/newton/nova.conf @@ -90,6 +90,10 @@ quota_server_group_members = {{ quota_server_group_members }} {% include "parts/novnc" %} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/templates/ocata/nova.conf b/templates/ocata/nova.conf index 3bcd944b..8c19881c 100644 --- a/templates/ocata/nova.conf +++ b/templates/ocata/nova.conf @@ -47,6 +47,10 @@ my_ip = {{ host_ip }} {% include "parts/novnc" %} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/templates/pike/nova.conf b/templates/pike/nova.conf index 50b72cd5..58d4a60e 100644 --- a/templates/pike/nova.conf +++ b/templates/pike/nova.conf @@ -52,6 +52,10 @@ my_ip = {{ host_ip }} {% include "parts/novnc" %} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/templates/rocky/nova.conf b/templates/rocky/nova.conf index 2be1d8d6..0174bad6 100644 --- a/templates/rocky/nova.conf +++ b/templates/rocky/nova.conf @@ -52,6 +52,10 @@ my_ip = {{ host_ip }} {% include "parts/novnc" %} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/templates/train/nova.conf b/templates/train/nova.conf index 004695f3..29fe82c1 100644 --- a/templates/train/nova.conf +++ b/templates/train/nova.conf @@ -52,6 +52,10 @@ my_ip = {{ host_ip }} {% include "parts/novnc" %} +{% if max_local_block_devices is not none -%} +max_local_block_devices = {{ max_local_block_devices }} +{% endif -%} + {% if rbd_pool -%} rbd_pool = {{ rbd_pool }} rbd_user = {{ rbd_user }} diff --git a/unit_tests/test_nova_cc_contexts.py b/unit_tests/test_nova_cc_contexts.py index d9f48127..a8420c51 100644 --- a/unit_tests/test_nova_cc_contexts.py +++ b/unit_tests/test_nova_cc_contexts.py @@ -401,6 +401,8 @@ class NovaComputeContextTests(CharmTestCase): ) self.assertEqual(ctxt['enable_isolated_aggregate_filtering'], self.config('enable-isolated-aggregate-filtering')) + self.assertEqual(ctxt['max_local_block_devices'], + self.config('max-local-block-devices')) _pci_alias1 = { "name": "IntelNIC",