Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 6df988c

Browse files
authored
[multi-asic] Added Support for multi-asic for telemetry/gnmi server (#77)
[multi-asic] support in telemetry. Summary of Changes:- Enhanced sonic_db_config package for multi-asic to read different namespace redis configuration. Added unit-test for same. Enhanced V2R Lookup for multi-asic by understanding namespace port belongs to Enhanced gNMI Server to initiate redis connection with all namespaces Enhanced gNMI Server Get and Subscribe tests for multi-namespace. Added test_utils package providing utility API's needed by test-cases. Also added multi-namespace specific json files into testdata Enhance parsing of Target in gNMI Request to understand namespace if present. Format the modified files using go fmt. Please ignore whitespaces diff as part of review. Added new test case to verify gNMI Get on non-counter DB (eg: STATE_DB) and fixed issue in existing GET of not verifying the return value. Fixed the gNMI Subscribe test issue where IntervalTimeTicker function pointer not re-assigned after test case is done.
1 parent 1c3f75e commit 6df988c

File tree

13 files changed

+1291
-782
lines changed

13 files changed

+1291
-782
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ check:
6060
sudo cp ./testdata/database_config.json ${DBDIR}
6161
sudo mkdir -p /usr/models/yang || true
6262
sudo find $(MGMT_COMMON_DIR)/models -name '*.yang' -exec cp {} /usr/models/yang/ \;
63-
-$(GO) test -mod=vendor $(BLD_FLAGS) -v github.com/Azure/sonic-telemetry/gnmi_server
64-
-$(GO) test -mod=vendor $(BLD_FLAGS) -v github.com/Azure/sonic-telemetry/dialout/dialout_client
63+
-sudo $(GO) test -v github.com/Azure/sonic-telemetry/sonic_db_config
64+
-sudo $(GO) test -mod=vendor $(BLD_FLAGS) -v github.com/Azure/sonic-telemetry/gnmi_server
65+
-sudo $(GO) test -mod=vendor $(BLD_FLAGS) -v github.com/Azure/sonic-telemetry/dialout/dialout_client
6566

6667
clean:
6768
$(RM) -r build
6869
$(RM) -r vendor
70+
sudo $(RM) -r ${DBDIR}
6971

7072
$(TELEMETRY_TEST_BIN): $(TEST_FILES) $(SRC_FILES)
7173
mkdir -p $(@D)

dialout/dialout_client/dialout_client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
spb "github.com/Azure/sonic-telemetry/proto"
99
sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
1010
sdcfg "github.com/Azure/sonic-telemetry/sonic_db_config"
11+
"github.com/Workiva/go-datastructures/queue"
1112
"github.com/go-redis/redis"
1213
log "github.com/golang/glog"
1314
gpb "github.com/openconfig/gnmi/proto/gnmi"
1415
"github.com/openconfig/ygot/ygot"
15-
"github.com/Workiva/go-datastructures/queue"
1616
"golang.org/x/net/context"
1717
"google.golang.org/grpc"
1818
"google.golang.org/grpc/credentials"
@@ -462,7 +462,7 @@ func setupDestGroupClients(ctx context.Context, destGroupName string) {
462462
// start/stop/update telemetry publist client as requested
463463
// TODO: more validation on db data
464464
func processTelemetryClientConfig(ctx context.Context, redisDb *redis.Client, key string, op string) error {
465-
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB")
465+
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB", sdcfg.GetDbDefaultNamespace())
466466
tableKey := "TELEMETRY_CLIENT" + separator + key
467467
fv, err := redisDb.HGetAll(tableKey).Result()
468468
if err != nil {
@@ -642,28 +642,28 @@ func processTelemetryClientConfig(ctx context.Context, redisDb *redis.Client, ke
642642
// read configDB data for telemetry client and start publishing service for client subscription
643643
func DialOutRun(ctx context.Context, ccfg *ClientConfig) error {
644644
clientCfg = ccfg
645-
dbn := sdcfg.GetDbId("CONFIG_DB")
645+
dbn := sdcfg.GetDbId("CONFIG_DB", sdcfg.GetDbDefaultNamespace())
646646

647647
var redisDb *redis.Client
648648
if sdc.UseRedisLocalTcpPort == false {
649649
redisDb = redis.NewClient(&redis.Options{
650650
Network: "unix",
651-
Addr: sdcfg.GetDbSock("CONFIG_DB"),
651+
Addr: sdcfg.GetDbSock("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
652652
Password: "", // no password set
653653
DB: dbn,
654654
DialTimeout: 0,
655655
})
656656
} else {
657657
redisDb = redis.NewClient(&redis.Options{
658658
Network: "tcp",
659-
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB"),
659+
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
660660
Password: "", // no password set
661661
DB: dbn,
662662
DialTimeout: 0,
663663
})
664664
}
665665

666-
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB")
666+
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB", sdcfg.GetDbDefaultNamespace())
667667
pattern := "__keyspace@" + strconv.Itoa(int(dbn)) + "__:TELEMETRY_CLIENT" + separator
668668
prefixLen := len(pattern)
669669
pattern += "*"

dialout/dialout_client/dialout_client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ func runServer(t *testing.T, s *sds.Server) {
9797
func getRedisClient(t *testing.T) *redis.Client {
9898
rclient := redis.NewClient(&redis.Options{
9999
Network: "tcp",
100-
Addr: sdcfg.GetDbTcpAddr("COUNTERS_DB"),
100+
Addr: sdcfg.GetDbTcpAddr("COUNTERS_DB", sdcfg.GetDbDefaultNamespace()),
101101
Password: "", // no password set
102-
DB: sdcfg.GetDbId("COUNTERS_DB"),
102+
DB: sdcfg.GetDbId("COUNTERS_DB", sdcfg.GetDbDefaultNamespace()),
103103
DialTimeout: 0,
104104
})
105105
_, err := rclient.Ping().Result()
@@ -126,9 +126,9 @@ func exe_cmd(t *testing.T, cmd string) {
126126
func getConfigDbClient(t *testing.T) *redis.Client {
127127
rclient := redis.NewClient(&redis.Options{
128128
Network: "tcp",
129-
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB"),
129+
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
130130
Password: "", // no password set
131-
DB: sdcfg.GetDbId("CONFIG_DB"),
131+
DB: sdcfg.GetDbId("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
132132
DialTimeout: 0,
133133
})
134134
_, err := rclient.Ping().Result()

gnmi_server/client_subscribe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
123123

124124
if target == "OTHERS" {
125125
dc, err = sdc.NewNonDbClient(paths, prefix)
126-
} else if isTargetDb(target) == true {
126+
} else if _, ok, _, _ := sdc.IsTargetDb(target); ok {
127127
dc, err = sdc.NewDbClient(paths, prefix)
128128
} else {
129129
/* For any other target or no target create new Transl Client. */

0 commit comments

Comments
 (0)