fix(ipam): keep extra addresses across a guest reboot
Some checks failed
Backend Tests / pytest (Python 3.12) (push) Failing after 1m44s
Deploy to Production / Trigger production update (push) Failing after 11s
SonarCloud / SonarCloud Analysis (push) Failing after 3m0s

Testing on a live AlmaLinux container showed the alias disappearing after
a restart even though it was reported as applied: Proxmox regenerates the
guest network configuration on every start (pve-container rewrites
/etc/network/interfaces, ifcfg or the NM keyfile from netN), wiping any
address added to the native stack.

    before reboot: address1=10.10.10.103/24 address2=10.10.10.106/24
    after reboot:  addresses=10.10.10.103/24     (file recreated by PVE)

Install a oneshot systemd unit that re-adds the recorded addresses after
network-online.target — /etc/systemd is not touched by Proxmox. The native
branches stay, so persist is now reported as e.g. "nm+systemd"; the unit
and its helper are removed once the last address is released.

Also fixed while testing on the two test instances:
- the alias script is ASCII-only now: it travels through the Proxmox API
  and its marker ends up in guest system configs
- a composite persist marker no longer falls through the parser, which
  used to report a successful apply as runtime_only
- allocate_ip marks the first address of a guest as primary on its own,
  so allocations coming from the creation wizard are flagged correctly
This commit is contained in:
2026-08-22 01:36:10 +05:00
parent 6ac505e481
commit 972d54d1f1
6 changed files with 263 additions and 43 deletions

View File

@@ -216,3 +216,25 @@ def test_unknown_guest_is_pending_not_crash(guest, monkeypatch):
assert result.status == guest_ip_service.PENDING
assert recorder.calls == []
def test_combined_persist_marker_is_understood(guest, monkeypatch):
"""Скрипт сообщает составной способ закрепления: родной стек + systemd."""
allocation = guest["add_alias"]("10.10.10.90")
_patch(monkeypatch, script_engine.ExecResult(
True, "PVEMANAGER_PERSIST=nm+systemd\nPVEMANAGER_OK=1\n", 0))
result = guest_ip_service.apply_address(guest["db"], allocation)
assert result.persist == "nm+systemd"
assert result.status == guest_ip_service.APPLIED
assert allocation.apply_status == guest_ip_service.APPLIED
def test_plain_systemd_persist_is_applied(guest, monkeypatch):
allocation = guest["add_alias"]("10.10.10.90")
_patch(monkeypatch, script_engine.ExecResult(
True, "PVEMANAGER_PERSIST=systemd\nPVEMANAGER_OK=1\n", 0))
assert guest_ip_service.apply_address(guest["db"], allocation).status == \
guest_ip_service.APPLIED