Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

JonasKs
Copy link

@JonasKs JonasKs commented Oct 2, 2024

Closes #936.

The implementation ended up being somewhat as described in #936, where we indicate that presence container has a nil value in the findSetLeaves function.
In addition to this, we added a presence container interface, which is used in the marshalStructOrOrderedList to isolate the presence container which might have values, to act like an empty struct.

The result is that we do not break any current tests (even without the diff option), but we decided to add a diff option, with the reasoning described in #936:

Adding this as a non-optional, paired with ygot.BuildEmptyTree would also probably be breaking, as it would set all these presence containers?

We've confirmed this works in our setup. We're able to successfully configure all presence containers, even nested ones.

Co-authored-by: Terje Lafton [email protected]

Copy link

google-cla bot commented Oct 2, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@JonasKs JonasKs force-pushed the support-presence-containers branch from 4970f67 to 519ff68 Compare October 2, 2024 12:21
@JonasKs
Copy link
Author

JonasKs commented Oct 2, 2024

Hello @wenovus and @robshakir - it took some time, but we finally managed to crack the code. Please review. 😊

@JonasKs JonasKs force-pushed the support-presence-containers branch from 519ff68 to 58943fa Compare October 2, 2024 13:22
@coveralls
Copy link

coveralls commented Oct 2, 2024

Coverage Status

coverage: 88.766% (-0.04%) from 88.807%
when pulling bcaa4dc on JonasKs:support-presence-containers
into 100bd44 on openconfig:master.

@JonasKs JonasKs force-pushed the support-presence-containers branch from 58943fa to 8c252eb Compare October 2, 2024 13:42
@JonasKs
Copy link
Author

JonasKs commented Oct 2, 2024

Also tagging #645 author, @hansthienpondt.

@JonasKs
Copy link
Author

JonasKs commented Oct 24, 2024

Hi @robshakir , friendly bump in case you missed this 😊

@robshakir
Copy link
Contributor

I did miss it -- apologies, let me review ASAP.

@JonasKs
Copy link
Author

JonasKs commented Nov 15, 2024

I did miss it -- apologies, let me review ASAP.

No worries, @robshakir! We’ve been using the fork in production and it’s worked like a charm.

@JonasKs
Copy link
Author

JonasKs commented Mar 30, 2025

@robshakir, would love to get this looked at. 😊

@robshakir
Copy link
Contributor

@JonasKs holy-moly! apologies! this one passed me by. reviewing now. 🔎

@@ -193,6 +193,16 @@ func getOrderedDirDetails(langMapper LangMapper, directory map[string]*Directory
}
default:
pd.Type = Container
if len(dir.Entry.Extra["presence"]) > 0 {
Copy link
Contributor

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.,:

TODO(https://github.com/openconfig/goyang/issues/286): update to use direct yang.Entry field once presence is natively supported in goyang.

Comment on lines +197 to +204
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],
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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],
)
}
if v := dir.Entry.Extra["presence"][0].(*yang.Value); v == nil {
return nil, fmt.Errorf("unable to retrieve presence statement, expected non-nil *yang.Value, got %v", dir.Entry.Extra["presence"][0])
}
pd.PresenceContainer = true

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.

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an empty container, isn't ival already set to nil? it's specified as ni.FieldValue.Interface() above.

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's appreciated! :-)

@JonasKs
Copy link
Author

JonasKs commented Apr 16, 2025

Thanks so much, @robshakir! I’m out of office for ~2 weeks, but I’ll address all comments when I’m back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ygot.Diff don't respect presence containers
3 participants