Added decriptive error message when plugins produce invalid state XML.
This commit is contained in:
parent
266e5581e4
commit
bf04131e54
11 changed files with 156 additions and 41 deletions
27
test/lib.sh
27
test/lib.sh
|
|
@ -345,20 +345,23 @@ expecteq(){
|
|||
|
||||
# Evaluate and return
|
||||
# like expecteq but partial match is OK
|
||||
# Example: expectpart $(fn arg) 0 "my return"
|
||||
# Example: expectpart $(fn arg) 0 "my return" -- "foo"
|
||||
# - evaluated expression
|
||||
# - expected command return value (0 if OK)
|
||||
# - expected stdout outcome*
|
||||
# - the token "--not--"
|
||||
# - not expected stdout outcome*
|
||||
# @note need to escape \[\]
|
||||
expectpart(){
|
||||
r=$?
|
||||
ret=$1
|
||||
retval=$2
|
||||
expect=$3
|
||||
|
||||
# echo "r:$r"
|
||||
# echo "ret:\"$ret\""
|
||||
# echo "retval:$retval"
|
||||
# echo "expect:$expect"
|
||||
# echo "expect:\"$expect\""
|
||||
if [ $r != $retval ]; then
|
||||
echo -e "\e[31m\nError ($r != $retval) in Test$testnr [$testname]:"
|
||||
echo -e "\e[0m:"
|
||||
|
|
@ -367,15 +370,26 @@ expectpart(){
|
|||
if [ -z "$ret" -a -z "$expect" ]; then
|
||||
return
|
||||
fi
|
||||
# Loop over all variable args expect strings
|
||||
# Loop over all variable args expect strings (skip first two args)
|
||||
# note that "expect" var is never actually used
|
||||
# Then test positive for strings, if the token --neg-- is detected, then test negative for the rest
|
||||
positive=true;
|
||||
let i=0;
|
||||
for exp in "$@"; do
|
||||
if [ $i -gt 1 ]; then
|
||||
if [ "$exp" == "--not--" ]; then
|
||||
positive=false;
|
||||
elif [ $i -gt 1 ]; then
|
||||
# echo "echo \"$ret\" | grep --null -o \"$exp"\"
|
||||
match=$(echo "$ret" | grep --null -o "$exp") # XXX -EZo: -E cant handle {}
|
||||
r=$?
|
||||
if [ $r != 0 ]; then
|
||||
err "$exp" "$ret"
|
||||
if $positive; then
|
||||
if [ $r != 0 ]; then
|
||||
err "$exp" "$ret"
|
||||
fi
|
||||
else
|
||||
if [ $r == 0 ]; then
|
||||
err "not $exp" "$ret"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
let i++;
|
||||
|
|
@ -385,7 +399,6 @@ expectpart(){
|
|||
# fi
|
||||
}
|
||||
|
||||
|
||||
# Pipe stdin to command
|
||||
# Arguments:
|
||||
# - Command
|
||||
|
|
|
|||
|
|
@ -167,10 +167,10 @@ expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><commit/></rpc>]]>]]>" "^<rpc-reply
|
|||
|
||||
# Leafref wrong
|
||||
new "netconf get / config+state should fail"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get content="all"><filter type="xpath" select="/"/></get></rpc>]]>]]>' '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-info><bad-element>x</bad-element></error-info><error-severity>error</error-severity><error-message>Leafref validation failed: No leaf x matching path /ex:sender-config/ex:name Internal error, state callback returned invalid XML</error-message></rpc-error></rpc-reply>]]>]]>$'
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get content="all"><filter type="xpath" select="/"/></get></rpc>]]>]]>' '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-info><bad-element>x</bad-element></error-info><error-severity>error</error-severity><error-message>Leafref validation failed: No leaf x matching path /ex:sender-config/ex:name. Internal error, state callback returned invalid XML</error-message></rpc-error></rpc-reply>]]>]]>$'
|
||||
|
||||
new "netconf get / state-only should fail"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get content="nonconfig"><filter type="xpath" select="/"/></get></rpc>]]>]]>' '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-info><bad-element>x</bad-element></error-info><error-severity>error</error-severity><error-message>Leafref validation failed: No leaf x matching path /ex:sender-config/ex:name Internal error, state callback returned invalid XML</error-message></rpc-error></rpc-reply>]]>]]>$'
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get content="nonconfig"><filter type="xpath" select="/"/></get></rpc>]]>]]>' '^<rpc-reply><rpc-error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-info><bad-element>x</bad-element></error-info><error-severity>error</error-severity><error-message>Leafref validation failed: No leaf x matching path /ex:sender-config/ex:name. Internal error, state callback returned invalid XML</error-message></rpc-error></rpc-reply>]]>]]>$'
|
||||
|
||||
new "netconf get / config-only ok"
|
||||
expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><get content="config"><filter type="xpath" select="/"/></get></rpc>]]>]]>' '^<rpc-reply><data><sender-config xmlns="urn:example:example"><name>y</name></sender-config></data></rpc-reply>]]>]]>$'
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ module $APPNAME{
|
|||
}
|
||||
EOF
|
||||
|
||||
# Mixed config + state XML
|
||||
new "generate state file with $perfnr list entries"
|
||||
echo -n "<interfaces xmlns=\"urn:example:clixon\"><a><name>foo</name><b>" > $fstate
|
||||
for (( i=0; i<$perfnr; i++ )); do
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@
|
|||
# Note this is different from an api-path that is invalid from a yang point
|
||||
# of view, this is interpreted as 400 Bad Request invalid-value/unknown-element
|
||||
# XXX: complete non-existent yang with unknown-element for all PUT/POST/GET api-paths
|
||||
#
|
||||
# Also generate an invalid state XML. This should generate an "Internal" error and the name of the
|
||||
# plugin should be visible in the error message.
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
|
@ -25,6 +28,7 @@ cfg=$dir/conf.xml
|
|||
fyang=$dir/example.yang
|
||||
fyang2=$dir/augment.yang
|
||||
fxml=$dir/initial.xml
|
||||
fstate=$dir/state.xml
|
||||
|
||||
# <CLICON_YANG_MODULE_MAIN>example</CLICON_YANG_MODULE_MAIN>
|
||||
cat <<EOF > $cfg
|
||||
|
|
@ -36,6 +40,8 @@ cat <<EOF > $cfg
|
|||
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
|
||||
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||
<CLICON_BACKEND_PIDFILE>$dir/restconf.pidfile</CLICON_BACKEND_PIDFILE>
|
||||
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
|
||||
<CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP>
|
||||
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||
|
|
@ -103,9 +109,32 @@ module example{
|
|||
}
|
||||
}
|
||||
}
|
||||
container mystate{
|
||||
config false;
|
||||
description "Just for generating a invalid XML";
|
||||
list parameter{
|
||||
key name;
|
||||
leaf name{
|
||||
type string;
|
||||
}
|
||||
leaf value{
|
||||
type string;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# State file with error: wrong namespace
|
||||
cat <<EOF > $fstate
|
||||
<mystate xmlns="urn:example:foobar">
|
||||
<parameter>
|
||||
<name>x</name>
|
||||
<value>x</value>
|
||||
</parameter>
|
||||
</mystate>
|
||||
EOF
|
||||
|
||||
# Initial tree
|
||||
XML=$(cat <<EOF
|
||||
<a xmlns="urn:example:clixon"><k>0</k><description>No leaf b, No container c, No leaf d</description></a>
|
||||
|
|
@ -121,28 +150,29 @@ if [ $BE -ne 0 ]; then
|
|||
err
|
||||
fi
|
||||
sudo pkill -f clixon_backend # to be sure
|
||||
new "start backend -s init -f $cfg"
|
||||
start_backend -s init -f $cfg
|
||||
new "start backend -s init -f $cfg -- -sS $fstate"
|
||||
start_backend -s init -f $cfg -- -sS $fstate
|
||||
fi
|
||||
|
||||
new "waiting"
|
||||
wait_backend
|
||||
|
||||
new "kill old restconf daemon"
|
||||
sudo pkill -u $wwwuser -f clixon_restconf
|
||||
if [ $RC -ne 0 ]; then
|
||||
new "kill old restconf daemon"
|
||||
sudo pkill -u $wwwuser -f clixon_restconf
|
||||
|
||||
new "start restconf daemon"
|
||||
start_restconf -f $cfg
|
||||
new "start restconf daemon"
|
||||
start_restconf -f $cfg
|
||||
|
||||
new "waiting"
|
||||
wait_restconf
|
||||
new "waiting"
|
||||
wait_restconf
|
||||
fi
|
||||
|
||||
new "restconf POST initial tree"
|
||||
expecteq "$(curl -s -X POST -H 'Content-Type: application/yang-data+xml' -d "$XML" http://localhost/restconf/data)" 0 ''
|
||||
expectpart "$(curl -si -X POST -H 'Content-Type: application/yang-data+xml' -d "$XML" http://localhost/restconf/data)" 0 'HTTP/1.1 201 Created'
|
||||
|
||||
new "restconf GET initial datastore"
|
||||
expecteq "$(curl -s -X GET -H 'Accept: application/yang-data+xml' http://localhost/restconf/data/example:a=0)" 0 "$XML
|
||||
"
|
||||
expectpart "$(curl -si -X GET -H 'Accept: application/yang-data+xml' http://localhost/restconf/data/example:a=0)" 0 'HTTP/1.1 200 OK' "$XML"
|
||||
|
||||
new "restconf GET non-qualified list"
|
||||
expectpart "$(curl -si -X GET http://localhost/restconf/data/example:a)" 0 'HTTP/1.1 400 Bad Request' "{\"ietf-restconf:errors\":{\"error\":{\"error-type\":\"rpc\",\"error-tag\":\"malformed-message\",\"error-severity\":\"error\",\"error-message\":\"malformed key =example:a, expected '=restval'\"}}}"
|
||||
|
|
@ -165,7 +195,7 @@ expectpart "$(curl -is -X POST -H 'Content-Type: application/yang-data+xml' -d "
|
|||
|
||||
# Test for multi-module path where an augment stretches across modules
|
||||
new "restconf POST augment multi-namespace path"
|
||||
expecteq "$(curl -s -X POST -H 'Content-Type: application/yang-data+xml' -d '<route-config xmlns="urn:example:aug"><dynamic><ospf xmlns="urn:example:clixon"><reference-bandwidth>23</reference-bandwidth></ospf></dynamic></route-config>' http://localhost/restconf/data)" 0 ''
|
||||
expectpart "$(curl -si -X POST -H 'Content-Type: application/yang-data+xml' -d '<route-config xmlns="urn:example:aug"><dynamic><ospf xmlns="urn:example:clixon"><reference-bandwidth>23</reference-bandwidth></ospf></dynamic></route-config>' http://localhost/restconf/data)" 0 'HTTP/1.1 201 Created'
|
||||
|
||||
new "restconf GET augment multi-namespace top"
|
||||
expectpart "$(curl -si -X GET http://localhost/restconf/data/augment:route-config)" 0 'HTTP/1.1 200 OK' '{"augment:route-config":{"dynamic":{"example:ospf":{"reference-bandwidth":23}}}}'
|
||||
|
|
@ -183,8 +213,15 @@ expectpart "$(curl -si -X GET http://localhost/restconf/data/augment:route-confi
|
|||
new "restconf GET augment multi-namespace, no 2nd module in api-path, fail"
|
||||
expectpart "$(curl -si -X GET http://localhost/restconf/data/augment:route-config/dynamic/ospf)" 0 'HTTP/1.1 404 Not Found' '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"invalid-value","error-severity":"error","error-message":"Instance does not exist"}}}'
|
||||
|
||||
new "Kill restconf daemon"
|
||||
stop_restconf
|
||||
#----------------------------------------------
|
||||
# Also generate an invalid state XML. This should generate an "Internal" error and the name of the
|
||||
new "restconf GET failed state"
|
||||
expectpart "$(curl -si -X GET -H 'Accept: application/yang-data+xml' http://localhost/restconf/data?content=nonconfig)" 0 '412 Precondition Failed' '<errors xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf"><error><error-type>application</error-type><error-tag>operation-failed</error-tag><error-info><bad-element>mystate</bad-element></error-info><error-severity>error</error-severity><error-message>No such yang module. Internal error, state callback returned invalid XML: example_backend</error-message></error></errors>'
|
||||
|
||||
if [ $RC -ne 0 ]; then
|
||||
new "Kill restconf daemon"
|
||||
stop_restconf
|
||||
fi
|
||||
|
||||
if [ $BE -eq 0 ]; then
|
||||
exit # BE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue