Skip to content

Commit

Permalink
BuildTree: fix json output Fixes #1186 (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCondon committed Sep 3, 2020
1 parent 3e3affb commit 93ec4d6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/onosproject/config-models/modelplugin/devicesim-1.0.0 v0.0.0-20200303111912-723f2289d4c2
github.com/onosproject/config-models/modelplugin/testdevice-1.0.0 v0.0.0-20200303111912-723f2289d4c2
github.com/onosproject/config-models/modelplugin/testdevice-2.0.0 v0.0.0-20200304144136-6992f473b240
github.com/onosproject/config-models/modelplugin/testdevice-2.0.0 v0.0.0-20200902145751-acff059d1869
github.com/onosproject/helmit v0.6.7
github.com/onosproject/onos-lib-go v0.6.18
github.com/onosproject/onos-test v0.6.2
Expand Down
12 changes: 2 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ github.com/atomix/go-client v0.1.0 h1:QdyjfvnbsBdEUY0L4VBACnqqlO/f7NFKu6q2v5NH35
github.com/atomix/go-client v0.1.0/go.mod h1:ILrAqt6cUNOdPyifTt1yZ8f51HJ47AUWAzPEu3+bYro=
github.com/atomix/go-client v0.2.1 h1:vg0vyjTEvvDZhNis0rePw4Hjve3ayFqWOQ6qrKk/XkE=
github.com/atomix/go-client v0.2.1/go.mod h1:2vnbQIfU7NwfJo+HwB5oBYkK2Me2rPexTpC1vvhveF4=
github.com/atomix/go-client v0.2.2 h1:urKLLKNe42iKER9jn3S1wEcOFpiQO4iyohIYc6kRnWs=
github.com/atomix/go-client v0.2.2/go.mod h1:2vnbQIfU7NwfJo+HwB5oBYkK2Me2rPexTpC1vvhveF4=
github.com/atomix/go-client v0.2.3 h1:xa6bIPU4Yyud6uAs9vioejfNghVuh/Ftd0EnUKGipVM=
github.com/atomix/go-client v0.2.3/go.mod h1:KxR4SPzNftASIN0tYFYBzT5lW8fLNvFGNW26tdZuTVU=
github.com/atomix/go-framework v0.0.0-20200123235029-e29fc7d6e104/go.mod h1:Dn7tjt5LIRA/qr5afQZDh9hdtvK82uQpMrADYIlVtfQ=
Expand Down Expand Up @@ -517,18 +515,12 @@ github.com/onosproject/config-models/modelplugin/devicesim-1.0.0 v0.0.0-20200303
github.com/onosproject/config-models/modelplugin/devicesim-1.0.0 v0.0.0-20200303111912-723f2289d4c2/go.mod h1:fnlrrfeXk6J57vIQ329fnNiOVCCeja9JzTaldVUb1cg=
github.com/onosproject/config-models/modelplugin/testdevice-1.0.0 v0.0.0-20200303111912-723f2289d4c2 h1:z885fAIiyK0nwhJcXzsLDa5eoLkQQMblj4KD5TVKVbg=
github.com/onosproject/config-models/modelplugin/testdevice-1.0.0 v0.0.0-20200303111912-723f2289d4c2/go.mod h1:WNjaBJ0e2gl1y7uu45AXmKCI0oxgCqSftha+FGMJ2JE=
github.com/onosproject/config-models/modelplugin/testdevice-2.0.0 v0.0.0-20200304144136-6992f473b240 h1:sI0zCRmIsUjpYf0MpgEsK2YLBpXcB4ynPHamoFybRGU=
github.com/onosproject/config-models/modelplugin/testdevice-2.0.0 v0.0.0-20200304144136-6992f473b240/go.mod h1:kHe1VPG+H+ow9IQYy5DW4qLxZsT3yVSc+3aGrO0KuVY=
github.com/onosproject/config-models/modelplugin/testdevice-2.0.0 v0.0.0-20200902145751-acff059d1869 h1:9jrMu2xDpjjIT+YmwtVN4bJSpHfzmPesfOku5pSBmSQ=
github.com/onosproject/config-models/modelplugin/testdevice-2.0.0 v0.0.0-20200902145751-acff059d1869/go.mod h1:1IY6EUMr+1JRIEeTeBXL46rGJDwrm+IMDNZiGW8G6Zw=
github.com/onosproject/helmit v0.6.4/go.mod h1:ZvjMu26Kd19hCHzkpnUH1Zgv/htt7iZbPG1EsFXBlhc=
github.com/onosproject/helmit v0.6.7 h1:vXMlRLUhN76NtQ0n/h6xuK0DvxVRbpJpDkmGotvfXZk=
github.com/onosproject/helmit v0.6.7/go.mod h1:EorNGSNGWojXGxBEuiNmPScae+R2C5WYfg/13gKEPLw=
github.com/onosproject/onos-lib-go v0.6.10/go.mod h1:rziMWU6yQa93ZSUGRJIPNqxWtbK1R7dYjyjxUcNep6k=
github.com/onosproject/onos-lib-go v0.6.15 h1:9UcxMZW9/718mLe2Plc7Myz1XvJJGShHTzSujpdXCKc=
github.com/onosproject/onos-lib-go v0.6.15/go.mod h1:WrNXx2u9DeKuAtOwcZJjrZeyNOfoyEyHepRXK3xH94E=
github.com/onosproject/onos-lib-go v0.6.16 h1:cF2/C0VihV5AEqGUf/eYH8udZ8HmxJhfol9Py7WmbbI=
github.com/onosproject/onos-lib-go v0.6.16/go.mod h1:WrNXx2u9DeKuAtOwcZJjrZeyNOfoyEyHepRXK3xH94E=
github.com/onosproject/onos-lib-go v0.6.17 h1:JjI0irntYxvXFICag/cWIEVnZwjutIwluul5V7meKA8=
github.com/onosproject/onos-lib-go v0.6.17/go.mod h1:iU1kl2scI+4cKL5UhrT/yGehE0n9NfqYdYytnt6B45M=
github.com/onosproject/onos-lib-go v0.6.18 h1:Q2k5SGTv6hVGN+BYnsx+hBNgLaFB/pqapNvcickuU8A=
github.com/onosproject/onos-lib-go v0.6.18/go.mod h1:x0vnsS7xhJVIHxtRFLmBW3sm9OdKnmTkCCVo8eGy8lU=
github.com/onosproject/onos-test v0.6.2 h1:eKnMXFBsMwfls+tMijeUlPKCmmj1XeHPBbrkkB8xK8s=
Expand Down
12 changes: 6 additions & 6 deletions pkg/modelregistry/modelregistryTestDevice2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ func Test_SchemaTestDevice2(t *testing.T) {
assert.Assert(t, leaf2cVtOk, "expected /cont1a/cont2a/leaf2c to have subpath /")
assert.Equal(t, leaf2cVt.Datatype, devicechange.ValueType_STRING)

cont1b, cont1bOk := readOnlyPathsTestDevice2["/cont1b-state"]
assert.Assert(t, cont1bOk, "expected to get /cont1b-state")
assert.Equal(t, len(cont1b), 5, "expected /cont1b-state to have 5 subpaths")
cont1bState, cont1bStateOk := readOnlyPathsTestDevice2["/cont1b-state"]
assert.Assert(t, cont1bStateOk, "expected to get /cont1b-state")
assert.Equal(t, len(cont1bState), 7, "expected /cont1b-state to have 5 subpaths")

cont1bVt, cont1bVtOk := cont1b["/leaf2d"]
cont1bVt, cont1bVtOk := cont1bState["/leaf2d"]
assert.Assert(t, cont1bVtOk, "expected /cont1b-state to have subpath /leaf2d")
assert.Equal(t, cont1bVt.Datatype, devicechange.ValueType_UINT)

l2bIdxVt, l2bIdxVtOk := cont1b["/list2b[index=*]/index"]
l2bIdxVt, l2bIdxVtOk := cont1bState["/list2b[index1 index2=*]/index2"]
assert.Assert(t, l2bIdxVtOk, "expected /cont1b-state to have subpath /list2b[index[*]/index")
assert.Equal(t, l2bIdxVt.Datatype, devicechange.ValueType_UINT)

l2bLeaf3cVt, l2bLeaf3cVtOk := cont1b["/list2b[index=*]/leaf3c"]
l2bLeaf3cVt, l2bLeaf3cVtOk := cont1bState["/list2b[index1 index2=*]/leaf3c"]
assert.Assert(t, l2bLeaf3cVtOk, "expected /cont1b-state to have subpath /list2b[index[*]/leaf3c")
assert.Equal(t, l2bLeaf3cVt.Datatype, devicechange.ValueType_STRING)

Expand Down
19 changes: 11 additions & 8 deletions pkg/store/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
devicechange "github.com/onosproject/onos-config/api/types/change/device"
"github.com/onosproject/onos-config/pkg/utils"
"reflect"
"strconv"
"strings"
)
Expand Down Expand Up @@ -115,27 +114,31 @@ func addPathToTree(path string, value *devicechange.TypedValue, nodeif *interfac
}
//Reuse existing listSlice
var listItemMap map[string]interface{}
var foundit bool
var foundkeys int

