@@ -4,22 +4,9 @@ package telemetry_dialout
44// Prerequisite: redis-server should be running.
55
66import (
7+ "context"
78 "crypto/tls"
89 "encoding/json"
9- "github.com/go-redis/redis"
10- //"github.com/golang/protobuf/proto"
11- testcert "github.com/sonic-net/sonic-gnmi/testdata/tls"
12-
13- //"github.com/kylelemons/godebug/pretty"
14- //"github.com/openconfig/gnmi/client"
15- pb "github.com/openconfig/gnmi/proto/gnmi"
16- "github.com/openconfig/gnmi/value"
17- "golang.org/x/net/context"
18- "google.golang.org/grpc"
19- //"google.golang.org/grpc/codes"
20- "google.golang.org/grpc/credentials"
21- //"google.golang.org/grpc/status"
22- //"fmt"
2310 "io/ioutil"
2411 "os"
2512 "os/exec"
@@ -28,10 +15,17 @@ import (
2815 "testing"
2916 "time"
3017
31- gclient "github.com/openconfig/gnmi/client/gnmi"
3218 sds "github.com/sonic-net/sonic-gnmi/dialout/dialout_server"
3319 sdc "github.com/sonic-net/sonic-gnmi/sonic_data_client"
3420 sdcfg "github.com/sonic-net/sonic-gnmi/sonic_db_config"
21+ testcert "github.com/sonic-net/sonic-gnmi/testdata/tls"
22+
23+ gclient "github.com/openconfig/gnmi/client/gnmi"
24+ pb "github.com/openconfig/gnmi/proto/gnmi"
25+ "github.com/openconfig/gnmi/value"
26+ "github.com/redis/go-redis/v9"
27+ "google.golang.org/grpc"
28+ "google.golang.org/grpc/credentials"
3529)
3630
3731var clientTypes = []string {gclient .Type }
@@ -56,7 +50,7 @@ func loadDB(t *testing.T, rclient *redis.Client, mpi map[string]interface{}) {
5650 for key , fv := range mpi {
5751 switch fv .(type ) {
5852 case map [string ]interface {}:
59- _ , err := rclient .HMSet (key , fv .(map [string ]interface {})).Result ()
53+ _ , err := rclient .HMSet (context . Background (), key , fv .(map [string ]interface {})).Result ()
6054 if err != nil {
6155 t .Fatal ("Invalid data for db: " , key , fv , err )
6256 }
@@ -111,7 +105,7 @@ func getRedisClient(t *testing.T) *redis.Client {
111105 DB : db ,
112106 DialTimeout : 0 ,
113107 })
114- _ , err = rclient .Ping ().Result ()
108+ _ , err = rclient .Ping (context . Background () ).Result ()
115109 if err != nil {
116110 t .Fatal ("failed to connect to redis server " , err )
117111 }
@@ -149,7 +143,7 @@ func getConfigDbClient(t *testing.T) *redis.Client {
149143 DB : db ,
150144 DialTimeout : 0 ,
151145 })
152- _ , err = rclient .Ping ().Result ()
146+ _ , err = rclient .Ping (context . Background () ).Result ()
153147 if err != nil {
154148 t .Fatalf ("failed to connect to redis server %v" , err )
155149 }
@@ -160,7 +154,7 @@ func loadConfigDB(t *testing.T, rclient *redis.Client, mpi map[string]interface{
160154 for key , fv := range mpi {
161155 switch fv .(type ) {
162156 case map [string ]interface {}:
163- _ , err := rclient .HMSet (key , fv .(map [string ]interface {})).Result ()
157+ _ , err := rclient .HMSet (context . Background (), key , fv .(map [string ]interface {})).Result ()
164158 if err != nil {
165159 t .Errorf ("Invalid data for db: %v : %v %v" , key , fv , err )
166160 }
@@ -173,7 +167,7 @@ func loadConfigDB(t *testing.T, rclient *redis.Client, mpi map[string]interface{
173167func prepareConfigDb (t * testing.T ) {
174168 rclient := getConfigDbClient (t )
175169 defer rclient .Close ()
176- rclient .FlushDB ()
170+ rclient .FlushDB (context . Background () )
177171
178172 fileName := "../../testdata/COUNTERS_PORT_ALIAS_MAP.txt"
179173 countersPortAliasMapByte , err := ioutil .ReadFile (fileName )
@@ -195,7 +189,7 @@ func prepareConfigDb(t *testing.T) {
195189func prepareDb (t * testing.T ) {
196190 rclient := getRedisClient (t )
197191 defer rclient .Close ()
198- rclient .FlushDB ()
192+ rclient .FlushDB (context . Background () )
199193 //Enable keysapce notification
200194 os .Setenv ("PATH" , "$PATH:/usr/bin:/sbin:/bin:/usr/local/bin:/usr/local/Cellar/redis/4.0.8/bin" )
201195 cmd := exec .Command ("redis-cli" , "config" , "set" , "notify-keyspace-events" , "KEA" )
@@ -483,9 +477,9 @@ func TestGNMIDialOutPublish(t *testing.T) {
483477 for _ , update := range tt .updates {
484478 switch update .op {
485479 case "hdel" :
486- rclient .HDel (update .tableName + update .delimitor + update .tableKey , update .field )
480+ rclient .HDel (context . Background (), update .tableName + update .delimitor + update .tableKey , update .field )
487481 default :
488- rclient .HSet (update .tableName + update .delimitor + update .tableKey , update .field , update .value )
482+ rclient .HSet (context . Background (), update .tableName + update .delimitor + update .tableKey , update .field , update .value )
489483 }
490484 time .Sleep (time .Millisecond * 500 )
491485 }
0 commit comments