Files
haproxy-openmanager/backend/tests/test_keepalive_fault_state.py
taylanbakircioglu a1192e602d feat: HA / VIP (Keepalived) management from the UI (#27)
Manage highly-available virtual IPs backed by Keepalived (VRRP) directly from the OpenManager
UI — no more SSHing into nodes to install/configure Keepalived by hand. Builds on the agent
pull-architecture: define the VIP centrally, click Apply, and the agents converge.

Highlights:
- New "HA / VIP" tab: create a virtual IP, pick a per-node interface, select which pool nodes
  participate (MASTER/BACKUP roles + priorities); live MASTER/BACKUP/FAULT per node.
- On Apply, agents install & configure Keepalived (unicast VRRP, cloud-safe default) across the
  major distros (Debian/Ubuntu, RHEL/CentOS/Alma/Rocky, Fedora, SUSE/openSUSE, Alpine) with a
  HAProxy health-check, so the VIP fails over automatically when HAProxy drops.
- Single-node (a managed floating IP without failover) and multi-node VRRP failover both work.
- VIP changes ride the standard Apply Management flow with the standard "View Change" diff.
- Approval-gated deletion (safety): deleting a running VIP is staged for approval and the VIP
  keeps running, untouched, until you approve it — an agent never tears a VIP down without an
  explicit human approval. Per-VIP Diagnostics view; opt-in package uninstall (only on nodes
  where OpenManager installed it). A node already running a hand-managed Keepalived is detected
  and never overwritten ("externally managed").
- Fully opt-in and backward compatible: nodes/clusters without a VIP are unaffected. Adds
  vip_instances + vip_members tables (idempotent SCHEMA_VERSION bump; existing data and
  passwords unaffected) and a `vip` RBAC permission group.
- Also includes a HAProxy config-generator robustness fix: auto-inject a stick-table when a
  frontend uses a stick counter (track-sc / sc_*_rate) but declares none.

On-prem / L2 (VRRP) scope; the UI notes the cloud caveat.
2026-06-07 01:52:20 +03:00

22 lines
1.0 KiB
Python

"""v1.7.6 — guard: the agent must surface keepalived FAULT state.
A VIP whose interface has no usable IPv4 (or whose track-script fails) puts keepalived into
FAULT — the virtual IP is NOT held. Previously get_keepalive_state only grepped (MASTER|BACKUP),
so a FAULT'd VIP reported as BACKUP — misleading (looks healthy-ish). It must report FAULT so the
UI shows it red. Both get_keepalive_state copies (installer + SKIP_TO_DAEMON daemon) must include
FAULT. Pure source guard."""
from __future__ import annotations
import os
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def test_keepalive_state_detects_fault_in_both_copies():
with open(os.path.join(ROOT, "utils", "agent_scripts", "linux_install.sh"), encoding="utf-8") as f:
s = f.read()
# FAULT added to the state grep in both copies (installer + daemon), both detection methods.
assert s.count("MASTER|BACKUP|FAULT") >= 2
# and the misleading MASTER|BACKUP-only grep is gone.
assert 'grep -oE "(MASTER|BACKUP)"' not in s