#!/usr/bin/env bash # Default handling and datastores. # There was a bug with loading startup and writing it back to candidate/running # where default mode in startup being "explicit" was transformed to "report-all" # according to RFC 6243. # Ie, all default values were populated. # Also: Check default values and xpaths # 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/example-default.yang cat < $cfg $cfg ietf-netconf:startup 42 ${YANG_INSTALLDIR} $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/backend example_backend.so$ /usr/local/lib/$APPNAME/netconf /usr/local/lib/$APPNAME/restconf /usr/local/lib/$APPNAME/cli $APPNAME $dir/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile $dir false EOF cat < $fyang module example-default { namespace "urn:example:default"; prefix "ex"; typedef def { description "Just a base type with a default value of 42"; type int32; default 42; } container a{ leaf d0 { description "container default"; type int32; default 88; } list b { key c; leaf c{ type string; } leaf d1 { description "direct default"; type string; default "foo"; } leaf d2 { /* <-- ys */ description "default in type"; type def; } } } } EOF # Initial data (default y not given) XML='0' db=startup if [ $db = startup ]; then sudo echo "<${DATASTORE_TOP}>$XML" > $dir/startup_db fi if [ $BE -ne 0 ]; then # Bring your own backend new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend -s $db -f $cfg" start_backend -s $db -f $cfg fi new "wait backend" wait_backend # permission kludges new "chmod datastores" sudo chmod 666 $dir/running_db if [ $? -ne 0 ]; then err1 "chmod $dir/running_db" fi sudo chmod 666 $dir/startup_db if [ $? -ne 0 ]; then err1 "chmod $dir/startup_db" fi new "Checking startup unchanged" ret=$(diff $dir/startup_db <(echo "<${DATASTORE_TOP}>$XML")) if [ $? -ne 0 ]; then err "<${DATASTORE_TOP}>$XML" "$ret" fi new "Checking running unchanged" ret=$(diff $dir/running_db <(echo -n "<${DATASTORE_TOP}>$XML")) if [ $? -ne 0 ]; then err "<${DATASTORE_TOP}>$XML" "$ret" fi new "check running defaults (report-all)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "880foo42" new "check running defaults" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "0" new "delete existing list element" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "0" "" "" new "netconf commit" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "set new list element" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "17" "" "" new "get the list top (report-all)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "8817foo42" new "get the list top" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "17" new "get the list xpath /a (report-all)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "8817foo42" new "get the list xpath /a" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "17" new "get the list xpath /a/b (report-all)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "17foo42" new "get the list xpath /a/b" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "17" new "get the list xpath /a/b/c (report-all)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "17" new "get the list xpath /a/b/c" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "17" new "get the list xpath /a/b/c=17 (report-all)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all17" "" "17foo42" new "get the list xpath /a/b/c=17" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "17" "" "17" new "get the list xpath /a/b/c=17/d1 (report-all)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all17" "" "17foo" new "get the list xpath /a/b/c=17/d1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "17" "" "17" if [ $BE -ne 0 ]; then # Bring your own backend 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 rm -rf $dir unset ret new "endtest" endtest