Skip to content

Commit

Permalink
TranslClient: use PathValidator to sanitize the request paths (#112)
Browse files Browse the repository at this point in the history
* TranslClient: use PathValidator to sanitize the request paths

TranslClient now uses the PathValidator utility to preprocess get, set
and subscribe request paths before calling translib APIs.
PathValidator is setup to performs following actions:

* Verify the get/set/subscribe paths are known to translib
* Insert missing module name prefixes in get/set/subscribe paths.
  gNMI allows the clients to omit them but translib APIs need them
* Insert missing wildcard keys in subscribe paths

Signed-off-by: Sachin Holla <[email protected]>

* Gotests for TranslClient based write cases

- Set ENABLE_TRANSLIB_WRITE=y during pipeline tests to enable all
  TranslClient based write tests. They were skipped earlier
- Setup correct translib test env in makefile 'check_gotest' target
- Fixed path & payload of existing TranslClient based write tests
- Added more get and set tests to cover path validator calls with
  prefixed and unprefixed paths
- Skip unsupported gNOI tests

---------

Signed-off-by: Sachin Holla <[email protected]>
  • Loading branch information
sachinholla authored Jun 16, 2023
1 parent a600dc9 commit 87d8eb3
Show file tree
Hide file tree
Showing 7 changed files with 288 additions and 132 deletions.
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,25 @@ 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 -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)" $(TESTENV) $(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)" $(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 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
2 changes: 1 addition & 1 deletion gnmi_server/client_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (c *Client) Run(stream gnmipb.GNMI_SubscribeServer) (err error) {
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 87d8eb3

Please sign in to comment.