#!/usr/bin/env bash # Yang test: multi-keys and empty type # 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/$APPNAME.yang fsubmod=$dir/example-types.yang fyangerr=$dir/err.yang clispec=$dir/clispec test -d $clispec || mkdir $clispec cat < $cfg $cfg ${YANG_INSTALLDIR} $dir $fyang $clispec /usr/local/lib/$APPNAME/cli example /usr/local/var/$APPNAME/$APPNAME.sock /usr/local/var/$APPNAME/$APPNAME.pidfile /usr/local/var/$APPNAME EOF cat < $fyang module $APPNAME{ yang-version 1.1; prefix ex; namespace "urn:example:clixon"; include example-types; revision 2020-12-01 { description "Added table/parameter/value as the primary data example"; } extension c-define { description "Example from RFC 6020"; argument "name"; } ex:c-define "MY_INTERFACES"; container x { list y { key "a b c"; leaf a { type string; } leaf b { type string; } leaf c { type string; } leaf val { type string; } } leaf d { type empty; } container f { leaf-list e { type string; } } leaf g { type string; } container nopresence { description "No presence should be removed if no children"; leaf j { type string; } } container presence { description "Presence should not be removed even if no children"; presence "even if empty should remain"; leaf j { type string; } } anyxml any{ description "testing of anyxml"; } } container state { config false; leaf-list op { type string; } } list mylist{ /* uses submodule */ key x; leaf x{ type string; } uses ex:subm-group; } } EOF # Submodule Example from rfc7950 sec 7.2.3 cat < $fsubmod submodule example-types { yang-version 1.1; belongs-to $APPNAME { prefix "sys"; } import ietf-yang-types { prefix "yang"; } organization "Example Inc."; contact "Joe L. User"; description "This submodule defines common Example types."; revision "2007-06-09" { description "Initial revision."; } grouping subm-group { description "Defined in submodule"; container subm-container{ leaf subm-leaf{ type string; } } } } EOF # This yang definition uses an extension which is not defined. Error when loading cat < $fyangerr module $APPNAME{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; extension c-define { description "Example from RFC 6020"; argument "name"; } ex:not-defined ARGUMENT; } EOF cat < $clispec/example.cli CLICON_MODE="example"; CLICON_PROMPT="cli> "; # Reference generated data model set @datamodel, cli_set(); commit("Commit the changes"), cli_commit(); quit("Quit"), cli_quit(); show("Show a particular state of the system"){ configuration("Show configuration"), cli_show_config("candidate", "text", "/"); version("Show version"), cli_show_version("candidate", "text", "/"); xpath("Show configuration") ("XPATH expression") ("Namespace"), show_conf_xpath("candidate"); yang("Show yang specs"), show_yang(); { example("Show example yang spec"), show_yang("example"); } } 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 new "start backend -s init -f $cfg" start_backend -s init -f "$cfg" fi new "wait backend" wait_backend new "cli show version" expectpart "$($clixon_cli -1f $cfg show version)" 0 "${CLIXON_VERSION}" new "cli show yang example" expectpart "$($clixon_cli -1f $cfg show yang example)" 0 "revision 2020-12-01" "Added table/parameter/value as the primary data example" new "empty values in leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOa]]>]]>" "^]]>]]>$" new "empty values in leaf-list2" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf get config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^a]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" #new "cli not defined extension" #new "netconf not defined extension" #expecteof "$clixon_netconf -qf $cfg -l o" 0 "$YANG" "Extension ex:not-defined not found" # This text yields an error, but the test cannot detect the error message yet #expectpart "$($clixon_cli -1f $cfg -y $fyangerr show version)" 0 "Yang error: Extension ex:not-defined not found" new "netconf schema resource, RFC 8525" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "ietf-yang-types2013-07-15urn:ietf:params:xml:ns:yang:ietf-yang-types" new "netconf edit config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO125one]]>]]>" "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" # text empty type in running new "netconf commit 2nd" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf get config xpath" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^125one]]>]]>$" new "netconf edit leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOhejhopp]]>]]>" "^]]>]]>$" new "netconf get leaf-list" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^hejhopp]]>]]>$" new "netconf get leaf-list path" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^hejhopp]]>]]>$" new "netconf get (should be some)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^125one" new "cli set leaf-list" expectpart "$($clixon_cli -1f $cfg set x f e foo)" 0 "" new "cli show leaf-list" expectpart "$($clixon_cli -1f $cfg show xpath /x/f/e urn:example:clixon)" 0 "foo" new "netconf set state data (not allowed)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO42]]>]]>" "^applicationbad-elementstateerrormodule example: state data node unexpected]]>]]>$" new "netconf set presence and not present" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf get presence only" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf get presence only" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf anyxml" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf validate anyxml" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf delete candidate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnone]]>]]>" "^]]>]]>$" # Check 3-keys new "netconf add one 3-key entry" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO111one]]>]]>" "^]]>]]>$" new "netconf check add one 3-key" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "111one]]>]]>" new "netconf add another (with same 1st key)" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO121two]]>]]>" "^]]>]]>$" new "netconf check add another" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "111one121two]]>]]>" new "netconf replace first" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO111replace]]>]]>" "^]]>]]>$" new "netconf check replace" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "111replace121two]]>]]>" new "netconf delete first" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO111]]>]]>" "^]]>]]>$" new "netconf check delete" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "121two]]>]]>" # clear db for next test new "netconf delete candidate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOnone]]>]]>" "^]]>]]>$" new "netconf commit empty candidate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconfig config submodule" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLOafoo]]>]]>" "^]]>]]>$" new "netconf submodule get config" expecteof "$clixon_netconf -qf $cfg -D 1 -l s" 0 "$DEFAULTHELLO]]>]]>" "^afoo]]>]]>$" new "netconf submodule validate" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf submodule discard-changes" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" 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