#!/usr/bin/env bash # Test plugin reset functionality # First go through all startup modes and modstate true/false and add a loopback XML # in reset # Then do the same with an outdated modstate requiring upgrade # 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@2020-01-01.yang changelog=$dir/changelog.xml # Module revision changelog # Create configuration cat < $cfg /usr/local/etc/clixon.xml *:* ietf-netconf:startup ${YANG_INSTALLDIR} $dir $fyang hello /usr/local/lib/hello/clispec /usr/local/var/hello.sock /usr/local/var/hello.pidfile /usr/local/lib/$APPNAME/backend $dir false false $changelog false EOF cat < $fyang module clixon-example { yang-version 1.1; namespace "urn:example:clixon"; prefix ex; revision 2020-01-01 { description "Clixon hello world example"; } revision 2010-01-01 { description "Clixon hello world example"; } container table{ list parameter{ key name; leaf name{ type string; } leaf value{ type string; } } } } EOF cat < $changelog urn:example:clixon 2010-01-01 2020-01-01 rename foo to value rename /ex:table/ex:parameter/ex:foo "value" EOF # Start and stop backend with reset function that adds extraxml # Args: # 1: db Startup db # 2: mode Startup mode (init, startup, running, none) # 3: modstate true: Add yang-lib modstate to sytartup file # 4: outdated true: Outdated modstate requires upgrade function testrun() { db=$1 mode=$2 modstate=$3 outdated=$4 if $outdated; then TAG=foo REV=2010-01-01 else TAG=value REV=2020-01-01 fi if [ -n "$db" ]; then sudo rm $dir/$db cat < $dir/$db <${DATASTORE_TOP}> x <$TAG>42
EOF if $modstate; then cat <> $dir/$db 42 default clixon-example $REV urn:example:clixon EOF fi cat <> $dir/$db EOF fi # 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 $mode -f $cfg -o CLICON_XMLDB_MODSTATE=$modstate -o CLICON_XML_CHANGELOG=$outdated -- -r" start_backend -s $mode -f $cfg -o CLICON_XMLDB_MODSTATE=$modstate -o CLICON_XML_CHANGELOG=$outdated -- -r fi new "wait backend" wait_backend if [ -n "$db" ]; then XMLDB="x42" else XMLDB="" fi XML="loopback99$XMLDB
" new "get config" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "$XML" 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 } new "test params: -f $cfg" new "Startup and modstate" testrun startup_db startup true false new "Startup and no modstate" testrun startup_db startup false false new "Running and modstate" testrun running_db running true false new "Running and no modstate" testrun running_db running false false new "Init and modstate" testrun "" init true false new "Init and no modstate" testrun "" init false false new "None and modstate" testrun "" none true false new "None and no modstate" testrun "" none false false new "Startup and old modstate" testrun startup_db startup true true new "Running and old modstate" testrun running_db running true true new "Init and old modstate" testrun "" init true true new "None and modstate" testrun "" none true true rm -rf $dir new "endtest" endtest