Skip to content

Commit

Permalink
[sdn_tests]: Adding Transceiver check tests to pins_ondatra. (sonic-n…
Browse files Browse the repository at this point in the history
…et#12993)

* [sdn_tests]: Adding Transceiver test to pins_ondatra.

* [sdn_tests]: Adding Transceiver check tests to pins_ondatra.
  • Loading branch information
VSuryaprasad-HCL authored May 29, 2024
1 parent f69c9c5 commit f3226a6
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 0 deletions.
66 changes: 66 additions & 0 deletions sdn_tests/pins_ondatra/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,69 @@ ondatra_test(
"@com_github_openconfig_ondatra//gnmi/oc",
],
)

# gNMI Features: GET Modes
ondatra_test(
name = "gnmi_get_modes_test",
srcs = ["gnmi_get_modes_test.go"],
deps = [
"//infrastructure/binding:pinsbind",
"//infrastructure/testhelper",
"@com_github_google_go_cmp//cmp",
"@com_github_google_go_cmp//cmp/cmpopts",
"@com_github_openconfig_gnmi//proto/gnmi:gnmi_go_proto",
"@com_github_openconfig_gnmi//value",
"@com_github_openconfig_ondatra//:go_default_library",
"@com_github_openconfig_ondatra//gnmi",
"@com_github_openconfig_ygot//ygot",
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_protobuf//encoding/prototext",
"@org_golang_google_protobuf//testing/protocmp",
],
)

#Transceiver test
ondatra_test(
name = "transceiver_test",
srcs = ["transceiver_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_ygot//ygot",
"@org_golang_google_grpc//:go_default_library",
],
)

# Inband SW Interface Tests
ondatra_test(
name = "inband_sw_interface_test",
srcs = ["inband_sw_interface_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_openconfig_testt//:testt",
],
)

# Software Platform Component Tests
ondatra_test(
name = "platforms_software_component_test",
srcs = ["platforms_software_component_test.go"],
deps = [
"//infrastructure/binding:pinsbind",
"//infrastructure/testhelper",
"@com_github_openconfig_gnoi//system:system_go_proto",
"@com_github_openconfig_ondatra//:go_default_library",
"@com_github_openconfig_ondatra//gnmi",
"@com_github_openconfig_ondatra//gnmi/oc",
"@com_github_openconfig_testt//:testt",
"@com_github_pkg_errors//:errors",
],
)
194 changes: 194 additions & 0 deletions sdn_tests/pins_ondatra/tests/transceiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,197 @@ func TestReadName(t *testing.T) {
t.Errorf("Component key name (%v) does not match config name path value: %v", xcvrName, configNamePath)
}
}

func TestIndex(t *testing.T) {
defer testhelper.NewTearDownOptions(t).WithID("2e63771a-4414-459b-a4ef-d56ed0de6a7a").Teardown(t)
dut := ondatra.DUT(t, "DUT")

xcvrName, _ := FindPresentTransceiver(t, dut)
t.Logf("Transceiver found: %v", xcvrName)

numChannels, err := xcvrLanesByXcvrName(t, dut, xcvrName)
if err != nil {
t.Fatalf("%v", err)
}

for channel := uint16(0); channel < numChannels; channel++ {
if channel != gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).Transceiver().Channel(channel).Index().State()) {
t.Errorf("Failed to get telemetry channel index %v", channel)
}
if channel != gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).Transceiver().Channel(channel).Index().Config()) {
t.Errorf("Failed to get config channel index %v", channel)
}
}

// TODO: uncomment after bug is fixed.
// Out-of-range get index should fail.
// testt.ExpectError(t, func(t testing.TB) {
// dutTelemetry.Component(xcvrName).Transceiver().Channel(numChannels).Index().Get(t)
// })
}

func TestReadTransceiverStaticData(t *testing.T) {
defer testhelper.NewTearDownOptions(t).WithID("5b255989-eb9d-4587-922f-160b9a011cf1").Teardown(t)

dut := ondatra.DUT(t, "DUT")

xcvrName, xcvrNum := FindPresentTransceiver(t, dut)

if len(gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).MfgName().State())) == 0 {
t.Errorf("Transceiver %v MfgName is empty", xcvrName)
}
if len(gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).PartNo().State())) == 0 {
t.Errorf("Transceiver %v PartNo is empty", xcvrName)
}
if len(gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).SerialNo().State())) == 0 {
t.Errorf("Transceiver %v SerialNo is empty", xcvrName)
}
if len(gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).FirmwareVersion().State())) == 0 {
t.Errorf("Transceiver %v FirmwareVersion is empty", xcvrName)
}
if len(testhelper.GetLatestAvailableFirmwareVersion(t, dut, xcvrName)) == 0 {
t.Errorf("Transceiver %v LatestAvailableFirmwareVersion is empty", xcvrName)
}

// Get() API for leaf nodes verifies that value complies with the format,
// specified in the YANG model, which will verify that the
// date is in YYYY-MM-DD format.
gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).MfgDate().State())

if ethernetPmd := testhelper.EthernetPMD(t, dut, xcvrName); ethernetPmd == "ETH_UNDEFINED" {
t.Errorf("Transceiver %v has undefined PMD type", xcvrName)
}

componentType := gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).Type().State())

if componentType != oc.PlatformTypes_OPENCONFIG_HARDWARE_COMPONENT_TRANSCEIVER {
t.Errorf("Transceiver %v has incorrect component type: %v, should be TRANSCEIVER", xcvrName, componentType)
}

