From bb82039179401de61e08364d6efa68a8eb86e8fd Mon Sep 17 00:00:00 2001 From: Sean Condon Date: Sun, 7 Feb 2021 15:14:23 +0000 Subject: [PATCH] Releasing v0.7.6 and fixing delete from list --- VERSION | 2 +- pkg/northbound/gnmi/set.go | 20 +++++++++++--------- pkg/northbound/gnmi/set_test.go | 30 ++++++++++++++++++++---------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/VERSION b/VERSION index aaf7d6e70..c00621855 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.6-dev +0.7.6 diff --git a/pkg/northbound/gnmi/set.go b/pkg/northbound/gnmi/set.go index f1c3029f7..52ddcfcf3 100644 --- a/pkg/northbound/gnmi/set.go +++ b/pkg/northbound/gnmi/set.go @@ -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" @@ -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)) } diff --git a/pkg/northbound/gnmi/set_test.go b/pkg/northbound/gnmi/set_test.go index b6c1a01e4..125d03079 100644 --- a/pkg/northbound/gnmi/set_test.go +++ b/pkg/northbound/gnmi/set_test.go @@ -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{ @@ -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)