Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/sdcio/cache v0.0.38
github.com/sdcio/logger v0.0.3
github.com/sdcio/schema-server v0.0.34
github.com/sdcio/sdc-protos v0.0.51
github.com/sdcio/sdc-protos v0.0.52-0.20260427142237-8af1b514bb92
github.com/sdcio/yang-parser v0.0.12
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ github.com/sdcio/logger v0.0.3 h1:IFUbObObGry+S8lHGwOQKKRxJSuOphgRU/hxVhOdMOM=
github.com/sdcio/logger v0.0.3/go.mod h1:yWaOxK/G6vszjg8tKZiMqiEjlZouHsjFME4zSk+SAEA=
github.com/sdcio/schema-server v0.0.34 h1:NNDOkvtUMONtBA7cVvN96F+FWGD/Do6HNqfchy9B8eI=
github.com/sdcio/schema-server v0.0.34/go.mod h1:6t8HLXpqUqEJmE5yNZh29u/KZw0jlOICdNWns7zE4GE=
github.com/sdcio/sdc-protos v0.0.51 h1:sFc2ct8v4D7rBgFdg/fmXgJffcFhupfx4QJKsSAoolA=
github.com/sdcio/sdc-protos v0.0.51/go.mod h1:FkJMZWtp7Rcc/EedbX2mt1tET/j8KdavNl2BsHf03+o=
github.com/sdcio/sdc-protos v0.0.52-0.20260427142237-8af1b514bb92 h1:gXS1rSERLsDy1miBfQKsnr7GGfW94qtrgJKTo6t+0uA=
github.com/sdcio/sdc-protos v0.0.52-0.20260427142237-8af1b514bb92/go.mod h1:FkJMZWtp7Rcc/EedbX2mt1tET/j8KdavNl2BsHf03+o=
github.com/sdcio/yang-parser v0.0.12 h1:RSSeqfAOIsJx5Lno5u4/ezyOmQYUduQ22rBfU/mtpJ4=
github.com/sdcio/yang-parser v0.0.12/go.mod h1:CBqn3Miq85qmFVGHxHXHLluXkaIOsTzV06IM4DW6+D4=
github.com/sirikothe/gotextfsm v1.0.1-0.20200816110946-6aa2cfd355e4 h1:FHUL2HofYJuslFOQdy/JjjP36zxqIpd/dcoiwLMIs7k=
Expand Down
10 changes: 9 additions & 1 deletion pkg/tree/processors/processor_blame_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ func (t *BlameConfigTask) Run(ctx context.Context, submit func(pool.Task) error)

// check if running equals the expected
runningLe := t.selfEntry.GetLeafVariants().GetRunning()
if runningLe != nil {

switch {
case runningLe != nil:
// if running value is different from the highest precedence value, then we have a deviation,
// so we set the deviation value to the running value
if !proto.Equal(runningLe.Update.Value(), highestLe.Update.Value()) {
t.self.SetDeviationValue(runningLe.Value())
}
case runningLe == nil && highestLe.GetUpdate().Owner() != consts.DefaultsIntentName:
// if running is nil and highest is not from default, then the deviation is from a non-existing running value,
// so we set it to empty
t.self.SetDeviationValue(&sdcpb.TypedValue{})
}
}
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/tree/processors/processor_blame_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package processors_test