expectedParent := fmt.Sprintf("1/%v", xcvrNum)
parent := gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).Parent().State())
if parent != expectedParent {
t.Errorf("Transceiver (%v) parent match failed! got:%v, want:%v", xcvrName, parent, expectedParent)
}
}

// TODO: Move platform-specific constants to testhelper.
// These ranges are arbitrary, and not necessarily the operational range for production.
const (
minTemp = 10.0
maxTemp = 55.0
minPower = -30.0
maxPower = 10.0
unsupportedPower = -40.0
)

// TODO: Once SetTransceiverState is implemented and supported in gNMI,
// and xcvrd threading issues are fixed, also test that input-power changes.
func TestReadTransceiverDynamicData(t *testing.T) {
defer testhelper.NewTearDownOptions(t).WithID("31c2b81d-a3b5-4841-a2ad-da4bcc1f4a8f").Teardown(t)
dut := ondatra.DUT(t, "DUT")

xcvrName, _, err := FindPresentOpticalTransceiver(t, dut)

if err != nil {
t.Fatalf("FindPresentOpticalTransceiver failed, %v", err.Error())
}

if xcvrName == "" {
t.Log("No optical transceiver found, skipping test")
t.Skip()
} else {
t.Logf("Testing transceiver %v", xcvrName)
}

temperature := gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).Temperature().Instant().State())
if temperature < minTemp || temperature > maxTemp {
t.Errorf("Transceiver temperature is %v, should be in range 10C-55C", temperature)
}

numChannels, err := xcvrLanesByXcvrName(t, dut, xcvrName)
if err != nil {
t.Fatalf("%v", err)
}

for channel := uint16(0); channel < numChannels; channel++ {
laserBiasCurrent := gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).Transceiver().Channel(channel).LaserBiasCurrent().Instant().State())
if laserBiasCurrent <= 0.0 {
t.Errorf("Laser bias current for channel %v is %v, should be positive", channel, laserBiasCurrent)
}
inputPower := gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).Transceiver().Channel(channel).InputPower().Instant().State())
if inputPower < minPower || inputPower > maxPower {
t.Errorf("Input power for channel %v is %v, should be in range [%v, %v]", channel, inputPower, minPower, maxPower)
}
outputPower := gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).Transceiver().Channel(channel).OutputPower().Instant().State())

// Output power is not supported on some modules: if unsupported, the value is reported as -40.
// Skip testing output power in this case.
if (outputPower != unsupportedPower) && (outputPower < minPower || outputPower > maxPower) {
t.Errorf("Output power for channel %v is %v, should be in range [%v, %v]", channel, outputPower, minPower, maxPower)
}
}

}

func TestReadParentPath(t *testing.T) {
defer testhelper.NewTearDownOptions(t).WithID("0057ca44-0cbc-4054-a20c-94bc99e9b984").Teardown(t)

dut := ondatra.DUT(t, "DUT")

xcvrName, xcvrNum := FindPresentTransceiver(t, dut)

transceiver := gnmi.Get(t, dut, gnmi.OC().Component(xcvrName).State())

transceiverPathName := transceiver.GetName()
if transceiverPathName != xcvrName {
t.Errorf("Transceiver parent path name got: %v, want: %v", transceiverPathName, xcvrName)
}

if len(transceiver.GetMfgName()) == 0 {
t.Errorf("Transceiver %v MfgName is empty", xcvrName)
}

mfgDate := transceiver.GetMfgDate()
dateMatched, err := regexp.MatchString(`^\d\d\d\d-\d\d-\d\d$`, mfgDate)
if err != nil {
t.Errorf("MatchString for MfgDate failed: %v", err)
} else if !dateMatched {
t.Errorf("MfgDate is %v, should be in format YYYY-MM-DD", mfgDate)
}

if len(transceiver.GetPartNo()) == 0 {
t.Errorf("Transceiver %v SerialNo is empty", xcvrName)
}
if len(transceiver.GetSerialNo()) == 0 {
t.Errorf("Transceiver %v PartNo is empty", xcvrName)
}
if len(transceiver.GetFirmwareVersion()) == 0 {
t.Errorf("Transceiver %v FirmwareVersion is empty", xcvrName)
}
if len(testhelper.GetLatestAvailableFirmwareVersion(t, dut, xcvrName)) == 0 {
t.Errorf("Transceiver %v LatestAvailableFirmwareVersion is empty", xcvrName)
}

componentType := transceiver.GetType()
if componentType != oc.PlatformTypes_OPENCONFIG_HARDWARE_COMPONENT_TRANSCEIVER {
t.Errorf("Transceiver %v has incorrect component type: %v, should be TRANSCEIVER", xcvrName, componentType)
}

expectedParent := fmt.Sprintf("1/%v", xcvrNum)
parent := transceiver.GetParent()
if parent != expectedParent {
t.Errorf("Transceiver (%v) parent match failed! got:%v, want:%v", xcvrName, parent, expectedParent)
}

numChannels, err := xcvrLanesByXcvrName(t, dut, xcvrName)
if err != nil {
t.Fatalf("%v", err)
}

for channel := uint16(0); channel < numChannels; channel++ {
if channel != transceiver.GetTransceiver().GetChannel(channel).GetIndex() {
t.Errorf("Failed to get channel index %v", channel)
}
}
}

0 comments on commit f3226a6

Please sign in to comment.