Skip to content

Commit 36b23e2

Browse files
[sdn_tests]: Adding LACP testhelper to pins_ondatra. (#12669)
* [sdn_tests]: Adding Build support for pins_ondatra * [sdn_tests]: Adding binding infra to pins_ondatra. * [sdn_tests]: Adding cert generation script and certs folder to pins_ondatra. * [sdn_tests]: Adding Data Infra to pins_ondatra. * [sdn_tests]: Adding gnmi testhelper to pins_ondatra. * [sdn_tests]: Adding GNOI testhelper to pins_ondatra. * [sdn_tests]: Adding LACP testhelper to pins_ondatra.
1 parent 7ac1570 commit 36b23e2

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-0
lines changed

sdn_tests/pins_ondatra/infrastructure/testhelper/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ go_library(
1010
testonly = 1,
1111
srcs = [
1212
"gnmi.go",
13+
"gnoi.go",
14+
"lacp.go",
1315
],
1416
data = [
1517
"//infrastructure/data",
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package testhelper
2+
3+
// This file contains helper method for gNOI services such as
4+
// Reboot, Install etc.
5+
import (
6+
"context"
7+
"fmt"
8+
"testing"
9+
"time"
10+
11+
"github.com/openconfig/ondatra"
12+
"github.com/openconfig/ondatra/gnmi"
13+
14+
healthzpb "github.com/openconfig/gnoi/healthz"
15+
syspb "github.com/openconfig/gnoi/system"
16+
)
17+
18+
// Function pointers that interact with the switch. They enable unit testing
19+
// of methods that interact with the switch.
20+
var (
21+
gnoiSystemClientGet = func(t *testing.T, d *ondatra.DUTDevice) syspb.SystemClient {
22+
return d.RawAPIs().GNOI(t).System()
23+
}
24+
25+
gnoiHealthzClientGet = func(t *testing.T, d *ondatra.DUTDevice) healthzpb.HealthzClient {
26+
return d.RawAPIs().GNOI(t).Healthz()
27+
}
28+
29+
gnmiSystemBootTimeGet = func(t *testing.T, d *ondatra.DUTDevice) uint64 {
30+
return gnmi.Get(t, d, gnmi.OC().System().BootTime().State())
31+
}
32+
)
33+
34+
// RebootParams specify the reboot parameters used by the Reboot API.
35+
type RebootParams struct {
36+
request any
37+
waitTime time.Duration
38+
checkInterval time.Duration
39+
lmTTkrID string // latency measurement testtracker UUID
40+
lmTitle string // latency measurement title
41+
}
42+
43+
// NewRebootParams returns RebootParams structure with default values.
44+
func NewRebootParams() *RebootParams {
45+
return &RebootParams{
46+
waitTime: 4 * time.Minute,
47+
checkInterval: 20 * time.Second,
48+
}
49+
}
50+
51+
// WithWaitTime adds the period of time to wait for the reboot operation to be
52+
// successful.
53+
func (p *RebootParams) WithWaitTime(t time.Duration) *RebootParams {
54+
p.waitTime = t
55+
return p
56+
}
57+
58+
// WithCheckInterval adds the time interval to check whether the reboot
59+
// operation has been successful.
60+
func (p *RebootParams) WithCheckInterval(t time.Duration) *RebootParams {
61+
p.checkInterval = t
62+
return p
63+
}
64+
65+
// WithRequest adds the reboot request in RebootParams. The reboot request can
66+
// be one of the following:
67+
// 1) RebootMethod such as syspb.RebootMethod_COLD.
68+
// 2) RebootRequest protobuf.
69+
func (p *RebootParams) WithRequest(r any) *RebootParams {
70+
p.request = r
71+
return p
72+
}
73+
74+
// WithLatencyMeasurement adds testtracker uuid and title for latency measurement.
75+
func (p *RebootParams) WithLatencyMeasurement(testTrackerID, title string) *RebootParams {
76+
p.lmTTkrID = testTrackerID
77+
p.lmTitle = title
78+
return p
79+
}
80+
81+
// measureLatency returns true if latency measurement parameters are set and valid.
82+
func (p *RebootParams) measureLatency() bool {
83+
return p.waitTime > 0 && p.lmTitle != ""
84+
}
85+
86+
// GNOIAble returns whether the gNOI server on the specified device is reachable
87+
// or not.
88+
func GNOIAble(t *testing.T, d *ondatra.DUTDevice) error {
89+
// Time() gNOI request is used to verify the gNOI server reachability.
90+
_, err := gnoiSystemClientGet(t, d).Time(context.Background(), &syspb.TimeRequest{})
91+
return err
92+
}
93+
94+
// HealthzGetPortDebugData returns port debug data given an interface.
95+
func HealthzGetPortDebugData(t *testing.T, d *ondatra.DUTDevice, intfName string) error {
96+
return fmt.Errorf("unimplemented method HealthzGetPortDebugData")
97+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package testhelper
2+
3+
import (
4+
"github.com/openconfig/ondatra/gnmi/oc"
5+
)
6+
7+
// PeerPorts holds the name of 2 Ethernet interfaces. These interfaces will be on separate machines,
8+
// but connected to each other by a cable.
9+
type PeerPorts struct {
10+
Host string
11+
Peer string
12+
}
13+
14+
// GeneratePortChannelInterface will return a minimal PortChannel interface that tests can extend as needed.
15+
func GeneratePortChannelInterface(portChannelName string) oc.Interface {
16+
enabled := true
17+
18+
description := "PortChannel: " + portChannelName + " used for testing gNMI configuration."
19+
minLinks := uint16(1)
20+
21+
// Unsupported fields: Id, Aggregation/LagType
22+
return oc.Interface{
23+
Name: &portChannelName,
24+
Enabled: &enabled,
25+
Type: oc.IETFInterfaces_InterfaceType_ieee8023adLag,
26+
Description: &description,
27+
Aggregation: &oc.Interface_Aggregation{
28+
LagType: oc.IfAggregate_AggregationType_LACP,
29+
MinLinks: &minLinks,
30+
},
31+
}
32+
}
33+
34+
// GenerateLACPInterface creates a minimal LACP interface that tests can then extend as needed.
35+
func GenerateLACPInterface(pcName string) oc.Lacp_Interface {
36+
37+
return oc.Lacp_Interface{
38+
Name: &pcName,
39+
Interval: oc.Lacp_LacpPeriodType_FAST,
40+
LacpMode: oc.Lacp_LacpActivityType_ACTIVE,
41+
}
42+
}

0 commit comments

Comments
 (0)