#!/usr/bin/env bash # Yang list unique tests # Use example in RFC7890 7.8.3.1, modify fields and also test a variant with # a single unique identifier (rfc example has two) # The test adds the rfc conf that fails, then one that passes, then makes add # to fail it and then del to pass it. # Then makes a fail / pass test on the single field case # Last, a complex unsorted list with several sub-elements. # 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/unique.yang cat < $cfg $cfg /usr/local/share/clixon $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF # Example (the list server part) from RFC7950 Sec 7.8.3.1 w changed types cat < $fyang module unique{ yang-version 1.1; namespace "urn:example:clixon"; prefix un; container c{ leaf a{ type string; } list server { description "RFC7950 7.8.3.1"; key "name"; unique "ip port"; leaf name { type string; } leaf ip { type string; } leaf port { type uint16; } } list other { description "random inserted data"; key a; leaf a{ type string; } } list single { description "similar with just a single unique field"; key "name"; unique "ip"; leaf name { type string; } leaf ip { type string; } } leaf b{ type string; } } } 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 new backend start_backend -s init -f $cfg new "waiting" wait_backend fi # RFC test two-field caes new "Add not valid example" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOreplace smtp 192.0.2.1 25 http 192.0.2.1 25 ]]>]]>" "^]]>]]>$" new "netconf validate (should fail)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationoperation-faileddata-not-uniqueerror192.0.2.125]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "Add valid example" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOreplace smtp 192.0.2.1 25 http 192.0.2.1 ftp 192.0.2.1 ]]>]]>" "^]]>]]>$" new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "make it invalid by adding port to ftp entry" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnoneftp25 ]]>]]>" "^]]>]]>$" new "netconf validate (should fail)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationoperation-faileddata-not-uniqueerror192.0.2.125]]>]]>$" new "make it valid by deleting port from smtp entry" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnonesmtp25 ]]>]]>" "^]]>]]>$" new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" # Then test single-field case new "Add not valid example" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOreplace smtp 192.0.2.1 http 192.0.2.1 ]]>]]>" "^]]>]]>$" new "netconf validate (should fail)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationoperation-faileddata-not-uniqueerror192.0.2.1]]>]]>$" new "make valid by replacing IP of http entry" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnonehttp178.23.34.1 ]]>]]>" "^]]>]]>$" new "netconf validate ok" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" # Then test composite case (detect duplicates among other elements) # and also unordered new "Add not valid example" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOreplace other smtp 192.0.2.1 other smtp 192.0.2.1 25 http 192.0.2.1 xx http 192.0.2.1 25 ]]>]]>" "^]]>]]>$" new "netconf validate (should fail)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^applicationoperation-faileddata-not-uniqueerror192.0.2.125]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" 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