@@ -1073,7 +1073,8 @@ launch_vm() {
10731073
10741074 # Cleanup the failed VM before trying to recreate it
10751075 # Keep the storage pool for the subsequent VM creation
1076- remove_vm " ${vmname} " true
1076+ # Force destroy even in scheduler mode so retry can work
1077+ remove_vm " ${vmname} " true true
10771078 done
10781079
10791080 if ${vm_created} ; then
@@ -1143,23 +1144,25 @@ launch_vm() {
11431144}
11441145
11451146# Clean up the resources for one VM, optionally skipping storage pool removal
1147+ # Parameters:
1148+ # vmname: name of the VM to remove
1149+ # keep_pool: if true, keep the storage pool (default: false)
1150+ # force_destroy: if true, destroy VM even in scheduler mode (default: false)
1151+ # Used by retry logic to clean up failed VM creation attempts
11461152remove_vm () {
11471153 local -r vmname=" ${1} "
11481154 local -r keep_pool=" ${2:- false} "
1155+ local -r force_destroy=" ${3:- false} "
11491156 local -r full_vmname=" $( full_vm_name " ${vmname} " ) "
11501157
1151- # In scheduler mode, the scheduler handles VM lifecycle
1152- # We only release the VM back to the scheduler, not destroy it
1153- if [ " ${SCHEDULER_ENABLED} " = " true" ]; then
1154- echo " Scheduler mode: releasing VM ${full_vmname} to scheduler"
1155- # The scheduler will handle destruction when no compatible scenarios remain
1156- # Just clean up scenario-specific state
1157- rm -rf " ${SCENARIO_INFO_DIR} /${SCENARIO} /vms/${vmname} "
1158+ # In scheduler mode, skip VM destruction unless forced (needed for retry logic)
1159+ # This allows VMs to be reused by subsequent scenarios
1160+ if [ " ${SCHEDULER_ENABLED} " = " true" ] && [ " ${force_destroy} " != " true" ]; then
11581161 return 0
11591162 fi
11601163
11611164 # Remove the actual VM
1162- if sudo virsh dumpxml " ${full_vmname} " > /dev/null; then
1165+ if sudo virsh dumpxml " ${full_vmname} " > /dev/null 2>&1 ; then
11631166 if ! sudo virsh dominfo " ${full_vmname} " | grep ' ^State' | grep -q ' shut off' ; then
11641167 sudo virsh destroy --graceful " ${full_vmname} " || true
11651168 fi
0 commit comments