Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use internal/gnoi/gnoi.KillProcess in tests #3376

Merged
merged 2 commits into from
Aug 13, 2024
Merged
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 @@ -23,14 +23,12 @@ import (
"github.com/openconfig/featureprofiles/internal/attrs"
"github.com/openconfig/featureprofiles/internal/deviations"
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/gnoi"
gpb "github.com/openconfig/gnmi/proto/gnmi"
gnps "github.com/openconfig/gnoi/system"
"github.com/openconfig/gnoigo/system"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ondatra/gnmi/oc/acl"
"github.com/openconfig/ondatra/gnoi"
"github.com/openconfig/ondatra/ixnet"
"github.com/openconfig/ygnmi/ygnmi"
"github.com/openconfig/ygot/ygot"
Expand Down Expand Up @@ -192,12 +190,6 @@ var (
IPv4Len: plenIPv4,
IPv6Len: plenIPv6,
}
routingDaemon = map[ondatra.Vendor]string{
ondatra.JUNIPER: "rpd",
ondatra.ARISTA: "Bgp-main",
ondatra.CISCO: "emsd",
ondatra.NOKIA: "sr_bgp_mgr",
}
)

func configureRoutePolicy(t *testing.T, dut *ondatra.DUTDevice, name string, pr oc.E_RoutingPolicy_PolicyResultType) {
Expand Down Expand Up @@ -652,56 +644,6 @@ func removeNewPeers(t *testing.T, dut *ondatra.DUTDevice, nbrs []*bgpNeighbor) {
fptest.LogQuery(t, "DUT BGP Config", dutConfPath.Config(), gnmi.Get(t, dut, dutConfPath.Config()))
}

func restartRoutingProcess(t *testing.T, dut *ondatra.DUTDevice) {
t.Helper()
if _, ok := routingDaemon[dut.Vendor()]; !ok {
t.Fatalf("Please add support for vendor %v in var routingDaemon", dut.Vendor())
}
t.Run("KillGRIBIDaemon", func(t *testing.T) {
// Find the PID of routing Daemon.
var pId uint64
pName := routingDaemon[dut.Vendor()]
t.Run("FindroutingDaemonPid", func(t *testing.T) {
pId = findProcessByName(t, dut, pName)
if pId == 0 {
t.Fatalf("Couldn't find pid of routing daemon '%s'", pName)
} else {
t.Logf("Pid of routing daemon '%s' is '%d'", pName, pId)
}
})

// Kill routing daemon through gNOI Kill Request.
t.Run("ExecuteGnoiKill", func(t *testing.T) {
// TODO - pid type is uint64 in oc-system model, but uint32 in gNOI Kill Request proto.
// Until the models are brought in line, typecasting the uint64 to uint32.
gNOIKillProcess(t, dut, pName, uint32(pId))
// Wait for a bit for routing daemon on the DUT to restart.
time.Sleep(30 * time.Second)
})
})
}

// findProcessByName uses telemetry to find out the PID of a process
func findProcessByName(t *testing.T, dut *ondatra.DUTDevice, pName string) uint64 {
t.Helper()
pList := gnmi.GetAll(t, dut, gnmi.OC().System().ProcessAny().State())
var pID uint64
for _, proc := range pList {
if proc.GetName() == pName {
pID = proc.GetPid()
t.Logf("Pid of daemon '%s' is '%d'", pName, pID)
}
}
return pID
}

// gNOIKillProcess kills a daemon on the DUT, given its name and pid.
func gNOIKillProcess(t *testing.T, dut *ondatra.DUTDevice, pName string, pID uint32) {
t.Helper()
killResponse := gnoi.Execute(t, dut, system.NewKillProcessOperation().Name(pName).PID(pID).Signal(gnps.KillProcessRequest_SIGNAL_TERM).Restart(true))
t.Logf("Got kill process response: %v\n\n", killResponse)
}

// setBgpPolicy is used to configure routing policy on DUT.
func setBgpPolicy(t *testing.T, dut *ondatra.DUTDevice, d *oc.Root) {
t.Helper()
Expand Down Expand Up @@ -943,7 +885,7 @@ func TestTrafficWithGracefulRestartLLGR(t *testing.T) {
})

t.Run("Restart routing", func(t *testing.T) {
restartRoutingProcess(t, dut)
gnoi.KillProcess(t, dut, gnoi.ROUTING, true)
dplore marked this conversation as resolved.
Show resolved Hide resolved
})

var bgpIxPeer []*ixnet.BGP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ Ensure that gRIBI entries are persisted over daemon failure.

* Issuing a gRIBI Get RPC results in 203.0.113.0/24 being returned.

## Protocol/RPC Parameter Coverage

* gRIBI
* ModifyRequest
* GetRequest
## OpenConfig Path and RPC Coverage
```yaml
rpcs:
gribi:
gRIBI.Get:
gRIBI.Modify:
gRIBI.Flush:
```

## Telemetry Parameter Coverage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ import (
"github.com/openconfig/featureprofiles/internal/attrs"
"github.com/openconfig/featureprofiles/internal/deviations"
"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/gnoi"
"github.com/openconfig/featureprofiles/internal/gribi"
"github.com/openconfig/featureprofiles/internal/otgutils"
gnps "github.com/openconfig/gnoi/system"
"github.com/openconfig/gnoigo/system"
grps "github.com/openconfig/gribi/v1/proto/service"
grpb "github.com/openconfig/gribi/v1/proto/service"
"github.com/openconfig/gribigo/fluent"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/openconfig/ondatra/gnoi"
"github.com/openconfig/ygnmi/ygnmi"
"github.com/openconfig/ygot/ygot"
)
Expand Down Expand Up @@ -88,13 +86,6 @@ var (
IPv4: "192.0.2.6",
IPv4Len: ipv4PrefixLen,
}

