This repository has been archived on 2026-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
Set-OPS/scripts/tests/test_inventory_host.py
Daniel Allaire b775b7f99d Neutraliser le moteur pour partage public (100% neutre)
Suppression de toute trace Chezlepro de l'outil (roles, scripts, docs
publiques, exemples, LICENSE). Prouve par scan exhaustif : git grep vide
pour chezlepro, asgard/TrueNAS, supernet reel 10.1.x.

Corrige 5 defauts de genericite fonctionnels (motd, app.ini Forgejo,
organisation openldap, nom AC step-ca, et IP reelles codees en dur dans
les defaults de roles -> plage d'exemple 10.0.x). LICENSE -> Alliance
Boreale. Fichiers mainteneur + CHANGELOG conserves (par decision).

La separation moteur/instance tient : OPS-Chezlepro surcharge deja ses
vraies valeurs de topologie. Verifie : make verifier exit 0 (4 tests).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 19:58:00 -04:00

115 lines
3.8 KiB
Python

#!/usr/bin/env python3
"""Tests stdlib (sans pytest) pour inventory_host.parametres_proxmox_hote.
Lancer : python3 scripts/tests/test_inventory_host.py
"""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from inventory_host import parametres_proxmox_hote # noqa: E402
def _inventaire_factice() -> dict:
return {
"all": {
"children": {
"hotes_planifies": {
"hosts": {
"app-01": {
"ansible_host": "10.0.2.11",
"ansible_user": "ansible",
"proxmox_cidr": 24,
"proxmox_coeurs": 4,
"proxmox_disque_taille": "160G",
"proxmox_memoire": 2048,
"proxmox_noeud": "noeud-a",
"proxmox_passerelle": "10.0.2.1",
"proxmox_stockage": "stockage-a",
"proxmox_vlan": 13,
"proxmox_vmid": 93101,
},
# app-02 : sans proxmox_noeud (champ optionnel).
"app-02": {
"ansible_host": "10.0.2.21",
"proxmox_cidr": 24,
"proxmox_disque_taille": "16G",
"proxmox_passerelle": "10.0.2.1",
"proxmox_stockage": "stockage-a",
"proxmox_vlan": 15,
"proxmox_vmid": 95201,
},
# incomplet-01 : il manque l'IP (champ requis).
"incomplet-01": {
"proxmox_vmid": 99901,
"proxmox_cidr": 24,
"proxmox_passerelle": "10.0.2.1",
"proxmox_vlan": 99,
},
}
},
"serveur_postgresql": {"hosts": {"app-01": {}}},
}
}
}
def test_hote_complet_avec_noeud() -> None:
lignes = parametres_proxmox_hote(_inventaire_factice(), "app-01")
attendu = {
"SETOPS_VMID='93101'",
"SETOPS_IP='10.0.2.11'",
"SETOPS_CIDR='24'",
"SETOPS_PASSERELLE='10.0.2.1'",
"SETOPS_VLAN='13'",
"SETOPS_STOCKAGE='stockage-a'",
"SETOPS_DISQUE='160G'",
"SETOPS_NOEUD='noeud-a'",
}
assert set(lignes) == attendu, lignes
def test_hote_sans_noeud_emet_noeud_vide() -> None:
lignes = parametres_proxmox_hote(_inventaire_factice(), "app-02")
assert "SETOPS_NOEUD=''" in lignes, lignes
assert "SETOPS_VMID='95201'" in lignes, lignes
def test_hote_absent_refuse() -> None:
try:
parametres_proxmox_hote(_inventaire_factice(), "inconnu-01")
except ValueError as exc:
assert "absent" in str(exc), exc
else:
raise AssertionError("un hote absent doit lever ValueError")
def test_champ_requis_manquant_refuse() -> None:
try:
parametres_proxmox_hote(_inventaire_factice(), "incomplet-01")
except ValueError as exc:
assert "manquants" in str(exc) and "ansible_host" in str(exc), exc
else:
raise AssertionError("un champ requis manquant doit lever ValueError")
def main() -> int:
tests = [
test_hote_complet_avec_noeud,
test_hote_sans_noeud_emet_noeud_vide,
test_hote_absent_refuse,
test_champ_requis_manquant_refuse,
]
for test in tests:
test()
print(f"ok {test.__name__}")
print(f"{len(tests)} tests passes.")
return 0
if __name__ == "__main__":
raise SystemExit(main())