Hi,
I have a question about the leaf’s default usage, use the below exampe to show it.
- The yang module:
# cat default.yang
module default{
namespace "http://complex/default";
prefix "default";
container test1 {
list test2{
key id;
leaf id{
type uint8 {
range "1..80";
}
}
leaf type{
type enumeration {
enum "Act";
enum "Term";
}
default "Act";
}
leaf trace{
when "../type = 'Act'";
type enumeration {
enum "URI";
enum "Number";
}
default "Number";
}
leaf name{
must "not(../trace = 'URI')";
type string;
}
}
}
}
- The XML file:
# cat default.xml
<test1 xmlns="http://complex/default">
<test2>
<id>1</id>
<type>Act</type>
<trace>Number</trace>
<name>abc</name>
</test2>
<test2>
<id>2</id>
<type>Term</type>
</test2>
</test1>
- The edit-config result will report error.
# /root/lab-5/confd/bin/netconf-console --port=2022 --edit-config default.xml
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<rpc-error>
<error-type>application</error-type>
<error-tag>unknown-element</error-tag>
<error-severity>error</error-severity>
<error-path xmlns:default="http://complex/default">
/rpc/edit-config/config/default:test1/default:test2[default:id='2']/default:trace
</error-path>
<error-message xml:lang="en">/test1/test2[id='2']/trace: the 'when' expression "../type = 'Act'" failed</error-message>
<error-info>
<bad-element>trace</bad-element>
</error-info>
</rpc-error>
</rpc-reply>
- My question is:
In the RFC7950 https://tools.ietf.org/html/rfc7950#section-7.6.1, the below description shows the default value won’t be used if thewhen
condition isfalse
. But the above error seems it still use the default value.
Note that if the leaf or any of its ancestors has a “when” condition
or “if-feature” expression that evaluates to “false”, then the
default value is not in use.
note: Only the leaf name
contains the must
check which uses the leaf trace
will trigger the when
error(i.e.if I remove the must
check in the leaf name
, the above when error
won’t be reported), I didn’t find in the RFC that the default valude
is in use if the leaf is referred by other value.