Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package dut_daemon_failure_test

import (
"context"
"fmt"
"testing"
"time"

Expand All @@ -31,6 +32,7 @@ import (
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/testt"
"github.com/openconfig/ygnmi/ygnmi"
"github.com/openconfig/ygot/ygot"
)
Expand All @@ -52,14 +54,43 @@ func TestMain(m *testing.M) {
// * Destination network: -> 203.0.113.0/24

const (
ipv4PrefixLen = 30
ateDstNetCIDR = "203.0.113.0/24"
ateDstNetStartIp = "203.0.113.1"
nhIndex = 1
nhgIndex = 42
flowName = "Flow"
ipv4PrefixLen = 30
ateDstNetCIDR = "203.0.113.0/24"
ateDstNetStartIp = "203.0.113.1"
nhIndex = 1
nhgIndex = 42
flowName = "Flow"
gribiRetryTimeout = 3 * time.Minute
gribiRetryInterval = 5 * time.Second
)

func startGRIBIWithRetry(t *testing.T, client *gribi.Client) {
t.Helper()
deadline := time.Now().Add(gribiRetryTimeout)
for attempt := 1; ; attempt++ {
var startErr error
fatalMsg := testt.CaptureFatal(t, func(tb testing.TB) {
startErr = client.Start(tb)
})
if fatalMsg != nil {
startErr = fmt.Errorf("%s", *fatalMsg)
}
if startErr == nil {
t.Logf("Re-established gRIBI connection after %d attempt(s)", attempt)
return
}

client.Close(t)
remaining := time.Until(deadline)
if remaining <= 0 {
t.Fatalf("gRIBI connection could not be re-established within %v, last error: %v", gribiRetryTimeout, startErr)
}
wait := min(gribiRetryInterval, remaining)
t.Logf("gRIBI connection attempt %d failed: %v; retrying in %v", attempt, startErr, wait)
time.Sleep(wait)
}
}

var (
dutPort1 = attrs.Attributes{
Desc: "dutPort1",
Expand Down Expand Up @@ -325,20 +356,7 @@ func TestDUTDaemonFailure(t *testing.T) {
defer clientA.FlushAll(t)

t.Log("Re-establish gRIBI client connection")
retryDuration := 180 * time.Second
retryInterval := 5 * time.Second
startTime := time.Now()
for {
if err := clientA.Start(t); err != nil {
if time.Since(startTime) > retryDuration {
t.Fatalf("gRIBI Connection for clientA could not be re-established after multiple attempts")
}
t.Logf("Retrying gRIBI client connection in %v...", retryInterval)
time.Sleep(retryInterval)
} else {
break
}
}
startGRIBIWithRetry(t, clientA)
t.Run("VerifyGRIBIGet", func(t *testing.T) {
verifyGRIBIGet(ctx, t, clientA, dut)
})
Expand Down
80 changes: 62 additions & 18 deletions internal/gnoi/gnoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ import (
"github.com/openconfig/featureprofiles/internal/components"
"github.com/openconfig/featureprofiles/internal/deviations"
"github.com/openconfig/featureprofiles/internal/system"
gpb "github.com/openconfig/gnmi/proto/gnmi"
spb "github.com/openconfig/gnoi/system"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/testt"
"github.com/openconfig/ygnmi/ygnmi"
)

var (
Expand Down Expand Up @@ -91,6 +89,67 @@ const (
SigUnspecified = spb.KillProcessRequest_SIGNAL_UNSPECIFIED
)

const (
processRestartTimeout = 3 * time.Minute
processRestartPollInterval = 5 * time.Second
)

// pollForProcessRestart polls until probe reports a non-zero PID that differs
// from oldPID. Probe errors are treated as transient until ctx expires.
func pollForProcessRestart(ctx context.Context, oldPID uint64, interval time.Duration, probe func() (uint64, error)) error {
ticker := time.NewTicker(interval)
defer ticker.Stop()

var (
lastErr error
lastPID uint64
)
for {
pid, err := probe()
if err != nil {
lastErr = err
} else {
lastErr = nil
lastPID = pid
if pid != 0 && pid != oldPID {
return nil
}
}

select {
case <-ctx.Done():
if lastErr != nil {
return fmt.Errorf("management service did not recover, last probe error: %v: %w", lastErr, ctx.Err())
}
return fmt.Errorf("process did not restart with a new PID, old PID: %d, last PID: %d: %w", oldPID, lastPID, ctx.Err())
case <-ticker.C:
}
}
}

func waitForProcessRestart(t *testing.T, dut *ondatra.DUTDevice, daemonName string, oldPID uint64) {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), processRestartTimeout)
defer cancel()

var attempts int
err := pollForProcessRestart(ctx, oldPID, processRestartPollInterval, func() (uint64, error) {
attempts++
var pid uint64
if fatalMsg := testt.CaptureFatal(t, func(tb testing.TB) {
pid = system.FindProcessIDByName(tb, dut, daemonName)
}); fatalMsg != nil {
t.Logf("Process restart probe %d failed while management recovers: %s", attempts, *fatalMsg)
return 0, fmt.Errorf("%s", *fatalMsg)
}
return pid, nil
})
if err != nil {
t.Fatalf("Timed out after %v waiting for process %s to restart and management service to recover: %v", processRestartTimeout, daemonName, err)
}
t.Logf("Process %s restarted with a new PID and management recovered after %d probe(s)", daemonName, attempts)
}

// KillProcess terminates the daemon on the DUT.
func KillProcess(t *testing.T, dut *ondatra.DUTDevice, daemon Daemon, signal spb.KillProcessRequest_Signal, restart bool, waitForRestart bool) {
t.Helper()
Expand Down Expand Up @@ -129,22 +188,7 @@ func KillProcess(t *testing.T, dut *ondatra.DUTDevice, daemon Daemon, signal spb
}

if waitForRestart {
_, ok := gnmi.WatchAll(
t,
dut.GNMIOpts().WithYGNMIOpts(ygnmi.WithSubscriptionMode(gpb.SubscriptionMode_SAMPLE)),
gnmi.OC().System().ProcessAny().State(),
time.Minute,
func(p *ygnmi.Value[*oc.System_Process]) bool {
val, ok := p.Val()
if !ok {
return false
}
return val.GetName() == daemonName && val.GetPid() != pid
},
).Await(t)
if !ok {
t.Fatalf("Timed out waiting for process %s to restart with a new PID", daemonName)
}
waitForProcessRestart(t, dut, daemonName, pid)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

// FindProcessIDByName uses telemetry to find out the PID of a process.
func FindProcessIDByName(t *testing.T, dut *ondatra.DUTDevice, pName string) uint64 {
func FindProcessIDByName(t testing.TB, dut *ondatra.DUTDevice, pName string) uint64 {
t.Helper()

var pid uint64
Expand Down
Loading