YANG must Constraint: XPath Validity Rule

300-435 By islever Editorial Last updated

Short answer

A A YANG must statement is an XPath expression evaluated against the instance tree, and the data is valid only when that expression evaluates to true.

Question

What is YANG 'must' constraint?
  1. XPath expression that must be true for valid data Correct Answer
  2. Optional
  3. Deprecated
  4. Ignored

Key Takeaways

A YANG must statement is an XPath validity constraint evaluated against the instance data tree, not an optional or deprecated annotation. The correct answer is A: the expression must evaluate to true for the data to be accepted, while optionality, lifecycle status, and non-enforcement describe different YANG axes. NETCONF and RESTCONF servers enforce the assertion during configuration validation, so the XPath condition is mandatory for valid data.

Expert Analysis

A must statement is an XPath assertion over a YANG data tree, so data that fails the expression is invalid and the only workable choice is A.

must Validity Versus Optional Cardinality and Deprecated Status

A YANG must statement sits on the validation axis: it is an XPath expression attached to a data node, a typedef, a grouping, or another schema location, and every instance that reaches that schema location must make the expression evaluate to true. Optional belongs to a different axis — cardinality, where a leaf or container may be absent (0..1) — and Deprecated is a lifecycle status that tells model readers the definition is obsolete but still present. Those labels do not describe the same property. A leaf can be optional in cardinality while still carrying a mandatory semantic condition through must; for example, an optional mtu leaf may be absent, but if present its value must satisfy must '. >= 68 and. <= 9216'. The constraint is not waived because the node is optional, and it is not weakened because the schema status is current or deprecated. Ignored is not a YANG axis at all; it is the absence of enforcement, which contradicts the purpose of a constraint. The boundary to retain is that must answers 'is the data valid?' while Optional and Deprecated answer 'may the node be absent?' and 'is the definition still recommended?'.

XPath Truth in the Instance Tree Makes Option A the Only Fit

The decisive condition is that a must expression is evaluated against the accessible instance tree, not against the schema text or a runtime flag, and the result must be boolean true for the data to be accepted. In a NETCONF or RESTCONF edit, a leaf carrying must '../enabled = "true"' can be set only when the referenced sibling has the required value; if the predicate is false, the datastore is not allowed to hold the resulting configuration. That makes the defining property of must an XPath condition that must be true for valid data, which is exactly the wording of option A. The test is not whether the statement is present in the module, whether it is marked optional, or whether a tool chooses to display it; the test is whether the instance satisfies the expression. A must on a container can also constrain a child's relationship to another subtree, so the expression may reference nodes beyond the immediate parent. In all cases the server evaluates the assertion at the point where the data is created or validated, and a false result is a validity failure rather than a warning.

Each of Optional, Deprecated, and Ignored Misreads a YANG Axis

Optional confuses absence in the data tree with the meaning of the constraint: treating must as optional would let a management agent store a leaf that violates a cross-node dependency, which is precisely the invalid state the assertion exists to block. Deprecated confuses lifecycle status with validation semantics: a deprecated must statement is still part of the schema and is still enforced unless the module revision removes it, so choosing this label would incorrectly license nonconforming data. Ignored denies the enforcement mechanism outright: a conforming server does not silently discard a must expression, because doing so would make the advertised model's validity rules unenforceable and would turn a deterministic validation error into an undetected misconfiguration. Each wrong choice therefore costs a different safeguard — optionality erases presence semantics, deprecation erases lifecycle semantics, and 'ignored' erases server enforcement — while option A preserves the one property that all three alternatives destroy: the data must satisfy an XPath predicate before it is accepted. None of those alternatives defines a constraint; they are a cardinality label, a status label, and a claim of non-enforcement.

RFC 7950 Section 7.5.3 Requires Server-Side Enforcement

The standards basis is RFC 7950, the YANG 1.1 data modeling language specification, which defines the must statement as a constraint whose argument is an XPath expression and states that the expression must evaluate to true for the data to be valid. The same rule is inherited by YANG 1.0 modules through RFC 6020, and NETCONF and RESTCONF servers that implement the module are expected to enforce it when configuration is loaded, edited, or validated. This is why the requirement is not a documentation preference: a false must result makes the instance invalid and the server can reject the request instead of committing it. Cisco IOS XE and NX-OS YANG models use must for exactly this kind of cross-leaf and cross-container validation, and the expression is visible in the module tree alongside the node it constrains. A tool such as pyang or YANG Suite can display the statement, but display is secondary; the normative behavior is evaluation by the server against instance data. That documented rule is what makes 'XPath expression that must be true for valid data' the required characterization, not a matter of interpretation.

Official Reference

Exam Strategy

When a YANG prompt pairs a one-line definition with status labels, anchor the answer in the validation purpose: a must statement always carries an XPath expression that must evaluate true. Eliminate choices describing cardinality (optional), lifecycle (deprecated), or non-enforcement (ignored) because none of those are constraint semantics. If the stem shifts to when, mandatory, or status, apply the same axis separation instead of matching a familiar word.

Practice All 300-435 Questions

Access 150 questions with complete answers and detailed explanations.

View Full 300-435 Practice Test →

← Back to 300-435 Study Guide