#!/bin/bash # Test restconf :startup # RFC 8040 Sec 1.4 says: # the NETCONF server supports :startup, the RESTCONF server MUST # automatically update the non-volatile startup configuration # datastore, after the "running" datastore has been altered as a # consequence of a RESTCONF edit operation. # 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.xml fyang=$dir/example.yang cat < $fyang module example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ip; container x { list y { key "a"; leaf a { type string; } leaf b { type string; } } } } EOF # Use yang in example cat < $cfg $cfg /usr/local/share/clixon /usr/local/lib/$APPNAME/backend example_backend.so$ /usr/local/lib/$APPNAME/restconf /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile $dir EOF testrun(){ option=$1 new "test params: -f $cfg -y $fyang $option" 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 -y $fyang $option" start_backend -s init -f $cfg -y $fyang $option fi new "kill old restconf daemon" sudo pkill -u www-data clixon_restconf new "start restconf daemon" start_restconf -f $cfg -y $fyang $option new "waiting" wait_backend wait_restconf new "restconf put 42" expecteq "$(curl -s -X PUT http://localhost/restconf/data/example:x/y=42 -d '{"example:y":{"a":"42","b":"42"}}')" 0 "" new "restconf put 99" expecteq "$(curl -s -X PUT http://localhost/restconf/data/example:x/y=99 -d '{"example:y":{"a":"99","b":"99"}}')" 0 "" new "restconf post 123" expecteq "$(curl -s -X POST http://localhost/restconf/data/example:x -d '{"example:y":{"a":"123","b":"123"}}')" 0 "" new "restconf delete 42" expecteq "$(curl -s -X DELETE http://localhost/restconf/data/example:x/y=42)" 0 "" new "Kill restconf daemon" stop_restconf 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 } # clear startup sudo rm -f $dir/startup_db; new "Run with startup option, check running is copied" testrun "-o CLICON_FEATURE=ietf-netconf:startup" new "Check running and startup exists and are same" if [ ! -f $dir/startup_db ]; then err "startup should exist but does not" fi echo "diff $dir/startup_db $dir/running_db" d=$(sudo diff $dir/startup_db $dir/running_db) if [ -n "$d" ]; then err "running and startup should be equal" "$d" fi # clear startup sudo rm -f $dir/startup_db; new "Run without startup option, check running is copied" testrun "" new "Check startup should not exist" if [ -f $dir/startup_db ]; then err "startup should not exist" fi rm -rf $dir