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

WIP: Gomod #77

Open
wants to merge 18 commits into
base: dell_sonic
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ debian/files
debian/sonic-telemetry.debhelper.log
debian/sonic-telemetry.substvars
debian/sonic-telemetry/
telemetry
vendor
src
cvl
translib
*.swp
131 changes: 50 additions & 81 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,95 +1,62 @@
all: precheck deps telemetry
GO=/usr/local/go/bin/go
ifeq ($(GOPATH),)
export GOPATH=/tmp/go
endif
export PATH := $(PATH):$(GOPATH)/bin

INSTALL := /usr/bin/install
DBDIR := /var/run/redis/sonic-db/
GO := /usr/local/go/bin/go
TOP_DIR := $(abspath ..)
TELEM_DIR := $(abspath .)
GOFLAGS:=
BUILD_DIR=build
GO_DEP_PATH=$(abspath .)/$(BUILD_DIR)
GO_MGMT_PATH=$(TOP_DIR)/sonic-mgmt-framework
GO_SONIC_TELEMETRY_PATH=$(TOP_DIR)
CVL_GOPATH=$(GO_MGMT_PATH)/build/gopkgs:$(GO_MGMT_PATH):$(GO_MGMT_PATH)/src/cvl/build
GOPATH = $(CVL_GOPATH):$(GO_DEP_PATH):$(GO_MGMT_PATH):/tmp/go:$(GO_SONIC_TELEMETRY_PATH):$(TELEM_DIR)
INSTALL := /usr/bin/install
BUILD_DIR := $(GOPATH)/bin
export CVL_SCHEMA_PATH := $(GO_MGMT_PATH)/src/cvl/schema

SRC_FILES=$(shell find . -name '*.go' | grep -v '_test.go' | grep -v '/tests/')
TEST_FILES=$(wildcard *_test.go)
TELEMETRY_TEST_DIR = $(GO_MGMT_PATH)/build/tests/gnmi_server
TELEMETRY_TEST_BIN = $(TELEMETRY_TEST_DIR)/server.test

.PHONY : all precheck deps telemetry clean cleanall check install deinstall

ifdef DEBUG
GOFLAGS += -gcflags="all=-N -l"
endif

all: deps telemetry $(TELEMETRY_TEST_BIN)

precheck:
$(shell mkdir -p $(BUILD_DIR))

deps: $(BUILD_DIR)/.deps

$(BUILD_DIR)/.deps: $(MAKEFILE_LIST)
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/Workiva/go-datastructures/queue
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/goyang
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/ygot/ygot
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/golang/glog
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/go-redis/redis
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/c9s/goprocinfo/linux
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/golang/protobuf/proto
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/gnmi/proto/gnmi
GOPATH=$(GO_DEP_PATH) $(GO) get -u golang.org/x/net/context
GOPATH=$(GO_DEP_PATH) $(GO) get -u google.golang.org/grpc
GOPATH=$(GO_DEP_PATH) $(GO) get -u google.golang.org/grpc/credentials
GOPATH=$(GO_DEP_PATH) $(GO) get -u gopkg.in/go-playground/validator.v9
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/gorilla/mux
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/goyang
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/ygot/ygot
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/google/gnxi/utils
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/jipanyang/gnxi/utils/xpath
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/jipanyang/gnmi/client/gnmi
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/xeipuuv/gojsonschema
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/openconfig/gnoi/system
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/msteinert/pam
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/dgrijalva/jwt-go
GOPATH=$(GO_DEP_PATH) $(GO) get -u gopkg.in/godbus/dbus.v5
GOPATH=$(GO_DEP_PATH) $(GO) get -u github.com/gogo/protobuf/gogoproto
touch $@
all: sonic-telemetry $(TELEMETRY_TEST_BIN)

go.mod:
/usr/local/go/bin/go mod init github.com/Azure/sonic-telemetry

