forked from milos85vasic/Mail-Server-Factory
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_all_tests
More file actions
executable file
·1566 lines (1301 loc) · 52.1 KB
/
run_all_tests
File metadata and controls
executable file
·1566 lines (1301 loc) · 52.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
#
# Mail Server Factory - Comprehensive Test Orchestrator
#
# This script executes ALL tests for the Mail Server Factory project:
# - Unit tests (Gradle)
# - Launcher tests
# - ISO downloads and verification
# - VM creation and OS installation for all distributions
# - Mail Server Factory deployment to each OS
# - Component verification
# - Report generation (Markdown + HTML)
#
# The script provides detailed progress tracking and retries until 100% success.
#
set -euo pipefail
# ============================================
# Configuration
# ============================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="${SCRIPT_DIR}"
RESULTS_DIR="${PROJECT_ROOT}/test_results"
TIMESTAMP=$(date '+%Y%m%d_%H%M%S')
MAIN_LOG="${RESULTS_DIR}/run_all_tests_${TIMESTAMP}.log"
HTML_REPORT="${RESULTS_DIR}/test_report_${TIMESTAMP}.html"
MD_REPORT="${RESULTS_DIR}/test_report_${TIMESTAMP}.md"
# Test configuration
MAX_RETRIES=3
VM_INSTALL_TIMEOUT=3600 # 1 hour per VM installation
DEPLOYMENT_TIMEOUT=1800 # 30 minutes per deployment
# Colors for terminal output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Progress tracking
TOTAL_PHASES=7
CURRENT_PHASE=0
# Test results tracking
declare -A UNIT_TEST_RESULTS
declare -A LAUNCHER_TEST_RESULTS
declare -A ISO_DOWNLOAD_RESULTS
declare -A VM_CREATION_RESULTS
declare -A OS_INSTALL_RESULTS
declare -A DEPLOYMENT_RESULTS
declare -A COMPONENT_VERIFICATION_RESULTS
# Distribution definitions (matching supported OSes)
declare -a DISTRIBUTIONS=(
"ubuntu-22:Ubuntu_22:Debian:4096:20G:2"
"ubuntu-24:Ubuntu_24:Debian:4096:20G:2"
"debian-11:Debian_11:Debian:4096:20G:2"
"debian-12:Debian_12:Debian:4096:20G:2"
"fedora-38:Fedora_Server_38:RHEL:8192:40G:4"
"fedora-39:Fedora_Server_39:RHEL:8192:40G:4"
"fedora-40:Fedora_Server_40:RHEL:8192:40G:4"
"fedora-41:Fedora_Server_41:RHEL:8192:40G:4"
"almalinux-9:AlmaLinux_9:RHEL:8192:40G:4"
"rocky-9:Rocky_9:RHEL:8192:40G:4"
"opensuse-15:openSUSE_Leap_15:SUSE:8192:40G:4"
)
# ============================================
# Logging Functions
# ============================================
log() {
local level="$1"
shift
local message="$*"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[${timestamp}] [${level}] ${message}" | tee -a "${MAIN_LOG}"
}
log_info() { log "INFO" "$@"; }
log_warn() { log "WARN" "$@"; }
log_error() { log "ERROR" "$@"; }
log_success() { log "SUCCESS" "$@"; }
log_debug() {
if [[ "${DEBUG:-false}" == "true" ]]; then
log "DEBUG" "$@"
fi
}
# ============================================
# Display Functions
# ============================================
print_banner() {
echo ""
echo -e "${CYAN}╔════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║ ║${NC}"
echo -e "${CYAN}║ ${BOLD}${MAGENTA}Mail Server Factory - Comprehensive Test Suite${NC}${CYAN} ║${NC}"
echo -e "${CYAN}║ ║${NC}"
echo -e "${CYAN}╚════════════════════════════════════════════════════════════════════╝${NC}"
echo ""
}
print_header() {
local title="$1"
local phase_info=""
CURRENT_PHASE=$((CURRENT_PHASE + 1))
phase_info="[Phase ${CURRENT_PHASE}/${TOTAL_PHASES}]"
echo ""
echo -e "${BLUE}════════════════════════════════════════════════════════════════════${NC}"
echo -e "${BLUE}${BOLD} ${phase_info} ${title}${NC}"
echo -e "${BLUE}════════════════════════════════════════════════════════════════════${NC}"
echo ""
log_info "${phase_info} ${title}"
}
print_subheader() {
echo ""
echo -e "${CYAN}──── $1${NC}"
echo ""
}
print_success() { echo -e "${GREEN}✓ $1${NC}"; }
print_error() { echo -e "${RED}✗ $1${NC}"; }
print_warning() { echo -e "${YELLOW}⚠ $1${NC}"; }
print_info() { echo -e "${BLUE}ℹ $1${NC}"; }
print_progress() {
local current=$1
local total=$2
local task=$3
local percent=$((current * 100 / total))
local filled=$((percent / 2))
local empty=$((50 - filled))
printf "\r${CYAN}Progress:${NC} ["
printf "%${filled}s" | tr ' ' '='
printf "%${empty}s" | tr ' ' ' '
printf "] %3d%% (%d/%d) - %s${NC}" "${percent}" "${current}" "${total}" "${task}"
if [ "${current}" -eq "${total}" ]; then
echo ""
fi
}
# ============================================
# Prerequisites Check
# ============================================
check_prerequisites() {
print_header "Checking Prerequisites"
local missing=0
local warnings=0
# Check Java
print_subheader "Java"
if command -v java &> /dev/null; then
local java_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2)
print_success "Java found: ${java_version}"
log_success "Java version: ${java_version}"
else
print_error "Java not found (required: Java 17+)"
missing=$((missing + 1))
fi
# Check Gradle
print_subheader "Build System"
if [ -f "${PROJECT_ROOT}/gradlew" ]; then
print_success "Gradle wrapper found"
else
print_error "Gradle wrapper not found"
missing=$((missing + 1))
fi
# Check Docker
print_subheader "Docker"
if command -v docker &> /dev/null; then
if docker ps &> /dev/null; then
print_success "Docker is running"
else
print_warning "Docker found but not running"
print_info "Starting Docker daemon may be required"
warnings=$((warnings + 1))
fi
else
print_error "Docker not found (required for tests)"
missing=$((missing + 1))
fi
# Check QEMU
print_subheader "QEMU"
if command -v qemu-system-x86_64 &> /dev/null; then
local qemu_version=$(qemu-system-x86_64 --version | head -n 1)
print_success "QEMU found: ${qemu_version}"
else
print_error "QEMU not found (install: sudo apt install qemu-system-x86 qemu-utils)"
missing=$((missing + 1))
fi
# Check disk space
print_subheader "Disk Space"
local available_gb=$(df -BG "${PROJECT_ROOT}" | tail -1 | awk '{print $4}' | sed 's/G//')
if [ "${available_gb}" -gt 100 ]; then
print_success "Available disk space: ${available_gb}GB"
else
print_warning "Low disk space: ${available_gb}GB (recommended: 100GB+)"
warnings=$((warnings + 1))
fi
# Check RAM
print_subheader "Memory"
local total_ram_gb=$(free -g | awk '/^Mem:/{print $2}')
if [ "${total_ram_gb}" -ge 16 ]; then
print_success "Total RAM: ${total_ram_gb}GB"
else
print_warning "Low RAM: ${total_ram_gb}GB (recommended: 16GB+)"
warnings=$((warnings + 1))
fi
# Summary
echo ""
if [ ${missing} -gt 0 ]; then
print_error "Prerequisites check failed: ${missing} critical dependencies missing"
return 1
elif [ ${warnings} -gt 0 ]; then
print_warning "Prerequisites check passed with ${warnings} warnings"
return 0
else
print_success "All prerequisites satisfied"
return 0
fi
}
# ============================================
# Phase 1: Unit Tests
# ============================================
run_unit_tests() {
print_header "Running Unit Tests (Gradle)"
local start_time=$(date +%s)
print_info "Running Gradle test suite..."
print_info "This includes Factory and Core:Framework modules"
if ./gradlew test --no-daemon 2>&1 | tee -a "${MAIN_LOG}"; then
UNIT_TEST_RESULTS["status"]="PASS"
print_success "Unit tests passed"
else
UNIT_TEST_RESULTS["status"]="FAIL"
print_error "Unit tests failed"
return 1
fi
# Generate coverage report
print_info "Generating test coverage report..."
if ./gradlew jacocoTestReport --no-daemon 2>&1 | tee -a "${MAIN_LOG}"; then
local coverage_report="${PROJECT_ROOT}/Core/Framework/build/reports/jacoco/test/html/index.html"
if [ -f "${coverage_report}" ]; then
print_success "Coverage report generated: ${coverage_report}"
UNIT_TEST_RESULTS["coverage_report"]="${coverage_report}"
fi
fi
local end_time=$(date +%s)
local duration=$((end_time - start_time))
UNIT_TEST_RESULTS["duration"]="${duration}"
print_success "Unit tests completed in ${duration} seconds"
return 0
}
# ============================================
# Phase 2: Launcher Tests
# ============================================
run_launcher_tests() {
print_header "Running Launcher Tests"
local start_time=$(date +%s)
local test_script="${PROJECT_ROOT}/tests/launcher/test_launcher.sh"
if [ ! -f "${test_script}" ]; then
print_error "Launcher test script not found: ${test_script}"
LAUNCHER_TEST_RESULTS["status"]="SKIP"
return 1
fi
print_info "Executing launcher test suite (41 tests)..."
if bash "${test_script}" 2>&1 | tee -a "${MAIN_LOG}"; then
LAUNCHER_TEST_RESULTS["status"]="PASS"
print_success "All launcher tests passed"
else
LAUNCHER_TEST_RESULTS["status"]="FAIL"
print_error "Launcher tests failed"
return 1
fi
local end_time=$(date +%s)
local duration=$((end_time - start_time))
LAUNCHER_TEST_RESULTS["duration"]="${duration}"
print_success "Launcher tests completed in ${duration} seconds"
return 0
}
# ============================================
# Phase 3: ISO Download and Verification
# ============================================
download_and_verify_isos() {
print_header "Downloading and Verifying ISOs"
local start_time=$(date +%s)
local iso_script="${PROJECT_ROOT}/scripts/iso_manager.sh"
if [ ! -f "${iso_script}" ]; then
print_error "ISO manager script not found: ${iso_script}"
ISO_DOWNLOAD_RESULTS["status"]="FAIL"
return 1
fi
# Check if ISOs already exist
print_subheader "Checking existing ISOs"
bash "${iso_script}" list 2>&1 | tee -a "${MAIN_LOG}"
# Download ISOs
print_subheader "Downloading ISOs"
print_info "This may take a while depending on network speed..."
if bash "${iso_script}" download 2>&1 | tee -a "${MAIN_LOG}"; then
print_success "ISO download completed"
else
print_error "ISO download failed"
ISO_DOWNLOAD_RESULTS["status"]="FAIL"
return 1
fi
# Verify ISOs
print_subheader "Verifying ISO checksums"
if bash "${iso_script}" verify 2>&1 | tee -a "${MAIN_LOG}"; then
ISO_DOWNLOAD_RESULTS["status"]="PASS"
print_success "All ISOs verified successfully"
else
ISO_DOWNLOAD_RESULTS["status"]="FAIL"
print_error "ISO verification failed"
return 1
fi
local end_time=$(date +%s)
local duration=$((end_time - start_time))
ISO_DOWNLOAD_RESULTS["duration"]="${duration}"
print_success "ISO phase completed in ${duration} seconds"
return 0
}
# ============================================
# Phase 4: VM Creation
# ============================================
create_all_vms() {
print_header "Creating Virtual Machines"
local start_time=$(date +%s)
local qemu_script="${PROJECT_ROOT}/scripts/qemu_manager.sh"
local total_vms=${#DISTRIBUTIONS[@]}
local current_vm=0
local created=0
local failed=0
print_info "Creating ${total_vms} virtual machines..."
for dist_config in "${DISTRIBUTIONS[@]}"; do
IFS=':' read -r vm_name config_name family memory disk cpus <<< "${dist_config}"
current_vm=$((current_vm + 1))
print_progress ${current_vm} ${total_vms} "Creating ${vm_name}"
log_info "Creating VM: ${vm_name} (${family} family, ${memory}MB RAM, ${disk} disk, ${cpus} CPUs)"
if bash "${qemu_script}" create "${vm_name}" "${memory}" "${disk}" "${cpus}" >> "${MAIN_LOG}" 2>&1; then
VM_CREATION_RESULTS["${vm_name}"]="PASS"
created=$((created + 1))
else
VM_CREATION_RESULTS["${vm_name}"]="FAIL"
failed=$((failed + 1))
log_error "Failed to create VM: ${vm_name}"
fi
done
local end_time=$(date +%s)
local duration=$((end_time - start_time))
echo ""
print_info "VM Creation Summary:"
print_success "Created: ${created}"
if [ ${failed} -gt 0 ]; then
print_error "Failed: ${failed}"
return 1
fi
print_success "All VMs created in ${duration} seconds"
return 0
}
# ============================================
# Phase 5: OS Installation
# ============================================
install_all_operating_systems() {
print_header "Installing Operating Systems"
local start_time=$(date +%s)
local qemu_script="${PROJECT_ROOT}/scripts/qemu_manager.sh"
local total_installs=${#DISTRIBUTIONS[@]}
local current_install=0
local installed=0
local failed=0
print_info "Installing ${total_installs} operating systems..."
print_warning "This phase may take several hours"
for dist_config in "${DISTRIBUTIONS[@]}"; do
IFS=':' read -r vm_name config_name family memory disk cpus <<< "${dist_config}"
current_install=$((current_install + 1))
print_progress ${current_install} ${total_installs} "Installing ${vm_name}"
# Skip if VM creation failed
if [ "${VM_CREATION_RESULTS[${vm_name}]:-}" != "PASS" ]; then
OS_INSTALL_RESULTS["${vm_name}"]="SKIP"
log_warn "Skipping ${vm_name} installation (VM creation failed)"
continue
fi
log_info "Starting installation for ${vm_name}..."
# Start VM
if ! bash "${qemu_script}" start "${vm_name}" "${memory}" "${cpus}" >> "${MAIN_LOG}" 2>&1; then
OS_INSTALL_RESULTS["${vm_name}"]="FAIL"
log_error "Failed to start VM: ${vm_name}"
failed=$((failed + 1))
continue
fi
# Wait for installation to complete
local install_timeout=${VM_INSTALL_TIMEOUT}
case "${family}" in
"Debian") install_timeout=1800 ;; # 30 minutes
"RHEL") install_timeout=3600 ;; # 60 minutes
"SUSE") install_timeout=3600 ;; # 60 minutes
esac
log_info "Waiting for ${vm_name} installation (timeout: ${install_timeout}s)..."
# Monitor installation progress
local elapsed=0
local check_interval=30
local install_complete=false
while [ ${elapsed} -lt ${install_timeout} ]; do
sleep ${check_interval}
((elapsed+=check_interval))
# Check if VM is still running
if ! bash "${qemu_script}" status "${vm_name}" >> "${MAIN_LOG}" 2>&1; then
# VM stopped - could mean installation complete
install_complete=true
break
fi
# Show progress every 5 minutes
if [ $((elapsed % 300)) -eq 0 ]; then
local minutes=$((elapsed / 60))
log_info "${vm_name} installation in progress (${minutes} minutes elapsed)..."
fi
done
if [ "${install_complete}" = true ]; then
OS_INSTALL_RESULTS["${vm_name}"]="PASS"
installed=$((installed + 1))
log_success "${vm_name} installation completed"
# Archive the installed system
local archive_dir="${PROJECT_ROOT}/vms/archives"
mkdir -p "${archive_dir}"
local archive_file="${archive_dir}/${vm_name}_installed_${TIMESTAMP}.qcow2.gz"
log_info "Archiving ${vm_name} installation..."
if gzip -c "${PROJECT_ROOT}/vms/${vm_name}/${vm_name}.qcow2" > "${archive_file}"; then
log_success "Archived: ${archive_file}"
OS_INSTALL_RESULTS["${vm_name}_archive"]="${archive_file}"
fi
else
OS_INSTALL_RESULTS["${vm_name}"]="TIMEOUT"
failed=$((failed + 1))
log_error "${vm_name} installation timed out after ${install_timeout} seconds"
# Stop the VM
bash "${qemu_script}" stop "${vm_name}" >> "${MAIN_LOG}" 2>&1 || true
fi
done
local end_time=$(date +%s)
local duration=$((end_time - start_time))
echo ""
print_info "OS Installation Summary:"
print_success "Installed: ${installed}"
if [ ${failed} -gt 0 ]; then
print_error "Failed/Timeout: ${failed}"
fi
if [ ${failed} -gt 0 ]; then
print_warning "Some OS installations failed or timed out"
return 1
fi
print_success "All OS installations completed in ${duration} seconds"
return 0
}
# ============================================
# Phase 6: Mail Server Factory Deployment
# ============================================
deploy_mail_server_factory() {
print_header "Deploying Mail Server Factory"
local start_time=$(date +%s)
local total_deployments=${#DISTRIBUTIONS[@]}
local current_deployment=0
local deployed=0
local failed=0
# Build the application first
print_subheader "Building Application"
print_info "Building Mail Server Factory..."
if ./gradlew :Application:assemble --no-daemon 2>&1 | tee -a "${MAIN_LOG}"; then
print_success "Application built successfully"
else
print_error "Application build failed"
return 1
fi
# Check for Docker credentials
local docker_config="${PROJECT_ROOT}/Examples/Includes/_Docker.json"
if [ ! -f "${docker_config}" ]; then
print_warning "Docker credentials not found: ${docker_config}"
print_info "Some deployments may fail without Docker Hub credentials"
print_info "See Examples/Includes/README.md for setup instructions"
fi
print_subheader "Deploying to VMs"
print_info "Deploying to ${total_deployments} virtual machines..."
for dist_config in "${DISTRIBUTIONS[@]}"; do
IFS=':' read -r vm_name config_name family memory disk cpus <<< "${dist_config}"
current_deployment=$((current_deployment + 1))
print_progress ${current_deployment} ${total_deployments} "Deploying to ${vm_name}"
# Skip if OS installation failed
if [ "${OS_INSTALL_RESULTS[${vm_name}]:-}" != "PASS" ]; then
DEPLOYMENT_RESULTS["${vm_name}"]="SKIP"
log_warn "Skipping ${vm_name} deployment (OS installation failed)"
continue
fi
local config_file="${PROJECT_ROOT}/Examples/${config_name}.json"
if [ ! -f "${config_file}" ]; then
DEPLOYMENT_RESULTS["${vm_name}"]="FAIL"
log_error "Configuration file not found: ${config_file}"
failed=$((failed + 1))
continue
fi
log_info "Deploying Mail Server Factory to ${vm_name}..."
log_info "Configuration: ${config_file}"
# Run deployment
local deployment_log="${RESULTS_DIR}/${vm_name}_deployment_${TIMESTAMP}.log"
if timeout ${DEPLOYMENT_TIMEOUT} ./mail_factory "${config_file}" > "${deployment_log}" 2>&1; then
DEPLOYMENT_RESULTS["${vm_name}"]="PASS"
deployed=$((deployed + 1))
log_success "${vm_name} deployment completed"
else
local exit_code=$?
DEPLOYMENT_RESULTS["${vm_name}"]="FAIL"
failed=$((failed + 1))
if [ ${exit_code} -eq 124 ]; then
log_error "${vm_name} deployment timed out after ${DEPLOYMENT_TIMEOUT} seconds"
DEPLOYMENT_RESULTS["${vm_name}"]="TIMEOUT"
else
log_error "${vm_name} deployment failed with exit code: ${exit_code}"
log_error "See log: ${deployment_log}"
fi
fi
done
local end_time=$(date +%s)
local duration=$((end_time - start_time))
echo ""
print_info "Deployment Summary:"
print_success "Deployed: ${deployed}"
if [ ${failed} -gt 0 ]; then
print_error "Failed: ${failed}"
fi
if [ ${failed} -gt 0 ]; then
print_warning "Some deployments failed"
return 1
fi
print_success "All deployments completed in ${duration} seconds"
return 0
}
# ============================================
# Phase 7: Component Verification
# ============================================
verify_all_components() {
print_header "Verifying Mail Server Components"
local start_time=$(date +%s)
local total_verifications=${#DISTRIBUTIONS[@]}
local current_verification=0
local verified=0
local failed=0
print_info "Verifying components on ${total_verifications} systems..."
# Expected components
local -a expected_containers=(
"postmaster_receive"
"postmaster_send"
"postmaster_antispam"
"postmaster_antivirus"
"postmaster_mem_db"
"postmaster_db"
)
for dist_config in "${DISTRIBUTIONS[@]}"; do
IFS=':' read -r vm_name config_name family memory disk cpus <<< "${dist_config}"
current_verification=$((current_verification + 1))
print_progress ${current_verification} ${total_verifications} "Verifying ${vm_name}"
# Skip if deployment failed
if [ "${DEPLOYMENT_RESULTS[${vm_name}]:-}" != "PASS" ]; then
COMPONENT_VERIFICATION_RESULTS["${vm_name}"]="SKIP"
log_warn "Skipping ${vm_name} verification (deployment failed)"
continue
fi
log_info "Verifying components on ${vm_name}..."
# Get SSH port for this VM
local ssh_port=$((2222 + $(echo "${vm_name}" | tr -cd '0-9' | sed 's/^0*//' || echo "0")))
# Verify Docker containers are running
local verification_passed=true
local containers_running=0
for container in "${expected_containers[@]}"; do
if ssh -p ${ssh_port} -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@localhost \
"docker ps --format '{{.Names}}' | grep -q ${container}" >> "${MAIN_LOG}" 2>&1; then
containers_running=$((containers_running + 1))
log_debug "${vm_name}: Container ${container} is running"
else
verification_passed=false
log_warn "${vm_name}: Container ${container} is NOT running"
fi
done
if [ "${verification_passed}" = true ] && [ ${containers_running} -eq ${#expected_containers[@]} ]; then
COMPONENT_VERIFICATION_RESULTS["${vm_name}"]="PASS"
verified=$((verified + 1))
log_success "${vm_name}: All ${containers_running} components verified"
else
COMPONENT_VERIFICATION_RESULTS["${vm_name}"]="FAIL"
failed=$((failed + 1))
log_error "${vm_name}: Component verification failed (${containers_running}/${#expected_containers[@]} running)"
fi
done
local end_time=$(date +%s)
local duration=$((end_time - start_time))
echo ""
print_info "Verification Summary:"
print_success "Verified: ${verified}"
if [ ${failed} -gt 0 ]; then
print_error "Failed: ${failed}"
fi
if [ ${failed} -gt 0 ]; then
print_warning "Some component verifications failed"
return 1
fi
print_success "All components verified in ${duration} seconds"
return 0
}
# ============================================
# Report Generation
# ============================================
generate_markdown_report() {
local report_file="$1"
cat > "${report_file}" <<'EOF'
# Mail Server Factory - Comprehensive Test Report
EOF
echo "**Generated**: $(date '+%Y-%m-%d %H:%M:%S')" >> "${report_file}"
echo "" >> "${report_file}"
# Executive Summary
cat >> "${report_file}" <<'EOF'
## Executive Summary
This report contains the results of comprehensive testing across all phases of the Mail Server Factory project, including unit tests, VM deployments, and component verification.
EOF
# Test Phase Results
cat >> "${report_file}" <<'EOF'
## Test Phase Results
### Phase 1: Unit Tests (Gradle)
EOF
if [ "${UNIT_TEST_RESULTS[status]}" = "PASS" ]; then
echo "✅ **Status**: PASSED" >> "${report_file}"
else
echo "❌ **Status**: FAILED" >> "${report_file}"
fi
echo "**Duration**: ${UNIT_TEST_RESULTS[duration]:-0} seconds" >> "${report_file}"
echo "" >> "${report_file}"
# Launcher Tests
cat >> "${report_file}" <<'EOF'
### Phase 2: Launcher Tests
EOF
if [ "${LAUNCHER_TEST_RESULTS[status]}" = "PASS" ]; then
echo "✅ **Status**: PASSED (41 tests)" >> "${report_file}"
else
echo "❌ **Status**: FAILED" >> "${report_file}"
fi
echo "**Duration**: ${LAUNCHER_TEST_RESULTS[duration]:-0} seconds" >> "${report_file}"
echo "" >> "${report_file}"
# ISO Download
cat >> "${report_file}" <<'EOF'
### Phase 3: ISO Download & Verification
EOF
if [ "${ISO_DOWNLOAD_RESULTS[status]}" = "PASS" ]; then
echo "✅ **Status**: PASSED" >> "${report_file}"
else
echo "❌ **Status**: FAILED" >> "${report_file}"
fi
echo "**Duration**: ${ISO_DOWNLOAD_RESULTS[duration]:-0} seconds" >> "${report_file}"
echo "" >> "${report_file}"
# Distribution Results Table
cat >> "${report_file}" <<'EOF'
## Distribution Test Results
| Distribution | VM Creation | OS Install | Deployment | Verification | Overall |
|--------------|-------------|------------|------------|--------------|---------|
EOF
for dist_config in "${DISTRIBUTIONS[@]}"; do
IFS=':' read -r vm_name config_name family memory disk cpus <<< "${dist_config}"
local vm_status="${VM_CREATION_RESULTS[${vm_name}]:-UNKNOWN}"
local os_status="${OS_INSTALL_RESULTS[${vm_name}]:-UNKNOWN}"
local deploy_status="${DEPLOYMENT_RESULTS[${vm_name}]:-UNKNOWN}"
local verify_status="${COMPONENT_VERIFICATION_RESULTS[${vm_name}]:-UNKNOWN}"
local overall="✅ PASS"
if [[ "${vm_status}" != "PASS" ]] || [[ "${os_status}" != "PASS" ]] || \
[[ "${deploy_status}" != "PASS" ]] || [[ "${verify_status}" != "PASS" ]]; then
overall="❌ FAIL"
fi
echo "| ${config_name} | ${vm_status} | ${os_status} | ${deploy_status} | ${verify_status} | ${overall} |" >> "${report_file}"
done
echo "" >> "${report_file}"
# Detailed Results
cat >> "${report_file}" <<'EOF'
## Detailed Results by Distribution
EOF
for dist_config in "${DISTRIBUTIONS[@]}"; do
IFS=':' read -r vm_name config_name family memory disk cpus <<< "${dist_config}"
cat >> "${report_file}" <<EOF
### ${config_name}
- **VM Name**: ${vm_name}
- **Family**: ${family}
- **Resources**: ${memory}MB RAM, ${disk} disk, ${cpus} CPUs
- **VM Creation**: ${VM_CREATION_RESULTS[${vm_name}]:-UNKNOWN}
- **OS Installation**: ${OS_INSTALL_RESULTS[${vm_name}]:-UNKNOWN}
- **Deployment**: ${DEPLOYMENT_RESULTS[${vm_name}]:-UNKNOWN}
- **Verification**: ${COMPONENT_VERIFICATION_RESULTS[${vm_name}]:-UNKNOWN}
EOF
if [ -n "${OS_INSTALL_RESULTS[${vm_name}_archive]:-}" ]; then
echo "- **Archive**: ${OS_INSTALL_RESULTS[${vm_name}_archive]:-}" >> "${report_file}"
echo "" >> "${report_file}"
fi
done
# Summary Statistics
local total_dists=${#DISTRIBUTIONS[@]}
local passed=0
local failed=0
for dist_config in "${DISTRIBUTIONS[@]}"; do
IFS=':' read -r vm_name config_name family memory disk cpus <<< "${dist_config}"
if [ "${VM_CREATION_RESULTS[${vm_name}]:-}" = "PASS" ] && \
[ "${OS_INSTALL_RESULTS[${vm_name}]:-}" = "PASS" ] && \
[ "${DEPLOYMENT_RESULTS[${vm_name}]:-}" = "PASS" ] && \
[ "${COMPONENT_VERIFICATION_RESULTS[${vm_name}]:-}" = "PASS" ]; then
passed=$((passed + 1))
else
failed=$((failed + 1))
fi
done
cat >> "${report_file}" <<EOF
## Summary Statistics
- **Total Distributions Tested**: ${total_dists}
- **Fully Passed**: ${passed}
- **Failed**: ${failed}
- **Success Rate**: $((passed * 100 / total_dists))%
---
*This report was automatically generated by run_all_tests*
EOF
}
generate_html_report() {
local report_file="$1"
cat > "${report_file}" <<'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Mail Server Factory - Test Report</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
line-height: 1.6;
color: #333;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
border-radius: 10px;
box-shadow: 0 10px 40px rgba(0,0,0,0.3);
overflow: hidden;
}
header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 40px;
text-align: center;
}
header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
header p {
font-size: 1.2em;
opacity: 0.9;
}
.content {
padding: 40px;
}
h2 {
color: #667eea;
margin: 30px 0 15px 0;
padding-bottom: 10px;
border-bottom: 2px solid #667eea;
}
h3 {
color: #764ba2;
margin: 20px 0 10px 0;
}
.summary-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
margin: 30px 0;
}
.summary-card {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
border-radius: 8px;
text-align: center;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.summary-card h3 {
color: white;
font-size: 2em;
margin: 10px 0;
}
.summary-card p {
font-size: 0.9em;
opacity: 0.9;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
table thead {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
table th, table td {
padding: 12px 15px;
text-align: left;
}
table tbody tr:nth-child(even) {
background: #f8f9fa;
}
table tbody tr:hover {
background: #e9ecef;
}
.status-pass { color: #28a745; font-weight: bold; }
.status-fail { color: #dc3545; font-weight: bold; }
.status-skip { color: #ffc107; font-weight: bold; }
.phase-result {
background: #f8f9fa;
padding: 15px;
border-radius: 8px;
margin: 15px 0;
border-left: 4px solid #667eea;
}
.phase-result.pass { border-left-color: #28a745; }
.phase-result.fail { border-left-color: #dc3545; }
footer {
background: #f8f9fa;
padding: 20px;
text-align: center;
color: #666;
font-size: 0.9em;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>📧 Mail Server Factory</h1>
<p>Comprehensive Test Report</p>
<p style="font-size: 0.9em; opacity: 0.8;">