#!/usr/bin/env bash # Tests of defaults in choices. # From RFC7950 Sec 7.9.3 # 1. Default case, the default if no child nodes from any of the choice's cases exist # 2. Default for child nodes under a case are only used if one of the nodes under that case # is present # 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/transfer.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 /usr/local/var/$APPNAME EOF # See example in RFC 7950 Sec 7.9.3 cat < $fyang module transfer{ yang-version 1.1; namespace "urn:example:transfer"; prefix tr; grouping transfer-container { description "Example from RFC 7950 Sec 7.9.3"; container transfer { choice how { default interval; case interval { leaf interval { type uint16; units minutes; default 30; } } case daily { leaf daily { type empty; } leaf time-of-day { type string; units 24-hour-clock; default "01.00"; } } case manual { leaf manual { type empty; } } } } } uses transfer-container; /* Same but within list */ list li{ key x; leaf x { type int32; } uses transfer-container; } } 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 new "Default value expected: interval=30" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "30" new "Set transfer/daily" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Default value expected: time-of-day=01:00" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "01.00" new "Set list element transfer container" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "
  • 42
  • " "" "" new "Default value expected: interval=30" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "
  • 4230
  • " new "Set transfer/daily" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "
  • 42
  • " "" "" new "Default value expected: time-of-day=01:00" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "report-all" "" "
  • 4201.00
  • " 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