refactor: streamline error handling with contextlib in template preparation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user