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

Add Virtual Database Client + Unit Tests #18

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
43a8fcd
Add feature to support query for PFC watchdog
chaliu Sep 5, 2018
3908994
fix typos;rewrite log messeages; replace hard-coded : with database s…
chaliu Sep 5, 2018
cca4c30
replace hardcoded table separator |
chaliu Sep 6, 2018
750133e
Implement new virtual path for pfcwd
chaliu Sep 26, 2018
b2c6c5e
Unit tests for virtual database target SONiC, rename new_sonic_data_c…
randygaulmsft Mar 25, 2019
9ea0465
Merge branch 'master' into new-pfcwd
randygaulmsft Mar 26, 2019
0fcf9a5
remove testing directory imports
randygaulmsft Mar 26, 2019
f0e0fdb
silence unnecessary printfs
randygaulmsft Apr 10, 2019
bd4af90
remove more debug printf's
randygaulmsft Apr 10, 2019
da43c69
Attempt to fixup import paths and remove old unnecessary debug format…
randygaulmsft Apr 25, 2019
6dbe27c
Merge branch 'new-pfcwd' of https://github.com/randygaulmsft/sonic-te…
randygaulmsft Apr 25, 2019
d16da4c
get tests in a good state
randygaulmsft May 5, 2019
b414595
Got a basic subscribe test working.
randygaulmsft May 6, 2019
e29cfa5
Figured out way to subscribe to target SONiC_DB
randygaulmsft May 6, 2019
e597358
Wrapped up stream queries.
randygaulmsft May 7, 2019
90d4437
gofmt on all code under folder.
randygaulmsft May 15, 2019
ede7a94
Remove dead code (comments).
randygaulmsft May 15, 2019
f01f39c
SONiC_DB to SONIC_DB
randygaulmsft May 15, 2019
d33fca6
Removed dead code.
randygaulmsft May 17, 2019
9f94324
Remove more dead code.
randygaulmsft May 17, 2019
6f2b220
sdc to vdc (use correct path for setting TCP redis settings)
randygaulmsft May 17, 2019
53c0e70
Remove dead code from sonic_data_client.
randygaulmsft May 17, 2019
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
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ There is also a test program dialout_server_cli for collecting data from dial-ou

The binaries will be installed under $GOPATH/bin/, they may be copied to any SONiC switch and run there.

You can also build a debian package and install it:
randygaulmsft marked this conversation as resolved.
Show resolved Hide resolved

git clone https://github.com/Azure/sonic-telemetry.git
pushd sonic-telemetry
dpkg-buildpackage -rfakeroot -b -us -uc
popd

### Running
* See [SONiC gRPC telemetry](./doc/grpc_telemetry.md) for how to run dial-in mode system telemetry server
* See [SONiC telemetry in dial-out mode](./doc/dialout.md) for how to run dial-out mode system telemetry client
Expand Down
3 changes: 2 additions & 1 deletion dialout/dialout_client/dialout_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"errors"
"fmt"
spb "github.com/Azure/sonic-telemetry/proto"
sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
//sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
randygaulmsft marked this conversation as resolved.
Show resolved Hide resolved
"github.com/go-redis/redis"
log "github.com/golang/glog"
gpb "github.com/openconfig/gnmi/proto/gnmi"
Expand All @@ -16,6 +16,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"net"
sdc "test/sonic-telemetry-new-pfcwd/sonic_data_client"
//"reflect"
"strconv"
"strings"
Expand Down
14 changes: 12 additions & 2 deletions dialout/dialout_client/dialout_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import (
"testing"
"time"

sds "github.com/Azure/sonic-telemetry/dialout/dialout_server"
//sds "github.com/Azure/sonic-telemetry/dialout/dialout_server"
randygaulmsft marked this conversation as resolved.
Show resolved Hide resolved
spb "github.com/Azure/sonic-telemetry/proto"
sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
sds "test/sonic-telemetry-new-pfcwd/dialout/dialout_server"
//sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
gclient "github.com/openconfig/gnmi/client/gnmi"
sdc "test/sonic-telemetry-new-pfcwd/sonic_data_client"
)

