#!/usr/bin/env bash
# RFC 6241:
# 7.3 - Even if it advertises the :writable-running capability, a device
# MAY choose not to support the configuration datastore
# as the parameter of a operation.
# - If the and parameters identify the same URL or
# configuration datastore, an error MUST be returned with an error-
# tag containing "invalid-value".
# 8.3.5.1 The candidate configuration can be used as a source or target
# 8.4.1 If :startup capability is advertized, from running to
# startup is also necessary
# 8.8.5.2 :url capability accepts element as value of
# the and the parameters.
#
# The test checks that these are allowed:
# running->startup
# running->candidate
# candidate->startup
# startup->candidate
# And checks that copying to running is not allowed
# 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
# include err() and new() functions and creates $dir
cfg=$dir/conf_yang.xml
# Use yang in example
# Define default restconfig config: RESTCONFIG
RESTCONFIG=$(restconf_config none true)
cat < $cfg
$cfgietf-netconf:startupclixon-restconf:allow-auth-none42/usr/local/share/clixon$IETFRFCclixon-example/usr/local/lib/$APPNAME/clispec/usr/local/lib/$APPNAME/backendexample_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
$RESTCONFIG
EOF
# Create empty startup
cat < $dir/startup_db
<${DATASTORE_TOP}/>
EOF
# rm candidate and running
rm -f $dir/running_db
rm -f $dir/candidate_db
new "test params: -f $cfg"
# Bring your own backend
if [ $BE -ne 0 ]; then
# kill old backend (if any)
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 "wait backend"
wait_backend
fi
if [ $RC -ne 0 ]; then
new "kill old restconf daemon"
stop_restconf_pre
new "start restconf daemon"
start_restconf -f $cfg
new "wait restconf"
wait_restconf
fi
new "Add config to candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0ex:ethnone]]>]]>" "^]]>]]>$"
new "netconf commit to running"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
new "Delete candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0ex:ethnone]]>]]>" "^]]>]]>$"
# Here startup and candidate are empty, only running has content
# test running->startup and running->candidate
new "Check candidate empty"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
new "Check startup empty"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
new "copy running->startup"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
new "copy running->candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
# Here startup and candidate have content
new "Check candidate content"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^eth/0/0ex:ethtrue]]>]]>$"
new "Check startup content"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^eth/0/0ex:ethtrue]]>]]>$"
new "Delete startup"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
# Here startup is empty and candidate has content
# test candidate->startup
new "Check startup empty"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
new "copy candidate->startup"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
new "Check startup content"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^eth/0/0ex:ethtrue]]>]]>$"
new "Delete candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0ex:ethnone]]>]]>" "^]]>]]>$"
# Here candidate is empty and startup has content
# test startup->candidate
new "Check candidate empty"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
new "copy startup->candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
new "Check candidate content"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^eth/0/0ex:ethtrue]]>]]>$"
# Negative test: check copying to running is not allowed
new "Delete candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0ex:ethnone]]>]]>" "^]]>]]>$"
new "netconf commit to running"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
# Here running is empty
new "Check running empty"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
# Add to candidate
new "copy startup->candidate"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
if ! $YANG_UNKNOWN_ANYDATA ; then
new "copy startup->running not allowed"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationunknown-elementrunningerrorFailed to find YANG spec of XML node: running with parent: target in namespace: urn:ietf:params:xml:ns:netconf:base:1.0]]>]]>$"
fi
# restconf copy
new "restconf copy-config smoketest, json"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+json" $RCPROTO://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '{"ietf-netconf:input": {"target": {"startup": [null]},"source": {"running": [null]}}}')" 0 'HTTP/1.1 204 No Content'
new "restconf copy-config smoketest, xml"
expectpart "$(curl $CURLOPTS -X POST -H "Content-Type: application/yang-data+xml" $RCPROTO://127.0.0.1/restconf/operations/ietf-netconf:copy-config -d '')" 0 'HTTP/1.1 204 No Content'
# Here running is empty
new "Check running empty"
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$"
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
# Set by restconf_config
unset RESTCONFIG
new "Endtest"
endtest
rm -rf $dir