refactor: streamline error handling with contextlib in template preparation

This commit is contained in:
2026-05-26 18:42:32 +02:00
parent 9c84e66dc3
commit 5d1ec39b1d
3 changed files with 6 additions and 11 deletions
+1 -1
View File
@@ -19,10 +19,10 @@ from __future__ import annotations
import json
import re
import shutil
import signal
import subprocess
import sys
import tempfile
import signal
import time
import uuid
from datetime import UTC, datetime
+4 -9
View File
@@ -55,6 +55,7 @@ template prepare-win
from __future__ import annotations
import contextlib
import fnmatch
import json
import socket
@@ -565,10 +566,8 @@ def template_prepare_win(
)
click.echo("[prepare-win] Windows Update requires reboot — rebooting ...")
try:
with contextlib.suppress(TransportError):
transport.run("Restart-Computer -Force", check=False)
except TransportError:
pass
transport.close()
time.sleep(30)
click.echo(f"[prepare-win] Waiting for WinRM after reboot ({winrm_timeout}s) ...")
@@ -638,10 +637,8 @@ Register-ScheduledTask -TaskName 'CI-StaticIp' `
# Final reboot to flush installation state
click.echo("[prepare-win] Final reboot to flush installation state ...")
try:
with contextlib.suppress(TransportError):
transport.run("Restart-Computer -Force", check=False)
except TransportError:
pass
transport.close()
time.sleep(30)
click.echo("[prepare-win] Waiting for WinRM after final reboot ...")
@@ -689,10 +686,8 @@ Register-ScheduledTask -TaskName 'CI-StaticIp' `
# Graceful shutdown
click.echo("[prepare-win] Sending graceful shutdown ...")
try:
with contextlib.suppress(TransportError):
transport.run("Stop-Computer -Force", check=False)
except TransportError:
pass
finally:
transport.close()
+1 -1
View File
@@ -17,7 +17,7 @@ and releases it on VM destroy. The guest applies the static IP at boot:
(``template/guest-setup/windows/ci-static-ip.ps1``) runs at system startup
as SYSTEM and applies the static IP before WinRM starts.
This eliminates the DHCP / VMware-Tools IP-detect polling loop (20180 s
This eliminates the DHCP / VMware-Tools IP-detect polling loop (20-180 s
variance observed in B7 benchmarks). After the VM reaches *running* state the
host knows the IP immediately and goes straight to the transport probe.