Skip to content

Commit

Permalink
Add read-only mode (sonic-net#27)
Browse files Browse the repository at this point in the history
* Add read-only mode

* Use go build flags instead of file method for readonly mode

* Change default from readwrite to readonly, change name of build-flag and const to reflect this

* Add SONIC preix to telemetry readonly flag

Co-authored-by: Eric Seifert <eric@seifert.casa>
  • Loading branch information
seiferteric and seiferteric committed Mar 23, 2020
1 parent aaa9188 commit c97e5c5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ 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
ifeq ($(SONIC_TELEMETRY_READWRITE),y)
BLD_FLAGS := -tags readwrite
endif

.phony: mgmt-deps

Expand Down Expand Up @@ -60,7 +63,7 @@ mgmt-deps:
make -C $(GO_MGMT_PATH)/models/yang/sonic

sonic-telemetry: go.mod mgmt-deps
$(GO) install -mod=vendor github.com/Azure/sonic-telemetry/telemetry
$(GO) install -mod=vendor $(BLD_FLAGS) github.com/Azure/sonic-telemetry/telemetry
$(GO) install -mod=vendor github.com/Azure/sonic-telemetry/dialout/dialout_client_cli
$(GO) install github.com/jipanyang/gnxi/gnmi_get
$(GO) install github.com/jipanyang/gnxi/gnmi_set
Expand Down
5 changes: 5 additions & 0 deletions gnmi_server/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build !readwrite

package gnmi

const READ_WRITE_MODE = false
5 changes: 5 additions & 0 deletions gnmi_server/constants_readwrite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build readwrite

package gnmi

const READ_WRITE_MODE = true
6 changes: 4 additions & 2 deletions gnmi_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewServer(config *Config, opts []grpc.ServerOption) (*Server, error) {
return nil, fmt.Errorf("failed to open listener port %d: %v", srv.config.Port, err)
}
gnmipb.RegisterGNMIServer(srv.s, srv)
log.V(1).Infof("Created Server on %s", srv.Address())
log.V(1).Infof("Created Server on %s, read-only: %t", srv.Address(), !READ_WRITE_MODE)
return srv, nil
}

Expand Down Expand Up @@ -208,8 +208,10 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe
return &gnmipb.GetResponse{Notification: notifications}, nil
}

// Set method is not implemented. Refer to gnxi for examples with openconfig integration
func (srv *Server) Set(ctx context.Context,req *gnmipb.SetRequest) (*gnmipb.SetResponse, error) {
if !READ_WRITE_MODE {
return nil, grpc.Errorf(codes.Unimplemented, "Telemetry is in read-only mode")
}
var results []*gnmipb.UpdateResult
var err error

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c h1:a380JP+B7xlMbEQOlha1buKhzBPXFqgFXplyWCEIGEY=
github.com/openconfig/gnmi v0.0.0-20190823184014-89b2bf29312c/go.mod h1:t+O9It+LKzfOAhKTT5O0ehDix+MTqbtT0T9t+7zzOvc=
github.com/openconfig/gnmi v0.0.0-20200307010808-e7106f7f5493 h1:e/znXbq+Yiws97a4lJYlUeRw9OGxT2q27L4aMUb0GuM=
github.com/openconfig/goyang v0.0.0-20190924211109-064f9690516f h1:BaekRUaWpfaRBP3mShDZaNi4+EHbdli7D6YXc/TP3lo=
github.com/openconfig/goyang v0.0.0-20190924211109-064f9690516f/go.mod h1:dhXaV0JgHJzdrHi2l+w0fZrwArtXL7jEFoiqLEdmkvU=
github.com/openconfig/ygot v0.6.0 h1:kJJFPBrczC6TDnz/HMlFTJEdW2CuyUftV13XveIukg0=
Expand Down

0 comments on commit c97e5c5

Please sign in to comment.