Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple database for DPU #174

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dialout/dialout_client/dialout_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func setupDestGroupClients(ctx context.Context, destGroupName string) {
// start/stop/update telemetry publist client as requested
// TODO: more validation on db data
func processTelemetryClientConfig(ctx context.Context, redisDb *redis.Client, key string, op string) error {
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB", sdcfg.GetDbDefaultNamespace())
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB", sdcfg.GetDbDefaultInstance())
tableKey := "TELEMETRY_CLIENT" + separator + key
fv, err := redisDb.HGetAll(tableKey).Result()
if err != nil {
Expand Down Expand Up @@ -640,28 +640,28 @@ func processTelemetryClientConfig(ctx context.Context, redisDb *redis.Client, ke
// read configDB data for telemetry client and start publishing service for client subscription
func DialOutRun(ctx context.Context, ccfg *ClientConfig) error {
clientCfg = ccfg
dbn := sdcfg.GetDbId("CONFIG_DB", sdcfg.GetDbDefaultNamespace())
dbn := sdcfg.GetDbId("CONFIG_DB", sdcfg.GetDbDefaultInstance())

var redisDb *redis.Client
if sdc.UseRedisLocalTcpPort == false {
redisDb = redis.NewClient(&redis.Options{
Network: "unix",
Addr: sdcfg.GetDbSock("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
Addr: sdcfg.GetDbSock("CONFIG_DB", sdcfg.GetDbDefaultInstance()),
Password: "", // no password set
DB: dbn,
DialTimeout: 0,
})
} else {
redisDb = redis.NewClient(&redis.Options{
Network: "tcp",
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB", sdcfg.GetDbDefaultInstance()),
Password: "", // no password set
DB: dbn,
DialTimeout: 0,
})
}

separator, _ := sdc.GetTableKeySeparator("CONFIG_DB", sdcfg.GetDbDefaultNamespace())
separator, _ := sdc.GetTableKeySeparator("CONFIG_DB", sdcfg.GetDbDefaultInstance())
pattern := "__keyspace@" + strconv.Itoa(int(dbn)) + "__:TELEMETRY_CLIENT" + separator
prefixLen := len(pattern)
pattern += "*"
Expand Down
8 changes: 4 additions & 4 deletions dialout/dialout_client/dialout_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func runServer(t *testing.T, s *sds.Server) {
func getRedisClient(t *testing.T) *redis.Client {
rclient := redis.NewClient(&redis.Options{
Network: "tcp",
Addr: sdcfg.GetDbTcpAddr("COUNTERS_DB", sdcfg.GetDbDefaultNamespace()),
Addr: sdcfg.GetDbTcpAddr("COUNTERS_DB", sdcfg.GetDbDefaultInstance()),
Password: "", // no password set
DB: sdcfg.GetDbId("COUNTERS_DB", sdcfg.GetDbDefaultNamespace()),
DB: sdcfg.GetDbId("COUNTERS_DB", sdcfg.GetDbDefaultInstance()),
DialTimeout: 0,
})
_, err := rclient.Ping().Result()
Expand All @@ -126,9 +126,9 @@ func exe_cmd(t *testing.T, cmd string) {
func getConfigDbClient(t *testing.T) *redis.Client {
rclient := redis.NewClient(&redis.Options{
Network: "tcp",
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
Addr: sdcfg.GetDbTcpAddr("CONFIG_DB", sdcfg.GetDbDefaultInstance()),
Password: "", // no password set
DB: sdcfg.GetDbId("CONFIG_DB", sdcfg.GetDbDefaultNamespace()),
DB: sdcfg.GetDbId("CONFIG_DB", sdcfg.GetDbDefaultInstance()),
DialTimeout: 0,
})
_, err := rclient.Ping().Result()
Expand Down
2 changes: 1 addition & 1 deletion gnmi_server/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (cm *ConnectionManager) GetThreshold() int {
}

func (cm *ConnectionManager) PrepareRedis() {
ns := sdcfg.GetDbDefaultNamespace()
ns := sdcfg.GetDbDefaultInstance()
rclient = redis.NewClient(&redis.Options{
Network: "tcp",
Addr: sdcfg.GetDbTcpAddr("STATE_DB", ns),
Expand Down
59 changes: 47 additions & 12 deletions gnmi_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func prepareDb(t *testing.T, namespace string) {
}

func prepareDbTranslib(t *testing.T) {
rclient := getRedisClient(t, sdcfg.GetDbDefaultNamespace())
rclient := getRedisClient(t, sdcfg.GetDbDefaultInstance())
rclient.FlushDB()
rclient.Close()

Expand All @@ -698,7 +698,7 @@ func prepareDbTranslib(t *testing.T) {
t.Fatalf("read file %v err: %v", fileName, err)
}
for n, v := range rj {
rclient := getRedisClientN(t, n, sdcfg.GetDbDefaultNamespace())
rclient := getRedisClientN(t, n, sdcfg.GetDbDefaultInstance())
loadDBNotStrict(t, rclient, v)
rclient.Close()
}
Expand Down Expand Up @@ -1208,7 +1208,7 @@ func runGnmiTestGet(t *testing.T, namespace string) {

stateDBPath := "STATE_DB"

if namespace != sdcfg.GetDbDefaultNamespace() {
if namespace != sdcfg.GetDbDefaultInstance() {
stateDBPath = "STATE_DB" + "/" + namespace
}

Expand Down Expand Up @@ -1444,9 +1444,9 @@ func TestGnmiGet(t *testing.T) {
s := createServer(t, 8081)
go runServer(t, s)

prepareDb(t, sdcfg.GetDbDefaultNamespace())
prepareDb(t, sdcfg.GetDbDefaultInstance())

runGnmiTestGet(t, sdcfg.GetDbDefaultNamespace())
runGnmiTestGet(t, sdcfg.GetDbDefaultInstance())

s.s.Stop()
}
Expand Down Expand Up @@ -2715,7 +2715,7 @@ func TestGnmiSubscribe(t *testing.T) {
s := createServer(t, 8081)
go runServer(t, s)

runTestSubscribe(t, sdcfg.GetDbDefaultNamespace())
runTestSubscribe(t, sdcfg.GetDbDefaultInstance())

s.s.Stop()
}
Expand Down Expand Up @@ -3125,7 +3125,7 @@ func TestTableKeyOnDeletion(t *testing.T) {
var neighStateTableDeletedJson61 interface{}
json.Unmarshal(neighStateTableDeletedByte61, &neighStateTableDeletedJson61)

namespace := sdcfg.GetDbDefaultNamespace()
namespace := sdcfg.GetDbDefaultInstance()
rclient := getRedisClientN(t, 6, namespace)
defer rclient.Close()
prepareStateDb(t, namespace)
Expand Down Expand Up @@ -3411,7 +3411,7 @@ func TestConnectionDataSet(t *testing.T) {
},
},
}
namespace := sdcfg.GetDbDefaultNamespace()
namespace := sdcfg.GetDbDefaultInstance()
rclient := getRedisClientN(t, 6, namespace)
defer rclient.Close()

Expand Down Expand Up @@ -3777,7 +3777,7 @@ print('%s')
pathTarget: "",
textPbPath: `
origin: "sonic-db",
elem: <name: "APPL_DB" > elem:<name:"DASH_QOS" >
elem: <name: "APPL_DB" > elem: <name: "localhost" > elem:<name:"DASH_QOS" >
`,
attributeData: "../testdata/batch.txt",
wantRetCode: codes.OK,
Expand Down Expand Up @@ -3828,14 +3828,14 @@ print('%s')
s := createServer(t, 8080)
go runServer(t, s)
defer s.s.Stop()
initFullConfigDb(t, sdcfg.GetDbDefaultNamespace())
initFullCountersDb(t, sdcfg.GetDbDefaultNamespace())
initFullConfigDb(t, sdcfg.GetDbDefaultInstance())
initFullCountersDb(t, sdcfg.GetDbDefaultInstance())

path, _ := os.Getwd()
path = filepath.Dir(path)

var cmd *exec.Cmd
cmd = exec.Command("bash", "-c", "cd "+path+" && "+"pytest")
cmd = exec.Command("bash", "-c", "cd "+path+" && "+"pytest -m 'not dpu'")
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-m 'not dpu'

Could you add some comment to explain the intention? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

if result, err := cmd.Output(); err != nil {
fmt.Println(string(result))
t.Errorf("Fail to execute pytest: %v", err)
Expand All @@ -3861,6 +3861,41 @@ print('%s')
s.s.Stop()
}

// Test DPU configuration with multiple databases
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DPU

This PR is gnmi general support the multi-db feature, not specific related to DPU, but also multi-asic, even single-asic with multiple database. Could you generalize naming/comments/etc ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also generalize the PR title?

func TestGNMINativeDPU(t *testing.T) {
sdcfg.Init()
err := test_utils.SetupMultiDPU()
if err != nil {
t.Fatalf("error Setting up MultiDPU files with err %T", err)
}

/* https://www.gopherguides.com/articles/test-cleanup-in-go-1-14*/
t.Cleanup(func() {
if err := test_utils.CleanUpMultiDPU(); err != nil {
t.Fatalf("error Cleaning up MultiDPU files with err %T", err)

}
})

s := createServer(t, 8080)
go runServer(t, s)
defer s.s.Stop()
initFullConfigDb(t, sdcfg.GetDbDefaultInstance())
initFullCountersDb(t, sdcfg.GetDbDefaultInstance())

path, _ := os.Getwd()
path = filepath.Dir(path)

var cmd *exec.Cmd
cmd = exec.Command("bash", "-c", "cd "+path+" && "+"pytest -m 'dpu'")
if result, err := cmd.Output(); err != nil {
fmt.Println(string(result))
t.Errorf("Fail to execute pytest: %v", err)
} else {
fmt.Println(string(result))
}
}

func TestServerPort(t *testing.T) {
s := createServer(t, -8080)
port := s.Port()
Expand Down
4 changes: 2 additions & 2 deletions gnmi_server/transl_sub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,8 @@ type DbDataMap map[string]map[string]map[string]interface{}
func updateDb(t *testing.T, data DbDataMap) {
t.Helper()
for dbName, tableData := range data {
n := dbconfig.GetDbId(dbName, dbconfig.GetDbDefaultNamespace())
redis := getRedisClientN(t, n, dbconfig.GetDbDefaultNamespace())
n := dbconfig.GetDbId(dbName, dbconfig.GetDbDefaultInstance())
redis := getRedisClientN(t, n, dbconfig.GetDbDefaultInstance())
defer redis.Close()
for key, fields := range tableData {
if fields == nil {
Expand Down
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
markers:
dpu

28 changes: 10 additions & 18 deletions sonic_data_client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,28 +309,20 @@ func TestJsonRemoveNegative(t *testing.T) {
}
}

func TestParseTarget(t *testing.T) {
func TestParseDatabase(t *testing.T) {
var test_paths []*gnmipb.Path
var err error

_, err = ParseTarget("test", test_paths)
if err != nil {
t.Errorf("ParseTarget failed for empty path: %v", err)
}

test_target := "TEST_DB"
path, err := xpath.ToGNMIPath("sonic-db:" + test_target + "/VLAN")
test_target := "APPL_DB"
test_inst := "dpu0"
path, err := xpath.ToGNMIPath("sonic-db:" + test_target + "/" + test_inst + "/VLAN")
test_paths = append(test_paths, path)
target, err := ParseTarget("", test_paths)
target, inst, err := ParseDatabase(nil, test_paths)
if err != nil {
t.Errorf("ParseTarget failed to get target: %v", err)
t.Errorf("ParseDatabase failed to get target: %v", err)
}
if target != test_target {
t.Errorf("ParseTarget return wrong target: %v", target)
}
target, err = ParseTarget("INVALID_DB", test_paths)
if err == nil {
t.Errorf("ParseTarget should fail for conflict")
if target != test_target || inst != test_inst {
t.Errorf("ParseDatabase return wrong target: %v", target)
}
}

Expand Down Expand Up @@ -386,15 +378,15 @@ func ReceiveFromZmq(consumer swsscommon.ZmqConsumerStateTable) (bool) {

func TestZmqReconnect(t *testing.T) {
// create ZMQ server
db := swsscommon.NewDBConnector(APPL_DB_NAME, SWSS_TIMEOUT, false)
db := swsscommon.NewDBConnector(PREV_APPL_DB_NAME, SWSS_TIMEOUT, false)
zmqServer := swsscommon.NewZmqServer("tcp://*:1234")
var TEST_TABLE string = "DASH_ROUTE"
consumer := swsscommon.NewZmqConsumerStateTable(db, TEST_TABLE, zmqServer)

// create ZMQ client side
zmqAddress := "tcp://127.0.0.1:1234"
client := MixedDbClient {
applDB : swsscommon.NewDBConnector(APPL_DB_NAME, SWSS_TIMEOUT, false),
applDB : swsscommon.NewDBConnector(PREV_APPL_DB_NAME, SWSS_TIMEOUT, false),
tableMap : map[string]swsscommon.ProducerStateTable{},
zmqClient : swsscommon.NewZmqClient(zmqAddress),
}
Expand Down
Loading