Skip to content

Commit

Permalink
Use global variable UnitTest as a flag to reinit
Browse files Browse the repository at this point in the history
fabric counters if invoked during unit testing

Signed-off-by: Suvarna Meenakshi <[email protected]>
  • Loading branch information
SuvarnaMeenakshi committed Feb 5, 2025
1 parent c4fe5c4 commit 812b1d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions gnmi_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4932,6 +4932,7 @@ func init() {

// Inform gNMI server to use redis tcp localhost connection
sdc.UseRedisLocalTcpPort = true
sdc.UnitTest = true
}

func TestMain(m *testing.M) {
Expand Down
13 changes: 6 additions & 7 deletions sonic_data_client/virtual_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ var (
}
)

// Will be set to True due unit testing to reset COUNTERS_DB
var UnitTest bool = false

func (t *Trie) v2rTriePopulate() {
for _, pt := range pathTransFuncTbl {
n := t.Add(pt.path, pt.transFunc)
Expand Down Expand Up @@ -125,7 +128,9 @@ func initCountersPfcwdNameMap() error {
}
func initCountersFabricPortNameMap() error {
var err error
if len(countersFabricPortNameMap) == 0 {
// Reset map for Unit test to ensure that counters db is updated
// after changing from single to multi-asic config
if len(countersFabricPortNameMap) == 0 || UnitTest == true {
countersFabricPortNameMap, err = getFabricCountersMap("COUNTERS_FABRIC_PORT_NAME_MAP")
if err != nil {
return err
Expand All @@ -134,12 +139,6 @@ func initCountersFabricPortNameMap() error {
return nil
}

func ResetFabricCountersMap() {
// Added this to support modification from
// single to multi-ns in unit-test
countersFabricPortNameMap = make(map[string]string)
}

// Get the mapping between sonic interface name and oids of their PFC-WD enabled queues in COUNTERS_DB
func GetPfcwdMap() (map[string]map[string]string, error) {
var pfcwdName_map = make(map[string]map[string]string)
Expand Down
3 changes: 0 additions & 3 deletions test_utils/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package test_utils
import (
"io"
"os"
"github.com/sonic-net/sonic-gnmi/sonic_data_client"
)

func SetupMultiNamespace() error {
err := os.MkdirAll("/var/run/redis0/sonic-db/", 0755)
if err != nil {
return err
}
client.ResetFabricCountersMap()
srcFileName := [2]string{"../testdata/database_global.json", "../testdata/database_config_asic0.json"}
dstFileName := [2]string{"/var/run/redis/sonic-db/database_global.json", "/var/run/redis0/sonic-db/database_config_asic0.json"}
for i := 0; i < len(srcFileName); i++ {
Expand Down Expand Up @@ -103,7 +101,6 @@ func CleanUpMultiInstance() error {
if err != nil {
return err
}
client.ResetFabricCountersMap()
return nil
}

0 comments on commit 812b1d0

Please sign in to comment.