#!/usr/bin/env bash # Test augmented state # Use main example -- -sS option to add state via a file # # 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/example-augment.yang fyang2=$dir/example-lib.yang fstate=$dir/state.xml cat < $cfg $cfg a:test $dir /usr/local/share/clixon $fyang /usr/local/lib/$APPNAME/clispec /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/lib/$APPNAME/backend false /usr/local/var/$APPNAME false EOF # This is the lib function with the base container cat < $fyang2 module example-lib { yang-version 1.1; namespace "urn:example:lib"; revision "2019-03-04"; prefix lib; container global-state { config false; leaf gbds{ description "Global base default state"; type string; default "gbds"; } leaf gbos{ description "Global base optional state"; type string; } container nopres{ description "This should be removed"; } } container base-config { list parameter{ key name; leaf name{ type string; } container param-state { config false; leaf lbds{ description "Local base default state"; type string; default "lbds"; } leaf lbos{ description "Local base optional state"; type string; } } } } } EOF # This is the main module where the augment exists cat < $fyang module example-augment { yang-version 1.1; namespace "urn:example:augment"; prefix aug; revision "2020-09-25"; import example-lib { prefix lib; } /* Augments global state */ augment "/lib:global-state" { leaf gads{ description "Global augmented default state"; type string; default "gads"; } leaf gaos{ description "Global augmented optional state"; type string; } } /* Augments state in config in-line */ augment "/lib:base-config/lib:parameter/lib:param-state" { leaf lads{ description "Local augmented default state"; type string; default "lads"; } leaf laos{ description "Local augmented optional state"; type string; } } } EOF # Get config and state # Arguments # - expected config # - expected state testrun() { config=$1 state=$2 new "get config" if [ -z "$config" ]; then expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" else expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^$config]]>]]>$" fi new "get state" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^$state]]>]]>$" } 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 -- -sS $fstate" start_backend -s init -f $cfg -- -sS $fstate fi new "waiting" wait_backend #----------------------------- new "1. Empty config/state, expect global default state" CONFIG="" cat < $fstate EOF EXPSTATE=$(cat <gbdsgads EOF ) testrun "$CONFIG" "$EXPSTATE" #----------------------------- new "2. Empty config/top-level state, expect global default state" cat < $fstate EOF testrun "$CONFIG" "$EXPSTATE" #----------------------------- new "3. Empty config/top-level w non-presence state, expect global default state" cat < $fstate EOF testrun "$CONFIG" "$EXPSTATE" #----------------------------- new "4. Empty config + optional state, expect global default + optional state" cat < $fstate gbos gaos EOF EXPSTATE=$(cat <gbdsgbosgadsgaos EOF ) testrun "$CONFIG" "$EXPSTATE" #----------------------------- # From here, add a config tree new "5. Config tree, empty top state, expect default top state and default local state" CONFIG=$(cat <a EOF ) cat < $fstate EOF EXPSTATE=$(cat <gbdsgadsalbdslads EOF ) new "Add config" expecteof "$clixon_netconf -qf $cfg" 0 "$CONFIG]]>]]>" "^]]>]]>" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" "^]]>]]>$" testrun "$CONFIG" "$EXPSTATE" #----------------------------- new "6. Config tree and optional tree state, empty top state, expect default top state and default local state" cat < $fstate a lbos laos EOF EXPSTATE=$(cat <gbdsgadsalbdslbosladslaos EOF ) testrun "$CONFIG" "$EXPSTATE" #----------------------------- 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