-
Notifications
You must be signed in to change notification settings - Fork 121
feat: support for diffing presence containers #990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8c252eb
688c727
bcaa4dc
32d9ebd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -193,6 +193,16 @@ func getOrderedDirDetails(langMapper LangMapper, directory map[string]*Directory | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||
| pd.Type = Container | ||||||||||||||||||||||||||
| if len(dir.Entry.Extra["presence"]) > 0 { | ||||||||||||||||||||||||||
| if v := dir.Entry.Extra["presence"][0].(*yang.Value); v != nil { | ||||||||||||||||||||||||||
| pd.PresenceContainer = true | ||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||
| return nil, fmt.Errorf( | ||||||||||||||||||||||||||
| "unable to retrieve presence statement, expected non-nil *yang.Value, got %v", | ||||||||||||||||||||||||||
| dir.Entry.Extra["presence"][0], | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+197
to
+204
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
since this uses the go-style approach of exiting early for errors and avoiding indentation. it also fixes the go-style point of not having linebreaks @80ch. |
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| for i, entry := 0, dir.Entry; ; i++ { | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,6 +254,8 @@ func findSetLeaves(s GoStruct, orderedMapAsLeaf bool, opts ...DiffOpt) (map[*pat | |
| return | ||
| } | ||
|
|
||
| isYangPresence := hasRespectPresenceContainers(opts) != nil && util.IsYangPresence(ni.StructField) | ||
|
|
||
| var sp [][]string | ||
| if pathOpt != nil && pathOpt.PreferShadowPath { | ||
| // Try the shadow-path tag first to see if it exists. | ||
|
|
@@ -313,9 +315,10 @@ func findSetLeaves(s GoStruct, orderedMapAsLeaf bool, opts ...DiffOpt) (map[*pat | |
| // Ignore structs unless it is an ordered map and we're | ||
| // treating it as a leaf (since it is assumed to be | ||
| // telemetry-atomic in order to preserve ordering of entries). | ||
| if (!isOrderedMap || !orderedMapAsLeaf) && util.IsValueStructPtr(ni.FieldValue) { | ||
| if util.IsValueStructPtr(ni.FieldValue) && (!isOrderedMap || !orderedMapAsLeaf) && !isYangPresence { | ||
| return | ||
| } | ||
|
|
||
| if isOrderedMap && orderedMap.Len() == 0 { | ||
| return | ||
| } | ||
|
|
@@ -335,7 +338,15 @@ func findSetLeaves(s GoStruct, orderedMapAsLeaf bool, opts ...DiffOpt) (map[*pat | |
| } | ||
|
|
||
| outs := out.(map[*pathSpec]interface{}) | ||
| outs[vp] = ival | ||
| if isYangPresence { | ||
| // If the current field is tagged as a presence container, | ||
| // we set it's value to `nil` instead of returning earlier. | ||
| // This is because empty presence containers has a meaning, | ||
| // unlike a normal container. | ||
| outs[vp] = nil | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In an empty container, isn't |
||
| } else { | ||
| outs[vp] = ival | ||
| } | ||
|
|
||
| if isOrderedMap && orderedMapAsLeaf { | ||
| // We treat the ordered map as a leaf, so don't | ||
|
|
@@ -426,6 +437,24 @@ func hasIgnoreAdditions(opts []DiffOpt) *IgnoreAdditions { | |
| return nil | ||
| } | ||
|
|
||
| // The RespectPresenceContainers DiffOpt indicates that presence containers | ||
| // should be respected in the diff output. | ||
| // This option was added to ensure we do not break backward compatibility. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And it's appreciated! :-) |
||
| type WithRespectPresenceContainers struct{} | ||
|
|
||
| func (*WithRespectPresenceContainers) IsDiffOpt() {} | ||
|
|
||
| // hasRespectPresenceContainers returns the first WithRespectPresenceContainers from an opts slice, or | ||
| // nil if there isn't one. | ||
JonasKs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func hasRespectPresenceContainers(opts []DiffOpt) *WithRespectPresenceContainers { | ||
| for _, o := range opts { | ||
| if rp, ok := o.(*WithRespectPresenceContainers); ok { | ||
| return rp | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // DiffPathOpt is a DiffOpt that allows control of the path behaviour of the | ||
| // Diff function. | ||
| type DiffPathOpt struct { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filed openconfig/goyang#286 since this is a little ugly. Can you add a TODO -- i.e.,: