diff --git a/CHANGELOG.md b/CHANGELOG.md index d71d1ec7..3305eb87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ * Support of submodule, include and belongs-to. * Openconfig yang specs parsed: https://github.com/openconfig/public * Improved unknown handling - * Yang Configure options changed + * Yang load file configure options changed * `CLICON_YANG_DIR` is changed from a single directory to a path of directories * Note CLIXON_DATADIR (=/usr/local/share/clixon) need to be in the list * CLICON_YANG_MAIN_FILE Provides a filename with a single module filename. diff --git a/doc/FAQ.md b/doc/FAQ.md index 9e54e304..9ecf46ff 100644 --- a/doc/FAQ.md +++ b/doc/FAQ.md @@ -121,15 +121,19 @@ are included. The following configuration file options control the loading of Yang files: - `CLICON_YANG_DIR` - A list of directories (yang dir path) where Clixon searches for module and submodules. -- `CLICON_YANG_MAIN_DIR` - Load all yang modules in this directory. -- `CLICON_YANG_MAIN_FILE` - Load a specific Yang module fiven by a file. +- `CLICON_YANG_MAIN_FILE` - Load a specific Yang module fiven by a file. - `CLICON_YANG_MODULE_MAIN` - Specifies a single module to load. The module is searched for in the yang dir path. - `CLICON_YANG_MODULE_REVISION` : Specifies a revision to the main module. +- `CLICON_YANG_MAIN_DIR` - Load all yang modules in this directory. Note that the special `CLIXON_DATADIR`, by default `/usr/local/share/clixon` should be included in the yang dir path for Clixon system files to be found. -You can combine the options, however, more specific options override -less specific. For example, `CLICON_YANG_MAIN_FILE` overrides `CLICON_YANG_MODULE_MAIN`. +You can combine the options, however, if there are different variants +of the same module, more specific options override less +specific. The precedence of the options are as follows: +- `CLICON_YANG_MAIN_FILE` +- `CLICON_YANG_MODULE_MAIN` +- `CLICON_YANG_MAIN_DIR` ## How do I enable Yang features? diff --git a/test/test_yang_load.sh b/test/test_yang_load.sh new file mode 100755 index 00000000..ae4f56e3 --- /dev/null +++ b/test/test_yang_load.sh @@ -0,0 +1,427 @@ +#!/bin/bash +# Load yang files. Test the different options +# CLICON_YANG_MODULE_DIR vs CLICON_YANG_MAIN_FILE vs CLICON_YANG_MAIN_DIR +# as well as revisions +# Test is made by having different config files and then try to set configure +# options available in specific modules +APPNAME=example +# include err() and new() functions and creates $dir +. ./lib.sh + +cfg=$dir/conf_yang.xml +fyang1=$dir/$APPNAME@2018-12-02.yang +fyang2=$dir/$APPNAME@2018-01-01.yang +fyang3=$dir/other.yang + +# /usr/local/share/$APPNAME/yang + +# 1st variant of the example module +cat < $fyang1 +module $APPNAME{ + prefix ex; + revision 2018-12-02; + namespace "urn:example:example"; + leaf newex{ + type string; + } +} +EOF + +# 2nd variant of the same example module +cat < $fyang2 +module $APPNAME{ + prefix ex; + revision 2018-01-01; + namespace "urn:example:example"; + leaf oldex{ + type string; + } +} +EOF + +# Other module +cat < $fyang3 +module other{ + prefix oth; + revision 2018-01-01; + namespace "urn:example:example2"; + leaf other{ + type string; + } +} +EOF + +#--------------------------------- +new "1. Load module as file" +cat < $cfg + + $cfg + $dir + /usr/local/share/clixon + $fyang1 + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + /usr/local/lib/xmldb/text.so + /usr/local/lib/$APPNAME/clispec + /usr/local/lib/$APPNAME/cli + $APPNAME + 1 + +EOF +# kill old backend (if any) +new "kill old backend" +sudo clixon_backend -zf $cfg +if [ $? -ne 0 ]; then + err +fi + +new "start backend -s init -f $cfg" +# start new backend +sudo $clixon_backend -s init -f $cfg +if [ $? -ne 0 ]; then + err +fi + +new "1. Set newex" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +new "Set oldex should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +new "Set other should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +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 +sudo clixon_backend -z -f $cfg +if [ $? -ne 0 ]; then + err "kill backend" +fi +sudo pkill -u root -f clixon_backend + +#-------------------------------------- +new "2. Load old module as file" +cat < $cfg + + $cfg + $dir + /usr/local/share/clixon + $fyang2 + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + /usr/local/lib/xmldb/text.so + /usr/local/lib/$APPNAME/clispec + /usr/local/lib/$APPNAME/cli + $APPNAME + 1 + +EOF + +new "start backend -s init -f $cfg" +# start new backend +sudo $clixon_backend -s init -f $cfg +if [ $? -ne 0 ]; then + err +fi + +new "Set oldex" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +new "Set newex should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +new "Set other should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +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 +sudo clixon_backend -z -f $cfg +if [ $? -ne 0 ]; then + err "kill backend" +fi +sudo pkill -u root -f clixon_backend + +#-------------------------------------- +new "3. Load module with no revision" +cat < $cfg + + $cfg + $dir + /usr/local/share/clixon + example + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + /usr/local/lib/xmldb/text.so + +EOF + +new "start backend -s init -f $cfg" +# start new backend +sudo $clixon_backend -s init -f $cfg +if [ $? -ne 0 ]; then + err +fi + +new "Set newex" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +new "Set oldex should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +new "Set other should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +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 +sudo clixon_backend -z -f $cfg +if [ $? -ne 0 ]; then + err "kill backend" +fi +sudo pkill -u root -f clixon_backend + +#-------------------------------------- +new "4. Load module with old revision" +cat < $cfg + + $cfg + $dir + /usr/local/share/clixon + example + 2018-01-01 + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + /usr/local/lib/xmldb/text.so + +EOF + +new "start backend -s init -f $cfg" +# start new backend +sudo $clixon_backend -s init -f $cfg +if [ $? -ne 0 ]; then + err +fi + +new "Set oldex" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +new "Set newex should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +new "Set other should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +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 +sudo clixon_backend -z -f $cfg +if [ $? -ne 0 ]; then + err "kill backend" +fi +sudo pkill -u root -f clixon_backend + +#-------------------------------------- +new "5. Load dir" +cat < $cfg + + $cfg + $dir + /usr/local/share/clixon + $dir + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + /usr/local/lib/xmldb/text.so + +EOF + +new "start backend -s init -f $cfg" +# start new backend +sudo $clixon_backend -s init -f $cfg +if [ $? -ne 0 ]; then + err +fi + +new "Set newex" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +new "Set oldex should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +new "Set other" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +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 +sudo clixon_backend -z -f $cfg +if [ $? -ne 0 ]; then + err "kill backend" +fi +sudo pkill -u root -f clixon_backend + +#-------------------------------------- +new "6. Load dir override with file" +cat < $cfg + + $cfg + $dir + /usr/local/share/clixon + $dir + $fyang2 + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + /usr/local/lib/xmldb/text.so + +EOF + +new "start backend -s init -f $cfg" +# start new backend +sudo $clixon_backend -s init -f $cfg +if [ $? -ne 0 ]; then + err +fi + +new "Set oldex" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +new "Set newex should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +new "Set other" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +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 +sudo clixon_backend -z -f $cfg +if [ $? -ne 0 ]; then + err "kill backend" +fi +sudo pkill -u root -f clixon_backend + + +#-------------------------------------- +new "7. Load dir override with module + revision" +cat < $cfg + + $cfg + $dir + /usr/local/share/clixon + $dir + example + 2018-01-01 + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + /usr/local/lib/xmldb/text.so + +EOF + +new "start backend -s init -f $cfg" +# start new backend +sudo $clixon_backend -s init -f $cfg +if [ $? -ne 0 ]; then + err +fi + +new "Set oldex" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +new "Set newex should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +new "Set other" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +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 +sudo clixon_backend -z -f $cfg +if [ $? -ne 0 ]; then + err "kill backend" +fi +sudo pkill -u root -f clixon_backend + +#-------------------------------------- +new "8. Load module w new revision overrided by old file" +cat < $cfg + + $cfg + $dir + /usr/local/share/clixon + $fyang2 + example + 2018-12-02 + /usr/local/var/$APPNAME/$APPNAME.sock + /usr/local/var/$APPNAME/$APPNAME.pidfile + /usr/local/var/$APPNAME + /usr/local/lib/xmldb/text.so + +EOF + +new "start backend -s init -f $cfg" +# start new backend +sudo $clixon_backend -s init -f $cfg +if [ $? -ne 0 ]; then + err +fi + +new "Set oldex" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$' + +new "Set newex should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +new "Set other should fail" +expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^operation-failedprotocolerrorXML' + +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 +sudo clixon_backend -z -f $cfg +if [ $? -ne 0 ]; then + err "kill backend" +fi +sudo pkill -u root -f clixon_backend + +rm -rf $dir