Skip to content

Commit 4e8612a

Browse files
committed
explicitDelete calculation
1 parent 23d03b1 commit 4e8612a

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

pkg/tree/leaf_variants.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,16 @@ func (lv *LeafVariants) canDelete() bool {
7676
return false
7777
}
7878

79+
// check if highest is explicit delete
80+
highest := lv.GetHighestPrecedence(false, false)
81+
if highest != nil && highest.IsExplicitDelete && lv.GetRunning() != nil {
82+
return true
83+
}
84+
7985
// go through all variants
8086
for _, l := range lv.les {
8187
// if the LeafVariant is not owned by running or default
82-
if l.Update.Owner() != RunningIntentName && l.Update.Owner() != DefaultsIntentName {
88+
if l.Update.Owner() != RunningIntentName && l.Update.Owner() != DefaultsIntentName && !l.IsExplicitDelete {
8389
// then we need to check that it remains, so not Delete Flag set or DeleteOnylIntended Flags set [which results in not doing a delete towards the device]
8490
if l.GetDeleteOnlyIntendedFlag() || !l.GetDeleteFlag() {
8591
// then this entry should not be deleted
@@ -101,11 +107,17 @@ func (lv *LeafVariants) shouldDelete() bool {
101107
return false
102108
}
103109

110+
// check if highest is explicit delete
111+
highest := lv.GetHighestPrecedence(false, false)
112+
if highest != nil && highest.IsExplicitDelete && lv.GetRunning() != nil {
113+
return true
114+
}
115+
104116
foundOtherThenRunningAndDefault := false
105117
// go through all variants
106118
for _, l := range lv.les {
107119
// if an entry exists that is not owned by running or default,
108-
if l.Update.Owner() == RunningIntentName || l.Update.Owner() == DefaultsIntentName {
120+
if l.Update.Owner() == RunningIntentName || l.Update.Owner() == DefaultsIntentName || l.IsExplicitDelete {
109121
continue
110122
}
111123
foundOtherThenRunningAndDefault = true

pkg/tree/visitor_explicit_delete_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ func TestExplicitDeleteVisitor_Visit(t *testing.T) {
8585
t.Error(err)
8686
}
8787

88+
err = testhelper.LoadYgotStructIntoTreeRoot(ctx, config1(), root, RunningIntentName, RunningValuesPrio, flagsNew)
89+
if err != nil {
90+
t.Error(err)
91+
}
92+
8893
return root
8994
},
9095
explicitDeletes: sdcpb.NewPathSet().
@@ -126,6 +131,11 @@ func TestExplicitDeleteVisitor_Visit(t *testing.T) {
126131
t.Error(err)
127132
}
128133

134+
err = testhelper.LoadYgotStructIntoTreeRoot(ctx, config1(), root, RunningIntentName, RunningValuesPrio, flagsNew)
135+
if err != nil {
136+
t.Error(err)
137+
}
138+
129139
testhelper.LoadYgotStructIntoTreeRoot(ctx, &sdcio_schema.Device{Interface: map[string]*sdcio_schema.SdcioModel_Interface{
130140
"ethernet-1/1": {
131141
Name: ygot.String("ethernet-1/1"),
@@ -179,6 +189,15 @@ func TestExplicitDeleteVisitor_Visit(t *testing.T) {
179189
return
180190
}
181191
}
192+
193+
//
194+
dels, err := root.GetDeletes(true)
195+
if err != nil {
196+
t.Error(err)
197+
return
198+
}
199+
t.Logf("Deletes:\n%s", dels.PathSlices().StringSlice())
200+
t.Errorf("foo")
182201
})
183202
}
184203
}

0 commit comments

Comments
 (0)