#!/usr/bin/env bash # test of choice implicit delete, see RFC7950 Sec 7.9 3rd paragraph: # Since only one of the choice's cases can be valid at any time in the # data tree, the creation of a node from one case implicitly deletes # all nodes from all other cases. If a request creates a node from a # case, the server will delete any existing nodes that are defined in # other cases inside the choice. # 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/choice.xml clidir=$dir/cli fyang=$dir/type.yang test -d ${clidir} || rm -rf ${clidir} mkdir $clidir cat < $cfg $cfg clixon-restconf:allow-auth-none $dir ${YANG_INSTALLDIR} $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME $clidir /usr/local/var/run/$APPNAME.sock /usr/local/var/run/$APPNAME.pidfile $dir EOF cat < $fyang module system{ yang-version 1.1; namespace "urn:example:config"; prefix ex; /* Case with container vs leaf */ container cont { description "One case is leaf, the other container+leaf, issue when replacing one with the other"; choice d { case d1 { container d1c { choice d11 { leaf d11x{ type string; } leaf d11y{ type string; } } } } case d2 { container d2c { leaf d2x{ type string; } } } } } } EOF cat < $clidir/ex.cli # Clixon example specification CLICON_MODE="example"; CLICON_PROMPT="%U@%H %W> "; CLICON_PLUGIN="example_cli"; # Autocli syntax tree operations set @datamodel, cli_auto_set(); delete("Delete a configuration item") { @datamodel, cli_auto_del(); all("Delete whole candidate configuration"), delete_all("candidate"); } validate("Validate changes"), cli_validate(); commit("Commit the changes"), cli_commit(); quit("Quit"), cli_quit(); discard("Discard edits (rollback 0)"), discard_changes(); show("Show a particular state of the system"){ configuration("Show configuration"), cli_show_auto_mode("candidate", "text", true, false);{ cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", true, false, "report-all", "set "); xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", true, false, NULL); } } 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 sudo pkill -f clixon_backend # to be sure new "start backend -s init -f $cfg" start_backend -s init -f $cfg fi new "wait backend" wait_backend # replace new "set d1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " aaa " "" "" new "replace d2 top" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "none bbb " "" "" new "check d2" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "bbb" "" new "replace d1 part" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "none ccc " "" "" new "check d1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "ccc" "" # merge new "merge d2 part" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "none ddd " "" "" new "check d2" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "ddd" "" # create new "create d1 part" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "none eee " "" "" new "check d1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "eee" "" # remove new "remove d2 part" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "none ddd " "" "" new "check d1" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "eee" "" # delete new "delete d2 part" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "none ddd " "" "applicationdata-missingerrorData does not exist; cannot delete resource" 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