#!/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
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"
sudo $clixon_backend -s init -f $cfg -D $DBG
if [ $? -ne 0 ]; then
err
fi
fi
new "1. Set newex"
expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^]]>]]>$'
new "Set oldex should fail (since oldex is in old revision and only the new is loaded)"
expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationoperation-failederrorValidation failed]]>]]>$'
new "Set other should fail"
expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationoperation-failederrorValidation failed]]>]]>$'
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
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]]>]]>' '^applicationoperation-failederrorValidation failed]]>]]>$'
new "Set other should fail"
expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationoperation-failederrorValidation failed]]>]]>$'
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]]>]]>' '^applicationoperation-failederror'
new "Set other should fail"
expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationoperation-failederror'
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]]>]]>' '^applicationoperation-failederror'
new "Set other should fail"
expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationoperation-failederror'
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]]>]]>' '^applicationoperation-failederror'
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]]>]]>' '^applicationoperation-failederror'
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]]>]]>' '^applicationoperation-failederror'
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]]>]]>' '^applicationoperation-failederror'
new "Set other should fail"
expecteof "$clixon_netconf -qf $cfg" 0 'str]]>]]>' '^applicationoperation-failederror'
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