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

Update GNMI path schema #197

Merged
merged 5 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion gnmi_server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3799,7 +3799,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
60 changes: 40 additions & 20 deletions sonic_data_client/mixed_db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func NewMixedDbClient(paths []*gnmipb.Path, prefix *gnmipb.Path, origin string,
}

// gnmiFullPath builds the full path from the prefix and path.
func (c *MixedDbClient) gnmiFullPath(prefix, path *gnmipb.Path) *gnmipb.Path {
func (c *MixedDbClient) gnmiFullPath(prefix, path *gnmipb.Path) (*gnmipb.Path, error) {
origin := ""
if prefix != nil {
origin = prefix.Origin
Expand All @@ -269,23 +269,19 @@ func (c *MixedDbClient) gnmiFullPath(prefix, path *gnmipb.Path) *gnmipb.Path {
origin = path.Origin
}
fullPath := &gnmipb.Path{Origin: origin}
if path.GetElement() != nil {
elements := path.GetElement()
if prefix != nil {
elements = append(prefix.GetElement(), elements...)
}
// Skip first elem
fullPath.Element = elements[1:]
}
if path.GetElem() != nil {
elems := path.GetElem()
if prefix != nil {
elems = append(prefix.GetElem(), elems...)
}
// Skip first elem
fullPath.Elem = elems[1:]
// Skip first two elem
// GNMI path schema is /CONFIG_DB/localhost/PORT
if len(elems) < 2 {
return nil, fmt.Errorf("Invalid gnmi path: length %d", len(elems))
}
fullPath.Elem = elems[2:]
}
return fullPath
return fullPath, nil
}

func (c *MixedDbClient) populateAllDbtablePath(paths []*gnmipb.Path, pathG2S *map[*gnmipb.Path][]tablePath) error {
Expand Down Expand Up @@ -319,7 +315,10 @@ func (c *MixedDbClient) populateDbtablePath(path *gnmipb.Path, value *gnmipb.Typ
return fmt.Errorf("Invalid target dbNameSpace %v", targetDbNameSpace)
}

fullPath := c.gnmiFullPath(c.prefix, path)
fullPath, err := c.gnmiFullPath(c.prefix, path)
if err != nil {
return err
}

stringSlice := []string{targetDbName}
separator, _ := GetTableKeySeparator(targetDbName, dbNamespace)
Expand Down Expand Up @@ -822,7 +821,10 @@ func (c *MixedDbClient) ConvertToJsonPatch(prefix *gnmipb.Path, path *gnmipb.Pat
return fmt.Errorf("Value encoding is not IETF JSON")
}
}
fullPath := c.gnmiFullPath(prefix, path)
fullPath, err := c.gnmiFullPath(prefix, path)
if err != nil {
return err
}

elems := fullPath.GetElem()
if t == nil {
Expand Down Expand Up @@ -917,7 +919,10 @@ func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*g
text := `[`
/* DELETE */
for _, path := range delete {
fullPath := c.gnmiFullPath(c.prefix, path)
fullPath, err := c.gnmiFullPath(c.prefix, path)
if err != nil {
return err
}
log.V(2).Infof("Path #%v", fullPath)

stringSlice := []string{}
Expand All @@ -944,7 +949,10 @@ func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*g

/* REPLACE */
for _, path := range replace {
fullPath := c.gnmiFullPath(c.prefix, path.GetPath())
fullPath, err := c.gnmiFullPath(c.prefix, path.GetPath())
if err != nil {
return err
}
log.V(2).Infof("Path #%v", fullPath)

stringSlice := []string{}
Expand Down Expand Up @@ -980,7 +988,10 @@ func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*g

/* UPDATE */
for _, path := range update {
fullPath := c.gnmiFullPath(c.prefix, path.GetPath())
fullPath, err := c.gnmiFullPath(c.prefix, path.GetPath())
if err != nil {
return err
}
log.V(2).Infof("Path #%v", fullPath)

stringSlice := []string{}
Expand Down Expand Up @@ -1110,8 +1121,14 @@ func (c *MixedDbClient) SetConfigDB(delete []*gnmipb.Path, replace []*gnmipb.Upd
replaceLen := len(replace)
updateLen := len(update)
if (deleteLen == 1 && replaceLen == 0 && updateLen == 1) {
deletePath := c.gnmiFullPath(c.prefix, delete[0])
updatePath := c.gnmiFullPath(c.prefix, update[0].GetPath())
deletePath, err := c.gnmiFullPath(c.prefix, delete[0])
if err != nil {
return err
}
updatePath, err := c.gnmiFullPath(c.prefix, update[0].GetPath())
if err != nil {
return err
}
if (len(deletePath.GetElem()) == 0) && (len(updatePath.GetElem()) == 0) {
return c.SetFullConfig(delete, replace, update)
}
Expand Down Expand Up @@ -1140,7 +1157,10 @@ func (c *MixedDbClient) GetCheckPoint() ([]*spb.Value, error) {
}
log.V(2).Infof("Getting #%v", c.jClient.jsonData)
for _, path := range c.paths {
fullPath := c.gnmiFullPath(c.prefix, path)
fullPath, err := c.gnmiFullPath(c.prefix, path)
if err != nil {
return nil, err
}
log.V(2).Infof("Path #%v", fullPath)

stringSlice := []string{}
Expand Down
Loading
Loading