#!/usr/bin/env bash # Detect duplicates in incoming edit-configs (not top-level) # Both list and leaf-list # See https://github.com/clicon/clixon-controller/issues/107 # Also, check CLICON_NETCONF_DUPLICATE_ALLOW # 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{ presence "trigger"; // force presence container to trigger error list server { description ""; key "name"; leaf name { type string; } leaf value { type string; } } list user { description ""; ordered-by user; key "name"; leaf name { type string; } leaf value { type string; } } leaf-list 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 new "Add list entry" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "merge one foo " "" "" new "Add duplicate list entries" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "none one bar one fie " "" "applicationoperation-faileddata-not-uniqueerror/rpc/edit-config/config/c/server[name=\"one\"]/name" new "Add list with duplicate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace one foo one foo " "" "applicationoperation-faileddata-not-uniqueerror/rpc/edit-config/config/c/server[name=\"one\"]/name" new "Add user sorted list with duplicate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace one foo two bar one foo " "" "applicationoperation-faileddata-not-uniqueerror/rpc/edit-config/config/c/user[name=\"one\"]/name" new "Add leaf-list with duplicate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace one two one " "" "applicationoperation-faileddata-not-uniqueerror/rpc/edit-config/config/c/b[.=\"one\"]/one" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi fi # Check CLICON_NETCONF_DUPLICATE_ALLOW if [ $BE -ne 0 ]; then new "start backend -s init -f $cfg" # start new backend start_backend -s init -f $cfg -o CLICON_NETCONF_DUPLICATE_ALLOW=true fi new "Wait backend 2" wait_backend new "Add list with duplicate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace bbb foo bbb bar " "" "" new "Check no duplicates" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "bbbbar" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Add complex list with duplicate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace aaa foo bbb foo ccc foo bbb bar ccc bar bbb fie ddd foo " "" "" new "Check complex no duplicates" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "aaafoobbbfiecccbardddfoo" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Add user sorted list with duplicate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace aaa foo bbb foo ccc foo bbb bar ccc bar bbb fie ddd foo " "" "" new "Check user sorted no duplicates" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "aaafoocccbarbbbfiedddfoo" new "netconf discard-changes" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Add leaf-list with duplicate" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "replace aaa aaa bbb " "" "" new "Check leaf-list no duplicates" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "aaabbb" 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