feat(benchmark): add static IP support to Measure-CIBenchmark
- Add -StaticIP/-Netmask/-Gateway params; injects guestinfo into cloned VMX before start, mirroring job.py _inject_guestinfo_ip behaviour - Add -GuestInfoOnly switch to Get-GuestIPAddress: skips vmrun getGuestIPAddress fallback to prevent race where transient DHCP address is returned before ci-static-ip.ps1 finishes reconfiguring the NIC - Benchmark passes -GuestInfoOnly automatically when -StaticIP is set - staticIP field added to benchmark.jsonl for DHCP vs static comparison Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -89,7 +89,14 @@ param(
|
||||
'/var/lib/ci/logs/'
|
||||
} else {
|
||||
'F:\CI\Logs'
|
||||
})
|
||||
}),
|
||||
|
||||
# Optional static IP injection (mirrors ip_pool in job.py).
|
||||
# If supplied, guestinfo.ip-assignment/netmask/gateway are written into the
|
||||
# cloned VMX before start so ci-static-ip.ps1 applies the IP at boot.
|
||||
[string] $StaticIP = '',
|
||||
[string] $Netmask = '255.255.255.0',
|
||||
[string] $Gateway = ''
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
@@ -138,9 +145,27 @@ if (-not (Test-Path $OutputDir)) {
|
||||
New-Item -ItemType Directory -Path $OutputDir -Force | Out-Null
|
||||
}
|
||||
|
||||
function Set-GuestInfoIP {
|
||||
param([string]$VmxPath, [string]$IP, [string]$Mask, [string]$Gw)
|
||||
$keys = @('guestinfo.ip-assignment', 'guestinfo.netmask', 'guestinfo.gateway')
|
||||
$lines = (Get-Content -LiteralPath $VmxPath -Encoding UTF8) |
|
||||
Where-Object { ($_ -split '=')[0].Trim().ToLower() -notin $keys }
|
||||
$lines += "guestinfo.ip-assignment = `"$IP`""
|
||||
if ($Mask) { $lines += "guestinfo.netmask = `"$Mask`"" }
|
||||
if ($Gw) { $lines += "guestinfo.gateway = `"$Gw`"" }
|
||||
Set-Content -LiteralPath $VmxPath -Value $lines -Encoding UTF8
|
||||
}
|
||||
|
||||
$benchmarkLog = Join-Path $OutputDir 'benchmark.jsonl'
|
||||
$results = [System.Collections.Generic.List[pscustomobject]]::new()
|
||||
|
||||
$useStaticIP = $StaticIP -match '^\d{1,3}(\.\d{1,3}){3}$'
|
||||
if ($useStaticIP) {
|
||||
Write-Host "[bench] Static IP mode: $StaticIP / $Netmask gw=$Gateway"
|
||||
} else {
|
||||
Write-Host "[bench] DHCP mode (no -StaticIP supplied)"
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "=== CI Benchmark template: $(Split-Path $TemplatePath -Leaf) snapshot: $SnapshotName iterations: $Iterations ==="
|
||||
Write-Host ""
|
||||
@@ -186,6 +211,12 @@ for ($i = 1; $i -le $Iterations; $i++) {
|
||||
Write-Warning "[bench] Could not measure clone size: $_"
|
||||
}
|
||||
|
||||
# ── Static IP injection (before start) ───────────────────────────────
|
||||
if ($useStaticIP) {
|
||||
Set-GuestInfoIP -VmxPath $cloneVmx -IP $StaticIP -Mask $Netmask -Gw $Gateway
|
||||
Write-Host "[bench] guestinfo injected: $StaticIP"
|
||||
}
|
||||
|
||||
# ── Phase: start ──────────────────────────────────────────────────────
|
||||
Write-Host "[bench] Starting VM..."
|
||||
$sw.Restart()
|
||||
@@ -198,7 +229,7 @@ for ($i = 1; $i -le $Iterations; $i++) {
|
||||
Write-Host "[bench] Waiting for guest IP..."
|
||||
$sw.Restart()
|
||||
$vmIP = Get-GuestIPAddress -VmrunPath $VmrunPath -VmxPath $cloneVmx `
|
||||
-TimeoutSeconds $TimeoutSeconds
|
||||
-TimeoutSeconds $TimeoutSeconds -GuestInfoOnly:$useStaticIP
|
||||
if (-not $vmIP) { throw "Timed out waiting for guest IP after $TimeoutSeconds s" }
|
||||
$t.ip = [math]::Round($sw.Elapsed.TotalSeconds, 2)
|
||||
$t.vmIP = $vmIP
|
||||
@@ -250,6 +281,7 @@ for ($i = 1; $i -le $Iterations; $i++) {
|
||||
template = Split-Path $TemplatePath -Leaf
|
||||
snapshot = $SnapshotName
|
||||
guestOS = $resolvedGuestOS
|
||||
staticIP = if ($useStaticIP) { $StaticIP } else { $null }
|
||||
cloneSec = $t.clone
|
||||
startSec = $t.start
|
||||
ipSec = $t.ip
|
||||
|
||||
Reference in New Issue
Block a user