Problem when commiting transaction with when and must statements

Hi!

I have a module:

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.

Best regards, Jaka

Hi,

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.

Hi, thank you for your reply!

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,

WTM4500(config)# synchronization ptp enabled
WTM4500(config)# interface Radio1
WTM4500(config-interface-Radio1)# synchronization synce enabled
WTM4500(config-interface-Radio1)# synchronization ptp enabled
WTM4500(config-interface-Radio1)# exit
WTM4500(config)# commit
Commit complete.
WTM4500(config)# synchronization ptp disabled
WTM4500(config)# interface Radio1
WTM4500(config-interface-Radio1)# synchronization synce disabled
WTM4500(config-interface-Radio1)# synchronization ptp disabled
WTM4500(config-interface-Radio1)# exit
WTM4500(config)# commit
Aborted: 'interface Radio1 synchronization ptp enabled' (value "true"): SyncE must be enabled on the Radio first.
WTM4500(config)# synchronization ptp enabled
WTM4500(config)# interface Radio1
WTM4500(config-interface-Radio1)# synchronization synce enabled
WTM4500(config-interface-Radio1)# synchronization ptp enabled
WTM4500(config-interface-Radio1)# exit
WTM4500(config)# commit
% No modifications to commit.
WTM4500(config)# interface Radio1
WTM4500(config-interface-Radio1)# synchronization synce disabled
WTM4500(config-interface-Radio1)# synchronization ptp disabled
WTM4500(config-interface-Radio1)# exit
WTM4500(config)# synchronization ptp disabled
WTM4500(config)# commit
Commit complete.  

This is the definiton of troubled leaf:

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";
    }

Can you please give it another look?
BR