gRIBIDaemons = map[ondatra.Vendor]string{
ondatra.ARISTA: "Gribi",
ondatra.CISCO: "emsd",
ondatra.JUNIPER: "rpd",
ondatra.NOKIA: "sr_grpc_server",
}
)

// configInterfaceDUT configures the DUT interfaces.
Expand Down Expand Up @@ -235,7 +226,7 @@ func verifyGRIBIGet(ctx context.Context, t *testing.T, clientA *gribi.Client, du
entries := getResponse.GetEntry()
var found bool
for _, entry := range entries {
v := entry.Entry.(*grps.AFTEntry_Ipv4)
v := entry.Entry.(*grpb.AFTEntry_Ipv4)
if prefix := v.Ipv4.GetPrefix(); prefix != "" {
if prefix == ateDstNetCIDR {
found = true
Expand All @@ -249,36 +240,12 @@ func verifyGRIBIGet(ctx context.Context, t *testing.T, clientA *gribi.Client, du
}
}

// gNOIKillProcess kills a daemon on the DUT, given its name and pid.
func gNOIKillProcess(ctx context.Context, t *testing.T, args *testArgs, pName string, pID uint32) {
killResponse := gnoi.Execute(t, args.dut, system.NewKillProcessOperation().Name(pName).PID(pID).Signal(gnps.KillProcessRequest_SIGNAL_TERM).Restart(true))
t.Logf("Got kill process response: %v\n\n", killResponse)
}

// findProcessByName uses telemetry to find out the PID of a process
func findProcessByName(ctx context.Context, t *testing.T, dut *ondatra.DUTDevice, pName string) uint64 {
pList := gnmi.GetAll(t, dut, gnmi.OC().System().ProcessAny().State())
var pID uint64
for _, proc := range pList {
if proc.GetName() == pName {
pID = proc.GetPid()
t.Logf("Pid of daemon '%s' is '%d'", pName, pID)
}
}
return pID
}

func TestDUTDaemonFailure(t *testing.T) {

start := time.Now()
dut := ondatra.DUT(t, "dut")
ctx := context.Background()

// Check if vendor specific gRIBI daemon name has been added to gRIBIDaemons var
if _, ok := gRIBIDaemons[dut.Vendor()]; !ok {
t.Fatalf("Please add support for vendor %v in var gRIBIDaemons", dut.Vendor())
}

// Configure the DUT.
t.Logf("Configure DUT")
configureDUT(t, dut)
Expand Down Expand Up @@ -343,30 +310,7 @@ func TestDUTDaemonFailure(t *testing.T) {
})

t.Run("KillGRIBIDaemon", func(t *testing.T) {

// Find the PID of gRIBI Daemon.
var pId uint64
pName := gRIBIDaemons[dut.Vendor()]
t.Run("FindGRIBIDaemonPid", func(t *testing.T) {

pId = findProcessByName(ctx, t, dut, pName)
if pId == 0 {
t.Fatalf("Couldn't find pid of gRIBI daemon '%s'", pName)
} else {
t.Logf("Pid of gRIBI daemon '%s' is '%d'", pName, pId)
}
})

// Kill gRIBI daemon through gNOI Kill Request.
t.Run("ExecuteGnoiKill", func(t *testing.T) {
// TODO - pid type is uint64 in oc-system model, but uint32 in gNOI Kill Request proto.
// Until the models are brought in line, typecasting the uint64 to uint32.
gNOIKillProcess(ctx, t, args, pName, uint32(pId))

// Wait for a bit for gRIBI daemon on the DUT to restart.
time.Sleep(30 * time.Second)

})
gnoi.KillProcess(t, dut, gnoi.GRIBI, true)

t.Logf("Time check: %s", time.Since(start))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func TestPrefixSetWithOCAgentRestart(t *testing.T) {
gnoi.KillProcess(t, dut, gnoi.OCAGENT, true)

v4PrefixSet = ds.GetOrCreatePrefixSet(tag3IPv4)
v4PrefixSet.SetMode(oc.PrefixSet_Mode_IPV4)
self-maurya marked this conversation as resolved.
Show resolved Hide resolved
if !deviations.SkipPrefixSetMode(dut) {
v4PrefixSet.SetMode(oc.PrefixSet_Mode_IPV4)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"time"

"github.com/openconfig/featureprofiles/internal/fptest"
"github.com/openconfig/featureprofiles/internal/system"
hpb "github.com/openconfig/gnoi/healthz"
spb "github.com/openconfig/gnoi/system"
tpb "github.com/openconfig/gnoi/types"
"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
)

var (
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestMain(m *testing.M) {
// DUT
//
// Test notes:
//. Note: Initiating checkin to experimental
// Note: Initiating checkin to experimental
// - KillProcess system call is used to kill a process.
// - The healthz call needs to be modified to reflect the right component and its path.
//
Expand All @@ -67,10 +67,14 @@ func TestCopyingDebugFiles(t *testing.T) {
if _, ok := processName[dut.Vendor()]; !ok {
t.Fatalf("Please add support for vendor %v in var processName", dut.Vendor())
}
pID := system.FindProcessIDByName(t, dut, processName[dut.Vendor()])
if pID == 0 {
t.Fatalf("process %v not found on device", processName[dut.Vendor()])
}
killProcessRequest := &spb.KillProcessRequest{
Signal: spb.KillProcessRequest_SIGNAL_KILL,
Name: processName[dut.Vendor()],
Pid: findProcessByName(context.Background(), t, dut, processName[dut.Vendor()]),
Pid: uint32(pID),
Restart: true,
}
processKillResponse, err := gnoiClient.System().KillProcess(context.Background(), killProcessRequest)
Expand Down Expand Up @@ -109,19 +113,6 @@ func TestCopyingDebugFiles(t *testing.T) {
}
}

// findProcessByName uses telemetry to find out the PID of a process
func findProcessByName(ctx context.Context, t *testing.T, dut *ondatra.DUTDevice, pName string) uint32 {
pList := gnmi.GetAll(t, dut, gnmi.OC().System().ProcessAny().State())
var pID uint32
for _, proc := range pList {
if proc.GetName() == pName {
pID = uint32(proc.GetPid())
t.Logf("Pid of daemon '%s' is '%d'", pName, pID)
}
}
return pID
}

func TestChassisComponentArtifacts(t *testing.T) {
dut := ondatra.DUT(t, "dut")
gnoiClient := dut.RawAPIs().GNOI(t)
Expand Down Expand Up @@ -153,20 +144,20 @@ func TestChassisComponentArtifacts(t *testing.T) {
t.Logf("Artifacts received for component %v: %v", componentName["name"], artifacts)
// Fetch artifact details by executing ArtifactRequest and passing the artifact ID along.
for _, artifact := range artifacts {
artId := artifact.GetId()
t.Logf("Executing ArtifactRequest for artifact ID %v", artId)
artID := artifact.GetId()
t.Logf("Executing ArtifactRequest for artifact ID %v", artID)
artReq := &hpb.ArtifactRequest{
Id: artId,
Id: artID,
}
// Verify that a valid response is received.
artRes, err := gnoiClient.Healthz().Artifact(context.Background(), artReq)
if err != nil {
t.Fatalf("Unexpected error on executing Healthz Artifact RPC: %v", err)
}
h1, err := artRes.Header()
t.Logf("Header of artifact %v: %v", artId, h1)
t.Logf("Header of artifact %v: %v", artID, h1)
if err != nil {
t.Fatalf("Unexpected error when fetching the header of artifact %v: %v", artId, err)
t.Fatalf("Unexpected error when fetching the header of artifact %v: %v", artID, err)
}
}
}
15 changes: 9 additions & 6 deletions feature/p4rt/otg_tests/p4rt_daemon_failure_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ Ensure that data plane traffic is not interrupted by P4RT daemon failure.
test tables only configure the control plane traffic. Instead, this test
configures the data plane using gRIBI.

## Protocol/RPC Parameter Coverage

* gRIBI
* ModifyRequest
* GetRequest
## OpenConfig Path and RPC Coverage
```yaml
rpcs:
gribi:
gRIBI.Get:
gRIBI.Modify:
gRIBI.Flush:
```

## Telemetry Parameter Coverage
* /network-instances/network-instance/afts/ipv4-unicast/ipv4-entry/state/prefix/
* /interfaces/interface/state/id
* /interfaces/interface/state/name
* /interfaces/interface/state/name
Loading
Loading