Skip to content

Commit

Permalink
AETHER-1263 - delete of container
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCondon committed Feb 15, 2021
1 parent 1400cf6 commit e9dc34e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/northbound/gnmi/set.go
Expand Up @@ -282,7 +282,7 @@ func (s *Server) formatUpdateOrReplace(prefix *gnmi.Path, u *gnmi.Update,
updates[cv.Path] = cv.GetValue()
}
} else {
rwPathElem, err := findPathFromModel(path, rwPaths)
rwPathElem, err := findPathFromModel(path, rwPaths, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func (s *Server) doDelete(prefix *gnmi.Path, u *gnmi.Path,
path = fmt.Sprintf("%s%s", prefixPath, path)
}
// Checks for read only paths
_, err := findPathFromModel(path, rwPaths)
_, err := findPathFromModel(path, rwPaths, false)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -380,7 +380,7 @@ func extractModelForTarget(target devicetype.ID,
return rwPaths, nil
}

func findPathFromModel(path string, rwPaths modelregistry.ReadWritePathMap) (*modelregistry.ReadWritePathElem, error) {
func findPathFromModel(path string, rwPaths modelregistry.ReadWritePathMap, exact bool) (*modelregistry.ReadWritePathElem, error) {
searchpathNoIndices := modelregistry.RemovePathIndices(path)
if strings.HasSuffix(path, "]") { //Ends with index
indices, _ := modelregistry.ExtractIndexNames(path)
Expand All @@ -392,8 +392,10 @@ func findPathFromModel(path string, rwPaths modelregistry.ReadWritePathMap) (*mo
for modelPath, modelElem := range rwPaths {
pathNoIndices := modelregistry.RemovePathIndices(modelPath)
// Find a short path
if pathNoIndices == searchpathNoIndices {
if exact && pathNoIndices == searchpathNoIndices {
return &modelElem, nil
} else if !exact && strings.HasPrefix(pathNoIndices, searchpathNoIndices) {
return &modelElem, nil // returns the first thing it finds that matches the prefix
}
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/northbound/gnmi/set_test.go
Expand Up @@ -661,3 +661,20 @@ func TestSet_BadDeviceType(t *testing.T) {
assert.Contains(t, setError.Error(), "target DeviceWithMultipleVersions type given NotTheSameType does not match expected TestDevice")
assert.Nil(t, setResponse)
}

func Test_findPathFromModel(t *testing.T) {
_, _, mgr := setUpForGetSetTests(t)

rwPath, err := findPathFromModel("/cont1a", mgr.ModelRegistry.ModelReadWritePaths["TestDevice-1.0.0"], false)
assert.NoError(t, err)
assert.NotNil(t, rwPath)

rwPath2, err := findPathFromModel("/cont1a/list2a", mgr.ModelRegistry.ModelReadWritePaths["TestDevice-1.0.0"], false)
assert.NoError(t, err)
assert.NotNil(t, rwPath2)

rwPath3, err := findPathFromModel("/cont1a/list2a[name=123]/name", mgr.ModelRegistry.ModelReadWritePaths["TestDevice-1.0.0"], true)
assert.NoError(t, err)
assert.NotNil(t, rwPath3)
assert.Equal(t, []string{"4..8"}, rwPath3.Length)
}

0 comments on commit e9dc34e

Please sign in to comment.