sonic-telemetry: go.mod
$(GO) mod vendor
cp -r $(GO_MGMT_PATH)/vendor/github.com/antchfx ./vendor/github.com/
cp -r $(GO_MGMT_PATH)/vendor/github.com/openconfig ./vendor/github.com/
cp -r $(GOPATH)/pkg/mod/github.com/jipanyang/gnxi@v0.0.0-20181221084354-f0a90cca6fd0/* vendor/github.com/jipanyang/gnxi/
cp -r $(GOPATH)/pkg/mod/golang.org/x/crypto@v0.0.0-20200302210943-78000ba7a073/* vendor/golang.org/x/crypto/
chmod -R u+w vendor
patch -d vendor -p0 <patches/gnmi_cli.all.patch
patch -d vendor -p0 <patches/gnmi_set.patch
patch -d vendor -p0 <patches/gnmi_get.patch

$(GO) install -mod=vendor github.com/Azure/sonic-telemetry/telemetry
$(GO) install -mod=vendor github.com/Azure/sonic-telemetry/dialout/dialout_client_cli
$(GO) install -mod=vendor github.com/Azure/sonic-telemetry/gnoi_client
$(GO) install -mod=vendor github.com/jipanyang/gnxi/gnmi_get
$(GO) install -mod=vendor github.com/jipanyang/gnxi/gnmi_set
$(GO) install -mod=vendor github.com/openconfig/gnmi/cmd/gnmi_cli

telemetry:$(BUILD_DIR)/telemetry $(BUILD_DIR)/dialout_client_cli $(BUILD_DIR)/gnmi_get $(BUILD_DIR)/gnmi_set $(BUILD_DIR)/gnmi_cli $(BUILD_DIR)/gnoi_client

$(BUILD_DIR)/telemetry:src/telemetry/telemetry.go
@echo "Building $@"
GOPATH=$(GOPATH) $(GO) build $(GOFLAGS) -o $@ $^
$(BUILD_DIR)/dialout_client_cli:src/dialout/dialout_client_cli/dialout_client_cli.go
GOPATH=$(GOPATH) $(GO) build $(GOFLAGS) -o $@ $^
$(BUILD_DIR)/gnmi_get:src/gnmi_clients/gnmi_get.go
GOPATH=$(GOPATH) $(GO) build $(GOFLAGS) -o $@ $^
$(BUILD_DIR)/gnmi_set:src/gnmi_clients/gnmi_set.go
GOPATH=$(GOPATH) $(GO) build $(GOFLAGS) -o $@ $^
$(BUILD_DIR)/gnmi_cli:src/gnmi_clients/src/github.com/openconfig/gnmi
GOPATH=$(PWD)/src/gnmi_clients:$(GOPATH) $(GO) build $(GOFLAGS) -o $@ github.com/openconfig/gnmi/cmd/gnmi_cli
$(BUILD_DIR)/gnoi_client:src/gnmi_clients/gnoi_client.go
GOPATH=$(PWD)/src/gnmi_clients:$(GOPATH) $(GO) build $(GOFLAGS) -o $@ $^
check:
sudo mkdir -p ${DBDIR}
sudo cp ./testdata/database_config.json ${DBDIR}
sudo mkdir -p /usr/models/yang || true
sudo find $(GO_MGMT_PATH)/models -name '*.yang' -exec cp {} /usr/models/yang/ \;
-$(GO) test -mod=vendor -v github.com/Azure/sonic-telemetry/gnmi_server
-$(GO) test -mod=vendor -v github.com/Azure/sonic-telemetry/dialout/dialout_client

clean:
rm -rf $(BUILD_DIR)/telemetry
rm -rf $(TELEMETRY_TEST_DIR)

cleanall:
rm -rf $(BUILD_DIR)
rm -rf $(TELEMETRY_TEST_DIR)

check:
-$(GO) test -v ${GOPATH}/src/gnmi_server
rm -rf vendor
chmod -f -R u+w $(GOPATH)/pkg || true
rm -rf $(GOPATH)
rm -f src

$(TELEMETRY_TEST_BIN): $(TEST_FILES) $(SRC_FILES)
GOPATH=$(GOPATH) $(GO) test -c -cover gnmi_server -o $@
cp -r src/testdata $(TELEMETRY_TEST_DIR)
cp test/01_create_MyACL1_MyACL2.json $(TELEMETRY_TEST_DIR)
cp -r $(GO_MGMT_PATH)/debian/sonic-mgmt-framework/usr/sbin/schema $(TELEMETRY_TEST_DIR)

$(GO) test -mod=vendor -c -cover github.com/Azure/sonic-telemetry/gnmi_server -o $@
cp -r testdata $(TELEMETRY_TEST_DIR)
cp -r $(GO_MGMT_PATH)/build/cvl/schema $(TELEMETRY_TEST_DIR)

install:
$(INSTALL) -D $(BUILD_DIR)/telemetry $(DESTDIR)/usr/sbin/telemetry
Expand All @@ -100,13 +67,15 @@ install:
$(INSTALL) -D $(BUILD_DIR)/gnoi_client $(DESTDIR)/usr/sbin/gnoi_client

mkdir -p $(DESTDIR)/usr/bin/
cp -r $(GO_MGMT_PATH)/debian/sonic-mgmt-framework/usr/sbin/schema $(DESTDIR)/usr/sbin
cp -r $(GO_MGMT_PATH)/debian/sonic-mgmt-framework/usr/sbin/schema $(DESTDIR)/usr/bin
cp -r $(GO_MGMT_PATH)/debian/sonic-mgmt-framework/usr/models $(DESTDIR)/usr/
cp -r $(GO_MGMT_PATH)/build/cvl/schema $(DESTDIR)/usr/sbin
mkdir -p $(DESTDIR)/usr/models/yang
find $(GO_MGMT_PATH)/models -name '*.yang' -exec cp {} $(DESTDIR)/usr/models/yang/ \;

deinstall:
rm $(DESTDIR)/usr/sbin/telemetry
rm $(DESTDIR)/usr/sbin/dialout_client_cli
rm $(DESTDIR)/usr/sbin/gnmi_get
rm $(DESTDIR)/usr/sbin/gnmi_set
rm $(DESTDIR)/usr/sbin/gnoi_client


12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ Install __go__ in your system https://golang.org/doc/install. Requires golang1.8

To install dial-in mode system telemetry server, run

go get -u github.com/project-arlo/sonic-telemetry/telemetry
go get -u github.com/Azure/sonic-telemetry/telemetry

To install dial-out mode system telemetry client, run

go get -u github.com/project-arlo/sonic-telemetry/dialout/dialout_client_cli
go get -u github.com/Azure/sonic-telemetry/dialout/dialout_client_cli

There is also a test program dialout_server_cli for collecting data from dial-out mode system telemetry client. _Note_: it is for testing purpose only.

go get -u github.com/project-arlo/sonic-telemetry/dialout/dialout_server_cli
go get -u github.com/Azure/sonic-telemetry/dialout/dialout_server_cli

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:

git clone https://github.com/project-arlo/sonic-telemetry.git
git clone https://github.com/Azure/sonic-telemetry.git
pushd sonic-telemetry
dpkg-buildpackage -rfakeroot -b -us -uc
popd
Expand All @@ -47,7 +47,7 @@ For bug reports or feature requests, please open an Issue.

## Contribution guide

See the [contributors guide](https://github.com/project-arlo/SONiC/blob/gh-pages/CONTRIBUTING.md) for information about how to contribute.
See the [contributors guide](https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md) for information about how to contribute.

### GitHub Workflow

Expand Down Expand Up @@ -80,4 +80,4 @@ For example:
* Each developer should fork this repository and [add the team as a Contributor](https://help.github.com/articles/adding-collaborators-to-a-personal-repository)
* Push your changes to your private fork and do "pull-request" to this repository
* Use a pull request to do code review
* Use issues to keep track of what is going on
* Use issues to keep track of what is going on
File renamed without changes.
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Priority: optional
Maintainer: Jipan Yang <jipan.yang@alibaba-inc.com>
Build-Depends: debhelper (>= 8.0.0),
Standards-Version: 3.9.3
Homepage: https://github.com/project-arlo/sonic-telemetry
XS-Go-Import-Path: github.com/project-arlo/sonic-telemetry
Homepage: https://github.com/Azure/sonic-telemetry
XS-Go-Import-Path: github.com/Azure/sonic-telemetry

Package: sonic-telemetry
Architecture: any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"crypto/tls"
"errors"
"fmt"
spb "proto"
sdc "sonic_data_client"
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/go-redis/redis"
log "github.com/golang/glog"
gpb "github.com/openconfig/gnmi/proto/gnmi"
Expand Down Expand Up @@ -641,23 +642,23 @@ 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 := spb.Target_value["CONFIG_DB"]
dbn := sdcfg.GetDbId("CONFIG_DB")

var redisDb *redis.Client
if sdc.UseRedisLocalTcpPort == false {
redisDb = redis.NewClient(&redis.Options{
Network: "unix",
Addr: sdc.Default_REDIS_UNIXSOCKET,
Addr: sdcfg.GetDbSock("CONFIG_DB"),
Password: "", // no password set
DB: int(dbn),
DB: dbn,
DialTimeout: 0,
})
} else {
redisDb = redis.NewClient(&redis.Options{
Network: "tcp",
Addr: sdc.Default_REDIS_LOCAL_TCP_PORT,
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB"),
Password: "", // no password set
DB: int(dbn),
DB: dbn,
DialTimeout: 0,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"encoding/json"
"github.com/go-redis/redis"
//"github.com/golang/protobuf/proto"
testcert "testdata/tls"
testcert "github.com/Azure/sonic-telemetry/testdata/tls"

//"github.com/kylelemons/godebug/pretty"
//"github.com/openconfig/gnmi/client"
Expand All @@ -28,9 +28,9 @@ import (
"testing"
"time"

sds "dialout/dialout_server"
spb "proto"
sdc "sonic_data_client"
sds "github.com/Azure/sonic-telemetry/dialout/dialout_server"
sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
sdcfg "github.com/Azure/sonic-telemetry/sonic_db_config"
gclient "github.com/openconfig/gnmi/client/gnmi"
)

Expand Down Expand Up @@ -95,12 +95,11 @@ func runServer(t *testing.T, s *sds.Server) {
}

func getRedisClient(t *testing.T) *redis.Client {
dbn := spb.Target_value["COUNTERS_DB"]
rclient := redis.NewClient(&redis.Options{
Network: "tcp",
Addr: "localhost:6379",
Addr: sdcfg.GetDbTcpAddr("COUNTERS_DB"),
Password: "", // no password set
DB: int(dbn),
DB: sdcfg.GetDbId("COUNTERS_DB"),
DialTimeout: 0,
})
_, err := rclient.Ping().Result()
Expand All @@ -125,12 +124,11 @@ func exe_cmd(t *testing.T, cmd string) {
}

func getConfigDbClient(t *testing.T) *redis.Client {
dbn := spb.Target_value["CONFIG_DB"]
rclient := redis.NewClient(&redis.Options{
Network: "tcp",
Addr: "localhost:6379",
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB"),
Password: "", // no password set
DB: int(dbn),
DB: sdcfg.GetDbId("CONFIG_DB"),
DialTimeout: 0,
})
_, err := rclient.Ping().Result()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package main
import (
"crypto/tls"
"flag"
dc "dialout/dialout_client"
dc "github.com/Azure/sonic-telemetry/dialout/dialout_client"
log "github.com/golang/glog"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"golang.org/x/net/context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dialout_server
import (
"errors"
"fmt"
spb "proto"
spb "github.com/Azure/sonic-telemetry/proto"
log "github.com/golang/glog"
"github.com/google/gnxi/utils"
gpb "github.com/openconfig/gnmi/proto/gnmi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

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

var (
Expand Down
2 changes: 1 addition & 1 deletion doc/grpc_telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Within each DB, the data usually is organized in hierarchy of Table, key, field
```
Some data like COUNTERS table in COUNTERS_DB doesn't have key, but field and value are stored directly under COUNTERS table.

Refer to [SONiC data schema](https://github.com/project-arlo/sonic-swss-common/blob/master/common/schema.h) for more info about DB and table.
Refer to [SONiC data schema](https://github.com/Azure/sonic-swss-common/blob/master/common/schema.h) for more info about DB and table.

For data not available in DBs, Target name "OTHERS" is designated for that category of data, paths like platform/cpu or proc/loadavg under "OTHERS" target may be used get/subscribe the data.

Expand Down
4 changes: 2 additions & 2 deletions src/gnmi_server/basicAuth.go → gnmi_server/basicAuth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gnmi_server
package gnmi

import (
"common_utils"
"github.com/Azure/sonic-telemetry/common_utils"
"github.com/golang/glog"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gnmi_server
package gnmi

import (
"common_utils"
"github.com/Azure/sonic-telemetry/common_utils"
"github.com/golang/glog"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gnmi_server
package gnmi

import (
"fmt"
Expand All @@ -11,8 +11,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"

//spb "github.com/project-arlo/sonic-telemetry/proto"
sdc "sonic_data_client"
sdc "github.com/Azure/sonic-telemetry/sonic_data_client"
gnmipb "github.com/openconfig/gnmi/proto/gnmi"
)

Expand Down Expand Up @@ -121,7 +120,7 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {

if target == "OTHERS" {
dc, err = sdc.NewNonDbClient(paths, prefix)
} else if target == "APP_DB" || target == "CONFIG_DB" || target == "COUNTERS_DB" {
} else if isTargetDb(target) == true {
dc, err = sdc.NewDbClient(paths, prefix)
} else {
/* For any other target or no target create new Transl Client. */
Expand Down
Loading