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
6 changes: 6 additions & 0 deletions openstack_hypervisor/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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", {})
Expand Down
3 changes: 3 additions & 0 deletions templates/nova.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from pathlib import Path

import pytest
from jinja2 import Environment, FileSystemLoader

TEMPLATES_DIR = Path(__file__).resolve().parents[2] / "templates"
Expand Down Expand Up @@ -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")

Expand Down
Loading