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

added support for leaf-list default substatement #136 #139

Merged
merged 19 commits into from
Jan 21, 2022

Conversation

hellt
Copy link
Contributor

@hellt hellt commented Sep 3, 2020

Hi @robshakir,
I've approached the issue described in #136
Let me plz know if that PR satisfies the requirements of the feature and contribution guidelines.

closes #136


Cumulative summary after edits by @wenovus:

  • LeafList now has a Default []*Value field.
  • Entry.Default changed to []string .
  • Entry.DefaultValue() string -> Entry.SingleDefaultValue() (string, bool) & Entry.DefaultValues() []string
    • Note that Entry.SingleDefaultValue() (string, bool) only returns true when there is one and only one default value. This includes the case when a leaf-list has a single default value.
  • new field YangType.HasDefault to determine whether the empty string is a default value.

NOTE: This is a backwards-incompatible change (see summary)

@coveralls
Copy link

coveralls commented Sep 3, 2020

Coverage Status

Coverage increased (+0.03%) to 83.933% when pulling ef69583 on hellt:leaflist-default into 6eefd78 on openconfig:master.

@hellt
Copy link
Contributor Author

hellt commented Sep 15, 2020

Hi @robshakir
Did you have time to look into this PR? Anything I should address/fix?

pkg/yang/yang.go Outdated Show resolved Hide resolved
@wenovus wenovus changed the base branch from master to deviation-fix August 3, 2021 00:20
@wenovus wenovus changed the base branch from deviation-fix to fix-deviate-default August 3, 2021 00:22
@wenovus wenovus requested a review from robshakir August 3, 2021 03:40
@wenovus wenovus marked this pull request as draft August 3, 2021 03:53
@wenovus wenovus marked this pull request as ready for review August 3, 2021 21:54
@wenovus
Copy link
Collaborator

wenovus commented Aug 3, 2021

leaf-list's default rules: https://datatracker.ietf.org/doc/html/rfc7950#section-7.7.2

@robshakir when reviewing please see summary in OP.

@wenovus wenovus deleted the branch openconfig:master September 29, 2021 22:48
@wenovus wenovus closed this Sep 29, 2021
@wenovus wenovus reopened this Oct 4, 2021
@wenovus wenovus changed the base branch from fix-deviate-default to master October 4, 2021 23:17
case deviatedNode.IsLeafList():
// It is unclear from RFC7950 on how deviate delete works
// when there are duplicate leaf-list values.
appendErr(fmt.Errorf("%s: deviate delete on default statements unsupported for leaf-lists, please use replace instead", Source(e.Node)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that I understand the error discussed above. Entries in a leaf-list must be unique (ref), and delete must match a specific keyword, so if you have:

leaf-list foo {
  type string;
  default "one";
  default "two";
}

then:

deviation "/foo" {
   deviate delete {
     default "one";
   }
}

then the default of foo would become ["two"] rather than ["one", "two"] in the before case. If there is no matching default for one that is removed then this is an error.

Copy link
Collaborator

Choose a reason for hiding this comment

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

https://datatracker.ietf.org/doc/html/rfc7950#section-7.7

In configuration data, the values in a leaf-list MUST be unique.

What if it's state data? Then which one do we delete?

Unfortunately I couldn't find it in https://datatracker.ietf.org/doc/html/rfc7950#section-7.7.2, and when looking at pyang's behaviour, I hit this: mbj4668/pyang#756.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that the behaviour can be implemented for config-false leaf-lists, so I've added a TODO to work on it after this PR. This PR is in someone else's repository so I prefer to open a PR for that after this is merged. We need to take care of erroring out when there are duplicate defaults.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds fine with me.

This whole idea that config true and config false leaf-lists have different approaches seems a problem to me -- it just creates more complexity in the language. I'd be OK with an interpretation that just enforces uniqueness for config true and config false leaflists the same way.

return len(e.DefaultValues()) > 0
}

// SingleDefaultValue returns the schema default value for e, if any. This is
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder whether rather than requiring a user to do two calls here - i.e.,:

var default string
if a.HasDefault() {
   default = a.SingledefaultValue()
}

it's better to have these combined, such that you can do:

if def, ok := a.SingleDefaultValue(); a.IsLeaf() && ok {
   default = def
}

Since DefaultValues will return nil, then this is detectable in a single call for the leaf-list case so this approach would create some symmetry between the leaf and leaf-list types.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Doing it this way seems better for usability as well since it makes error handling more natural. I'll make the change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that Entry.SingleDefaultValue() (string, bool) only returns true when there is one and only one default value. This includes the case when a leaf-list has a single default value.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM!

}
}`,
},
wantProcessErrSubstring: "deviate delete on default statements unsupported for leaf-lists",
Copy link
Contributor

Choose a reason for hiding this comment

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

Potentially we can remove this TODO and address the issue here if you agree with my assessment of 7950 above.

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 see my reply above to see if you agree with what I intend to do for this here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that sounds good to me.

`SingleDefaultValue` now has an `ok` return value to indicate whether
there is one and only one default value for `Entry`. Previously, this
function returned the first default value if there are more than one;
now, it returns the empty string with `ok=false` since this helps users
avoid misuse.
Copy link
Collaborator

@wenovus wenovus left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @hellt!

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

Successfully merging this pull request may close these issues.

allow default substatments for leaf-list
5 participants