Skip to content

Commit

Permalink
Merge branch 'master' into gnmi_ma_impl
Browse files Browse the repository at this point in the history
  • Loading branch information
sallylsy authored Jul 19, 2023
2 parents eb56525 + 01fe667 commit eb7242a
Show file tree
Hide file tree
Showing 18 changed files with 2,280 additions and 556 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Semgrep

on:
pull_request: {}
push:
branches:
- master
- '201[7-9][0-1][0-9]'
- '202[0-9][0-1][0-9]'

jobs:
semgrep:
if: github.repository_owner == 'sonic-net'
name: Semgrep
runs-on: ubuntu-latest
container:
image: returntocorp/semgrep
steps:
- uses: actions/checkout@v3
- run: semgrep ci
env:
SEMGREP_RULES: p/default
35 changes: 29 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ ifneq ($(BLD_TAGS),)
BLD_FLAGS := -tags "$(strip $(BLD_TAGS))"
endif

ENABLE_DIALOUT_VALUE := 1
ifeq ($(ENABLE_DIALOUT),n)
ENABLE_DIALOUT_VALUE = 0
endif

GO_DEPS := vendor/.done
PATCHES := $(wildcard patches/*.patch)
PATCHES += $(shell find $(MGMT_COMMON_DIR)/patches -type f)
Expand Down Expand Up @@ -63,15 +68,19 @@ go-deps-clean:
sonic-gnmi: $(GO_DEPS)
ifeq ($(CROSS_BUILD_ENVIRON),y)
$(GO) build -o ${GOBIN}/telemetry -mod=vendor $(BLD_FLAGS) github.com/sonic-net/sonic-gnmi/telemetry
ifneq ($(ENABLE_DIALOUT_VALUE),0)
$(GO) build -o ${GOBIN}/dialout_client_cli -mod=vendor $(BLD_FLAGS) github.com/sonic-net/sonic-gnmi/dialout/dialout_client_cli
endif
$(GO) build -o ${GOBIN}/gnmi_get -mod=vendor github.com/jipanyang/gnxi/gnmi_get
$(GO) build -o ${GOBIN}/gnmi_set -mod=vendor github.com/jipanyang/gnxi/gnmi_set
$(GO) build -o ${GOBIN}/gnmi_cli -mod=vendor github.com/openconfig/gnmi/cmd/gnmi_cli
$(GO) build -o ${GOBIN}/gnoi_client -mod=vendor github.com/sonic-net/sonic-gnmi/gnoi_client
$(GO) build -o ${GOBIN}/gnmi_dump -mod=vendor github.com/sonic-net/sonic-gnmi/gnmi_dump
else
$(GO) install -mod=vendor $(BLD_FLAGS) github.com/sonic-net/sonic-gnmi/telemetry
ifneq ($(ENABLE_DIALOUT_VALUE),0)
$(GO) install -mod=vendor $(BLD_FLAGS) github.com/sonic-net/sonic-gnmi/dialout/dialout_client_cli
endif
$(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
Expand All @@ -82,17 +91,27 @@ endif
swsscommon_wrap:
make -C swsscommon

check_gotest:
DBCONFG = $(DBDIR)/database_config.json
ENVFILE = build/test/env.txt
TESTENV = $(shell cat $(ENVFILE))

$(DBCONFG): testdata/database_config.json
sudo mkdir -p ${DBDIR}
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/ \;

$(ENVFILE):
mkdir -p $(@D)
tools/test/env.sh | grep -v DB_CONFIG_PATH | tee $@

check_gotest: $(DBCONFG) $(ENVFILE)
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(GO) test -race -coverprofile=coverage-config.txt -covermode=atomic -v github.com/sonic-net/sonic-gnmi/sonic_db_config
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(GO) test -race -coverprofile=coverage-gnmi.txt -covermode=atomic -mod=vendor $(BLD_FLAGS) -v github.com/sonic-net/sonic-gnmi/gnmi_server -coverpkg ../...
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(GO) test -coverprofile=coverage-dialcout.txt -covermode=atomic -mod=vendor $(BLD_FLAGS) -v github.com/sonic-net/sonic-gnmi/dialout/dialout_client
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(TESTENV) $(GO) test -race -timeout 20m -coverprofile=coverage-gnmi.txt -covermode=atomic -mod=vendor $(BLD_FLAGS) -v github.com/sonic-net/sonic-gnmi/gnmi_server -coverpkg ../...
ifneq ($(ENABLE_DIALOUT_VALUE),0)
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(TESTENV) $(GO) test -coverprofile=coverage-dialcout.txt -covermode=atomic -mod=vendor $(BLD_FLAGS) -v github.com/sonic-net/sonic-gnmi/dialout/dialout_client
endif
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(GO) test -race -coverprofile=coverage-data.txt -covermode=atomic -mod=vendor -v github.com/sonic-net/sonic-gnmi/sonic_data_client
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(GO) test -race -coverprofile=coverage-dbus.txt -covermode=atomic -mod=vendor -v github.com/sonic-net/sonic-gnmi/sonic_service_client
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(GO) test -race -coverprofile=coverage-translutils.txt -covermode=atomic -mod=vendor -v github.com/sonic-net/sonic-gnmi/transl_utils
sudo CGO_LDFLAGS="$(CGO_LDFLAGS)" CGO_CXXFLAGS="$(CGO_CXXFLAGS)" $(TESTENV) $(GO) test -race -coverprofile=coverage-translutils.txt -covermode=atomic -mod=vendor -v github.com/sonic-net/sonic-gnmi/transl_utils
$(GO) get github.com/axw/gocov/...
$(GO) get github.com/AlekSi/gocov-xml
$(GO) mod vendor
Expand All @@ -114,7 +133,9 @@ endif

install:
$(INSTALL) -D $(BUILD_DIR)/telemetry $(DESTDIR)/usr/sbin/telemetry
ifneq ($(ENABLE_DIALOUT_VALUE),0)
$(INSTALL) -D $(BUILD_DIR)/dialout_client_cli $(DESTDIR)/usr/sbin/dialout_client_cli
endif
$(INSTALL) -D $(BUILD_DIR)/gnmi_get $(DESTDIR)/usr/sbin/gnmi_get
$(INSTALL) -D $(BUILD_DIR)/gnmi_set $(DESTDIR)/usr/sbin/gnmi_set
$(INSTALL) -D $(BUILD_DIR)/gnmi_cli $(DESTDIR)/usr/sbin/gnmi_cli
Expand All @@ -124,7 +145,9 @@ install:

deinstall:
rm $(DESTDIR)/usr/sbin/telemetry
ifneq ($(ENABLE_DIALOUT_VALUE),0)
rm $(DESTDIR)/usr/sbin/dialout_client_cli
endif
rm $(DESTDIR)/usr/sbin/gnmi_get
rm $(DESTDIR)/usr/sbin/gnmi_set
rm $(DESTDIR)/usr/sbin/gnoi_client
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ stages:
- script: |
pushd sonic-gnmi
make check_gotest
make check_gotest ENABLE_TRANSLIB_WRITE=y
displayName: "Test"
- publish: $(Build.ArtifactStagingDirectory)/
Expand Down
36 changes: 24 additions & 12 deletions gnmi_server/client_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
log "github.com/golang/glog"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
sdc "github.com/sonic-net/sonic-gnmi/sonic_data_client"
gnmipb "github.com/openconfig/gnmi/proto/gnmi"
)
Expand Down Expand Up @@ -128,23 +129,23 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
return grpc.Errorf(codes.InvalidArgument, "first message must be SubscriptionList: %q", query)
}

var target string
prefix := c.subscribe.GetPrefix()
if prefix == nil {
return grpc.Errorf(codes.Unimplemented, "No target specified in prefix")
} else {
target = prefix.GetTarget()
// TODO: add data client support for fetching non-db data
if target == "" {
return grpc.Errorf(codes.Unimplemented, "Empty target data not supported yet")
}
}
origin := prefix.GetOrigin()
target := prefix.GetTarget()

paths, err := c.populateDbPathSubscrition(c.subscribe)
if err != nil {
return grpc.Errorf(codes.NotFound, "Invalid subscription path: %v %q", err, query)
}

if o, err := ParseOrigin(paths); err != nil {
return err // origin conflict within paths
} else if len(origin) == 0 {
origin = o // Use origin from paths if not given in prefix
} else if len(o) != 0 && o != origin {
return status.Error(codes.InvalidArgument, "Origin conflict between prefix and paths")
}

if connectionKey, valid = connectionManager.Add(c.addr, query.String()); !valid {
return grpc.Errorf(codes.Unavailable, "Server connections are at capacity.")
}
Expand All @@ -155,15 +156,26 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {

mode := c.subscribe.GetMode()

if target == "OTHERS" {
log.V(3).Infof("mode=%v, origin=%q, target=%q", mode, origin, target)

if origin == "openconfig" {
dc, err = sdc.NewTranslClient(prefix, paths, ctx, extensions, sdc.TranslWildcardOption{})
} else if len(origin) != 0 {
return grpc.Errorf(codes.Unimplemented, "Unsupported origin: %s", origin)
} else if target == "" {
// This and subsequent conditions handle target based path identification
// when origin == "". As per the spec it should have been treated as "openconfig".
// But we take a deviation and stick to legacy logic for backward compatibility
return grpc.Errorf(codes.Unimplemented, "Empty target data not supported")
} else if target == "OTHERS" {
dc, err = sdc.NewNonDbClient(paths, prefix)
} else if ((target == "EVENTS") && (mode == gnmipb.SubscriptionList_STREAM)) {
dc, err = sdc.NewEventClient(paths, prefix, c.logLevel)
} 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. */
dc, err = sdc.NewTranslClient(prefix, paths, ctx, extensions)
dc, err = sdc.NewTranslClient(prefix, paths, ctx, extensions, sdc.TranslWildcardOption{})
}

if err != nil {
Expand Down
Loading

0 comments on commit eb7242a

Please sign in to comment.