Skip to content

Commit 3f07c55

Browse files
committed
chore: improve DHCP renew test error reporting
Signed-off-by: Pau Capdevila <[email protected]>
1 parent 97fc7de commit 3f07c55

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

pkg/hhfab/release.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,14 +2477,48 @@ func (testCtx *VPCPeeringTestCtx) performDHCPRenewal(ctx context.Context, server
24772477
for {
24782478
pollCount++
24792479
out, err := execNodeCmdWOutput(testCtx.hhfabBin, testCtx.workDir, serverName,
2480-
fmt.Sprintf("ip addr show dev %s proto 4 | grep valid_lft", ifName))
2480+
fmt.Sprintf("ip addr show dev %s proto 4", ifName))
2481+
2482+
// Parse the output to understand what's happening
2483+
var leaseInfo string
2484+
var hasInterface bool
2485+
var hasIP bool
2486+
2487+
if err == nil {
2488+
hasInterface = true
2489+
if strings.Contains(out, "valid_lft") {
2490+
// Extract just the lease line for logging
2491+
lines := strings.Split(out, "\n")
2492+
for _, line := range lines {
2493+
if strings.Contains(line, "valid_lft") {
2494+
leaseInfo = strings.TrimSpace(line)
2495+
hasIP = true
2496+
2497+
break
2498+
}
2499+
}
2500+
}
2501+
}
2502+
2503+
// Improved logging based on interface state
2504+
if pollCount%3 == 0 || err != nil || !hasIP {
2505+
var status string
2506+
switch {
2507+
case err != nil:
2508+
status = "interface command failed"
2509+
case !hasInterface:
2510+
status = "interface not found"
2511+
case !hasIP:
2512+
status = "interface up but no DHCP lease"
2513+
default:
2514+
status = "interface has lease"
2515+
}
24812516

2482-
if pollCount%3 == 0 || err != nil {
2483-
slog.Debug("Lease polling", "server", serverName, "interface", ifName, "poll", pollCount, "lease", strings.TrimSpace(out), "error", err)
2517+
slog.Debug("Lease polling", "server", serverName, "interface", ifName, "poll", pollCount, "status", status, "lease", leaseInfo, "error", err)
24842518
}
24852519

2486-
if err == nil && strings.TrimSpace(out) != "" {
2487-
tokens := strings.Split(strings.TrimLeft(out, " \t"), " ")
2520+
if hasIP && leaseInfo != "" {
2521+
tokens := strings.Split(strings.TrimLeft(leaseInfo, " \t"), " ")
24882522
if len(tokens) >= 2 {
24892523
stripped, _ := strings.CutSuffix(tokens[1], "sec")
24902524
if currentLease, parseErr := strconv.Atoi(stripped); parseErr == nil {

0 commit comments

Comments
 (0)