#!/usr/bin/env bash # Test two modules example1 and example2 with overlapping statements x. # x is leaf in example1 and list on example2. # Test netconf and restconf # BTW, this is not supported in generated CLI # 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 fyang1=$dir/example1.yang fyang2=$dir/example2.yang # Define default restconfig config: RESTCONFIG RESTCONFIG=$(restconf_config none false) cat < $cfg $cfg clixon-restconf:allow-auth-none $dir ${YANG_INSTALLDIR} /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME $RESTCONFIG EOF cat < $fyang1 module example1{ yang-version 1.1; prefix ex1; namespace "urn:example:clixon1"; leaf x{ type int32; } } EOF # For testing namespaces - # x.y is different type. Here it is string whereas in fyang1 it is list. # cat < $fyang2 module example2{ yang-version 1.1; prefix ex2; namespace "urn:example:clixon2"; container x { leaf y { type uint32; } } } EOF 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 fi new "wait backend" wait_backend if [ $RC -ne 0 ]; then new "kill old restconf daemon" stop_restconf_pre new "start restconf daemon" start_restconf -f $cfg fi new "wait restconf" wait_restconf new "netconf set x in example1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "42" "" "" new "netconf get config example1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "42" new "netconf set x in example2" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "99" "" "" new "netconf get config example1 and example2" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "4299" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "restconf set x in example1" expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d '{"example1:x":42}' $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 201" new "restconf get config example1" expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example1:x)" 0 "HTTP/$HVER 200" '{"example1:x":42}' new "restconf set x in example2" expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" -d '{"example2:x":{"y":99}}' $RCPROTO://localhost/restconf/data)" 0 "HTTP/$HVER 201" # XXX GET ../example1:x is translated to select=/x which gets both example1&2 #new "restconf get config example1" #expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example1:x)" 0 "HTTP/$HVER 200" '{"example1:x":42}' # XXX GET ../example2:x is translated to select=/x which gets both example1&2 #new "restconf get config example2" #expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/example2:x)" 0 "HTTP/$HVER 200" '{"example2:x":{"y":42}}' new "restconf get config example1 and example2" ret=$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data) expect='"example1:x":42,"example2:x":{"y":99}' match=`echo $ret | grep "$expect"` if [ -z "$match" ]; then err "$expect" "$ret" fi if [ $RC -ne 0 ]; then new "Kill restconf daemon" stop_restconf fi 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 rm -rf $dir new "endtest" endtest