Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
23 changes: 23 additions & 0 deletions openstack_hypervisor/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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()
)
Expand Down
3 changes: 3 additions & 0 deletions templates/nova.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions tests/unit/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -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")

Expand Down
Loading