fix(templates): replace Test-NetConnection with TcpClient in Prepare scripts
Test-NetConnection is Windows-only. Replace with cross-platform TcpClient async-connect helper (same pattern as Measure-CIBenchmark.ps1) so the Prepare scripts run on the Linux host under PowerShell. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -163,7 +163,19 @@ param(
|
|||||||
|
|
||||||
Set-StrictMode -Version Latest
|
Set-StrictMode -Version Latest
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (Test-NetConnection, IWR, etc.)
|
$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (IWR, etc.)
|
||||||
|
|
||||||
|
function Test-TcpPort {
|
||||||
|
param([string]$ComputerName, [int]$Port, [int]$TimeoutMs = 3000)
|
||||||
|
try {
|
||||||
|
$tcp = [System.Net.Sockets.TcpClient]::new()
|
||||||
|
$ar = $tcp.BeginConnect($ComputerName, $Port, $null, $null)
|
||||||
|
$ok = $ar.AsyncWaitHandle.WaitOne($TimeoutMs, $false)
|
||||||
|
$connected = $ok -and $tcp.Connected
|
||||||
|
$tcp.Close()
|
||||||
|
return $connected
|
||||||
|
} catch { return $false }
|
||||||
|
}
|
||||||
|
|
||||||
# ── Locate vmrun.exe ──────────────────────────────────────────────────────────
|
# ── Locate vmrun.exe ──────────────────────────────────────────────────────────
|
||||||
$vmrunCandidates = @(
|
$vmrunCandidates = @(
|
||||||
@@ -247,8 +259,7 @@ Write-Host "[Prepare] Waiting for WinRM on $VMIPAddress`:5986 (timeout ${winrmTi
|
|||||||
$winrmDeadline = [datetime]::UtcNow.AddSeconds($winrmTimeoutSec)
|
$winrmDeadline = [datetime]::UtcNow.AddSeconds($winrmTimeoutSec)
|
||||||
$winrmReady = $false
|
$winrmReady = $false
|
||||||
while ([datetime]::UtcNow -lt $winrmDeadline) {
|
while ([datetime]::UtcNow -lt $winrmDeadline) {
|
||||||
if (Test-NetConnection -ComputerName $VMIPAddress -Port 5986 `
|
if (Test-TcpPort -ComputerName $VMIPAddress -Port 5986 -TimeoutMs 5000) {
|
||||||
-InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue) {
|
|
||||||
$winrmReady = $true; break
|
$winrmReady = $true; break
|
||||||
}
|
}
|
||||||
Start-Sleep -Seconds 5
|
Start-Sleep -Seconds 5
|
||||||
|
|||||||
@@ -163,7 +163,19 @@ param(
|
|||||||
|
|
||||||
Set-StrictMode -Version Latest
|
Set-StrictMode -Version Latest
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (Test-NetConnection, IWR, etc.)
|
$ProgressPreference = 'SilentlyContinue' # suppress Write-Progress (IWR, etc.)
|
||||||
|
|
||||||
|
function Test-TcpPort {
|
||||||
|
param([string]$ComputerName, [int]$Port, [int]$TimeoutMs = 3000)
|
||||||
|
try {
|
||||||
|
$tcp = [System.Net.Sockets.TcpClient]::new()
|
||||||
|
$ar = $tcp.BeginConnect($ComputerName, $Port, $null, $null)
|
||||||
|
$ok = $ar.AsyncWaitHandle.WaitOne($TimeoutMs, $false)
|
||||||
|
$connected = $ok -and $tcp.Connected
|
||||||
|
$tcp.Close()
|
||||||
|
return $connected
|
||||||
|
} catch { return $false }
|
||||||
|
}
|
||||||
|
|
||||||
# ── Locate vmrun.exe ──────────────────────────────────────────────────────────
|
# ── Locate vmrun.exe ──────────────────────────────────────────────────────────
|
||||||
$vmrunCandidates = @(
|
$vmrunCandidates = @(
|
||||||
@@ -247,8 +259,7 @@ Write-Host "[Prepare] Waiting for WinRM on $VMIPAddress`:5986 (timeout ${winrmTi
|
|||||||
$winrmDeadline = [datetime]::UtcNow.AddSeconds($winrmTimeoutSec)
|
$winrmDeadline = [datetime]::UtcNow.AddSeconds($winrmTimeoutSec)
|
||||||
$winrmReady = $false
|
$winrmReady = $false
|
||||||
while ([datetime]::UtcNow -lt $winrmDeadline) {
|
while ([datetime]::UtcNow -lt $winrmDeadline) {
|
||||||
if (Test-NetConnection -ComputerName $VMIPAddress -Port 5986 `
|
if (Test-TcpPort -ComputerName $VMIPAddress -Port 5986 -TimeoutMs 5000) {
|
||||||
-InformationLevel Quiet -WarningAction SilentlyContinue -ErrorAction SilentlyContinue) {
|
|
||||||
$winrmReady = $true; break
|
$winrmReady = $true; break
|
||||||
}
|
}
|
||||||
Start-Sleep -Seconds 5
|
Start-Sleep -Seconds 5
|
||||||
|
|||||||
Reference in New Issue
Block a user