#!/bin/bash
APPNAME=example
# test two modules example1 and example2 with overlapping statements x.
# x is leaf in example1 and list on example2.
# Test netconf and restconf
# BTW, this is not supported in generated CLI
. ./lib.sh
cfg=$dir/conf_yang.xml
fyang1=$dir/example1.yang
fyang2=$dir/example2.yang
# /usr/local/share/$APPNAME/yang
cat < $cfg
$cfg$dir/usr/local/share/$APPNAME/yang/usr/local/share/clixon/usr/local/lib/$APPNAME/clispec/usr/local/lib/$APPNAME/cli$APPNAMEfalse/usr/local/var/$APPNAME/$APPNAME.sock/usr/local/var/$APPNAME/$APPNAME.pidfile1/usr/local/var/$APPNAME/usr/local/lib/xmldb/text.sotruetrue
EOF
cat < $fyang1
module example1{
yang-version 1.1;
prefix ex1;
namespace "urn:example:clixon1";
import ietf-routing {
description "defines fib-route";
prefix rt;
}
leaf x{
type int32;
}
}
EOF
# For testing namespaces -
# x.y is different type. Here it is string whereas in fyang1 it is list.
#
cat < $fyang2
module example2{
yang-version 1.1;
prefix ex2;
namespace "urn:example:clixon2";
container x {
leaf y {
type uint32;
}
}
}
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 new backend
sudo $clixon_backend -s init -f $cfg -D $DBG
if [ $? -ne 0 ]; then
err
fi
fi
new "kill old restconf daemon"
sudo pkill -u www-data clixon_restconf
new "start restconf daemon"
sudo su -c "$clixon_restconf -f $cfg -D $DBG" -s /bin/sh www-data &
new "netconf set x in example1"
expecteof "$clixon_netconf -qf $cfg" 0 '42]]>]]>' '^]]>]]>$'
new "netconf get config example1"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" '^42]]>]]>$'
new "netconf set x in example2"
expecteof "$clixon_netconf -qf $cfg" 0 '99]]>]]>' '^]]>]]>$'
new "netconf get config example1 and example2"
expecteof "$clixon_netconf -qf $cfg" 0 "]]>]]>" '^4299]]>]]>$'
new "netconf discard-changes"
expecteof "$clixon_netconf -qf $cfg -y $fyang1" 0 "]]>]]>" "^]]>]]>$"
new "restconf set x in example1"
expecteq "$(curl -s -X POST -d '{"example1:x":42}' http://localhost/restconf/data)" ''
new2 "restconf get config example1"
expecteq "$(curl -s -X GET http://localhost/restconf/data/example1:x)" '{"example1:x": 42}
'
new "restconf set x in example2"
expecteq "$(curl -s -X POST -d '{"example2:x":{"y":99}}' http://localhost/restconf/data)" ''
# XXX GET ../example1:x is translated to select=/x which gets both example1&2
#new "restconf get config example1"
#expecteq "$(curl -s -X GET http://localhost/restconf/data/example1:x)" '{"example1:x": 42}
#
'
# XXX GET ../example2:x is translated to select=/x which gets both example1&2
#new "restconf get config example2"
#expecteq "$(curl -s -X GET http://localhost/restconf/data/example2:x)" '{"example2:x": {"y":42}}
#
'
new "restconf get config example1 and example2"
ret=$(curl -s -X GET http://localhost/restconf/data)
expect='"example1:x": 42,"example2:x": {"y": 99}'
match=`echo $ret | grep -EZo "$expect"`
if [ -z "$match" ]; then
err "$expect" "$ret"
fi
new "Kill restconf daemon"
sudo pkill -u www-data -f "/www-data/clixon_restconf"
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
rm -rf $dir