#!/usr/bin/env bash # Test for isolating modules between mount-points. # That is, so that two modules with same name, revision and namespaces can have different content # in two separate mount-points. # Note the mylabel domain is hardcoded in example_backend.c ca_yang_mount callback # 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_mount.xml clispec=$dir/automode.cli test -d $dir/main || mkdir $dir/main fyang=$dir/main/clixon-example.yang test -d $dir/domains/mylabel || mkdir -p $dir/domains/mylabel #fyang0=$dir/domains/mylabel/clixon-mount0.yang fyang0=$dir/domains/mylabel/clixon-example.yang fyang1=$dir/domains/mylabel/clixon-mount1.yang fyang2=$dir/domains/mylabel/clixon-mount2.yang CFD=$dir/conf.d test -d $CFD || mkdir -p $CFD AUTOCLI=$(autocli_config clixon-\* kw-nokey false) if [ $? -ne 0 ]; then err1 "Error when generating certs" fi cat < $cfg $cfg $CFD clixon-restconf:allow-auth-none ${YANG_INSTALLDIR} ${dir} $fyang $dir/domains true $dir /usr/local/lib/$APPNAME/cli $APPNAME /usr/local/var/run/$APPNAME.sock /usr/local/lib/$APPNAME/backend /usr/local/var/run/$APPNAME.pidfile $dir true true true true EOF cat < $CFD/autocli.xml false kw-nokey true include clixon enable clixon-* EOF cat < $fyang module clixon-example{ yang-version 1.1; namespace "urn:example:clixon"; prefix ex; import ietf-yang-schema-mount { prefix yangmnt; } container top{ list mylist{ key name; leaf name{ type string; } container root{ presence "Otherwise root is not visible"; yangmnt:mount-point "mylabel"{ description "Root for other yang models"; } } } } } EOF cat < $fyang0 module clixon-example{ yang-version 1.1; namespace "urn:example:clixon"; prefix m0; import clixon-mount1 { prefix m1; } import clixon-mount2 { prefix m2; } } EOF cat < $fyang1 module clixon-mount1{ yang-version 1.1; namespace "urn:example:mount1"; prefix m1; container mount1{ list mylist1{ key name1; leaf name1{ type string; } } } } EOF cat < $fyang2 module clixon-mount2{ yang-version 1.1; namespace "urn:example:mount2"; prefix m2; import clixon-mount1 { prefix m1; } grouping ag2 { leaf option2{ type string; } } grouping ag1 { container options { leaf option1{ type string; } uses ag2; } } augment /m1:mount1/m1:mylist1 { uses ag1; } } EOF cat < $clispec CLICON_MODE="example"; CLICON_PROMPT="%U@%H %W> "; CLICON_PLUGIN="example_cli"; # Autocli syntax tree operations set @datamodel, cli_auto_set(); merge @datamodel, cli_auto_merge(); create @datamodel, cli_auto_create(); delete("Delete a configuration item") @datamodel, cli_auto_del(); validate("Validate changes"), cli_validate(); commit("Commit the changes"), cli_commit(); quit("Quit"), cli_quit(); show("Show a particular state of the system"){ configuration("Show configuration"), cli_show_auto_mode("candidate", "xml", true, false);{ xml("Show configuration as XML"), cli_show_auto_mode("candidate", "xml", false, false); cli("Show configuration as CLI commands"), cli_show_auto_mode("candidate", "cli", false, false, "report-all", "set "); netconf("Show configuration as netconf edit-config operation"), cli_show_auto_mode("candidate", "netconf", false, false); text("Show configuration as text"), cli_show_auto_mode("candidate", "text", false, false); json("Show configuration as JSON"), cli_show_auto_mode("candidate", "json", false, false); } state("Show configuration and state"), cli_show_auto_mode("running", "xml", false, true); } 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 -- -m clixon-example -M urn:example:clixon" start_backend -s init -f $cfg -- -m clixon-example -M urn:example:clixon fi new "wait backend" wait_backend new "Add two mountpoints: x and y" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "xy" "" "" new "netconf commit" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Retrieve schema-mounts with Operation" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "clixon-exampletrue" new "get yang-lib at mountpoint" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" ">" "xmylabelclixon-exampleurn:example:clixonymylabelclixon-exampleurn:example:clixon" new "Add data to mounts" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "xx1" "" "" new "netconf commit" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "Add mounted augment data 2" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "xx1bar" "" "" new "netconf commit" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "get mounted augment data" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "xx1bary" new "cli show config" expectpart "$($clixon_cli -1 -f $cfg show config xml -- -m clixon-example -M urn:example:clixon)" 0 "xx1bary" 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 sudo rm -rf $dir new "endtest" endtest