From 4824cf9883af9af55984efee62d79efbc04db260 Mon Sep 17 00:00:00 2001 From: ggouzi Date: Thu, 8 Oct 2026 21:52:34 +0200 Subject: [PATCH] feat: expose compute.images-type for ephemeral storage backend Add a compute.images-type snap config key that renders [libvirt] images_type in nova.conf, letting operators select the ephemeral storage backend (raw, qcow2, rbd, flat...). The value is validated against nova's allowed values; invalid values are dropped with an error log so nova-compute keeps its default (qcow2) instead of failing to start. Assisted-By: DeepSeek v4 (openrouter) Signed-off-by: ggouzi --- README.md | 7 +++++++ openstack_hypervisor/hooks.py | 23 +++++++++++++++++++++++ templates/nova.conf.j2 | 3 +++ tests/unit/test_hooks.py | 11 +++++++++++ tests/unit/test_templates.py | 15 +++++++++++++++ 5 files changed, 59 insertions(+) diff --git a/README.md b/README.md index 712eeac..9f02cda 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,13 @@ Configuration of options related to compute (Nova): This option is runtime detected by the snap and will be set to `kvm` if the host is capable of full virtualization or `qemu` if not. +* `compute.images-type` libvirt image backend for ephemeral storage + +Valid values: `raw`, `qcow2`, `rbd`, `flat` (and Nova's `lvm`, `ploop`, +`default`). If unset, Nova's default (`qcow2`) is used. +`rbd` requires Ceph access (see `compute.rbd-user`, `compute.rbd-secret-uuid`) +and an RBD pool for Nova images. + * `compute.cpu-mode` (`host-model`) CPU mode for instances Valid values: `host-model`, `host-passthrough`, `custom`, `none`. diff --git a/openstack_hypervisor/hooks.py b/openstack_hypervisor/hooks.py index 02c9193..c1f3480 100644 --- a/openstack_hypervisor/hooks.py +++ b/openstack_hypervisor/hooks.py @@ -113,6 +113,8 @@ SNAP_USER = "snap_daemon" SNAP_GROUP = "snap_daemon" +IMAGES_TYPE_CHOICES = frozenset({"raw", "flat", "qcow2", "lvm", "rbd", "ploop", "default"}) + class OwnedPath(Path): """Path subclass that includes ownership information.""" @@ -513,6 +515,7 @@ def _get_local_ip_by_default_route() -> str: # Nova "compute.cpu-mode": "host-model", "compute.virt-type": "auto", + "compute.images-type": UNSET, "compute.cpu-models": UNSET, "compute.spice-proxy-address": _get_local_ip_by_default_route, # noqa: F821 "compute.rbd-user": "nova", @@ -2763,6 +2766,23 @@ def configure(snap: Snap) -> None: ) +def _validate_images_type(images_type: str | None) -> str: + """Return a valid images_type or an empty string when invalid. + + Logs an error so operators get feedback, and avoids rendering an + invalid value that would make nova-compute fail to start. + """ + if images_type is not None and images_type not in IMAGES_TYPE_CHOICES: + logging.error( + "Invalid compute.images-type %r, ignoring it (nova default " + "applies). Valid values: %s", + images_type, + ", ".join(sorted(IMAGES_TYPE_CHOICES)), + ) + return "" + return images_type or "" + + def _get_configure_context(snap: Snap) -> dict: context = snap.config.get_options( "compute", @@ -2791,6 +2811,9 @@ def _get_configure_context(snap: Snap) -> dict: context.setdefault("network", {}) context.setdefault("identity", {}) context.setdefault("credentials", {}) + context["compute"]["images_type"] = _validate_images_type( + context["compute"].get("images_type") + ) context["compute"]["multipath_enabled"] = ( context["compute"].get("multipath_forced", False) or _is_multipathd_available() ) diff --git a/templates/nova.conf.j2 b/templates/nova.conf.j2 index 7094a7d..dee61c2 100644 --- a/templates/nova.conf.j2 +++ b/templates/nova.conf.j2 @@ -64,6 +64,9 @@ skip_cpu_compare_on_dest = True volume_use_multipath = True {% endif -%} virt_type = {{ compute.virt_type }} +{% if compute.images_type -%} +images_type = {{ compute.images_type }} +{% endif -%} cpu_mode = {{ compute.cpu_mode }} {% if compute.cpu_mode == 'custom' -%} cpu_models = {{ compute.cpu_models }} diff --git a/tests/unit/test_hooks.py b/tests/unit/test_hooks.py index bc8d7b9..5b6ce08 100644 --- a/tests/unit/test_hooks.py +++ b/tests/unit/test_hooks.py @@ -2037,3 +2037,14 @@ def test_falls_back_to_data_dir_when_no_old_revisions(self, snap, short_env): dest = snap.paths.common / "var/lib/libvirt" assert (dest / "nvram").is_dir() + + +class TestImagesTypeValidation: + def test_invalid_images_type_returned_empty(self, caplog): + """Invalid images-type is dropped and logged; valid ones pass.""" + assert hooks._validate_images_type("qcow2") == "qcow2" + assert hooks._validate_images_type("rbd") == "rbd" + assert hooks._validate_images_type(None) == "" + with caplog.at_level("ERROR", logger="openstack_hypervisor.hooks"): + assert hooks._validate_images_type("qcow23") == "" + assert "Invalid compute.images-type" in caplog.text diff --git a/tests/unit/test_templates.py b/tests/unit/test_templates.py index 69278a9..5954392 100644 --- a/tests/unit/test_templates.py +++ b/tests/unit/test_templates.py @@ -34,6 +34,7 @@ "block_device_allocate_retries_interval": "", "multipath_enabled": False, "virt_type": "kvm", + "images_type": "", "cpu_mode": "host-passthrough", "cpu_models": "", "migration_address": "", @@ -115,6 +116,20 @@ def test_nova_block_device_allocate_retries_only_render_when_set(): assert "block_device_allocate_retries_interval = 3" in output +def test_nova_libvirt_images_type_only_render_when_set(): + output = _render("nova.conf.j2") + + assert "images_type" not in output + + compute = { + **BASE_CONTEXT["compute"], + "images_type": "qcow2", + } + output = _render("nova.conf.j2", compute=compute) + + assert "images_type = qcow2" in output + + def test_neutron_clients_use_internal_interface(): output = _render("neutron.conf.j2")