#!/usr/bin/env bash # Test for RFC6022 YANG Module for NETCONF Monitoring # See eg Examples: # 4.1. Retrieving Schema List via Operation # 4.2. Retrieving Schema Instances # Also: loop over all installed yang files and compare with get-schema # 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/clixon-example@2022-01-01.yang fyangsub=$dir/clixon-sub@2022-01-01.yang cat < $cfg $cfg ${YANG_INSTALLDIR} ${dir} $fyang false /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/$APPNAME/backend /usr/local/var/$APPNAME/$APPNAME.pidfile $dir true EOF cat < $fyang module clixon-example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; include clixon-sub; revision 2022-01-01; } EOF cat < $fyangsub submodule clixon-sub{ yang-version 1.1; belongs-to clixon-example { prefix ex; } revision 2022-01-01; } EOF new "test params: -f $cfg" 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" start_backend -s init -f $cfg fi new "wait backend" wait_backend new "Retrieving all state via operation" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "urn:ietf:params:netconf:base:1.0urn:ietf:params:netconf:base:1.1.*urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring.*candidaterunning.*.*.*" # send multiple frames using locks for more interesting datastore stat rpc=$(chunked_framing "") rpc="${rpc} $(chunked_framing "candidate")" new "Get databases with lock" ret=$($clixon_netconf -q -f $cfg <" "candidate[0-9]+202.*Z Operation # match bith module and sub-module # 2.1.3 new "Retrieving Schema List via Operation" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "clixon-example2022-01-01yangurn:example:clixonNETCONF.*clixon-sub2022-01-01yangurn:example:clixonNETCONF.*" # Session 2.1.4 new "Retrieve Session" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "[1-9][0-9]*cl:netconf.*.*[0-9][0-9]*[0-9][0-9]*[0-9][0-9]*[0-9][0-9]*.*" # Statistics 2.1.5 new "Retrieve Statistics" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "20[0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\.[0-9]*Z[0-9]\+[1-9][0-9]*[0-9]\+[1-9][0-9]*[0-9]\+[0-9]\+[0-9]\+" # 4.2. Retrieving Schema Instances # From 2b. bar, version 2008-06-1 in YANG format, via get-schema new "Retrieving clixon-example schema instance using id, version, format" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "clixon-example2022-01-01yang" "module clixon-example{" new "Retrieving clixon-example schema instance using id, version only" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "clixon-example2022-01-01" "module clixon-example{" new "Retrieving clixon-example schema instance using id only" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "clixon-example" "module clixon-example{" new "Retrieving ietf-inet-types schema" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "ietf-inet-types" "module ietf-inet-types {" # Negative tests new "get-schema: no id" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "applicationmissing-elementidentifiererrorMandatory variable of get-schema in module ietf-netconf-monitoring" new "get-schema: non-existing schema" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "not-found" "protocolinvalid-valueerrorNo schema matching: not-found" new "get-schema: non-existing format" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "clixon-example2022-01-01xsd" "protocolinvalid-valueerrorFormat not supported: xsd" new "get-schema: non-existing date" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "clixon-example2013-01-01yang" "protocolinvalid-valueerrorNo schema matching: clixon-example@2013-01-01" 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 # for some reason valgrind tests fail below? if [ ${valgrindtest} -eq 0 ]; then # Error dont cleanup mem OK # XXX there may be inconsistent YANGs in this dir YANGDIR=$YANG_INSTALLDIR if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg -o CLICON_YANG_MAIN_DIR=$YANGDIR -o CLICON_YANG_MAIN_FILE=$fyang" start_backend -s init -f $cfg -o CLICON_YANG_MAIN_DIR=$YANGDIR fi new "wait backend" wait_backend new "Loop over all yangs in $YANGDIR" for f in ${YANGDIR}/*.yang; do b=$(basename $f) id=$(echo "$b" | sed 's/.yang//' | sed 's/@.*//') version=$(echo "$b" | sed 's/.yang//' | sed 's/.*@//') $clixon_netconf -qf $cfg < $dir/ex.yang $HELLONO11 $id $version yang ]]>]]> EOF grep "" $dir/ex.yang > /dev/null if [ $? -eq 0 ]; then continue fi # Mask netconf header and footer sed -i -e "s///" $dir/ex.yang sed -i -e 's/<\/data><\/rpc-reply>]]>]]>//' $dir/ex.yang # Decode XML sed -i -e 's/>/>/g' $dir/ex.yang sed -i -e 's/</