for idx, ls := range listSliceIf {
lsMap, ok := ls.(map[string]interface{})
if !ok {
return fmt.Errorf("Failed to convert list slice %d", idx)
}
if reflect.DeepEqual(lsMap, keyMap) {
listItemMap = lsMap
foundit = true
break
for k, v := range keyMap {
if l, ok := lsMap[k]; ok {
if l == v {
foundkeys++
listItemMap = lsMap
}
}
}
}
if !foundit {
if foundkeys < len(keyMap) {
listItemMap = keyMap
}
listItemIf := interface{}(listItemMap)
err := addPathToTree(refinePath, value, &listItemIf, floatAsStr)
if err != nil {
return err
}
if !foundit {
if foundkeys < len(keyMap) {
listSliceIf = append(listSliceIf, listItemIf)
(nodemap)[listName] = listSliceIf
}
Expand Down
10 changes: 2 additions & 8 deletions pkg/store/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@ const testJSON1 = `{
"list2a": [
{
"name": "First",
"rx-power": 6,
"tx-power": 5
},
{
"name": "First",
"rx-power": 6
},
{
"name": "Second",
"rx-power": 8,
"tx-power": 7
},
{
"name": "Second",
"rx-power": 8
}
]
},
Expand Down

0 comments on commit 93ec4d6

Please sign in to comment.