Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
[multi-asic] Added Support for multi-asic for telemetry/gnmi server (#77
Browse files Browse the repository at this point in the history
)

[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.
  • Loading branch information
abdosi authored Jun 14, 2021
1 parent 1c3f75e commit 6df988c
Show file tree
Hide file tree
Showing 13 changed files with 1,291 additions and 782 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ check:
sudo cp ./testdata/database_config.json ${DBDIR}
sudo mkdir -p /usr/models/yang || true
sudo find $(MGMT_COMMON_DIR)/models -name '*.yang' -exec cp {} /usr/models/yang/ \;
-$(GO) test -mod=vendor $(BLD_FLAGS) -v github.com/Azure/sonic-telemetry/gnmi_server
-$(GO) test -mod=vendor $(BLD_FLAGS) -v github.com/Azure/sonic-telemetry/dialout/dialout_client
-sudo $(GO) test -v github.com/Azure/sonic-telemetry/sonic_db_config
-sudo $(GO) test -mod=vendor $(BLD_FLAGS) -v github.com/Azure/sonic-telemetry/gnmi_server
-sudo $(GO) test -mod=vendor $(BLD_FLAGS) -v github.com/Azure/sonic-telemetry/dialout/dialout_client

clean:
$(RM) -r build
$(RM) -r vendor
sudo $(RM) -r ${DBDIR}

$(TELEMETRY_TEST_BIN): $(TEST_FILES) $(SRC_FILES)
mkdir -p $(@D)
Expand Down
12 changes: 6 additions & 6 deletions dialout/dialout_client/dialout_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
spb "github.com/Azure/sonic-telemetry/proto"
sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
sdcfg "github.com/Azure/sonic-telemetry/sonic_db_config"
"github.com/Workiva/go-datastructures/queue"
"github.com/go-redis/redis"
log "github.com/golang/glog"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/ygot/ygot"
"github.com/Workiva/go-datastructures/queue"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -462,7 +462,7 @@ func setupDestGroupClients(ctx context.Context, destGroupName string) {
// start/stop/update telemetry publist client as requested
// TODO: more validation on db data
func processTelemetryClientConfig(ctx context.Context, redisDb *redis.Client, key string, op string) error {
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB")
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB", sdcfg.GetDbDefaultNamespace())
tableKey := "TELEMETRY_CLIENT" + separator + key
fv, err := redisDb.HGetAll(tableKey).Result()
if err != nil {
Expand Down Expand Up @@ -642,28 +642,28 @@ func processTelemetryClientConfig(ctx context.Context, redisDb *redis.Client, ke
// read configDB data for telemetry client and start publishing service for client subscription
func DialOutRun(ctx context.Context, ccfg *ClientConfig) error {
clientCfg = ccfg
dbn := sdcfg.GetDbId("CONFIG_DB")
dbn := sdcfg.GetDbId("CONFIG_DB", sdcfg.GetDbDefaultNamespace())

var redisDb *redis.Client
if sdc.UseRedisLocalTcpPort == false {
redisDb = redis.NewClient(&redis.Options{
Network: "unix",
Addr: sdcfg.GetDbSock("CONFIG_DB"),
Addr: sdcfg.GetDbSock("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
Password: "", // no password set
DB: dbn,
DialTimeout: 0,
})
} else {
redisDb = redis.NewClient(&redis.Options{
Network: "tcp",
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB"),
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
Password: "", // no password set
DB: dbn,
DialTimeout: 0,
})
}

separator, _ := sdc.GetTableKeySeparator("CONFIG_DB")
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB", sdcfg.GetDbDefaultNamespace())
pattern := "__keyspace@" + strconv.Itoa(int(dbn)) + "__:TELEMETRY_CLIENT" + separator
prefixLen := len(pattern)
pattern += "*"
Expand Down
8 changes: 4 additions & 4 deletions dialout/dialout_client/dialout_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func runServer(t *testing.T, s *sds.Server) {
func getRedisClient(t *testing.T) *redis.Client {
rclient := redis.NewClient(&redis.Options{
Network: "tcp",
Addr: sdcfg.GetDbTcpAddr("COUNTERS_DB"),
Addr: sdcfg.GetDbTcpAddr("COUNTERS_DB", sdcfg.GetDbDefaultNamespace()),
Password: "", // no password set
DB: sdcfg.GetDbId("COUNTERS_DB"),
DB: sdcfg.GetDbId("COUNTERS_DB", sdcfg.GetDbDefaultNamespace()),
DialTimeout: 0,
})
_, err := rclient.Ping().Result()
Expand All @@ -126,9 +126,9 @@ func exe_cmd(t *testing.T, cmd string) {
func getConfigDbClient(t *testing.T) *redis.Client {
rclient := redis.NewClient(&redis.Options{
Network: "tcp",
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB"),
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
Password: "", // no password set
DB: sdcfg.GetDbId("CONFIG_DB"),
DB: sdcfg.GetDbId("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
DialTimeout: 0,
})
_, err := rclient.Ping().Result()
Expand Down
2 changes: 1 addition & 1 deletion gnmi_server/client_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {

if target == "OTHERS" {
dc, err = sdc.NewNonDbClient(paths, prefix)
} else if isTargetDb(target) == true {
} else if _, ok, _, _ := sdc.IsTargetDb(target); ok {
dc, err = sdc.NewDbClient(paths, prefix)
} else {
/* For any other target or no target create new Transl Client. */
Expand Down
Loading

0 comments on commit 6df988c

Please sign in to comment.