* Restconf with startup feature will now copy all edit changes to startup db (as it should according to RFC 8040)
* See [Restconf does not handle startup datastore according to the RFC](https://github.com/clicon/clixon/issues/74) * Netconf Startup feature is no longer hardcoded, you need to explicitly enable it (See RFC 6241, Section 8.7) * Enable in config file with: `<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>`, or use `*:*`
This commit is contained in:
parent
161ef9c7b0
commit
6bf2a74e24
26 changed files with 270 additions and 128 deletions
126
test/test_restconf_startup.sh
Executable file
126
test/test_restconf_startup.sh
Executable file
|
|
@ -0,0 +1,126 @@
|
|||
#!/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 <<EOF > $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 <<EOF > $cfg
|
||||
<clixon-config xmlns="http://clicon.org/config">
|
||||
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP>
|
||||
<CLICON_RESTCONF_DIR>/usr/local/lib/$APPNAME/restconf</CLICON_RESTCONF_DIR>
|
||||
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_XMLDB_DIR>$dir</CLICON_XMLDB_DIR>
|
||||
</clixon-config>
|
||||
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"
|
||||
sleep $RCWAIT
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue