Skip to content

Commit

Permalink
[sdn_tests]: Adding module reset test to pins_ondatra. (#12928)
Browse files Browse the repository at this point in the history
* [sdn_tests]: Adding LACP time-out test to pins_ondatra.

* [sdn_tests]: Adding Link event damping test to pins_ondatra.

* [sdn_tests]: Adding port debug data test to pins_ondatra.

* [sdn_tests]: Adding module reset test to pins_ondatra.
  • Loading branch information
VSuryaprasad-HCL authored May 22, 2024
1 parent b003978 commit 7038840
Show file tree
Hide file tree
Showing 2 changed files with 271 additions and 0 deletions.
58 changes: 58 additions & 0 deletions sdn_tests/pins_ondatra/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,61 @@ ondatra_test(
"@com_github_openconfig_ondatra//:go_default_library",
],
)

#lacp time-out test
ondatra_test(
name = "lacp_timeout_test",
srcs = ["lacp_timeout_test.go"],
deps = [
"//infrastructure/binding:pinsbind",
"//infrastructure/testhelper",
"@com_github_openconfig_ondatra//:go_default_library",
"@com_github_openconfig_ondatra//gnmi",
"@com_github_openconfig_ondatra//gnmi/oc",
"@com_github_pkg_errors//:errors",
],
)

# Link event damping tests
ondatra_test(
name = "link_event_damping_test",
srcs = ["link_event_damping_test.go"],
deps = [
"//infrastructure/binding:pinsbind",
"//infrastructure/testhelper",
"@com_github_openconfig_gnmi//proto/gnmi:gnmi_go_proto",
"@com_github_openconfig_ondatra//:go_default_library",
"@com_github_openconfig_ondatra//gnmi",
"@com_github_openconfig_ondatra//gnmi/oc",
"@com_github_openconfig_ygnmi//ygnmi",
"@com_github_pkg_errors//:errors",
"@org_golang_google_grpc//:go_default_library",
],
)

#port debug test
ondatra_test(
name = "port_debug_data_test",
srcs = ["port_debug_data_test.go"],
deps = [
"//infrastructure/binding:pinsbind",
"//infrastructure/testhelper",
"@com_github_openconfig_ondatra//:go_default_library",
"@com_github_openconfig_ondatra//gnmi",
],
)

#module reset test
ondatra_test_suite(
name = "module_reset_test",
srcs = ["module_reset_test.go"],
deps = [
"//infrastructure/binding:pinsbind",
"//infrastructure/testhelper",
"@com_github_openconfig_gnoi//system:system_go_proto",
"@com_github_openconfig_gnoi//types:types_go_proto",
"@com_github_openconfig_ondatra//:go_default_library",
"@com_github_openconfig_ondatra//gnmi",
"@com_github_openconfig_ondatra//gnmi/oc",
],
)
213 changes: 213 additions & 0 deletions sdn_tests/pins_ondatra/tests/module_reset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
package module_reset_test

import (
"fmt"
"strings"
"testing"
"time"

"github.com/openconfig/ondatra"
"github.com/openconfig/ondatra/gnmi"
"github.com/openconfig/ondatra/gnmi/oc"
"github.com/sonic-net/sonic-mgmt/sdn_tests/pins_ondatra/infrastructure/binding/pinsbind"
"github.com/sonic-net/sonic-mgmt/sdn_tests/pins_ondatra/infrastructure/testhelper/testhelper"

syspb "github.com/openconfig/gnoi/system"
typespb "github.com/openconfig/gnoi/types"
)

func TestMain(m *testing.M) {
ondatra.RunTests(m, pinsbind.New)
}

const (
waitTimeInterfacesUp = 60 * time.Second
transceiverPrefix = "Ethernet"
)

// Enum to represent which modules to reset in each test case.
type testModules int

const (
oneModule testModules = iota
allModules
)

func TestResetModules(t *testing.T) {
dut := ondatra.DUT(t, "DUT")

// Get all ports connected to peer device.
var dutPorts []string
for _, port := range dut.Ports() {
dutPorts = append(dutPorts, port.Name())
}

tests := []struct {
name string
uuid string
modules testModules
}{
{
name: "TestResetOneModule",
uuid: "4593ff89-892b-46f7-a049-959c8681912d",
modules: oneModule,
},
{
name: "TestResetAllModules",
uuid: "af9877f2-40f3-4abe-873b-e1db155a917d",
modules: allModules,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
defer testhelper.NewTearDownOptions(t).WithID(tt.uuid).Teardown(t)

operStatusInfo, err := testhelper.FetchPortsOperStatus(t, dut, dutPorts...)
if err != nil {
t.Fatalf("Failed to fetch ports oper status: %v", err)
}
upPorts := operStatusInfo.Up
if len(upPorts) == 0 {
t.Log("No up ports found at start of test")
}

paths := []*typespb.Path{}

// Name of transceiver to reset, for OneModule test.
var testXcvr string

for _, component := range gnmi.GetAll(t, dut, gnmi.OC().ComponentAny().State()) {
xcvrName := component.GetName()
// Skip non-transceiver components.
if !strings.HasPrefix(xcvrName, transceiverPrefix) {
continue
}
if !component.GetEmpty() {
// Add transceiver name to paths.
pathElems := []*typespb.PathElem{
&typespb.PathElem{Name: "components"},
&typespb.PathElem{Name: "component", Key: map[string]string{"name": xcvrName}},
}
path := &typespb.Path{
Origin: "openconfig",
Elem: pathElems,
}
paths = append(paths, path)
if tt.modules == oneModule {
t.Logf("Testing transceiver %v", xcvrName)
testXcvr = xcvrName
break
}
}
}
if len(paths) == 0 {
t.Fatal("No non-empty transceivers found")
}
req := &syspb.RebootRequest{
Method: syspb.RebootMethod_COLD,
Message: "Reset transceiver modules",
Subcomponents: paths,
}

params := testhelper.NewRebootParams().WithWaitTime(0 * time.Second).WithCheckInterval(0 * time.Second).WithRequest(req)

if err := testhelper.Reboot(t, dut, params); err != nil {
t.Fatalf("Reboot RPC failed: %v", err)
}

// If test resets one module, verify that ports on all the other modules are still up.
if tt.modules == oneModule {
for _, intf := range upPorts {
// Verify that interfaces not on testXcvr are up.
xcvrName := gnmi.Get(t, dut, gnmi.OC().Interface(intf).Transceiver().State())
if xcvrName != testXcvr {
if got := gnmi.Get(t, dut, gnmi.OC().Interface(intf).OperStatus().State()); got != oc.Interface_OperStatus_UP {
t.Errorf("Interface %v oper status is not UP", intf)
}
}
}
}

if len(upPorts) > 0 {
time.Sleep(waitTimeInterfacesUp)
if err := testhelper.VerifyPortsOperStatus(t, dut, upPorts...); err != nil {
t.Fatalf("Not all ports are up at the end of the test %v: %v", tt.name, err)
}
}
})
}
}

func TestResetModuleInvalidTransceiver(t *testing.T) {
defer testhelper.NewTearDownOptions(t).WithID("9b1c5bb4-f79e-4aab-9488-ce7294728abd").Teardown(t)
dut := ondatra.DUT(t, "DUT")

// Get all ports connected to peer device.
var dutPorts []string
for _, port := range dut.Ports() {
dutPorts = append(dutPorts, port.Name())
}

operStatusInfo, err := testhelper.FetchPortsOperStatus(t, dut, dutPorts...)
if err != nil {
t.Fatalf("Failed to fetch ports oper status: %v", err)
}
upPorts := operStatusInfo.Up
if len(upPorts) == 0 {
t.Log("No up ports found at start of test")
}

maxXcvrNum := 0

for _, component := range gnmi.GetAll(t, dut, gnmi.OC().ComponentAny().State()) {
xcvrName := component.GetName()
// Skip non-transceiver components.
if !strings.HasPrefix(xcvrName, transceiverPrefix) {
continue
}
var phyPortNum int
_, err := fmt.Sscanf(xcvrName, transceiverPrefix+"%d", &phyPortNum)
if err == nil {
if phyPortNum > maxXcvrNum {
maxXcvrNum = phyPortNum
}
}
}
if maxXcvrNum == 0 {
t.Fatalf("No transceivers found")
}

invalidXcvrName := fmt.Sprintf("Ethernet%v", maxXcvrNum+1)
t.Logf("Testing with invalid transceiver name %v", invalidXcvrName)

pathElems := []*typespb.PathElem{
&typespb.PathElem{Name: "components"},
&typespb.PathElem{Name: "component", Key: map[string]string{"name": invalidXcvrName}},
}
path := &typespb.Path{
Origin: "openconfig",
Elem: pathElems,
}
paths := []*typespb.Path{path}

req := &syspb.RebootRequest{
Method: syspb.RebootMethod_COLD,
Message: "Reset transceiver",
Subcomponents: paths,
}

params := testhelper.NewRebootParams().WithWaitTime(0 * time.Second).WithCheckInterval(0 * time.Second).WithRequest(req)

err = testhelper.Reboot(t, dut, params)
t.Logf("Reboot err: %v", err)

if err == nil {
t.Errorf("Reboot RPC expected to fail")
}
if len(upPorts) > 0 {
if err := testhelper.VerifyPortsOperStatus(t, dut, upPorts...); err != nil {
t.Fatalf("Not all ports are up at the end of the test: %v", err)
}
}
}

0 comments on commit 7038840

Please sign in to comment.