#!/usr/bin/env bash # Basic Netconf functionality # Mainly default/null prefix, but also xx: prefix # XXX: could add tests for dual prefixes xx and xy with doppelganger names, ie xy:filter that is # syntactic correct but wrong # 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 tmp=$dir/tmp.x # Use yang in example cat < $cfg $cfg ietf-netconf:startup 42 /usr/local/share/clixon $IETFRFC clixon-example /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/backend example_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 /usr/local/var/$APPNAME true EOF new "test params: -f $cfg -- -s" # 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 -- -s" start_backend -s init -f $cfg -- -s new "waiting" wait_backend fi # Framing. with -q to inhibit rcv hello new "Empty frame" expecteof "$clixon_netconf -qf $cfg" 0 ']]>]]>' 'rpcoperation-failederrorEmpty XML]]>]]>' if [ $valgrindtest -eq 0 ]; then # Some leakage in lex / error handling difficult to catch new "Frame invalid non-xml" expecteof "$clixon_netconf -qf $cfg" 0 "This is not XML]]>]]>" 'rpcoperation-failederrorxml_parse: line 0: syntax error: at or before: This]]>]]>' 2> /dev/null fi new "Frame with two messages" expecteof "$clixon_netconf -qf $cfg" 0 "urn:ietf:params:netconf:base:1.1]]>]]>" 'rpcmalformed-messageerrorMore than one message in netconf rpc frame]]>]]>' new "Frame with unknown message" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^protocolunknown-elementxxxerrorUnrecognized netconf operation]]>]]>$" new "netconf rcv hello, disable RFC7895/ietf-yang-library" expecteof "$clixon_netconf -f $cfg -o CLICON_MODULE_LIBRARY_RFC7895=0" 0 "$DEFAULTHELLO]]>]]>" "^urn:ietf:params:netconf:base:1.1urn:ietf:params:netconf:base:1.0urn:ietf:params:netconf:capability:candidate:1.0urn:ietf:params:netconf:capability:validate:1.1urn:ietf:params:netconf:capability:startup:1.0urn:ietf:params:netconf:capability:xpath:1.0urn:ietf:params:netconf:capability:notification:1.0[0-9]*]]>]]>]]>]]>$" new "netconf get-config nc prefix" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf get-config xx prefix" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf get-config double quotes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf get-config single quotes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "Add subtree eth/0/0 using none which should not change anything" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnoneeth/0/0]]>]]>" "^]]>]]>$" # Trying prefixes new "Add subtree eth/0/0 using nc prefix" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnoneeth/0/0]]>]]>" "^]]>]]>$" new "Add subtree eth/0/0 using xx prefix" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnoneeth/0/0]]>]]>" "^]]>]]>$" new "Check nothing added" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "Add subtree eth/0/0 using none and create which should add eth/0/0" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0ex:ethnone ]]>]]>" "^]]>]]>$" # Too many quotes, (single inside double inside single) need to fool bash cat < $tmp # new $DEFAULTHELLO]]>]]> EOF new "Check eth/0/0 added using xpath" expecteof "$clixon_netconf -qf $cfg" 0 "$(cat $tmp)" "^eth/0/0ex:ethtrue]]>]]>$" new "Re-create same eth/0/0 which should generate error" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0ex:ethnone ]]>]]>" "^" new "Delete eth/0/0 using none config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0ex:ethnone ]]>]]>" "^]]>]]>$" new "Check deleted eth/0/0 (non-presence container)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "Re-Delete eth/0/0 using none should generate error" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0ex:ethnone ]]>]]>" "^" new "Add interface without key" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOex:ethnone ]]>]]>" "^applicationmissing-elementnameerrorMandatory key]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf discard-changes using xx prefix" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf edit config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0eth1true9.2.3.424]]>]]>" "^]]>]]>$" # Too many quotes cat < $tmp # new $DEFAULTHELLO]]>]]> EOF new "netconf get config xpath" expecteof "$clixon_netconf -qf $cfg" 0 "$(cat $tmp)" "^eth1true]]>]]>$" # Too many quotes cat < $tmp # new $DEFAULTHELLO]]>]]> EOF new "netconf get config xpath parent" expecteof "$clixon_netconf -qf $cfg" 0 "$(cat $tmp)" "^eth/0/0trueeth1truetruefalse9.2.3.424]]>]]>$" new "netconf validate missing type" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^" new "netconf validate using xx prefix" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf get empty config2" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf edit extra xml" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf edit config eth1" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth1ex:eth]]>]]>" "^]]>]]>$" new "netconf validate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf commit using prefix xx" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf edit config merge eth2" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth2ex:ethmerge]]>]]>" "^]]>]]>$" # Note, the type here is non-existant identityref, fails on validation new "netconf edit ampersand encoding(<&): name:'eth&' type:'t<>'" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth&t<>]]>]]>" "^]]>]]>$" new "netconf get replaced config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^eth&t<>trueeth1ex:ethtrueeth2ex:ethtrue]]>]]>$" new "cli show configuration eth& - encoding tests" expectpart "$($clixon_cli -1 -f $cfg show conf cli)" 0 "interfaces interface eth& type t<> interfaces interface eth& enabled true" new "netconf edit CDATA" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOeth/0/0ex:eth]]>]]>" "^]]>]]>$" #new "netconf get CDATA" #expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "eth/0/0true]]>]]>" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf edit state operation should fail" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOe0up]]>]]>" "^applicationbad-elementoper-statuserrormodule ietf-interfaces: state data node unexpected]]>]]>" new "netconf get state operation" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^eth1ex:ethtrueup42foo]]>]]>$" new "netconf get state operation use prefix xx" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^eth1ex:ethtrueup42foo]]>]]>$" new "netconf lock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf unlock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^protocollock-denied0errorUnlock failed, lock is not currently active]]>]]>$" new "netconf lock using prefix xx" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf unlock using prefix xx" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^protocollock-denied0errorUnlock failed, lock is not currently active]]>]]>$" new "netconf lock/unlock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>]]>]]>" "^]]>]]>]]>]]>$" new "netconf lock/unlock/lock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>]]>]]>]]>]]>" "^]]>]]>]]>]]>]]>]]>$" new "netconf lock/lock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>]]>]]>" "^]]>]]>protocollock-denied" new "netconf unlock/unlock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>]]>]]>" "^protocollock-denied0errorUnlock failed, lock is not currently active]]>]]>protocollock-denied0errorUnlock failed, lock is not currently active]]>]]>$" new "close-session" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "close-session using prefix xx" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" # XXX NOTE that this does not actually kill a running session - and may even kill some random process,... new "kill-session" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO44]]>]]>" "^]]>]]>$" new "kill-session using prefix xx" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO44]]>]]>" "^]]>]]>$" # modify candidate, then lock, should fail. new "netconf edit config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOa
]]>]]>" "^]]>]]>$" new "netconf lock: should fail" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^protocollock-denied0errorOperation failed, candidate has already been modified and the changes have not been committed or rolled back (RFC 6241 7.5)]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf lock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "copy startup to candidate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "copy startup to candidate using prefix xx" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf get startup" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^eth1ex:ethtrue]]>]]>$" new "netconf delete startup" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf delete startup using prefix xx" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf check empty startup" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf example rpc" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO42]]>]]>" "^4242]]>]]>$" new "netconf example rpc using prefix xx" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO42]]>]]>" "^4242]]>]]>$" new "netconf empty rpc" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf client-side rpc" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOval42]]>]]>" "^val42]]>]]>$" new "netconf extra leaf in leaf should fail" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOe0e1]]>]]>" "^applicationunknown-elementnameerrorFailed to find YANG spec of XML node: name with parent: name in namespace: urn:ietf:params:xml:ns:yang:ietf-interfaces]]>]]>$" 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