#!/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 ${YANG_INSTALLDIR} $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/run/$APPNAME.sock /usr/local/var/run/$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 fi new "wait backend" wait_backend # RFC test two-field case new "Add not valid example" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace smtp 192.0.2.1 25 http 192.0.2.1 25 " "" "applicationoperation-faileddata-not-uniqueerror/rpc/edit-config/config/c/server[name=\"http\"]/ip/rpc/edit-config/config/c/server[name=\"http\"]/port" new "Add valid example" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace smtp 192.0.2.1 25 http 192.0.2.1 ftp 192.0.2.1 " "" "" new "netconf validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "make it invalid by adding port to ftp entry" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "noneftp25 " "" "" new "netconf validate (should fail)" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationoperation-faileddata-not-uniqueerror/c/server[name=\"smtp\"]/ip/c/server[name=\"smtp\"]/port" new "make it valid by deleting port from smtp entry" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "nonesmtp25 " "" "" new "netconf validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" # Then test single-field case new "Add not valid example: 1st single" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace smtp 192.0.2.1 " "" "" new "Add not valid example: 2nd single" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "merge http 192.0.2.1 " "" "" new "netconf validate (should fail) 2nd" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationoperation-faileddata-not-uniqueerror/c/single[name=\"smtp\"]/ip" new "make valid by replacing IP of http entry" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "nonehttp178.23.34.1 " "" "" new "netconf validate ok" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" # Then test composite case (detect duplicates among other elements) # and also unordered new "Add not valid example3" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace 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 " "" "applicationoperation-faileddata-not-uniqueerror/rpc/edit-config/config/c/server[name=\"smtp\"]/ip/rpc/edit-config/config/c/server[name=\"smtp\"]/port" 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