Skip to content
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

Retain Extra fields over Uses,Augments #244

Merged
merged 3 commits into from
May 15, 2023

Conversation

bclasse
Copy link
Contributor

@bclasse bclasse commented May 2, 2023

Hi,

In a YANG model, uses or augments can be used to extend modules. It's possible to define under those nodes an IfFeature attribute. But when turning those into an Entry (yang.ToEntry), IfFeature field disappears. It should become an attribute located under Extras, but when using Uses, it simply isn't copied hence some information is lost.

This PR adds support for moving all the Extra fields defined in Uses or Merge to the augment element.

@coveralls
Copy link

coveralls commented May 3, 2023

Coverage Status

Coverage: 84.048% (+0.03%) from 84.021% when pulling 817fc21 on bclasse:extra-uses-augment-handling into 9a319ef on openconfig:master.

Comment on lines 1489 to 1492
if v.Extra[lk] == nil {
v.Extra[lk] = lv
continue
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This if block can be omitted without impacting functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

v.Extra[lk] = lv
continue
}
v.Extra[lk] = append(v.Extra[lk], oe.Extra[lk]...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a test in TestIfFeature in entry_test.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

v.Extra[lk] = lv
continue
}
v.Extra[lk] = append(v.Extra[lk], oe.Extra[lk]...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

(optional) Note that currently only augments in uses statements are going to be picked up. Raw augments won't be. I'd also suggest adding this statement outside of the for loop as well and fixing the relevant test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please give an example where this would occur?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For what I see, augment defined in uses are ignored, regardless of if-feature field - could we open a new issue, approve this PR, and treat that corner case separately? What do you reckon @wenovus ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually my comment here was misled by my naive thought that if-features should be applied to the target node where they should only be applied to the nodes within the uses or augment, which is exactly what your PR does. This LGTM.

@bclasse bclasse requested a review from wenovus May 5, 2023 03:35
v.Extra[lk] = lv
continue
}
v.Extra[lk] = append(v.Extra[lk], oe.Extra[lk]...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually my comment here was misled by my naive thought that if-features should be applied to the target node where they should only be applied to the nodes within the uses or augment, which is exactly what your PR does. This LGTM.

@@ -2269,6 +2276,15 @@ func TestIfFeature(t *testing.T) {
inIfFeatures: ms.Modules["if-feature"].Uses[0].IfFeature,
wantIfFeatures: []string{"ft-uses"},
},
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you can add a comment above this test block, something like "// Testing that if-features are merged correctly" I think that would help make this more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@wenovus
Copy link
Collaborator

wenovus commented May 15, 2023

Thanks!

@wenovus wenovus merged commit 1d9b70a into openconfig:master May 15, 2023
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.

3 participants