feat(tree): validate YANG unique list constraints#448
Conversation
Implement unique constraint validation in the tree validation pipeline. Reads UniqueConstraint entries from ContainerSchema, collects leaf values across all list entries, and reports violations via ValidationStats. Covers single-leaf, multi-leaf composite, and descendant-path unique statements. Co-authored-by: Cursor <cursoragent@cursor.com>
db96bc0 to
0b9a3ec
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! 🚀 New features to boost your workflow:
|
| unique "ip port"; | ||
| unique "description"; |
There was a problem hiding this comment.
should these not be in one unique entry?
There was a problem hiding this comment.
According to the YANG 1.1 Specification (RFC 7950, Section 7.8.3), the unique statement can be used multiple times within a single list definition.
Because each unique statement enforces a distinct constraint on a different set of leafes, our validation logic must iterate through all instances of the statement rather than assuming a single occurrence per list.
There was a problem hiding this comment.
so there is no difference between
unique "ip port xyz"
and
unique "ip port"
unique "xyz"
?
I couldn't get this from the RFC
There was a problem hiding this comment.
so there is no difference between
unique "ip port xyz"and
unique "ip port" unique "xyz"?
I couldn't get this from the RFC
No — they are not the same. Each unique statement is one constraint; multiple unique statements mean multiple independent constraints.
unique "ip port xyz" (one constraint)
This enforces uniqueness of the composite (ip, port, xyz) across list entries (with the usual RFC rules for missing/empty values). Two entries may share the same ip and port if xyz differs, because it is the full triple that must not repeat.
unique "ip port" plus unique "xyz" (two constraints)
unique "ip port"— the pair(ip, port)must not repeat. Sameip+porton two rows is invalid even ifxyzdiffers.unique "xyz"—xyzmust not repeat by itself, even ifip/portdiffer.
So the second form is not equivalent: it adds a separate uniqueness requirement on (ip, port) and another on xyz alone.
Tiny example
Assume all three leaves are set:
| Scenario | Row A | Row B | unique "ip port xyz" |
unique "ip port" + unique "xyz" |
|---|---|---|---|---|
Same ip,port; different xyz |
1,1,a | 1,1,b | OK | Fails unique "ip port" |
Different ip,port; same xyz |
1,1,x | 2,2,x | OK | Fails unique "xyz" |
RFC reference: RFC 7950 §7.8.3 (unique statement).
Summary
validation_entry_unique.go: walks list children, collects leaf values per unique statement, reports violationsvalidation_dispatch.goandValidationStatssdcio_model_list_unique.yang) covering single-leaf, multi-leaf composite, and descendant-path unique statementstests/sdcioygot/sdcio_schema.gowith updated schemaCloses #445
Related
UniqueConstraintmessage +unique_constraintsfield)unique_constraintsfrom YANGuniquestatements)