#!/usr/bin/env 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). # Also: ordered-by-user and "insert" and "key"/"value" attributes # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Which format to use as datastore format internally : ${format:=xml} 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 $fyang /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 $format EOF cat < $fyang module order-example{ yang-version 1.1; namespace "urn:example:order"; prefix exo; 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; } /* Follow list of all int types mostly to get coverage */ leaf-list myint8{ type int8; ordered-by system; } leaf-list myint16{ type int16; ordered-by system; } leaf-list myint32{ type int32; ordered-by system; } leaf-list myint64{ type int64; ordered-by system; } leaf-list myuint8{ type uint8; ordered-by system; } leaf-list myuint16{ type uint16; ordered-by system; } leaf-list myuint32{ type uint32; ordered-by system; } leaf-list myuint64{ type uint64; 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 <${DATASTORE_TOP}> 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 -- -s" if [ $BE -ne 0 ]; then new "kill old backend" sudo clixon_backend -zf $cfg if [ $? -ne 0 ]; then err fi new "start backend" start_backend -s running -f $cfg -- -s fi new "wait backend" wait_backend # STATE (should not be ordered) #new "state data (should be unordered: 42,41,43)" # Eeh I changed that to sortered unless STATE_ORDERED_BY_SYSTEM new "state data (should be ordered: 41,42,43)" cat < $tmp $DEFAULTHELLO]]>]]> EOF expecteof "$clixon_netconf -qf $cfg" 0 "$(cat $tmp)" "414243]]>]]>" # 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" 0 "$DEFAULTHELLO]]>]]>" "^hejhoppdbcaabcddbarabarcbarbbarabarbbarcbardbar]]>]]>$" new "get each ordered-by user leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^abar]]>]]>$" new "get each ordered-by user leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^abar]]>]]>$" new "get each ordered-by user leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^bbar]]>]]>$" new "get each ordered-by user leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^bbar]]>]]>$" new "delete candidate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnone]]>]]>" "^]]>]]>$" # LEAF_LISTS new "add two entries (c,b) to leaf-list user order" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOcb]]>]]>" "^]]>]]>$" new "add one entry (a) to leaf-list user order" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOa]]>]]>" "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "add one entry (0) to leaf-list user order after commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO0]]>]]>" "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "verify leaf-list user order in running (as entered: c,b,a,0)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^cba0]]>]]>$" # LISTS new "add two entries to list user order" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOcbarbfoo]]>]]>" "^]]>]]>$" new "add one entry to list user order" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOafie]]>]]>" "^]]>]]>$" new "verify list user order (as entered)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^cbarbfooafie]]>]]>$" new "Overwrite existing ordered-by user y2->c" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO cnewc ]]>]]>" new "Overwrite existing ordered-by user y2->b" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO bnewb ]]>]]>" new "Overwrite existing ordered-by user y2->a" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO anewa ]]>]]>" new "Tests for no duplicates." expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^cnewcbnewbanewa]]>]]>$" #-- 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" 0 "$DEFAULTHELLO 1021 ]]>]]>" "^]]>]]>$" new "check string order (1,10,2)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^1102]]>]]>$" for s in int uint; do for t in 8 16 32 64; do type=$s$t new "put leaf-list $type (10,2,1)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO 1021 ]]>]]>" "^]]>]]>$" new "check leaf-list $type order (1,2,10)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^1210]]>]]>$" done done new "netconf validate ints" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "put list int (10,2,1)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO 1021 ]]>]]>" "^]]>]]>$" new "check list int order (1,2,10)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^1210]]>]]>$" new "put leaf-list decimal64 (10,2,1)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO 10.02.01.0 ]]>]]>" "^]]>]]>$" new "check leaf-list decimal64 order (1,2,10)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^1.02.010.0]]>]]>$" new "put list decimal64 (10,2,1)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO 10.02.01.0 ]]>]]>" "^]]>]]>$" new "check list decimal64 order (1,2,10)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^1.02.010.0]]>]]>$" new "delete candidate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnone]]>]]>" "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" # leaf-list ordered-by-user, "insert" and "value" attributes # y0 is leaf-list ordered by user new "add one entry (c) to leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOc]]>]]>" "^]]>]]>$" new "add one entry (a) to leaf-list first (with no yang namespace - error)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOa]]>]]>" "^applicationbad-attributeinserterrorUnresolved attribute prefix (no namespace?)]]>]]>$" new "add one entry (b) to leaf-list first" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOb]]>]]>" "^]]>]]>$" new "add one entry (d) to leaf-list last" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOd]]>]]>" "^]]>]]>$" new "add one entry (a) to leaf-list first" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOa]]>]]>" "^]]>]]>$" new "add one entry (e) to leaf-list last" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOe]]>]]>" "^]]>]]>$" new "check ordered-by-user: a,b,c,d,e" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^abcde]]>]]>$" new "move one entry (e) to leaf-list first" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOe]]>]]>" "^]]>]]>$" new "check ordered-by-user: e,a,b,c,d" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^eabcd]]>]]>$" # before and after and value attribute new "add one leaf-list entry 71 before b" XML="$DEFAULTHELLO71]]>]]>" expecteof "$clixon_netconf -qf $cfg" 0 "$XML" "^]]>]]>$" new "add one entry 42 after b" XML="$DEFAULTHELLO42]]>]]>" expecteof "$clixon_netconf -qf $cfg" 0 "$XML" "^]]>]]>$" # XXX actually not right error message, should be as RFC7950 Sec 15.7 new "add one entry 99 after Q (not found, error)" XML="$DEFAULTHELLO99]]>]]>" RES="^protocoloperation-failederrorbad-attribute: value, missing-instance: Q]]>]]>$" expecteof "$clixon_netconf -qf $cfg" 0 "$XML" "$RES" new "check ordered-by-user: e,a,71,b,42,c,d" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^ea71b42cd]]>]]>$" new "delete candidate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnone]]>]]>" "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" # list ordered-by-user, "insert" and "value" attributes # y2 is list ordered by user new "add one entry (key c) to list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOcfoo]]>]]>" "^]]>]]>$" new "add one entry (key a) to list first (with no yang namespace - error)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOafoo]]>]]>" "^applicationbad-attributeinserterrorUnresolved attribute prefix (no namespace?)]]>]]>$" new "add one entry (key b) to list first" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLObbar]]>]]>" "^]]>]]>$" new "add one entry (d) to list last" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOdfie]]>]]>" "^]]>]]>$" new "add one entry (a) to list first" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOafoo]]>]]>" "^]]>]]>$" new "add one entry (e) to list last" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOebar]]>]]>" "^]]>]]>$" new "check ordered-by-user: a,b,c,d,e" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^afoobbarcfoodfieebar]]>]]>$" new "move one entry (e) to list first" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOebar]]>]]>" "^]]>]]>$" new "check ordered-by-user: e,a,b,c,d" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^ebarafoobbarcfoodfie]]>]]>$" # before and after and key attribute new "add one entry 71 before key b" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO71fie]]>]]>" "^]]>]]>$" new "add one entry 42 after key b" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO42fum]]>]]>" "^]]>]]>$" # XXX actually not right error message, should be as RFC7950 Sec 15.7 new "add one entry key 99 after Q (not found, error)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO99bar]]>]]>" "^protocoloperation-failederrorbad-attribute: key, missing-instance: Q]]>]]>$" new "check ordered-by-user: e,a,71,b,42,c,d" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^ebarafoo71fiebbar42fumcfoodfie]]>]]>$" 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 # unset conditional parameters unset format new "endtest" endtest