creer-vm HOTE=<hote> ne prend plus qu'un argument : il lit VMID/IP/CIDR/passerelle/VLAN/stockage/disque/noeud dans l'inventaire genere (nouvelle sous-commande inventory_host parametres-proxmox), comme deployer lit ses groupes, et n'ecrit plus dans l'inventaire (plus de hote-ajouter). Les 3 cibles legacy hote-ajouter/planifier/groupes sont neutralisees (refus -> plan). Aide + docs alignees. Premier test stdlib du depot + cible make test, cablee dans make verifier. Verifie : make verifier exit 0 (4 tests), extraction testee sur l'inventaire reel + chemins de refus. Clonage reel non execute (Proxmox). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
115 lines
3.8 KiB
Python
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": {
|
|
"data-01": {
|
|
"ansible_host": "10.1.13.11",
|
|
"ansible_user": "ansible",
|
|
"proxmox_cidr": 24,
|
|
"proxmox_coeurs": 4,
|
|
"proxmox_disque_taille": "160G",
|
|
"proxmox_memoire": 2048,
|
|
"proxmox_noeud": "asgard",
|
|
"proxmox_passerelle": "10.1.13.1",
|
|
"proxmox_stockage": "TrueNAS",
|
|
"proxmox_vlan": 13,
|
|
"proxmox_vmid": 93101,
|
|
},
|
|
# collab-01 : sans proxmox_noeud (champ optionnel).
|
|
"collab-01": {
|
|
"ansible_host": "10.1.15.21",
|
|
"proxmox_cidr": 24,
|
|
"proxmox_disque_taille": "16G",
|
|
"proxmox_passerelle": "10.1.15.1",
|
|
"proxmox_stockage": "TrueNAS",
|
|
"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.1.99.1",
|
|
"proxmox_vlan": 99,
|
|
},
|
|
}
|
|
},
|
|
"serveur_postgresql": {"hosts": {"data-01": {}}},
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
def test_hote_complet_avec_noeud() -> None:
|
|
lignes = parametres_proxmox_hote(_inventaire_factice(), "data-01")
|
|
attendu = {
|
|
"SETOPS_VMID='93101'",
|
|
"SETOPS_IP='10.1.13.11'",
|
|
"SETOPS_CIDR='24'",
|
|
"SETOPS_PASSERELLE='10.1.13.1'",
|
|
"SETOPS_VLAN='13'",
|
|
"SETOPS_STOCKAGE='TrueNAS'",
|
|
"SETOPS_DISQUE='160G'",
|
|
"SETOPS_NOEUD='asgard'",
|
|
}
|
|
assert set(lignes) == attendu, lignes
|
|
|
|
|
|
def test_hote_sans_noeud_emet_noeud_vide() -> None:
|
|
lignes = parametres_proxmox_hote(_inventaire_factice(), "collab-01")
|
|
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())
|