(Work in progress) Restconf error handling for get and edit operations
This commit is contained in:
parent
0a11445963
commit
859d424ea3
9 changed files with 165 additions and 119 deletions
73
test/clixon
73
test/clixon
|
|
@ -1,73 +0,0 @@
|
|||
#!/bin/sh
|
||||
# Top-level cron scripts. Add this to (for example) /etc/cron.daily
|
||||
|
||||
err(){
|
||||
testname=$1
|
||||
errcode=$2
|
||||
echo "Error in [$testname]"
|
||||
logger "CLIXON: Error in [$testname]"
|
||||
exit $errcode
|
||||
}
|
||||
|
||||
# cd to working dir
|
||||
cd /var/tmp
|
||||
if [ $# -ne 0 ]; then
|
||||
err "usage: $0" 0
|
||||
fi
|
||||
rm -rf cligen
|
||||
rm -rf clixon
|
||||
git clone https://github.com/olofhagsand/cligen.git
|
||||
if [ $? -ne 0 ]; then
|
||||
err "git clone cligen" 1
|
||||
fi
|
||||
cd cligen
|
||||
CFLAGS=-Werror ./configure
|
||||
if [ $? -ne 0 ]; then
|
||||
err "configure" 2
|
||||
fi
|
||||
make
|
||||
if [ $? -ne 0 ]; then
|
||||
err "make" 3
|
||||
fi
|
||||
cd ..
|
||||
git clone https://github.com/clicon/clixon.git
|
||||
if [ $? -ne 0 ]; then
|
||||
err "git clone clixon" 1
|
||||
fi
|
||||
cd clixon
|
||||
CFLAGS=-Werror ./configure --with-cligen=../cligen
|
||||
if [ $? -ne 0 ]; then
|
||||
err "configure" 2
|
||||
fi
|
||||
make
|
||||
if [ $? -ne 0 ]; then
|
||||
err "make" 3
|
||||
fi
|
||||
sudo make install
|
||||
if [ $? -ne 0 ]; then
|
||||
err "make install" 4
|
||||
fi
|
||||
sudo make install-include
|
||||
if [ $? -ne 0 ]; then
|
||||
err "make install include" 5
|
||||
exit 1
|
||||
fi
|
||||
cd example
|
||||
make
|
||||
if [ $? -ne 0 ]; then
|
||||
err "make example" 6
|
||||
fi
|
||||
sudo make install
|
||||
if [ $? -ne 0 ]; then
|
||||
err "make install example" 7
|
||||
fi
|
||||
cd ../test
|
||||
#./all.sh
|
||||
(cd /home/olof/src/clixon/test; ./all.sh)
|
||||
errcode=$?
|
||||
if [ $errcode -ne 0 ]; then
|
||||
err "test" $errcode
|
||||
fi
|
||||
cd ../..
|
||||
rm -rf clixon cligen
|
||||
logger "CLIXON: tests OK"
|
||||
|
|
@ -128,7 +128,6 @@ new "restconf get empty config + state json"
|
|||
expectfn "curl -sSG http://localhost/restconf/data" "{\"data\": $state}"
|
||||
|
||||
new "restconf get empty config + state xml"
|
||||
# Cant get shell macros to work, inline matching from lib.sh
|
||||
ret=$(curl -s -H "Accept: application/yang-data+xml" -G http://localhost/restconf/data)
|
||||
expect="<data><interfaces-state><interface><name>eth0</name><type>eth</type><if-index>42</if-index></interface></interfaces-state></data>"
|
||||
match=`echo $ret | grep -EZo "$expect"`
|
||||
|
|
@ -161,8 +160,19 @@ if [ -z "$match" ]; then
|
|||
err "$expect" "$ret"
|
||||
fi
|
||||
|
||||
new "restconf Add subtree to datastore using POST"
|
||||
expectfn 'curl -s -X POST -d {"interfaces":{"interface":{"name":"eth/0/0","type":"eth","enabled":true}}} http://localhost/restconf/data' ""
|
||||
new "restconf GET datastore"
|
||||
expectfn "curl -s -X GET http://localhost/restconf/data" "data"
|
||||
|
||||
new "restconf Add subtree to datastore using POST"
|
||||
ret=$(curl -s -i -X POST -H "Accept: application/yang-data+json" -d '{"interfaces":{"interface":{"name":"eth/0/0","type":"eth","enabled":true}}}' http://localhost/restconf/data)
|
||||
expect="HTTP/1.1 200 OK"
|
||||
match=`echo $ret | grep -EZo "$expect"`
|
||||
if [ -z "$match" ]; then
|
||||
err "$expect" "$ret"
|
||||
fi
|
||||
|
||||
new "restconf Re-add subtree which should give error"
|
||||
expectfn 'curl -s -i -X POST -d {"interfaces":{"interface":{"name":"eth/0/0","type":"eth","enabled":true}}} http://localhost/restconf/data' '{"error-tag": "operation-failed"'
|
||||
|
||||
new "restconf Check interfaces eth/0/0 added"
|
||||
expectfn "curl -s -G http://localhost/restconf/data" '{"interfaces": {"interface": \[{"name": "eth/0/0","type": "eth","enabled": true}\]},"interfaces-state": {"interface": \[{"name": "eth0","type": "eth","if-index": 42}\]}}
|
||||
|
|
@ -182,7 +192,7 @@ expectfn "curl -s -G http://localhost/restconf/data" '{"interfaces": {"interface
|
|||
$'
|
||||
|
||||
new "restconf Re-post eth/0/0 which should generate error"
|
||||
expectfn 'curl -s -X POST -d {"interface":{"name":"eth/0/0","type":"eth","enabled":true}} http://localhost/restconf/data/interfaces' "Data resource already exists"
|
||||
expectfn 'curl -s -X POST -d {"interface":{"name":"eth/0/0","type":"eth","enabled":true}} http://localhost/restconf/data/interfaces' 'Object to create already exists'
|
||||
|
||||
new "Add leaf description using POST"
|
||||
expectfn 'curl -s -X POST -d {"description":"The-first-interface"} http://localhost/restconf/data/interfaces/interface=eth%2f0%2f0' ""
|
||||
|
|
|
|||
|
|
@ -81,10 +81,10 @@ new "restconf POST interface"
|
|||
expectfn 'curl -s -X POST -d {"interface":{"name":"TEST","type":"eth0"}} http://localhost/restconf/data/cont1' ""
|
||||
|
||||
new "restconf POST again"
|
||||
expectfn 'curl -s -X POST -d {"interface":{"name":"TEST","type":"eth0"}} http://localhost/restconf/data/cont1' "Data resource already exis"
|
||||
expectfn 'curl -s -X POST -d {"interface":{"name":"TEST","type":"eth0"}} http://localhost/restconf/data/cont1' "Object to create already exists"
|
||||
|
||||
new "restconf POST from top"
|
||||
expectfn 'curl -s -X POST -d {"cont1":{"interface":{"name":"TEST","type":"eth0"}}} http://localhost/restconf/data' "Data resource already exists"
|
||||
expectfn 'curl -s -X POST -d {"cont1":{"interface":{"name":"TEST","type":"eth0"}}} http://localhost/restconf/data' "Object to create already exists"
|
||||
|
||||
new "restconf DELETE"
|
||||
expectfn 'curl -s -X DELETE http://localhost/restconf/data/cont1' ""
|
||||
|
|
|
|||
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
# include err() and new() functions and creates $dir
|
||||
. ./lib.sh
|
||||
fyang=$dir/type.yang
|
||||
|
||||
cfg=$dir/conf_yang.xml
|
||||
fyang=$dir/type.yang
|
||||
|
||||
|
||||
cat <<EOF > $cfg
|
||||
<config>
|
||||
|
|
@ -70,6 +72,57 @@ module example{
|
|||
enum down;
|
||||
}
|
||||
}
|
||||
leaf length1 {
|
||||
type string {
|
||||
length "1";
|
||||
}
|
||||
}
|
||||
/* leaf length2 {
|
||||
type string {
|
||||
length "max";
|
||||
}
|
||||
}
|
||||
leaf length3 {
|
||||
type string {
|
||||
length "min";
|
||||
}
|
||||
}*/
|
||||
leaf length4 {
|
||||
type string {
|
||||
length "4..4000";
|
||||
}
|
||||
}
|
||||
/* leaf length5 {
|
||||
type string {
|
||||
length "min..max";
|
||||
}
|
||||
}*/
|
||||
leaf num1 {
|
||||
type int32 {
|
||||
range "1";
|
||||
}
|
||||
}
|
||||
/* leaf num2 {
|
||||
type int32 {
|
||||
range "min";
|
||||
}
|
||||
}
|
||||
leaf num3 {
|
||||
type int32 {
|
||||
range "max";
|
||||
}
|
||||
}
|
||||
*/
|
||||
leaf num4 {
|
||||
type int32 {
|
||||
range "4..4000";
|
||||
}
|
||||
}
|
||||
/* leaf num5 {
|
||||
type int32 {
|
||||
range "min..max";
|
||||
}
|
||||
}*/
|
||||
}
|
||||
EOF
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue