#!/bin/bash # Order test. test ordered-by user and ordered-by system. # For each leaf and leaf-lists, there are two lists, # one ordered-by user and one ordered by system. # The ordered-by user MUST be the order it is entered. # No test of ordered-by system is done yet # (we may want to sort them alphabetically for better performance). # 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/order.yang tmp=$dir/tmp.x # For memcheck # clixon_netconf="valgrind --leak-check=full --show-leak-kinds=all clixon_netconf" dbdir=$dir/order rm -rf $dbdir if [ ! -d $dbdir ]; then mkdir $dbdir fi cat < $cfg /tmp/conf_yang.xml /usr/local/share/clixon $IETFRFC /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/lib/example/backend /usr/local/var/$APPNAME/$APPNAME.pidfile $dbdir /usr/local/lib/xmldb/text.so EOF cat < $fyang module order-example{ yang-version 1.1; namespace "urn:example:order"; prefix ex; import clixon-example { /* for state callback */ prefix ex; } container c{ leaf d{ type string; } } leaf l{ type string; } leaf-list y0 { ordered-by user; type string; } leaf-list y1 { ordered-by system; type string; } list y2 { ordered-by user; key "k"; leaf k { type string; } leaf a { type string; } } list y3 { ordered-by system; key "k"; leaf k { type string; } leaf a { type string; } } container types{ description "For testing ordering using other types than strings"; leaf-list strings{ type string; ordered-by system; } leaf-list ints{ type int32; ordered-by system; } list listints{ ordered-by system; key a; leaf a { type int32; } } leaf-list decs{ type decimal64{ fraction-digits 3; } ordered-by system; } list listdecs{ ordered-by system; key a; leaf a { type decimal64{ fraction-digits 3; } } } } } EOF rm -f $dbdir/candidate_db # alt cat < $dbdir/running_db d d dbar dbar b b hej c c abar abar hopp a a cbar cbar bbar bbar EOF new "test params: -s running -f $cfg -y $fyang -- -s" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg -y $fyang if [ $? -ne 0 ]; then err fi new "start backend" start_backend -s running -f $cfg -y $fyang -- -s new "waiting" sleep $RCWAIT fi # STATE (should not be ordered) new "state data (should be unordered: 42,41,43)" cat < $tmp ]]>]]> EOF expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "$(cat $tmp)" '424143]]>]]>' # Check as file new "verify running from start, should be: c,l,y0,y1,y2,y3; y1 and y3 sorted." expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^hejhoppdbcaabcddbarabarcbarbbarabarbbarcbardbar]]>]]>$' new "get each ordered-by user leaf-list" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" '^abar]]>]]>$' new "get each ordered-by user leaf-list" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" '^abar]]>]]>$' new "get each ordered-by user leaf-list" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" '^bbar]]>]]>$' new "get each ordered-by user leaf-list" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" '^bbar]]>]]>$' new "delete candidate" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 'none]]>]]>' "^]]>]]>$" # LEAF_LISTS new "add two entries (c,b) to leaf-list user order" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 'cb]]>]]>' "^]]>]]>$" new "add one entry (a) to leaf-list user order" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 'a]]>]]>' "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "add one entry (0) to leaf-list user order after commit" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 '0]]>]]>' "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "verify leaf-list user order in running (as entered: c,b,a,0)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^cba0]]>]]>$' # LISTS new "add two entries to list user order" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 'cbarbfoo]]>]]>' "^]]>]]>$" new "add one entry to list user order" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 'afie]]>]]>' "^]]>]]>$" new "verify list user order (as entered)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^cbarbfooafie]]>]]>$' #-- order by type rather than strings. # there are three leaf-lists:strings, ints, and decimal64, and two lists: # listints and listdecs # the strings is there for comparison # The check is to write the entries as: 10,2,1, and then expect them to # get back as 1,2,10 (if typed). new "put strings (10,2,1)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ' 1021 ]]>]]>' "^]]>]]>$" new "check string order (1,10,2)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^1102]]>]]>$' new "put leaf-list int (10,2,1)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ' 1021 ]]>]]>' "^]]>]]>$" new "check leaf-list int order (1,2,10)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^1210]]>]]>$' new "put list int (10,2,1)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ' 1021 ]]>]]>' "^]]>]]>$" new "check list int order (1,2,10)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^1210]]>]]>$' new "put leaf-list decimal64 (10,2,1)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ' 10.02.01.0 ]]>]]>' "^]]>]]>$" new "check leaf-list decimal64 order (1,2,10)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^1.02.010.0]]>]]>$' new "put list decimal64 (10,2,1)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ' 10.02.01.0 ]]>]]>' "^]]>]]>$" new "check list decimal64 order (1,2,10)" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 ']]>]]>' '^1.02.010.0]]>]]>$' if [ $BE -eq 0 ]; then exit # BE fi 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 rm -rf $dir