#!/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 fyang=$dir/clixon-example.yang # Use yang in example cat < $cfg $cfg ietf-netconf:startup ietf-netconf:confirmed-commit 42 $dir ${YANG_INSTALLDIR} $IETFRFC $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/backend example_backend.so$ /usr/local/lib/$APPNAME/netconf false /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 cat < $fyang module clixon-example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; import ietf-interfaces { prefix if; } import ietf-ip { prefix ip; } /* Example interface type for tests, local callbacks, etc */ identity eth { base if:interface-type; } /* Generic config data */ container table{ list parameter{ key name; leaf name{ type string; } } } /* State data (not config) for the example application*/ container state { config false; description "state data for the example application (must be here for example get operation)"; leaf-list op { type string; } } augment "/if:interfaces/if:interface" { container my-status { config false; description "For testing augment+state"; leaf int { type int32; } leaf str { type string; } } } rpc client-rpc { description "Example local client-side RPC that is processed by the the netconf/restconf and not sent to the backend. This is a clixon implementation detail: some rpc:s are better processed by the client for API or perf reasons"; input { leaf x { type string; } } output { leaf x { type string; } } } rpc empty { description "Smallest possible RPC with no input or output sections"; } rpc example { description "Some example input/output for testing RFC7950 7.14. RPC simply echoes the input for debugging."; input { leaf x { description "If a leaf in the input tree has a 'mandatory' statement with the value 'true', the leaf MUST be present in an RPC invocation."; type string; mandatory true; } leaf y { description "If a leaf in the input tree has a 'mandatory' statement with the value 'true', the leaf MUST be present in an RPC invocation."; type string; default "42"; } } output { leaf x { type string; } leaf y { type string; } } } } 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 fi new "wait backend" wait_backend # Framing. with -q to inhibit rcv hello new "Empty frame" expecteof_netconf "$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 "Frame without message-id attribute" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "^rpcmissing-attributemessage-iderrorIncoming rpc$" #urn:ietf:params:netconf:base:1.1 new "netconf rcv hello, disable RFC7895/ietf-yang-library" expecteof_netconf "$clixon_netconf -f $cfg -o CLICON_YANG_LIBRARY=0" 0 "$DEFAULTHELLO" "" "" "" new "netconf get-config nc prefix" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf get-config xx prefix" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf get-config double quotes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf get-config single quotes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Add subtree eth/0/0 using none which should not change anything" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "noneeth/0/0" "" "" # Trying prefixes new "Add subtree eth/0/0 using nc prefix" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "noneeth/0/0" "" "" new "Add subtree eth/0/0 using xx prefix" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "noneeth/0/0" "" "" new "Check nothing added" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Add subtree eth/0/0 using none and create which should add eth/0/0" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "eth/0/0ex:ethnone " "" "" # Too many quotes, (single inside double inside single) need to fool bash rpc=$(chunked_framing "") cat < $tmp # new $DEFAULTHELLO$rpc EOF new "Check eth/0/0 added using xpath" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$rpc" "" "eth/0/0ex:eth" new "Re-create same eth/0/0 which should generate error" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "eth/0/0ex:ethnone " "" "" new "Delete eth/0/0 using none config" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "eth/0/0ex:ethnone " "" "" new "Check deleted eth/0/0 (non-presence container)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Re-Delete eth/0/0 using none should generate error" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "eth/0/0ex:ethnone " "" "" new "Add interface without key" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "ex:ethnone " "" "applicationmissing-elementnameerrorMandatory key in 'list interface' in ietf-interfaces.yang:107" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf discard-changes using xx prefix" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf edit config" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "eth/0/0eth1true9.2.3.424" "" "" rpc="" new "netconf get config xpath" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$rpc" "" "eth1true" rpc="" new "netconf get config xpath parent" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$rpc" "" "eth/0/0eth1true
9.2.3.424
" new "netconf validate missing type" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf validate using xx prefix" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf get empty config2" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf edit extra xml" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf edit config eth1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "eth1ex:eth" "" "" new "netconf validate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf commit" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf commit using prefix xx" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf edit config merge eth2" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "eth2ex:ethmerge" "" "" # Note, the type here is non-existant identityref, fails on validation new "netconf edit ampersand encoding(<&): name:'eth&' type:'t<>'" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "eth&t<>" "" "" new "netconf get replaced config" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "eth&t<>eth1ex:etheth2ex:eth" new "netconf get replaced config (report-all)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "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_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "eth/0/0ex:eth" "" "" #new "netconf get CDATA" #expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "eth/0/0true" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf edit state operation should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "e0up" "" "applicationbad-elementoper-statuserrormodule ietf-interfaces: state data node unexpected" new "netconf get state operation" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "eth1ex:ethup42foo" new "netconf get state operation use prefix xx" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "eth1ex:ethup42foo" new "netconf lock" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf unlock" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocollock-denied0errorUnlock failed, lock is not currently active" new "netconf lock using prefix xx" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf unlock using prefix xx" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocollock-denied0errorUnlock failed, lock is not currently active" # send multiple frames rpc=$(chunked_framing "") rpc="${rpc} $(chunked_framing "")" reply=$(chunked_framing "") rpc="${rpc} $(chunked_framing "")" new "netconf lock/unlock/lock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO$rpc" "$reply" rpc=$(chunked_framing "") rpc="${rpc} $(chunked_framing "")" new "netconf lock/lock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO$rpc" "protocollock-denied") rpc="${rpc} $(chunked_framing "")" new "netconf unlock/unlock" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO$rpc" "protocollock-denied0errorUnlock failed, lock is not currently active" new "close-session" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "close-session using prefix xx" expecteof_netconf "$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_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "44" "" "" new "kill-session using prefix xx" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "44" "" "" new "asynchronous lock running" sleep 60 | cat <(echo "$HELLONO11]]>]]>") -| $clixon_netconf -qf $cfg >> /dev/null & if [ $valgrindtest -eq 1 ]; then sleep 1 fi PIDS=($(jobs -l % | cut -c 6- | awk '{print $1}')) new "try commit should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "protocolin-useerrorOperation failed, lock is already held" new "soft kill ${PIDS[0]}" kill ${PIDS[0]} # kill the while loop above to close STDIN on 1st new "asynchronous confirmed commit" sleep 60 | cat <(echo "$HELLONO1160]]>]]>") -| $clixon_netconf -qf $cfg >> /dev/null & PIDS=($(jobs -l % | cut -c 6- | awk '{print $1}')) new "try lock should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "protocollock-denied[0-9]*errorOperation failed, " new "soft kill ${PIDS[0]}" kill ${PIDS[0]} # kill the while loop above to close STDIN on 1st new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" # modify candidate, then lock, should fail. new "netconf edit config" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "a
" "" "" new "netconf lock: should fail" expecteof_netconf "$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_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf lock" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "copy startup to candidate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "copy startup to candidate using prefix xx" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf get startup" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "eth1ex:eth" new "netconf delete startup" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf delete startup using prefix xx" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf check empty startup" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf example rpc" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "42" "" "4242" new "netconf example rpc using prefix xx" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "42" "" "4242" new "netconf empty rpc" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf client-side rpc" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "val42" "" "val42" new "netconf extra leaf in leaf should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "e0e1" "" "applicationunknown-elementnameerrorFailed to find YANG spec of XML node: name with parent: name in namespace: urn:ietf:params:xml:ns:yang:ietf-interfaces" # Negative tests new "netconf xpath syntax error (api-path not xpath) should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationoperation-failederrorxpath parser on line 1: syntax error at or before: ','" new "netconf xpath syntax error" rpc="" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$rpc" "" "applicationoperation-failederrorxpath parser on line 1: syntax error at or before: ']'" new "netconf not found xpath should fail" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf xpath mixed types" rpc="@er='x']\" xmlns:if=\"urn:ietf:params:xml:ns:yang:ietf-interfaces\"/>" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$rpc" "" "applicationoperation-failederrorGet candidate datastore: Mixed types not supported, 1 3" 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