Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit 27ad9e3

Browse files
author
Vlastimil Holer
committed
gh-43: Network not ready for custom scripts
Change implements a wait loop with a self-ping to the assigned IPs. When interface isn't ready yet, the ping operation fails on: > Test-Connection : Generic Failure Retries until the IP is reachable with max. 20 checks. Closes #43.
1 parent 3d32a29 commit 27ad9e3

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

context.ps1

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function addLocalUser($context) {
130130
function configureNetwork($context) {
131131

132132
# Get the NIC in the Context
133-
$nicIds = ($context.Keys | Where {$_ -match '^ETH\d+_IP6?$'} | ForEach-Object {$_ -replace '(^ETH|_IP$|_IP6$)',''} | Get-Unique)
133+
$nicIds = ($context.Keys | Where {$_ -match '^ETH\d+_IP6?$'} | ForEach-Object {$_ -replace '(^ETH|_IP$|_IP6$)',''} | Get-Unique | Sort-Object)
134134

135135
$nicId = 0;
136136

@@ -351,6 +351,12 @@ function configureNetwork($context) {
351351
netsh interface ipv6 add dnsserver $na.NetConnectionId address=$dns6Server
352352
}
353353
}
354+
355+
doPing($ip6)
356+
}
357+
358+
If ($ip) {
359+
doPing($ip)
354360
}
355361
}
356362
Write-Output ""
@@ -477,6 +483,25 @@ function enablePing()
477483
Write-Output ""
478484
}
479485

486+
function doPing($ip, $retries=20)
487+
{
488+
Write-Output "- Ping Interface IP $ip"
489+
490+
$ping = $false
491+
$retry = 0
492+
do {
493+
$retry++
494+
Start-Sleep -s 1
495+
$ping = Test-Connection -ComputerName $ip -Count 1 -Quiet -ErrorAction SilentlyContinue
496+
} while (!$ping -and ($retry -lt $retries))
497+
498+
If ($ping) {
499+
Write-Output " ... Success ($retry tries)"
500+
} Else {
501+
Write-Output " ... Failed ($retry tries)"
502+
}
503+
}
504+
480505
function runScripts($context, $contextLetter)
481506
{
482507
Write-Output "Running Scripts"

0 commit comments

Comments
 (0)