module test {
namespace "urn:uuid:5b748c91-bfad-419c-a8a4-b341cf5a6d14";
prefix tst;
import some-external-module {prefix sem;}
container test {
leaf a {
type boolean;
default true;
}
container b {
when "/sem:something/sem:enabled = 'true'";
leaf ba {
must "not (../../a = 'false' and . = 'true')" {
error-message "a must be enabled first.";
}
type boolean;
default true;
}
}
}
}
When commiting this sometimes happens:
CLI(config)# something enabled
CLI(config)# test a true
CLI(config)# test b ba true
CLI(config)# commit
Commit complete.
CLI(config)# test b ba false
CLI(config)# something disabled
CLI(config)# test a false
CLI(config)# commit
Aborted: 'test b ba' (value "true"): a must be enabled first.
The order of setting the leaves cannot be controlled.
Is there a way to avoid commit abort.
Order does not matter. Your “must” statement expression is evaluated against the resulting configuration regardless if the ancestor container b has a “when” statement.
And since your “when” statement expression becomes false as “something” is disabled, leaf ba is deleted and the default value will be used for evaluating the “must” statement expression.
I re-ran the test with default statements removed and it works as you stated.
But in my real life situation, the order does matter. Here is an output from CLI,
augment /if:interfaces/if:interface/ac:synchronization {
container ptp {
when "/ac:synchronization/ptp:ptp/enabled = 'true' and derived-from(../../if:type, 'avift:ptp-capable')";
leaf enabled {
must "not (derived-from(../../../if:type, 'rl:radio-link-terminal-base') and
../../synce:synce/synce:enabled = 'false' and . = 'true')" {
error-message "SyncE must be enabled on the Radio first.";
}
type boolean;
description
"This is the individual enable/disable for PTP on each interface respectively";
}