import (
"context"
"fmt"
"runtime"
"testing"

Expand Down Expand Up @@ -61,7 +62,7 @@ func Test_sharedEntryAttributes_BlameConfig(t *testing.T) {

return root
},
want: []byte(`{"name":"root", "childs":[{"name":"choices", "childs":[{"name":"case1", "childs":[{"name":"case-elem", "childs":[{"name":"elem", "owner":"owner1", "value":{"stringVal":"foocaseval"}}]}]}]}, {"name":"interface", "childs":[{"name":"ethernet-1/1", "keyName":"name", "childs":[{"name":"admin-state", "owner":"owner1", "value":{"stringVal":"enable"}}, {"name":"description", "owner":"owner1", "value":{"stringVal":"Foo"}}, {"name":"name", "owner":"owner1", "value":{"stringVal":"ethernet-1/1"}}, {"name":"subinterface", "childs":[{"name":"0", "keyName":"index", "childs":[{"name":"description", "owner":"owner1", "value":{"stringVal":"Subinterface 0"}}, {"name":"index", "owner":"owner1", "value":{"uintVal":"0"}}, {"name":"type", "owner":"owner1", "value":{"identityrefVal":{"value":"routed", "prefix":"sdcio_model_common", "module":"sdcio_model_common"}}}]}]}]}]}, {"name":"leaflist", "childs":[{"name":"entry", "owner":"owner1", "value":{"leaflistVal":{"element":[{"stringVal":"foo"}, {"stringVal":"bar"}]}}}]}, {"name":"network-instance", "childs":[{"name":"default", "keyName":"name", "childs":[{"name":"admin-state", "owner":"owner1", "value":{"stringVal":"disable"}}, {"name":"description", "owner":"owner1", "value":{"stringVal":"Default NI"}}, {"name":"name", "owner":"owner1", "value":{"stringVal":"default"}}, {"name":"type", "owner":"owner1", "value":{"identityrefVal":{"value":"default", "prefix":"sdcio_model_ni", "module":"sdcio_model_ni"}}}]}]}, {"name":"patterntest", "owner":"owner1", "value":{"stringVal":"hallo 00"}}]}`),
want: []byte(`{"name":"root","childs":[{"name":"choices","childs":[{"name":"case1","childs":[{"name":"case-elem","childs":[{"name":"elem","owner":"owner1","value":{"stringVal":"foocaseval"},"deviationValue":{}}]}]}]},{"name":"interface","childs":[{"name":"ethernet-1/1","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"enable"},"deviationValue":{}},{"name":"description","owner":"owner1","value":{"stringVal":"Foo"},"deviationValue":{}},{"name":"name","owner":"owner1","value":{"stringVal":"ethernet-1/1"},"deviationValue":{}},{"name":"subinterface","childs":[{"name":"0","keyName":"index","childs":[{"name":"description","owner":"owner1","value":{"stringVal":"Subinterface 0"},"deviationValue":{}},{"name":"index","owner":"owner1","value":{"uintVal":"0"},"deviationValue":{}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"routed","prefix":"sdcio_model_common","module":"sdcio_model_common"}},"deviationValue":{}}]}]}]}]},{"name":"leaflist","childs":[{"name":"entry","owner":"owner1","value":{"leaflistVal":{"element":[{"stringVal":"foo"},{"stringVal":"bar"}]}},"deviationValue":{}}]},{"name":"network-instance","childs":[{"name":"default","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"disable"},"deviationValue":{}},{"name":"description","owner":"owner1","value":{"stringVal":"Default NI"},"deviationValue":{}},{"name":"name","owner":"owner1","value":{"stringVal":"default"},"deviationValue":{}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"default","prefix":"sdcio_model_ni","module":"sdcio_model_ni"}},"deviationValue":{}}]}]},{"name":"patterntest","owner":"owner1","value":{"stringVal":"hallo 00"},"deviationValue":{}}]}`),
},
{
name: "with defaults",
Expand Down Expand Up @@ -94,7 +95,7 @@ func Test_sharedEntryAttributes_BlameConfig(t *testing.T) {
return root
},
includeDefaults: true,
want: []byte(`{"name":"root","childs":[{"name":"choices","childs":[{"name":"case1","childs":[{"name":"case-elem","childs":[{"name":"elem","owner":"owner1","value":{"stringVal":"foocaseval"}}]},{"name":"log","owner":"default","value":{"boolVal":false}}]}]},{"name":"interface","childs":[{"name":"ethernet-1/1","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"enable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Foo"}},{"name":"name","owner":"owner1","value":{"stringVal":"ethernet-1/1"}},{"name":"subinterface","childs":[{"name":"0","keyName":"index","childs":[{"name":"admin-state","owner":"default","value":{"stringVal":"enable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Subinterface 0"}},{"name":"index","owner":"owner1","value":{"uintVal":"0"}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"routed","prefix":"sdcio_model_common","module":"sdcio_model_common"}}}]}]}]}]},{"name":"leaflist","childs":[{"name":"entry","owner":"owner1","value":{"leaflistVal":{"element":[{"stringVal":"foo"},{"stringVal":"bar"}]}}},{"name":"with-default","owner":"default","value":{"leaflistVal":{"element":[{"stringVal":"foo"},{"stringVal":"bar"}]}}}]},{"name":"network-instance","childs":[{"name":"default","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"disable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Default NI"}},{"name":"name","owner":"owner1","value":{"stringVal":"default"}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"default","prefix":"sdcio_model_ni","module":"sdcio_model_ni"}}}]}]},{"name":"patterntest","owner":"owner1","value":{"stringVal":"hallo 00"}}]}`),
want: []byte(`{"name":"root","childs":[{"name":"choices","childs":[{"name":"case1","childs":[{"name":"case-elem","childs":[{"name":"elem","owner":"owner1","value":{"stringVal":"foocaseval"},"deviationValue":{}}]},{"name":"log","owner":"default","value":{"boolVal":false}}]}]},{"name":"interface","childs":[{"name":"ethernet-1/1","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"enable"},"deviationValue":{}},{"name":"description","owner":"owner1","value":{"stringVal":"Foo"},"deviationValue":{}},{"name":"name","owner":"owner1","value":{"stringVal":"ethernet-1/1"},"deviationValue":{}},{"name":"subinterface","childs":[{"name":"0","keyName":"index","childs":[{"name":"admin-state","owner":"default","value":{"stringVal":"enable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Subinterface 0"},"deviationValue":{}},{"name":"index","owner":"owner1","value":{"uintVal":"0"},"deviationValue":{}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"routed","prefix":"sdcio_model_common","module":"sdcio_model_common"}},"deviationValue":{}}]}]}]}]},{"name":"leaflist","childs":[{"name":"entry","owner":"owner1","value":{"leaflistVal":{"element":[{"stringVal":"foo"},{"stringVal":"bar"}]}},"deviationValue":{}},{"name":"with-default","owner":"default","value":{"leaflistVal":{"element":[{"stringVal":"foo"},{"stringVal":"bar"}]}}}]},{"name":"network-instance","childs":[{"name":"default","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"disable"},"deviationValue":{}},{"name":"description","owner":"owner1","value":{"stringVal":"Default NI"},"deviationValue":{}},{"name":"name","owner":"owner1","value":{"stringVal":"default"},"deviationValue":{}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"default","prefix":"sdcio_model_ni","module":"sdcio_model_ni"}},"deviationValue":{}}]}]},{"name":"patterntest","owner":"owner1","value":{"stringVal":"hallo 00"},"deviationValue":{}}]}`),
},
{
name: "with defaults multiple intents",
Expand Down Expand Up @@ -148,7 +149,7 @@ func Test_sharedEntryAttributes_BlameConfig(t *testing.T) {
return root
},
includeDefaults: true,
want: []byte(`{"name":"root","childs":[{"name":"choices","childs":[{"name":"case1","childs":[{"name":"case-elem","childs":[{"name":"elem","owner":"owner1","value":{"stringVal":"foocaseval"}}]},{"name":"log","owner":"default","value":{"boolVal":false}}]}]},{"name":"interface","childs":[{"name":"ethernet-1/1","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"enable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Foo"},"deviationValue":{"stringVal":"Changed Description"}},{"name":"name","owner":"owner1","value":{"stringVal":"ethernet-1/1"}},{"name":"subinterface","childs":[{"name":"0","keyName":"index","childs":[{"name":"admin-state","owner":"default","value":{"stringVal":"enable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Subinterface 0"}},{"name":"index","owner":"owner1","value":{"uintVal":"0"}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"routed","prefix":"sdcio_model_common","module":"sdcio_model_common"}}}]}]}]},{"name":"ethernet-1/2","keyName":"name","childs":[{"name":"admin-state","owner":"owner2","value":{"stringVal":"enable"}},{"name":"description","owner":"owner2","value":{"stringVal":"Foo"}},{"name":"name","owner":"owner2","value":{"stringVal":"ethernet-1/2"}},{"name":"subinterface","childs":[{"name":"5","keyName":"index","childs":[{"name":"admin-state","owner":"default","value":{"stringVal":"enable"}},{"name":"description","owner":"owner2","value":{"stringVal":"Subinterface 5"}},{"name":"index","owner":"owner2","value":{"uintVal":"5"}},{"name":"type","owner":"owner2","value":{"identityrefVal":{"value":"routed","prefix":"sdcio_model_common","module":"sdcio_model_common"}}}]}]}]},{"name":"ethernet-1/3","keyName":"name","childs":[{"name":"admin-state","owner":"default","value":{"stringVal":"enable"}},{"name":"description","owner":"running","value":{"stringVal":"ethernet-1/3 description"}},{"name":"name","owner":"running","value":{"stringVal":"ethernet-1/3"}}]}]},{"name":"leaflist","childs":[{"name":"entry","owner":"owner1","value":{"leaflistVal":{"element":[{"stringVal":"foo"},{"stringVal":"bar"}]}}},{"name":"with-default","owner":"default","value":{"leaflistVal":{"element":[{"stringVal":"foo"},{"stringVal":"bar"}]}}}]},{"name":"network-instance","childs":[{"name":"default","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"disable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Default NI"}},{"name":"name","owner":"owner1","value":{"stringVal":"default"}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"default","prefix":"sdcio_model_ni","module":"sdcio_model_ni"}}}]},{"name":"other","keyName":"name","childs":[{"name":"admin-state","owner":"owner2","value":{"stringVal":"enable"}},{"name":"description","owner":"owner2","value":{"stringVal":"Other NI"}},{"name":"name","owner":"owner2","value":{"stringVal":"other"}},{"name":"type","owner":"owner2","value":{"identityrefVal":{"value":"ip-vrf","prefix":"sdcio_model_ni","module":"sdcio_model_ni"}}}]}]},{"name":"patterntest","owner":"owner1","value":{"stringVal":"hallo 00"},"deviationValue":{"stringVal":"hallo 0"}}]}`),
want: []byte(`{"name":"root","childs":[{"name":"choices","childs":[{"name":"case1","childs":[{"name":"case-elem","childs":[{"name":"elem","owner":"owner1","value":{"stringVal":"foocaseval"}}]},{"name":"log","owner":"default","value":{"boolVal":false}}]}]},{"name":"interface","childs":[{"name":"ethernet-1/1","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"enable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Foo"},"deviationValue":{"stringVal":"Changed Description"}},{"name":"name","owner":"owner1","value":{"stringVal":"ethernet-1/1"}},{"name":"subinterface","childs":[{"name":"0","keyName":"index","childs":[{"name":"admin-state","owner":"default","value":{"stringVal":"enable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Subinterface 0"}},{"name":"index","owner":"owner1","value":{"uintVal":"0"}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"routed","prefix":"sdcio_model_common","module":"sdcio_model_common"}}}]}]}]},{"name":"ethernet-1/2","keyName":"name","childs":[{"name":"admin-state","owner":"owner2","value":{"stringVal":"enable"},"deviationValue":{}},{"name":"description","owner":"owner2","value":{"stringVal":"Foo"},"deviationValue":{}},{"name":"name","owner":"owner2","value":{"stringVal":"ethernet-1/2"},"deviationValue":{}},{"name":"subinterface","childs":[{"name":"5","keyName":"index","childs":[{"name":"admin-state","owner":"default","value":{"stringVal":"enable"}},{"name":"description","owner":"owner2","value":{"stringVal":"Subinterface 5"},"deviationValue":{}},{"name":"index","owner":"owner2","value":{"uintVal":"5"},"deviationValue":{}},{"name":"type","owner":"owner2","value":{"identityrefVal":{"value":"routed","prefix":"sdcio_model_common","module":"sdcio_model_common"}},"deviationValue":{}}]}]}]},{"name":"ethernet-1/3","keyName":"name","childs":[{"name":"admin-state","owner":"default","value":{"stringVal":"enable"}},{"name":"description","owner":"running","value":{"stringVal":"ethernet-1/3 description"}},{"name":"name","owner":"running","value":{"stringVal":"ethernet-1/3"}}]}]},{"name":"leaflist","childs":[{"name":"entry","owner":"owner1","value":{"leaflistVal":{"element":[{"stringVal":"foo"},{"stringVal":"bar"}]}}},{"name":"with-default","owner":"default","value":{"leaflistVal":{"element":[{"stringVal":"foo"},{"stringVal":"bar"}]}}}]},{"name":"network-instance","childs":[{"name":"default","keyName":"name","childs":[{"name":"admin-state","owner":"owner1","value":{"stringVal":"disable"}},{"name":"description","owner":"owner1","value":{"stringVal":"Default NI"}},{"name":"name","owner":"owner1","value":{"stringVal":"default"}},{"name":"type","owner":"owner1","value":{"identityrefVal":{"value":"default","prefix":"sdcio_model_ni","module":"sdcio_model_ni"}}}]},{"name":"other","keyName":"name","childs":[{"name":"admin-state","owner":"owner2","value":{"stringVal":"enable"},"deviationValue":{}},{"name":"description","owner":"owner2","value":{"stringVal":"Other NI"},"deviationValue":{}},{"name":"name","owner":"owner2","value":{"stringVal":"other"},"deviationValue":{}},{"name":"type","owner":"owner2","value":{"identityrefVal":{"value":"ip-vrf","prefix":"sdcio_model_ni","module":"sdcio_model_ni"}},"deviationValue":{}}]}]},{"name":"patterntest","owner":"owner1","value":{"stringVal":"hallo 00"},"deviationValue":{"stringVal":"hallo 0"}}]}`),
},
}
for _, tt := range tests {
Expand All @@ -171,11 +172,11 @@ func Test_sharedEntryAttributes_BlameConfig(t *testing.T) {
if err != nil {
t.Fatalf("failed to unmarshal JSON to proto: %v", err)
}
// gotB, err := protojson.Marshal(got)
// if err != nil {
// t.Fatalf("failed to marshal proto to JSON: %v", err)
// }
// fmt.Println(string(gotB))
gotB, err := protojson.Marshal(got)
if err != nil {
t.Fatalf("failed to marshal proto to JSON: %v", err)
}
fmt.Println(string(gotB))

if diff := cmp.Diff(want, got, protocmp.Transform()); diff != "" {
t.Errorf("BlameConfig() mismatch (-want +got)\n%s", diff)
Expand Down
Loading