Skip to content

Commit

Permalink
Releasing v0.7.6 and fixing delete from list
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCondon committed Feb 7, 2021
1 parent 9e7d4e3 commit bb82039
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.7.6-dev
0.7.6
20 changes: 11 additions & 9 deletions pkg/northbound/gnmi/set.go
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"github.com/grpc-ecosystem/go-grpc-middleware/util/metautils"
"strings"
"time"

devicechange "github.com/onosproject/onos-api/go/onos/config/change/device"
Expand Down Expand Up @@ -381,20 +382,21 @@ func extractModelForTarget(target devicetype.ID,

func findPathFromModel(path string, rwPaths modelregistry.ReadWritePathMap) (*modelregistry.ReadWritePathElem, error) {
searchpathNoIndices := modelregistry.RemovePathIndices(path)
if strings.HasSuffix(path, "]") { //Ends with index
indices := modelregistry.ExtractIndexNames(path)
// Add on the last index
searchpathNoIndices = fmt.Sprintf("%s/%s", searchpathNoIndices, indices[len(indices)-1])
}

// First search through the RW paths
var rwPathElem modelregistry.ReadWritePathElem
var ok bool
for modelPath, modelElem := range rwPaths {
pathNoIndices := modelregistry.RemovePathIndices(modelPath)
// Find a short path
if pathNoIndices == searchpathNoIndices {
rwPathElem = modelElem
ok = true
break
return &modelElem, nil
}
}
if !ok {
return nil, fmt.Errorf("unable to find RW model path %s", path)
}
return &rwPathElem, nil

return nil, fmt.Errorf("unable to find RW model path %s ( without index %s). %d paths inspected",
path, searchpathNoIndices, len(rwPaths))
}
30 changes: 20 additions & 10 deletions pkg/northbound/gnmi/set_test.go
Expand Up @@ -394,6 +394,9 @@ func Test_doSingleDelete(t *testing.T) {
pathElemsRefs, _ := utils.ParseGNMIElements([]string{"cont1a", "cont2a", "leaf2a"})
deletePath := &gnmi.Path{Elem: pathElemsRefs.Elem, Target: "Device1"}
deletePaths = append(deletePaths, deletePath)
pathElemsRefs2, _ := utils.ParseGNMIElements([]string{"cont1a", "list2a[name=n1]"})
deletePath2 := &gnmi.Path{Elem: pathElemsRefs2.Elem, Target: "Device1"}
deletePaths = append(deletePaths, deletePath2)

ext100Name := gnmi_ext.Extension_RegisteredExt{
RegisteredExt: &gnmi_ext.RegisteredExtension{
Expand All @@ -418,19 +421,26 @@ func Test_doSingleDelete(t *testing.T) {
// Check that Response is correct
assert.NotNil(t, setResponse, "Expected setResponse to exist")

assert.Equal(t, len(setResponse.Response), 1)
assert.Equal(t, len(setResponse.Response), 2)

assert.Equal(t, setResponse.Response[0].Op.String(), gnmi.UpdateResult_DELETE.String())

path := setResponse.Response[0].Path

assert.Equal(t, path.Target, "Device1")

assert.Equal(t, len(path.Elem), 3, "Expected 3 path elements")

assert.Equal(t, path.Elem[0].Name, "cont1a")
assert.Equal(t, path.Elem[1].Name, "cont2a")
assert.Equal(t, path.Elem[2].Name, "leaf2a")
for _, r := range setResponse.Response {
path := r.Path
assert.Equal(t, path.Target, "Device1")

switch len(path.Elem) {
case 2: // The list item
assert.Equal(t, path.Elem[0].Name, "cont1a")
assert.Equal(t, path.Elem[1].Name, "list2a")
case 3: // the leaf 2a
assert.Equal(t, path.Elem[0].Name, "cont1a")
assert.Equal(t, path.Elem[1].Name, "cont2a")
assert.Equal(t, path.Elem[2].Name, "leaf2a")
default:
t.Errorf("unexpected response length in Single delete. %d", len(path.Elem))
}
}

// Check that an the network change ID is given in extension 100 and that the device is currently disconnected
assert.Equal(t, len(setResponse.Extension), 1)
Expand Down

0 comments on commit bb82039

Please sign in to comment.