Skip to content

Commit ba6d45b

Browse files
Merge branch 'master' into gnsi_credz_fe_pr_1
2 parents 9e6b332 + 9f58bd6 commit ba6d45b

31 files changed

+626
-224
lines changed

common_utils/notification_producer.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package common_utils
22

33
import (
4+
"context"
45
"encoding/json"
56
"fmt"
67

7-
"github.com/go-redis/redis"
8-
log "github.com/golang/glog"
98
sdcfg "github.com/sonic-net/sonic-gnmi/sonic_db_config"
9+
10+
log "github.com/golang/glog"
11+
"github.com/redis/go-redis/v9"
1012
)
1113

1214
const (
@@ -35,7 +37,7 @@ func GetRedisDBClient() (*redis.Client, error) {
3537
if rclient == nil {
3638
return nil, fmt.Errorf("Cannot create redis client.")
3739
}
38-
if _, err := rclient.Ping().Result(); err != nil {
40+
if _, err := rclient.Ping(context.Background()).Result(); err != nil {
3941
return nil, err
4042
}
4143
return rclient, nil
@@ -85,5 +87,5 @@ func (n *NotificationProducer) Send(op, data string, kvs map[string]string) erro
8587
return err
8688
}
8789
log.Infof("Publishing to channel %s: %v.", n.ch, string(val))
88-
return n.rc.Publish(n.ch, val).Err()
90+
return n.rc.Publish(context.Background(), n.ch, val).Err()
8991
}

dialout/dialout_client/dialout_client.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
package telemetry_dialout
22

33
import (
4-
// "encoding/json"
4+
"context"
55
"crypto/tls"
66
"errors"
77
"fmt"
8+
"net"
9+
"strconv"
10+
"strings"
11+
"sync"
12+
"time"
13+
14+
spb "github.com/sonic-net/sonic-gnmi/proto"
15+
sdc "github.com/sonic-net/sonic-gnmi/sonic_data_client"
16+
sdcfg "github.com/sonic-net/sonic-gnmi/sonic_db_config"
17+
818
"github.com/Workiva/go-datastructures/queue"
9-
"github.com/go-redis/redis"
1019
log "github.com/golang/glog"
1120
gpb "github.com/openconfig/gnmi/proto/gnmi"
1221
"github.com/openconfig/ygot/ygot"
13-
spb "github.com/sonic-net/sonic-gnmi/proto"
14-
sdc "github.com/sonic-net/sonic-gnmi/sonic_data_client"
15-
sdcfg "github.com/sonic-net/sonic-gnmi/sonic_db_config"
16-
"golang.org/x/net/context"
22+
"github.com/redis/go-redis/v9"
1723
"google.golang.org/grpc"
1824
"google.golang.org/grpc/credentials"
19-
"net"
20-
//"reflect"
21-
"strconv"
22-
"strings"
23-
"sync"
24-
"time"
2525
)
2626

2727
const (
@@ -468,7 +468,7 @@ func processTelemetryClientConfig(ctx context.Context, redisDb *redis.Client, ke
468468
return err
469469
}
470470
tableKey := "TELEMETRY_CLIENT" + separator + key
471-
fv, err := redisDb.HGetAll(tableKey).Result()
471+
fv, err := redisDb.HGetAll(context.Background(), tableKey).Result()
472472
if err != nil {
473473
log.V(2).Infof("redis HGetAll failed for %s with error %v", tableKey, err)
474474
return fmt.Errorf("redis HGetAll failed for %s with error %v", tableKey, err)
@@ -687,10 +687,10 @@ func DialOutRun(ctx context.Context, ccfg *ClientConfig) error {
687687
prefixLen := len(pattern)
688688
pattern += "*"
689689

690-
pubsub := redisDb.PSubscribe(pattern)
690+
pubsub := redisDb.PSubscribe(context.Background(), pattern)
691691
defer pubsub.Close()
692692

693-
msgi, err := pubsub.ReceiveTimeout(time.Second)
693+
msgi, err := pubsub.ReceiveTimeout(context.Background(), time.Second)
694694
if err != nil {
695695
log.V(1).Infof("psubscribe to %s failed %v", pattern, err)
696696
return fmt.Errorf("psubscribe to %s failed %v", pattern, err)
@@ -704,7 +704,7 @@ func DialOutRun(ctx context.Context, ccfg *ClientConfig) error {
704704

705705
var dbkeys []string
706706
dbkey_prefix := "TELEMETRY_CLIENT" + separator
707-
dbkeys, err = redisDb.Keys(dbkey_prefix + "*").Result()
707+
dbkeys, err = redisDb.Keys(context.Background(), dbkey_prefix+"*").Result()
708708
if err != nil {
709709
log.V(2).Infof("redis Keys failed for %v with err %v", pattern, err)
710710
return err
@@ -715,7 +715,7 @@ func DialOutRun(ctx context.Context, ccfg *ClientConfig) error {
715715
}
716716

717717
for {
718-
msgi, err := pubsub.ReceiveTimeout(time.Millisecond * 1000)
718+
msgi, err := pubsub.ReceiveTimeout(context.Background(), time.Millisecond*1000)
719719
if err != nil {
720720
neterr, ok := err.(net.Error)
721721
if ok {

dialout/dialout_client/dialout_client_test.go

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,9 @@ package telemetry_dialout
44
// Prerequisite: redis-server should be running.
55

66
import (
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

3731
var 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{
173167
func 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) {
195189
func 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
}

dialout/dialout_client_cli/dialout_client_cli.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
package main
33

44
import (
5+
"context"
56
"crypto/tls"
67
"flag"
7-
log "github.com/golang/glog"
8-
gpb "github.com/openconfig/gnmi/proto/gnmi"
9-
dc "github.com/sonic-net/sonic-gnmi/dialout/dialout_client"
10-
"golang.org/x/net/context"
118
"os"
129
"os/signal"
1310
"time"
11+
12+
dc "github.com/sonic-net/sonic-gnmi/dialout/dialout_client"
13+
14+
log "github.com/golang/glog"
15+
gpb "github.com/openconfig/gnmi/proto/gnmi"
1416
)
1517

1618
var (

gnmi_server/chassis_state_db_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ package gnmi
44
// Covers: Poll mode, Sample mode, and Get operations for DPU_STATE table
55

66
import (
7+
"context"
78
"crypto/tls"
89
"encoding/json"
910
"io/ioutil"
1011
"sync"
1112
"testing"
1213
"time"
1314

14-
"github.com/go-redis/redis"
15+
sdcfg "github.com/sonic-net/sonic-gnmi/sonic_db_config"
16+
1517
"github.com/kylelemons/godebug/pretty"
1618
"github.com/openconfig/gnmi/client"
1719
pb "github.com/openconfig/gnmi/proto/gnmi"
18-
sdcfg "github.com/sonic-net/sonic-gnmi/sonic_db_config"
19-
"golang.org/x/net/context"
20+
"github.com/redis/go-redis/v9"
2021
"google.golang.org/grpc"
2122
"google.golang.org/grpc/codes"
2223
"google.golang.org/grpc/credentials"
@@ -38,7 +39,7 @@ func getChassisStateDbRedisClient(t *testing.T, namespace string) *redis.Client
3839
DB: db,
3940
DialTimeout: 0,
4041
})
41-
_, err = rclient.Ping().Result()
42+
_, err = rclient.Ping(context.Background()).Result()
4243
if err != nil {
4344
t.Fatalf("failed to connect to redis server %v", err)
4445
}
@@ -49,7 +50,7 @@ func getChassisStateDbRedisClient(t *testing.T, namespace string) *redis.Client
4950
func prepareChassisStateDb(t *testing.T, namespace string) {
5051
rclient := getChassisStateDbRedisClient(t, namespace)
5152
defer rclient.Close()
52-
rclient.FlushDB()
53+
rclient.FlushDB(context.Background())
5354

5455
fileName := "../testdata/DPU_STATE.txt"
5556
dpuStateBytes, err := ioutil.ReadFile(fileName)

gnmi_server/cli_helpers_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gnmi
22

33
import (
4+
"context"
45
"io/ioutil"
56
"os/exec"
67
"reflect"
@@ -55,7 +56,7 @@ func FlushDataSet(t *testing.T, dbNum int) {
5556
ns, _ := sdcfg.GetDbDefaultNamespace()
5657
rclient := getRedisClientN(t, dbNum, ns)
5758
defer rclient.Close()
58-
rclient.FlushDB()
59+
rclient.FlushDB(context.Background())
5960
}
6061

6162
func AddDataSet(t *testing.T, dbNum int, fileName string) {

gnmi_server/connection_manager.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package gnmi
22

33
import (
4-
log "github.com/golang/glog"
4+
"context"
55
"net"
66
"regexp"
77
"sync"
88
"time"
99

10-
"github.com/go-redis/redis"
1110
sdcfg "github.com/sonic-net/sonic-gnmi/sonic_db_config"
11+
12+
log "github.com/golang/glog"
13+
"github.com/redis/go-redis/v9"
1214
)
1315

1416
const table = "TELEMETRY_CONNECTIONS"
@@ -45,14 +47,14 @@ func (cm *ConnectionManager) PrepareRedis() {
4547
DialTimeout: 0,
4648
})
4749

48-
res, _ := rclient.HGetAll("TELEMETRY_CONNECTIONS").Result()
50+
res, _ := rclient.HGetAll(context.Background(), "TELEMETRY_CONNECTIONS").Result()
4951

5052
if res == nil {
5153
return
5254
}
5355

5456
for key, _ := range res {
55-
rclient.HDel(table, key)
57+
rclient.HDel(context.Background(), table, key)
5658
}
5759
}
5860

@@ -109,8 +111,7 @@ func storeKeyRedis(key string) {
109111
log.V(1).Infof("Redis client is nil, cannot store connection key")
110112
return
111113
}
112-
ret, err := rclient.HSet(table, key, "active").Result()
113-
if !ret {
114+
if _, err := rclient.HSet(context.Background(), table, key, "active").Result(); err != nil {
114115
log.V(1).Infof("Subscribe client failed to update telemetry connection key:%s err:%v", key, err)
115116
}
116117
}
@@ -121,7 +122,7 @@ func deleteKeyRedis(key string) {
121122
return
122123
}
123124

124-
ret, err := rclient.HDel(table, key).Result()
125+
ret, err := rclient.HDel(context.Background(), table, key).Result()
125126
if ret == 0 {
126127
log.V(1).Infof("Subscribe client failed to delete telemetry connection key:%s err:%v", key, err)
127128
}

gnmi_server/gnoi_system.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/go-redis/redis"
11-
log "github.com/golang/glog"
12-
"github.com/golang/protobuf/proto"
13-
syspb "github.com/openconfig/gnoi/system"
1410
"github.com/sonic-net/sonic-gnmi/common_utils"
1511
"github.com/sonic-net/sonic-gnmi/pkg/gnoi/system"
1612
ssc "github.com/sonic-net/sonic-gnmi/sonic_service_client"
13+
14+
log "github.com/golang/glog"
15+
"github.com/golang/protobuf/proto"
16+
syspb "github.com/openconfig/gnoi/system"
17+
"github.com/redis/go-redis/v9"
1718
"google.golang.org/grpc/codes"
1819
"google.golang.org/grpc/status"
1920
pjson "google.golang.org/protobuf/encoding/protojson"
@@ -120,8 +121,8 @@ func sendRebootReqOnNotifCh(ctx context.Context, req proto.Message, sc *redis.Cl
120121
defer np.Close()
121122

122123
// Subscribe to the response channel.
123-
sub := sc.Subscribe(rebootRespCh)
124-
if _, err = sub.Receive(); err != nil {
124+
sub := sc.Subscribe(ctx, rebootRespCh)
125+
if _, err = sub.Receive(ctx); err != nil {
125126
return nil, status.Errorf(codes.Internal, err.Error()), msgDataStr
126127
}
127128
defer sub.Close()

0 commit comments

Comments
 (0)