Groupes d'hotes : objet HG et suggestions dans le champ de l'hote
build / Images Harbor (catalog-sync, Dockerfile.catalog-sync) (push) Successful in 9m49s
build / Garde-fou (push) Successful in 10m37s
build / Images Harbor (web, Dockerfile) (push) Successful in 13m15s

This commit is contained in:
hcornet committed 2026-09-11 19:06:36 +02:00
1 parent 23395779ee
commit 2187a1971e
9 files changed
+215 -6

No files matched your search

+1 -1
View File
@@ -60,7 +60,7 @@ if (!rail || !principal) {
}
// Chaque type d'objet doit se creer, s'afficher, et remplir la fenetre.
const types = ['command', 'stpl', 'htpl', 'host', 'calendrier', 'perimetre'];
const types = ['command', 'stpl', 'htpl', 'host', 'groupehote', 'calendrier', 'perimetre'];
if (erreurs.length === 0) {
for (const type of types) {
const ajouter = [...rail.querySelectorAll('button')].filter((b) => b.textContent === '+');
+40
View File
@@ -168,3 +168,43 @@ def test_le_repertoire_correspond_a_la_categorie():
for pack in Catalog("catalog").packs.values():
repertoire = os.path.basename(os.path.dirname(pack.source_file))
assert repertoire == pack.category, f"{pack.id} : {repertoire} != {pack.category}"
def test_groupes_d_hotes_crees_et_rattaches():
"""Un hote sans groupe devient introuvable des que le parc grandit."""
projet = Project.from_dict(
{
"groupes_hotes": [{"name": "HG-Serveurs-Linux", "alias": "Serveurs Linux"}],
"hosts": [
{
"name": "srv-01",
"address": "10.0.4.1",
"templates": ["OS-Linux-SNMP-custom"],
"hostgroups": ["HG-Serveurs-Linux", "HG-Production"],
}
],
}
)
lignes = [o.import_line() for o in build_plan(projet).ops if o.obj != "#"]
assert "HG;ADD;HG-Serveurs-Linux;Serveurs Linux" in lignes
hote = next(ligne for ligne in lignes if ligne.startswith("HOST;ADD;"))
assert hote.endswith("HG-Serveurs-Linux|HG-Production")
# Un groupe absent du projet est signale, sans bloquer : il peut exister deja.
messages = [i["message"] for i in build_plan(projet).issues]
assert any("HG-Production" in m for m in messages)
def test_ancien_format_de_groupes_accepte():
"""Les projets enregistres avant la 1.12 portaient une chaine unique."""
projet = Project.from_dict(
{"hosts": [{"name": "srv", "address": "10.0.0.1", "hostgroups": "HG-A|HG-B"}]}
)
assert projet.hosts[0].hostgroups == ["HG-A", "HG-B"]
def test_rollback_supprime_les_groupes_d_hotes():
projet = Project.from_dict({"groupes_hotes": [{"name": "HG-Essai"}]})
lignes = [o.import_line() for o in build_plan(projet).rollback_ops]
assert "HG;DEL;HG-Essai" in lignes
+43
View File
@@ -432,3 +432,46 @@ def test_un_pack_importe_produit_le_cablage_complet():
)
assert any("STPL;setcontactgroup;" in ligne for ligne in lignes)
assert any("notification_period;24x7" in ligne for ligne in lignes)
def test_la_fusion_d_un_pack_apporte_tout(app):
"""L'import doit apporter le calendrier, le perimetre et les prerequis,
pas seulement les commandes et les modeles."""
client = app.test_client()
# Un projet vide, puis deux packs successifs.
reponse = client.post(
"/api/packs/app-mysql/fusionner", json={"project": {"name": "Essai"}}
)
assert reponse.status_code == 200
projet = reponse.get_json()["project"]
assert projet["perimetres"], "aucun perimetre importe"
assert projet["perimetres"][0]["groupe"] == "CG-App-DB-MySQL"
assert projet["prerequis"]["paquets_debian"], "les prerequis du pack sont perdus"
assert projet["host_templates"][0]["perimetre"] == projet["perimetres"][0]["name"]
# Le second pack apporte son propre calendrier sans ecraser le premier.
suite = client.post(
"/api/packs/hw-printer-rfc3805/fusionner", json={"project": projet}
).get_json()["project"]
assert len(suite["perimetres"]) == 2
assert [c["name"] for c in suite["calendriers"]] == ["Heures-Ouvrees"]
assert len(suite["host_templates"]) == 2
def test_la_fusion_signale_les_doublons(app):
client = app.test_client()
projet = client.post(
"/api/packs/app-mysql/fusionner", json={"project": {"name": "Essai"}}
).get_json()["project"]
rejoue = client.post("/api/packs/app-mysql/fusionner", json={"project": projet}).get_json()
assert rejoue["ignores"], "un pack importe deux fois doit signaler les doublons"
assert len(rejoue["project"]["perimetres"]) == 1
def test_fusion_d_un_pack_inconnu(app):
reponse = app.test_client().post("/api/packs/inexistant/fusionner", json={"project": {}})
assert reponse.status_code == 404