var clientTypes = []string{gclient.Type}
Expand Down Expand Up @@ -166,6 +168,14 @@ func prepareConfigDb(t *testing.T) {
}
mpi_alias_map := loadConfig(t, "", countersPortAliasMapByte)
loadConfigDB(t, rclient, mpi_alias_map)

fileName = "../../testdata/CONFIG_PFCWD_PORTS.txt"
configPfcwdByte, err := ioutil.ReadFile(fileName)
if err != nil {
t.Fatalf("read file %v err: %v", fileName, err)
}
mpi_pfcwd_map := loadConfig(t, "", configPfcwdByte)
loadConfigDB(t, rclient, mpi_pfcwd_map)
}

func prepareDb(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion dialout/dialout_server_cli/dialout_server_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

ds "github.com/Azure/sonic-telemetry/dialout/dialout_server"
//ds "github.com/Azure/sonic-telemetry/dialout/dialout_server"
testcert "github.com/Azure/sonic-telemetry/testdata/tls"
ds "test/sonic-telemetry-new-pfcwd/dialout/dialout_server"
)

var (
Expand Down
13 changes: 12 additions & 1 deletion gnmi_server/client_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import (
"google.golang.org/grpc/codes"

//spb "github.com/Azure/sonic-telemetry/proto"
randygaulmsft marked this conversation as resolved.
Show resolved Hide resolved
sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
//sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
sdc "test/sonic-telemetry-new-pfcwd/sonic_data_client"
vdc "test/sonic-telemetry-new-pfcwd/virtual_database_client"

gnmipb "github.com/openconfig/gnmi/proto/gnmi"
)

Expand Down Expand Up @@ -101,6 +104,7 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
}

var target string
fmt.Printf("Subscribe Prefix: %v\n", target)
randygaulmsft marked this conversation as resolved.
Show resolved Hide resolved
prefix := c.subscribe.GetPrefix()
if prefix == nil {
return grpc.Errorf(codes.Unimplemented, "No target specified in prefix")
Expand All @@ -119,6 +123,8 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
var dc sdc.Client
if target == "OTHERS" {
dc, err = sdc.NewNonDbClient(paths, prefix)
} else if target == "SONiC_DB" {
randygaulmsft marked this conversation as resolved.
Show resolved Hide resolved
dc, err = vdc.NewDbClient(paths, prefix)
} else {
dc, err = sdc.NewDbClient(paths, prefix)
}
Expand Down Expand Up @@ -226,6 +232,11 @@ func (c *Client) send(stream gnmipb.GNMI_SubscribeServer) error {
c.errors++
return err
}
case vdc.Value:
if resp, err = vdc.ValToResp(v); err != nil {
c.errors++
return err
}
default:
log.V(1).Infof("Unknown data type %v for %s in queue", items[0], c)
c.errors++
Expand Down
15 changes: 14 additions & 1 deletion gnmi_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import (
"google.golang.org/grpc/reflection"
"google.golang.org/grpc/status"

sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
sdc "test/sonic-telemetry-new-pfcwd/sonic_data_client"
vdc "test/sonic-telemetry-new-pfcwd/virtual_database_client"

gnmipb "github.com/openconfig/gnmi/proto/gnmi"
)

Expand Down Expand Up @@ -77,6 +79,11 @@ func (srv *Server) Serve() error {
return srv.s.Serve(srv.lis)
}

func (srv *Server) Stop() {
s := srv.s
s.Stop()
}

// Address returns the port the Server is listening to.
func (srv *Server) Address() string {
addr := srv.lis.Addr().String()
Expand Down Expand Up @@ -174,6 +181,8 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe
var dc sdc.Client
if target == "OTHERS" {
dc, err = sdc.NewNonDbClient(paths, prefix)
} else if target == "SONiC_DB" {
dc, err = vdc.NewDbClient(paths, prefix)
} else {
dc, err = sdc.NewDbClient(paths, prefix)
}
Expand All @@ -186,6 +195,10 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe
return nil, status.Error(codes.NotFound, err.Error())
}

if target == "SONiC_DB" {
notifications = make([]*gnmipb.Notification, len(spbValues))
}

for index, spbValue := range spbValues {
update := &gnmipb.Update{
Path: spbValue.GetPath(),
Expand Down
Loading