Skip to content

Commit

Permalink
Merge branch 'master' into dev/liuh/add_gnmi_cert_name
Browse files Browse the repository at this point in the history
  • Loading branch information
liuh-80 authored Jun 13, 2024
2 parents 90322b3 + 424212b commit 9b65bde
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 10 deletions.
1 change: 1 addition & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ stages:
- script: |
# PYTEST
sudo pip3 install -U pytest
sudo pip3 install -U jsonpatch
# REDIS
sudo apt-get update
Expand Down
17 changes: 8 additions & 9 deletions sonic_data_client/mixed_db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const RETRY_DELAY_FACTOR uint = 2
const CHECK_POINT_PATH string = "/etc/sonic"
const ELEM_INDEX_DATABASE = 0
const ELEM_INDEX_INSTANCE = 1
const UPDATE_OPERATION = "add"
const DELETE_OPERATION = "remove"
const REPLACE_OPERATION = "replace"

const (
opAdd = iota
Expand Down Expand Up @@ -1110,7 +1113,7 @@ func (c *MixedDbClient) handleTableData(tblPaths []tablePath) error {
}

/* Populate the JsonPatch corresponding each GNMI operation. */
func (c *MixedDbClient) ConvertToJsonPatch(prefix *gnmipb.Path, path *gnmipb.Path, t *gnmipb.TypedValue, output *string) error {
func (c *MixedDbClient) ConvertToJsonPatch(prefix *gnmipb.Path, path *gnmipb.Path, t *gnmipb.TypedValue, operation string, output *string) error {
if t != nil {
if len(t.GetJsonIetfVal()) == 0 {
return fmt.Errorf("Value encoding is not IETF JSON")
Expand All @@ -1122,11 +1125,7 @@ func (c *MixedDbClient) ConvertToJsonPatch(prefix *gnmipb.Path, path *gnmipb.Pat
}

elems := fullPath.GetElem()
if t == nil {
*output = `{"op": "remove", "path": "/`
} else {
*output = `{"op": "add", "path": "/`
}
*output = `{"op": "` + operation + `", "path": "/`

if elems != nil {
/* Iterate through elements. */
Expand Down Expand Up @@ -1237,7 +1236,7 @@ func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*g
}
}
curr = ``
err = c.ConvertToJsonPatch(c.prefix, path, nil, &curr)
err = c.ConvertToJsonPatch(c.prefix, path, nil, DELETE_OPERATION, &curr)
if err != nil {
return err
}
Expand Down Expand Up @@ -1276,7 +1275,7 @@ func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*g
}
}
curr = ``
err = c.ConvertToJsonPatch(c.prefix, path.GetPath(), path.GetVal(), &curr)
err = c.ConvertToJsonPatch(c.prefix, path.GetPath(), path.GetVal(), REPLACE_OPERATION, &curr)
if err != nil {
return err
}
Expand Down Expand Up @@ -1311,7 +1310,7 @@ func (c *MixedDbClient) SetIncrementalConfig(delete []*gnmipb.Path, replace []*g
}
}
curr = ``
err = c.ConvertToJsonPatch(c.prefix, path.GetPath(), path.GetVal(), &curr)
err = c.ConvertToJsonPatch(c.prefix, path.GetPath(), path.GetVal(), UPDATE_OPERATION, &curr)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_gnmi_configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_gnmi_incremental_replace(self, test_data):
test_path = item['path']
test_value = item['value']
for patch_data in patch_json:
assert patch_data['op'] == 'add', "Invalid operation"
assert patch_data['op'] == 'replace', "Invalid operation"
if test_path == '/sonic-db:CONFIG_DB/localhost' + patch_data['path'] and test_value == patch_data['value']:
break
else:
Expand Down
Loading

0 comments on commit 9b65bde

Please sign in to comment.