#!/usr/bin/env bash # Clixon leaf default test # Check top-level default as https://github.com/clicon/clixon/issues/111 # Also check # Sanity check default value may not be in list key # RFC 7950: # 7.6.1 The usage of the default value depends on the leaf's closest ancestor node in the # schema tree that is not a non-presence container (see Section 7.5.1): # 7.8.2 any default values in the key leafs or their types are ignored. # v non-presence container (presence false) DEFAULT # ancestor--> ancestor --> leaf --> default # ^leafs closest ancestor that is not a non-presence container # Test has three parts where system is started three times: # 1) with init # 2) with startup: r1 only # 3) with startup: p4 only # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example cfg=$dir/conf_yang.xml fyang=$dir/leafref.yang cat < $cfg $cfg ietf-netconf:startup $dir /usr/local/share/clixon $IETFRFC $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile $dir EOF cat < $fyang module example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; leaf r1 { description "Top level leaf"; type uint32; default 11; /* should be set */ } leaf r2 { description "Top level leaf"; type uint32; default 22; /* should be set on startup */ } container np3{ description "No presence container"; leaf s3 { type uint32; default 33; /* should be set on startup */ } container np31{ leaf s31 { type uint32; default 31; /* should be set on startup */ } } } container p4{ presence "A presence container"; description "Not a no presence container"; leaf s4 { type uint32; default 44; } container np45{ description "No presence container"; leaf s5 { type uint32; default 45; } } } container xs-config { description "Typical contruct where a list element has a default leaf"; list x { key "name"; leaf name { type string; } container y { leaf inside { type boolean; default false; } } leaf outside { type boolean; default false; } } } } EOF # This is base default XML with all default values from root filled in XML='11223331' new "test params: -f $cfg" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s init -f $cfg" start_backend -s init -f $cfg new "waiting" wait_backend fi new "get config" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^$XML]]>]]>$" new "Change default value r1" expecteof "$clixon_netconf -qf $cfg" 0 "99]]>]]>" "^]]>]]>$" new "get config r1" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^99]]>]]>$" new "Remove r1" expecteof "$clixon_netconf -qf $cfg" 0 "99]]>]]>" "^]]>]]>$" new "get config" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^$XML]]>]]>$" new "Set x list element" expecteof "$clixon_netconf -qf $cfg" 0 "a]]>]]>" "^]]>]]>$" new "get config (should contain y/inside+outside)" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^$XMLafalsefalse]]>]]>$" if [ $BE -ne 0 ]; then new "Kill backend" # Check if premature kill pid=$(pgrep -u root -f clixon_backend) if [ -z "$pid" ]; then err "backend already dead" fi # kill backend stop_backend -f $cfg fi # From startup 1, only r1, all else should be filled in SXML='99' cat < $dir/startup_db $SXML EOF XML='99223331' if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s startup -f $cfg" start_backend -s startup -f $cfg new "waiting" wait_backend fi new "get startup config" # Should have all defaults, except r1 that is set to 99 expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^$XML]]>]]>$" # permission kludges sudo chmod 666 $dir/running_db new "Check running no defaults: r1 only" # Running should have only non-defaults, ie only r1 that is set to 99 moreret=$(diff $dir/running_db <(echo " $SXML ")) if [ $? -ne 0 ]; then err "$SXML" "$moreret" fi new "Change default value r2" expecteof "$clixon_netconf -qf $cfg" 0 "88]]>]]>" "^]]>]]>$" new "commit" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" new "Check running no defaults: r1 and r2" # Again, running should have only non-defaults, ie only r1 and r2 moreret=$(diff $dir/running_db <(echo " $SXML 88 ")) if [ $? -ne 0 ]; then err "$SXML88" "$moreret" fi new "Kill backend" # Check if premature kill pid=$(pgrep -u root -f clixon_backend) if [ -z "$pid" ]; then err "backend already dead" fi # From startup 2, only presence p4, s4/np5 should be filled in cat < $dir/startup_db EOF XML='112233314445' if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s startup -f $cfg" start_backend -s startup -f $cfg new "waiting" wait_backend fi new "get startup config with presence" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^$XML]]>]]>$" new "Kill backend" # Check if premature kill pid=$(pgrep -u root -f clixon_backend) if [ -z "$pid" ]; then err "backend already dead" fi # Only single x list element cat < $dir/startup_db a EOF XML='11223331' if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s startup -f $cfg" start_backend -s startup -f $cfg new "waiting" wait_backend fi new "get startup config with list default" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^$XMLafalsefalse]]>]]>$" new "Kill backend" # Check if premature kill pid=$(pgrep -u root -f clixon_backend) if [ -z "$pid" ]; then err "backend already dead" fi rm -rf $dir