问题
The RFC6020 says:
The "key" statement [...] takes as an argument a string that specifies a space-separated list of leaf identifiers of this list. [...] Each such leaf identifier MUST refer to a child leaf of the list. The leafs can be defined directly in substatements to the list, or in groupings used in the list.
Despite this fact it is possible to successfully validate the below grouping in pyang:
grouping my-grouping {
list my-list-in-a-grouping {
key there-is-no-such-leaf;
}
}
If the list is outside of a grouping, or if I use the grouping without any augmentations, then I get an error (which is expected):
error: the key "there-is-no-such-leaf" does not reference an existing leaf
What is the point of having groupings that require augmentations in order to be used?
回答1:
According to Martin Bjorklund, an author of the related RFCs, this is not valid YANG. Pyang fails to detect this due to a bug in its implementation. The RFC text which you quoted in your question does not permit any other interpretation and appears to be intentional. Groupings were never meant to be used in such a way.
回答2:
Could it be because grouping
is not a data definition node and pyang validates only such nodes?
The grouping statement is not a data definition statement and, as such, does not define any nodes in the schema tree.
RFC6020
来源:https://stackoverflow.com/questions/37854667/why-does-pyang-validation-allow-to-define-a-list-without-a-valid-key-if-the-list