Files
wevads-platform/scripts/test_mta_vmta_lifecycle.sh
2026-02-26 04:53:11 +01:00

93 lines
3.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🧪 TEST LIFECYCLE MTA + VMTA"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "📊 État initial..."
sudo -u postgres psql -d adx_system -c "SELECT COUNT(*) as servers FROM admin.servers WHERE server_type='mta';"
sudo -u postgres psql -d adx_system -c "SELECT COUNT(*) as vmtas FROM admin.vmtas;"
echo ""
echo "1⃣ TEST CRÉATION - Créer 1 serveur MTA..."
RESULT=$(curl -s -X POST "http://localhost:5821/api/huawei_ir.php?action=provision" \
-H "Content-Type: application/json" \
-d '{"region":"eu-west-0","flavor":"s6.medium.2","count":1,"prefix":"test-mta"}')
echo "$RESULT" | python3 -m json.tool 2>/dev/null || echo "$RESULT"
SERVER_ID=$(echo "$RESULT" | python3 -c "import sys,json; data=json.load(sys.stdin); print(data['results'][0]['db_id'] if data.get('results') else 0)" 2>/dev/null)
echo ""
echo "2⃣ Vérification VMTAs créés automatiquement..."
sudo -u postgres psql -d adx_system << EOSQL
SELECT
s.id as server_id,
s.name as server_name,
COUNT(v.id) as vmtas_created,
string_agg(v.name, ', ') as vmta_names
FROM admin.servers s
LEFT JOIN admin.vmtas v ON v.server_id = s.id
WHERE s.id = $SERVER_ID
GROUP BY s.id, s.name;
-- Détail des VMTAs
SELECT id, name, ip_address, hostname, status
FROM admin.vmtas
WHERE server_id = $SERVER_ID;
EOSQL
echo ""
echo "3⃣ Vérification logs..."
sudo -u postgres psql -d adx_system -c "SELECT step, status, message FROM admin.installation_logs WHERE server_id = $SERVER_ID ORDER BY created_at;"
echo ""
echo "4⃣ TEST SUPPRESSION - Supprimer serveur..."
if [ "$SERVER_ID" -gt 0 ]; then
curl -s -X POST "http://localhost:5821/api/huawei_ir.php?action=delete" \
-H "Content-Type: application/json" \
-d "{\"server_id\":$SERVER_ID}" | python3 -m json.tool
echo ""
echo "5⃣ Vérification VMTAs supprimés automatiquement..."
REMAINING=$(sudo -u postgres psql -d adx_system -t -c "SELECT COUNT(*) FROM admin.vmtas WHERE server_id = $SERVER_ID;")
if [ "$REMAINING" -eq 0 ]; then
echo "✅ VMTAs correctement supprimés (0 restant)"
else
echo "❌ ERREUR: $REMAINING VMTAs orphelins!"
fi
else
echo "⚠️ Pas de server_id pour tester la suppression"
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📊 RÉSUMÉ FINAL"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
sudo -u postgres psql -d adx_system << 'EOSQL'
SELECT
'Total MTA servers' as metric,
COUNT(*) as value
FROM admin.servers WHERE server_type='mta'
UNION ALL
SELECT
'Total VMTAs',
COUNT(*)
FROM admin.vmtas
UNION ALL
SELECT
'Orphan VMTAs',
COUNT(*)
FROM admin.vmtas v
WHERE NOT EXISTS (SELECT 1 FROM admin.servers s WHERE s.id = v.server_id)
UNION ALL
SELECT
'MTA without VMTAs',
COUNT(*)
FROM admin.servers s
WHERE s.server_type='mta'
AND s.pmta_installed = true
AND NOT EXISTS (SELECT 1 FROM admin.vmtas v WHERE v.server_id = s.id);
EOSQL