From e918331d6ec24f4b8b9981650b4d52fd572effd4 Mon Sep 17 00:00:00 2001 From: Guillaume Boutry Date: Wed, 25 Nov 2026 15:13:10 +0100 Subject: [PATCH] feat: configure Nova parallel live migration Validate the QEMU connection count supplied in snap configuration and render it in Nova's libvirt section when parallel migration is enabled. Assisted-By: Codex (gpt-6) --- openstack_hypervisor/hooks.py | 6 ++++++ templates/nova.conf.j2 | 3 +++ tests/unit/test_hooks.py | 24 ++++++++++++++++++++++++ tests/unit/test_templates.py | 17 +++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/openstack_hypervisor/hooks.py b/openstack_hypervisor/hooks.py index 2fc9213..a5265bb 100644 --- a/openstack_hypervisor/hooks.py +++ b/openstack_hypervisor/hooks.py @@ -522,6 +522,7 @@ def _get_local_ip_by_default_route() -> str: "compute.cert": UNSET, "compute.key": UNSET, "compute.migration-address": UNSET, + "compute.live-migration-parallel-connections": UNSET, "compute.resume-on-boot": True, "compute.block-device-allocate-retries": UNSET, "compute.block-device-allocate-retries-interval": UNSET, @@ -2788,6 +2789,11 @@ def _get_configure_context(snap: Snap) -> dict: ) context = _context_compat(context) context.setdefault("compute", {}) + parallel_connections = context["compute"].get("live_migration_parallel_connections", 1) + if type(parallel_connections) is not int or not 1 <= parallel_connections <= 255: + raise ValueError( + "compute.live-migration-parallel-connections must be an integer between 1 and 255" + ) context.setdefault("network", {}) context.setdefault("identity", {}) context.setdefault("credentials", {}) diff --git a/templates/nova.conf.j2 b/templates/nova.conf.j2 index 23e0dd4..0f0ff7d 100644 --- a/templates/nova.conf.j2 +++ b/templates/nova.conf.j2 @@ -71,6 +71,9 @@ cpu_models = {{ compute.cpu_models }} {% endif %} live_migration_with_native_tls = true live_migration_scheme = tls +{% if compute.live_migration_parallel_connections | default(1) > 1 -%} +live_migration_parallel_connections = {{ compute.live_migration_parallel_connections }} +{% endif -%} {% if compute.migration_address %} live_migration_inbound_addr = {{ compute.migration_address }} {% endif -%} diff --git a/tests/unit/test_hooks.py b/tests/unit/test_hooks.py index 018959f..d509cd4 100644 --- a/tests/unit/test_hooks.py +++ b/tests/unit/test_hooks.py @@ -988,6 +988,30 @@ def test_configure_stops_ovn_agent_without_usable_environment(mocker, snap, ovn_ snapctl.start.assert_not_called() +def test_get_configure_context_reads_parallel_connections(mocker, snap): + """Read the snap key as the Nova template variable.""" + _prepare_minimal_configure_context(mocker, snap) + snap.config.get_options.return_value["compute"] = { + "live-migration-parallel-connections": 2, + } + + context = hooks._get_configure_context(snap) + + assert context["compute"]["live_migration_parallel_connections"] == 2 + + +@pytest.mark.parametrize("connections", [0, 256, True, "2\n[DEFAULT]"]) +def test_get_configure_context_rejects_invalid_parallel_connections(mocker, snap, connections): + """Reject invalid snap values before templates are rendered.""" + _prepare_minimal_configure_context(mocker, snap) + snap.config.get_options.return_value["compute"] = { + "live-migration-parallel-connections": connections, + } + + with pytest.raises(ValueError, match="compute.live-migration-parallel-connections"): + hooks._get_configure_context(snap) + + def test_get_configure_context_reads_ovn_connections_without_logging_them(mocker, snap, caplog): nb_connection = "ssl:192.0.2.10:6641" sb_connection = "ssl:192.0.2.10:6642" diff --git a/tests/unit/test_templates.py b/tests/unit/test_templates.py index 69278a9..f17f91b 100644 --- a/tests/unit/test_templates.py +++ b/tests/unit/test_templates.py @@ -3,6 +3,7 @@ from pathlib import Path +import pytest from jinja2 import Environment, FileSystemLoader TEMPLATES_DIR = Path(__file__).resolve().parents[2] / "templates" @@ -115,6 +116,22 @@ def test_nova_block_device_allocate_retries_only_render_when_set(): assert "block_device_allocate_retries_interval = 3" in output +@pytest.mark.parametrize("connections", [None, 1, 2, 255]) +def test_nova_live_migration_parallel_connections(connections): + """Render the QEMU connection count only when parallelism is enabled.""" + compute = dict(BASE_CONTEXT["compute"]) + if connections is not None: + compute["live_migration_parallel_connections"] = connections + + output = _render("nova.conf.j2", compute=compute) + + if connections in (None, 1): + assert "live_migration_parallel_connections" not in output + else: + libvirt = output.split("[libvirt]\n", 1)[1].split("\n[", 1)[0] + assert f"live_migration_parallel_connections = {connections}" in libvirt.splitlines() + + def test_neutron_clients_use_internal_interface(): output = _render("neutron.conf.j2")