Skip to content
Draft
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
161 changes: 161 additions & 0 deletions gnmi_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7583,3 +7583,164 @@ func TestServeUDSErrorDoesNotStopTCP(t *testing.T) {
t.Error("Serve() did not return after Stop()")
}
}

func TestGnmiGetTranslibPfmCompXcvr(t *testing.T) {

//t.Log("Start server")
s := createServer(t, 8081)
go runServer(t, s)

prepareDbTranslib(t)
ctx := context.Background()
ns, _ := sdcfg.GetDbDefaultNamespace()
configClient := getRedisClientN(t, 4, ns) // Force target DB 0
defer configClient.Close()

listFields := map[string]interface{}{
"name": "Ethernet0",
}
listStatusFields := map[string]interface{}{
"name": "Ethernet0",
"status": true,
}

// Explicitly write both delimiter schemas into DB 0
configClient.HSet(ctx, "TRANSCEIVER_CFG|Ethernet0", listFields)
configClient.HSet(ctx, "TRANSCEIVER_INFO|Ethernet0", listFields)
configClient.HSet(ctx, "TRANSCEIVER_STATUS|Ethernet0", listStatusFields)
configClient.HSet(ctx, "TRANSCEIVER_DOM_SENSOR|Ethernet0", listFields)

stateClient := getRedisClientN(t, 6, ns) // Force target DB 0
defer stateClient.Close()

// Explicitly write both delimiter schemas into DB 0
stateClient.HSet(ctx, "TRANSCEIVER_INFO|Ethernet0", listFields)
stateClient.HSet(ctx, "TRANSCEIVER_INFO|Ethernet0", listFields)
stateClient.HSet(ctx, "TRANSCEIVER_STATUS|Ethernet0", listStatusFields)
stateClient.HSet(ctx, "TRANSCEIVER_DOM_SENSOR|Ethernet0", listFields)

//t.Log("Start gNMI client")
tlsConfig := &tls.Config{InsecureSkipVerify: true}
opts := []grpc.DialOption{grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))}

targetAddr := "127.0.0.1:8081"
conn, err := grpc.Dial(targetAddr, opts...)
if err != nil {
t.Fatalf("Dialing to %q failed: %v", targetAddr, err)
}
defer conn.Close()

gClient := pb.NewGNMIClient(conn)

var emptyRespVal interface{}
tds := []struct {
desc string
pathTarget string
textPbPath string
timeout time.Duration
wantRetCode codes.Code
wantRespVal interface{}
valTest bool
}{
{
desc: "Get OC Platform Comp Xcvr",
pathTarget: "OC_YANG",
textPbPath: `
elem: <name: "openconfig-platform:components" > elem: <name: "component" key:<key:"name" value:"Ethernet0" > >
`,
wantRetCode: codes.OK,
wantRespVal: emptyRespVal,
valTest: false,
},
}
for _, td := range tds {
t.Run(td.desc, func(t *testing.T) {
if td.timeout == 0 {
td.timeout = 10 * time.Second
}
ctx, cancel := context.WithTimeout(context.Background(), td.timeout)
defer cancel()

runTestGet(t, ctx, gClient, td.pathTarget, td.textPbPath, td.wantRetCode, td.wantRespVal, td.valTest)
})
}
s.Stop()
}

func TestGnmiSetCompTxvr(t *testing.T) {
s := createServer(t, 8081)
go runServer(t, s)

prepareDbTranslib(t)

ctx := context.Background()
ns, _ := sdcfg.GetDbDefaultNamespace()
configClient := getRedisClientN(t, 4, ns) // Force target DB 0
defer configClient.Close()

listFields := map[string]interface{}{
"name": "Ethernet0",
}
listStatusFields := map[string]interface{}{
"name": "Ethernet0",
"status": true,
}

// Explicitly write both delimiter schemas into DB 0
configClient.HSet(ctx, "TRANSCEIVER_CFG|Ethernet0", listFields)
configClient.HSet(ctx, "TRANSCEIVER_INFO|Ethernet0", listFields)
configClient.HSet(ctx, "TRANSCEIVER_STATUS|Ethernet0", listStatusFields)
configClient.HSet(ctx, "TRANSCEIVER_DOM_SENSOR|Ethernet0", listFields)

stateClient := getRedisClientN(t, 6, ns) // Force target DB 0
defer stateClient.Close()

// Explicitly write both delimiter schemas into DB 0
stateClient.HSet(ctx, "TRANSCEIVER_INFO|Ethernet0", listFields)
stateClient.HSet(ctx, "TRANSCEIVER_INFO|Ethernet0", listFields)
stateClient.HSet(ctx, "TRANSCEIVER_STATUS|Ethernet0", listStatusFields)
stateClient.HSet(ctx, "TRANSCEIVER_DOM_SENSOR|Ethernet0", listFields)

//t.Log("Start gNMI client")
tlsConfig := &tls.Config{InsecureSkipVerify: true}
opts := []grpc.DialOption{grpc.WithTransportCredentials(credentials.NewTLS(tlsConfig))}

targetAddr := fmt.Sprintf("127.0.0.1:%d", s.config.Port)
conn, err := grpc.Dial(targetAddr, opts...)
if err != nil {
t.Fatalf("Dialing to %q failed: %v", targetAddr, err)
}
defer conn.Close()

gClient := pb.NewGNMIClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

tds := []struct {
desc string
pathTarget string
textPbPath string
wantRetCode codes.Code
wantRespVal interface{}
attributeData string
operation op_t
valTest bool
}{
{
desc: "Plfm xvr delete",
pathTarget: "OC_YANG",
textPbPath: pathToPb("openconfig-platform:components/component[name=Ethernet0]/"),
attributeData: "",
wantRetCode: codes.Unknown,
operation: Delete,
valTest: false,
},
}

for _, td := range tds {
t.Run(td.desc, func(t *testing.T) {
runTestSet(t, ctx, gClient, td.pathTarget, td.textPbPath, td.wantRetCode, td.wantRespVal, td.attributeData, td.operation)
})
}
s.Stop()
}
Loading