From 712d86a81fa3b29430e5d93de0ce7ad9b5280983 Mon Sep 17 00:00:00 2001 From: steiler Date: Mon, 27 Apr 2026 16:34:24 +0200 Subject: [PATCH 1/2] Fix Blame for non-revertive deleted values --- pkg/tree/processors/processor_blame_config.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/tree/processors/processor_blame_config.go b/pkg/tree/processors/processor_blame_config.go index fd32c593..3a935832 100644 --- a/pkg/tree/processors/processor_blame_config.go +++ b/pkg/tree/processors/processor_blame_config.go @@ -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{}) } } } From 4dc5a777cc2a6cd7080cf6f7024a64fb0cd24425 Mon Sep 17 00:00:00 2001 From: steiler Date: Tue, 28 Apr 2026 09:48:56 +0200 Subject: [PATCH 2/2] fix tests --- go.mod | 2 +- go.sum | 4 ++-- .../processors/processor_blame_config_test.go | 17 +++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 9691778c..3e6147b0 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ab43f6d6..0aa501d7 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/tree/processors/processor_blame_config_test.go b/pkg/tree/processors/processor_blame_config_test.go index 0fd688f6..9e1bcfcd 100644 --- a/pkg/tree/processors/processor_blame_config_test.go +++ b/pkg/tree/processors/processor_blame_config_test.go @@ -2,6 +2,7 @@ package processors_test import ( "context" + "fmt" "runtime" "testing" @@ -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", @@ -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", @@ -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 { @@ -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)