From 7a1b7cd99105cf1e183e8de03cbeb80a942a60af Mon Sep 17 00:00:00 2001 From: ganglv <88995770+ganglyu@users.noreply.github.com> Date: Fri, 25 Aug 2023 10:25:05 +0800 Subject: [PATCH] Improve full path logic (#146) Why I did it Full path has dependency for prefix. How I did it Always generate full path with API. How to verify it Run sonic-gnmi unit test. --- sonic_data_client/mixed_db_client.go | 30 ++++++---------------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/sonic_data_client/mixed_db_client.go b/sonic_data_client/mixed_db_client.go index 52917003..60445ed5 100644 --- a/sonic_data_client/mixed_db_client.go +++ b/sonic_data_client/mixed_db_client.go @@ -310,10 +310,7 @@ func (c *MixedDbClient) populateDbtablePath(path *gnmipb.Path, value *gnmipb.Typ return fmt.Errorf("Invalid target dbNameSpace %v", targetDbNameSpace) } - fullPath := path - if c.prefix != nil { - fullPath = c.gnmiFullPath(c.prefix, path) - } + fullPath := c.gnmiFullPath(c.prefix, path) stringSlice := []string{targetDbName} separator, _ := GetTableKeySeparator(targetDbName, dbNamespace) @@ -816,10 +813,7 @@ func (c *MixedDbClient) ConvertToJsonPatch(prefix *gnmipb.Path, path *gnmipb.Pat return fmt.Errorf("Value encoding is not IETF JSON") } } - fullPath := path - if prefix != nil { - fullPath = c.gnmiFullPath(prefix, path) - } + fullPath := c.gnmiFullPath(prefix, path) elems := fullPath.GetElem() if t == nil { @@ -914,10 +908,7 @@ func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*g text := `[` /* DELETE */ for _, path := range delete { - fullPath := path - if c.prefix != nil { - fullPath = c.gnmiFullPath(c.prefix, path) - } + fullPath := c.gnmiFullPath(c.prefix, path) log.V(2).Infof("Path #%v", fullPath) stringSlice := []string{} @@ -944,10 +935,7 @@ func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*g /* REPLACE */ for _, path := range replace { - fullPath := path.GetPath() - if c.prefix != nil { - fullPath = c.gnmiFullPath(c.prefix, path.GetPath()) - } + fullPath := c.gnmiFullPath(c.prefix, path.GetPath()) log.V(2).Infof("Path #%v", fullPath) stringSlice := []string{} @@ -983,10 +971,7 @@ func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*g /* UPDATE */ for _, path := range update { - fullPath := path.GetPath() - if c.prefix != nil { - fullPath = c.gnmiFullPath(c.prefix, path.GetPath()) - } + fullPath := c.gnmiFullPath(c.prefix, path.GetPath()) log.V(2).Infof("Path #%v", fullPath) stringSlice := []string{} @@ -1146,10 +1131,7 @@ func (c *MixedDbClient) GetCheckPoint() ([]*spb.Value, error) { } log.V(2).Infof("Getting #%v", c.jClient.jsonData) for _, path := range c.paths { - fullPath := path - if c.prefix != nil { - fullPath = c.gnmiFullPath(c.prefix, path) - } + fullPath := c.gnmiFullPath(c.prefix, path) log.V(2).Infof("Path #%v", fullPath) stringSlice := []string{}