Add Virtual Database Client + Unit Tests#18
Add Virtual Database Client + Unit Tests#18randygaulmsft wants to merge 22 commits intosonic-net:masterfrom
Conversation
…lient to virtual_database_client
|
The flowchart and callstack is very helpful to new developers and reviewers. Thanks for adding them. |
|
Add Wenda to verify PFC WD logic |
|
@hui-ma PollRun is not implemented. StreamRun is implemented though. Many of Jipan's tests from gnmi_server are not possible with the virtual database client, because it does not support some of the query features such as lookup up a single field under PfcCounter. However, it is possible to write some tests for StreamRun via Subscribe. Not implemented in virtual database:
Can have additional testing to closer match Jipan's tests:
I will work on StreamRun tests. |
|
Could you use gofmt to format your changes? There are some existing virtual path implementations integrated with the StreamRun() and PollRun() as of today. It looks you duplicated part of the code, what are the major differences? |
|
Could you share the command line to unit test? We plan to add it into PR checker and automate it, even for this PR. #Closed |
|
@qiluo-msft: @randygaulmsft is working on adding the PR check build. |
hui-ma
left a comment
There was a problem hiding this comment.
Please push your latest change. Thanks!
sonic_data_client/db_client.go
Outdated
| // Debug log | ||
| //log.V(5).Infof("msi: %v\n", msi) | ||
| //log.V(5).Infof("key: %v\n", key) | ||
| //log.V(5).Infof("op: %v\n", op) |
There was a problem hiding this comment.
They don't appear to have been removed.
There was a problem hiding this comment.
Ah these were in multiple files. I removed them from virtual_database_client but this one was under sonic_data_client.
There was a problem hiding this comment.
Please remove if you have not. Thanks!
@jipanyang Ran go format (push pending). Also I noticed a lot of code duplication in Your code was duplicated to avoid potentially breaking the existing implementation. As far as I know there are no significant changes, other than string translations from vendor-specific form through the new generic query form. |
|
I've already setup the PR builder. Here's the current version of the script as-is in Jenkins. #!/bin/bash -xe
# Install golang.
go_version=go1.12.4.linux-amd64
if [ ! -e $go_version.tar.gz ]
then
wget -q -o /dev/null https://storage.googleapis.com/golang/$go_version.tar.gz
tar xf $go_version.tar.gz
fi
export GOROOT=$WORKSPACE/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=$HOME/go
# Setup and install redis, which requires some minor conf settings for the unit tests.
sudo apt -qq -y install redis-server
sudo sed -i 's/^supervised no/supervised systemd/' /etc/redis/redis.conf
sudo sed -i '$ a unixsocket /var/run/redis/redis.sock' /etc/redis/redis.conf
sudo sed -i '$ a unixsocketperm 766' /etc/redis/redis.conf
sudo service redis stop
sudo service redis start
# Install and test specific packages.
go get -v -t github.com/Azure/sonic-telemetry/gnmi_server/...
go test -v $GOPATH/src/github.com/Azure/sonic-telemetry/gnmi_server
go get -v -t github.com/Azure/sonic-telemetry/virtual_database_client/...
go test -v $GOPATH/src/github.com/Azure/sonic-telemetry/virtual_database_clientNOTE: I just now added |
|
Get and run code: |
|
Please note the Jenkins script is failing now since I added the new package path. This is expected. The tests are running properly as expected, and besides any more feedback the pull request is ready for merging. |
|
The new unittest depends on unixsocket while the legacy on doesn't need. Ideally, the new one should not either. Please check what the new dependence is introduced in the new test case. unixsocket is for better performance. Therefore, unit test doesn't necessary depends on it. |
|
Even with unixsocket, I saw failure case. e.g, FAIL: TestVirtualDatabaseGNMISubscribe/Stream_query_for_Interfaces/Port[name=Ethernet68]/Queue[name=Queue3]/Pfcwd,_updating_PFC_WD_QUEUE_STATS_DEADLOCK_DETECTED_from_0_to_1. (2.53s) Please verify and fix if there is any |
sonic_data_client/db_client.go
Outdated
| // Debug log | ||
| //log.V(5).Infof("msi: %v\n", msi) | ||
| //log.V(5).Infof("key: %v\n", key) | ||
| //log.V(5).Infof("op: %v\n", op) |
There was a problem hiding this comment.
Please remove if you have not. Thanks!
| func v2rPortQueuePfcwdStats(path *gnmipb.Path, pathG2S *map[*gnmipb.Path][]tablePath) error { | ||
| var tmpl = gnmipb.Path{} | ||
| GetTmpl_PortQueuePfcwdStats(&tmpl) | ||
| //fmt.Printf("tmpl: %v\n", &tmpl) |
| out_tblPaths = append(out_tblPaths, tblPath_port) | ||
| } | ||
|
|
||
| //fmt.Printf("tablePath: %v\n", &tblPath_que) |
There was a problem hiding this comment.
please do a search and remove such commented "printf" lines.
This commit adds virtual database support for the SONiC target, built by an intern Chang Lui. I added some integration tests over the top of the virtual path + virtual database work by Chang. Here is a diagram describing the high level organization of most of Chang's contributions. Some important pieces are numbered, and described below.
Information about the Numbered Pieces of the Above Diagram
Important Callstacks
Get
The below callstack reaches into the handlers to construct gNMI to Redis mappings.
The final line calls into the "virtual to real" conversion functions as defined in the handler_<YOUR_DATA_TYPE>.go files. Once a value is retrieved it is handed to tableData2TypedValue and converted to JSON form ready for gNMI proto stream return.
This callstack converts a Redis key value to an appropriate proto stream return value.
tableData2Msi calls into the redis API with redis.HGetAll, passing in redis keys for actual SONiC values. The redis return value is converted to gNMI proto stream form via msi2TypedValue.
Subscribe (StreamRun)
Subscribe (PollRun)
PollRun is not implemented!
NewDbClient
Called when an RPC is recieved by the gNMI service running on the SONiC device (gnmi_server/*.go). These functions are called to initialize gNMI to Redis mappings:
These functions load the various Redis targets into suitable run-time formats, used in gNMI <-> SONiC key transformations via the database client's trie data structure. These functions are using redis.HGetAll, from the Go redis API to load out key-value pairs.
Running Tests
Use
go test -v ./package_folder. Make sure the folder points to a particular package you want to test.