fix: don't clean up test VM in 06_VMs — later files depend on it

06_VMs AfterAll was deleting pester-test-vm, causing 07_Snapshots,
09_CloudInit, and 15_Tasks to fail with VMID 100 (wrong VM or
nonexistent). Now 99_Cleanup handles all pester-* resource removal.

Also fixed cleanup timing:
- Use -Wait on Stop-PveVm/Container before Remove
- Add sleep after removal for API propagation
- 10_Containers AfterAll uses -Wait on stop

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Clint Branham
2026-03-25 13:32:51 -05:00
parent df70e278ed
commit 72280e3697
3 changed files with 15 additions and 18 deletions
@@ -17,16 +17,8 @@ BeforeAll {
}
AfterAll {
if (-not $script:SkipReason -and $script:TestVmId) {
# Stop and remove pester-test-vm and any clone
foreach ($vmId in @($script:TestVmId, ($script:TestVmId + 1000))) {
try {
Stop-PveVm -Node $script:Node -VmId $vmId -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
Start-Sleep -Seconds 3
Remove-PveVm -Node $script:Node -VmId $vmId -Force -Purge -Confirm:$false -ErrorAction SilentlyContinue
} catch { }
}
}
# Do NOT clean up pester-test-vm here — later test files (07_Snapshots,
# 09_CloudInit, 15_Tasks) depend on it. 99_Cleanup handles removal.
Disconnect-TestPve
}
@@ -21,11 +21,12 @@ AfterAll {
if ($null -eq $script:SkipReason) {
foreach ($ctId in $script:CreatedContainerIds) {
try {
Stop-PveContainer -Node $script:Node -VmId $ctId -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
Start-Sleep -Seconds 3
Stop-PveContainer -Node $script:Node -VmId $ctId -Wait -Timeout 30 -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
} catch { }
Start-Sleep -Seconds 2
try {
Remove-PveContainer -Node $script:Node -VmId $ctId -Force -Purge -Confirm:$false -ErrorAction SilentlyContinue
}
catch { <# non-fatal #> }
} catch { }
}
}
Disconnect-TestPve
@@ -19,9 +19,9 @@ Describe 'Safety-Net Cleanup — Integration' -Tag 'Integration' {
$pesterVms = $vms | Where-Object { $_.Name -like 'pester-*' }
foreach ($vm in $pesterVms) {
try {
Stop-PveVm -Node $script:Node -VmId $vm.VmId -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
Start-Sleep -Seconds 3
Stop-PveVm -Node $script:Node -VmId $vm.VmId -Wait -Timeout 30 -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
} catch { }
Start-Sleep -Seconds 2
try {
# Try removing as template first (templates need Remove-PveTemplate)
Remove-PveTemplate -Node $script:Node -VmId $vm.VmId -Confirm:$false -ErrorAction SilentlyContinue
@@ -31,6 +31,8 @@ Describe 'Safety-Net Cleanup — Integration' -Tag 'Integration' {
} catch { }
}
}
# Wait for removals to complete
Start-Sleep -Seconds 3
# Verify
$remaining = Get-PveVm -Node $script:Node -ErrorAction SilentlyContinue |
@@ -45,13 +47,15 @@ Describe 'Safety-Net Cleanup — Integration' -Tag 'Integration' {
$pesterCts = $containers | Where-Object { $_.Name -like 'pester-*' }
foreach ($ct in $pesterCts) {
try {
Stop-PveContainer -Node $script:Node -VmId $ct.VmId -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
Start-Sleep -Seconds 3
Stop-PveContainer -Node $script:Node -VmId $ct.VmId -Wait -Timeout 30 -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
} catch { }
Start-Sleep -Seconds 2
try {
Remove-PveContainer -Node $script:Node -VmId $ct.VmId -Force -Purge -Confirm:$false -ErrorAction SilentlyContinue
} catch { }
}
# Wait for removals to complete
Start-Sleep -Seconds 3
# Verify
$remaining = Get-PveContainer -Node $script:Node -ErrorAction SilentlyContinue |