Tests:
- Added tests for more coverage, including test_debug.sh - Added yang deviation test
This commit is contained in:
parent
6981daf595
commit
030715df61
7 changed files with 276 additions and 5 deletions
|
|
@ -332,6 +332,13 @@ evhtp_method2str(enum htp_method m)
|
||||||
case htp_method_DELETE:
|
case htp_method_DELETE:
|
||||||
return "DELETE";
|
return "DELETE";
|
||||||
break;
|
break;
|
||||||
|
case htp_method_OPTIONS:
|
||||||
|
return "OPTIONS";
|
||||||
|
break;
|
||||||
|
case htp_method_PATCH:
|
||||||
|
return "PATCH";
|
||||||
|
break;
|
||||||
|
#ifdef NOTUSED
|
||||||
case htp_method_MKCOL:
|
case htp_method_MKCOL:
|
||||||
return "MKCOL";
|
return "MKCOL";
|
||||||
break;
|
break;
|
||||||
|
|
@ -362,9 +369,7 @@ evhtp_method2str(enum htp_method m)
|
||||||
case htp_method_CONNECT:
|
case htp_method_CONNECT:
|
||||||
return "CONNECT";
|
return "CONNECT";
|
||||||
break;
|
break;
|
||||||
case htp_method_PATCH:
|
#endif /* NOTUSED */
|
||||||
return "PATCH";
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
break;
|
break;
|
||||||
|
|
@ -898,6 +903,7 @@ restconf_connection(int s,
|
||||||
}
|
}
|
||||||
h = (clicon_handle*)conn->htp->arg;
|
h = (clicon_handle*)conn->htp->arg;
|
||||||
while (readmore) {
|
while (readmore) {
|
||||||
|
clicon_debug(1, "%s readmore", __FUNCTION__);
|
||||||
readmore = 0;
|
readmore = 0;
|
||||||
/* Example: curl -Ssik -u wilma:bar -X GET https://localhost/restconf/data/example:x */
|
/* Example: curl -Ssik -u wilma:bar -X GET https://localhost/restconf/data/example:x */
|
||||||
if (conn->ssl){
|
if (conn->ssl){
|
||||||
|
|
@ -991,6 +997,7 @@ restconf_connection(int s,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0 /* debug */
|
||||||
/*! Debug print all loaded certs
|
/*! Debug print all loaded certs
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
|
|
@ -1017,6 +1024,7 @@ restconf_listcerts(SSL *ssl)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif/* debug */
|
||||||
|
|
||||||
/*! Check if a "cert" file exists
|
/*! Check if a "cert" file exists
|
||||||
*
|
*
|
||||||
|
|
@ -1237,9 +1245,10 @@ restconf_accept_client(int fd,
|
||||||
clicon_debug(1, "%s peername:%s", __FUNCTION__, peername);
|
clicon_debug(1, "%s peername:%s", __FUNCTION__, peername);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if 0 /* debug */
|
||||||
if (clicon_debug_get())
|
if (clicon_debug_get())
|
||||||
restconf_listcerts(ssl);
|
restconf_listcerts(ssl);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Register callbacks for actual data socket
|
* Register callbacks for actual data socket
|
||||||
|
|
|
||||||
|
|
@ -20,5 +20,6 @@ comment:
|
||||||
require_changes: no
|
require_changes: no
|
||||||
|
|
||||||
ignore:
|
ignore:
|
||||||
- "util/" # ignore folders and all its contents
|
- "util/"
|
||||||
|
- "example/"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,3 +28,5 @@ find . -name "*.gcda" | xargs sudo chmod 777
|
||||||
# The -f dont seem to work
|
# The -f dont seem to work
|
||||||
bash <(curl -s https://codecov.io/bash) -t ${TOKEN}
|
bash <(curl -s https://codecov.io/bash) -t ${TOKEN}
|
||||||
|
|
||||||
|
sleep 1 # ensure OK is last
|
||||||
|
echo OK
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,9 @@ CONFNS='xmlns="http://clicon.org/config"'
|
||||||
# Namespace: Clixon lib
|
# Namespace: Clixon lib
|
||||||
LIBNS='xmlns="http://clicon.org/lib"'
|
LIBNS='xmlns="http://clicon.org/lib"'
|
||||||
|
|
||||||
|
# Namespace: Clixon restconf
|
||||||
|
RESTCONFNS='xmlns="http://clicon.org/restconf"'
|
||||||
|
|
||||||
# Default netconf namespace statement, typically as placed on top-level <rpc xmlns=""
|
# Default netconf namespace statement, typically as placed on top-level <rpc xmlns=""
|
||||||
DEFAULTONLY="xmlns=\"$BASENS\""
|
DEFAULTONLY="xmlns=\"$BASENS\""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,12 @@ expectpart "$($clixon_cli -1 -f $cfg copy interface eth/0/0 to eth99)" 0 "^$"
|
||||||
new "cli success validate"
|
new "cli success validate"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o validate)" 0 "^$"
|
expectpart "$($clixon_cli -1 -f $cfg -l o validate)" 0 "^$"
|
||||||
|
|
||||||
|
new "cli compare diff"
|
||||||
|
expectpart "$($clixon_cli -1 -f $cfg -l o compare)" 0 "+ ip 1.2.3.4;"
|
||||||
|
|
||||||
|
new "cli start shell"
|
||||||
|
expectpart "$($clixon_cli -1 -f $cfg -l o shell echo foo)" 0 "foo"
|
||||||
|
|
||||||
new "cli commit"
|
new "cli commit"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o commit)" 0 "^$"
|
expectpart "$($clixon_cli -1 -f $cfg -l o commit)" 0 "^$"
|
||||||
|
|
||||||
|
|
|
||||||
130
test/test_debug.sh
Executable file
130
test/test_debug.sh
Executable file
|
|
@ -0,0 +1,130 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Turn on debug on backend/cli/restconf/netconf
|
||||||
|
|
||||||
|
# Magic line must be first in script (see README.md)
|
||||||
|
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||||
|
|
||||||
|
APPNAME=example
|
||||||
|
|
||||||
|
cfg=$dir/conf.xml
|
||||||
|
fyang=$dir/restconf.yang
|
||||||
|
|
||||||
|
# Define default restconfig config: RESTCONFIG
|
||||||
|
RESTCONFIG=$(restconf_config none false)
|
||||||
|
|
||||||
|
# <CLICON_YANG_MODULE_MAIN>example</CLICON_YANG_MODULE_MAIN>
|
||||||
|
cat <<EOF > $cfg
|
||||||
|
<clixon-config xmlns="http://clicon.org/config">
|
||||||
|
<CLICON_FEATURE>clixon-restconf:allow-auth-none</CLICON_FEATURE> <!-- Use auth-type=none -->
|
||||||
|
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||||
|
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||||
|
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
|
||||||
|
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
|
||||||
|
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||||
|
<CLICON_BACKEND_PIDFILE>$dir/restconf.pidfile</CLICON_BACKEND_PIDFILE>
|
||||||
|
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||||
|
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||||
|
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||||
|
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||||
|
$RESTCONFIG
|
||||||
|
</clixon-config>nn
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat <<EOF > $fyang
|
||||||
|
module example{
|
||||||
|
yang-version 1.1;
|
||||||
|
namespace "urn:example:clixon";
|
||||||
|
prefix ex;
|
||||||
|
/* Generic config data */
|
||||||
|
container table{
|
||||||
|
list parameter{
|
||||||
|
key name;
|
||||||
|
leaf name{
|
||||||
|
type string;
|
||||||
|
}
|
||||||
|
leaf value{
|
||||||
|
type string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
sudo pkill -f clixon_backend # to be sure
|
||||||
|
new "start backend -s init -f $cfg"
|
||||||
|
start_backend -s init -f $cfg
|
||||||
|
fi
|
||||||
|
|
||||||
|
new "waiting"
|
||||||
|
wait_backend
|
||||||
|
|
||||||
|
if [ $RC -ne 0 ]; then
|
||||||
|
new "kill old restconf daemon"
|
||||||
|
stop_restconf_pre
|
||||||
|
|
||||||
|
new "start restconf daemon"
|
||||||
|
start_restconf -f $cfg
|
||||||
|
|
||||||
|
new "waiting"
|
||||||
|
wait_restconf
|
||||||
|
fi
|
||||||
|
|
||||||
|
new "Set backend debug using netconf"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><debug $LIBNS><level>1</level></debug></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
|
new "Set backend debug using restconf"
|
||||||
|
expectpart "$(curl $CURLOPTS -X POST -H 'Content-Type: application/yang-data+json' http://localhost/restconf/operations/clixon-lib:debug -d '{"clixon-lib:input":{"level":1}}')" 0 'HTTP/1.1 204 No Content'
|
||||||
|
|
||||||
|
new "Set restconf debug using netconf"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><restconf $RESTCONFNS><debug>1</debug></restconf></config></edit-config></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
|
new "netconf commit"
|
||||||
|
expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO<rpc $DEFAULTNS><commit/></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
|
||||||
|
|
||||||
|
new "Set restconf debug using restconf"
|
||||||
|
expectpart "$(curl $CURLOPTS -X PUT -H 'Content-Type: application/yang-data+json' http://localhost/restconf/data/clixon-restconf:restconf/debug -d '{"clixon-restconf:debug":1}')" 0 "HTTP/1.1 204 No Content"
|
||||||
|
|
||||||
|
new "Set cli debug using cli"
|
||||||
|
expectpart "$($clixon_cli -1 -f $cfg -l o debug cli 1)" 0 "^$"
|
||||||
|
|
||||||
|
new "Set backend debug using cli"
|
||||||
|
expectpart "$($clixon_cli -1 -f $cfg -l o debug backend 1)" 0 "^$"
|
||||||
|
|
||||||
|
new "Set restconf debug using cli"
|
||||||
|
expectpart "$($clixon_cli -1 -f $cfg -l o debug restconf 1)" 0 "^$"
|
||||||
|
|
||||||
|
# Exercse debug code
|
||||||
|
new "get and put config using restconf"
|
||||||
|
expectpart "$(curl $CURLOPTS -H "Accept: application/yang-data+xml" -X GET $RCPROTO://localhost/restconf/data?content=config --next $CURLOPTS -H "Content-Type: application/yang-data+json" -X POST $RCPROTO://localhost/restconf/data -d '{"example:table":{"parameter":{"name":"local0","value":"foo"}}}')" 0 "HTTP/1.1 200 OK" '<data>' 'HTTP/1.1 201 Created'
|
||||||
|
|
||||||
|
if [ $RC -ne 0 ]; then
|
||||||
|
new "Kill restconf daemon"
|
||||||
|
stop_restconf
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $BE -ne 0 ]; then
|
||||||
|
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
|
||||||
|
stop_backend -f $cfg
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set by restconf_config
|
||||||
|
unset RESTCONFIG
|
||||||
|
|
||||||
|
rm -rf $dir
|
||||||
|
|
||||||
|
new "endtest"
|
||||||
|
endtest
|
||||||
120
test/test_yang_deviation.sh
Executable file
120
test/test_yang_deviation.sh
Executable file
|
|
@ -0,0 +1,120 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Yang deviate tests
|
||||||
|
# See RFC 7950 5.6.3 and 7.20.3
|
||||||
|
# Four examples: not supported, add, replace, delete
|
||||||
|
|
||||||
|
# Magic line must be first in script (see README.md)
|
||||||
|
s="$_" ; . ./lib.sh || if [ "$s" = "$0" ]; then exit 0; else return 0; fi
|
||||||
|
|
||||||
|
APPNAME=example
|
||||||
|
|
||||||
|
cfg=$dir/conf_yang.xml
|
||||||
|
fyangbase=$dir/example-base.yang
|
||||||
|
fyangdev=$dir/example-deviations.yang
|
||||||
|
|
||||||
|
cat <<EOF > $cfg
|
||||||
|
<clixon-config xmlns="http://clicon.org/config">
|
||||||
|
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
|
||||||
|
<CLICON_YANG_DIR>/usr/local/share/clixon</CLICON_YANG_DIR>
|
||||||
|
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
|
||||||
|
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
|
||||||
|
<CLICON_YANG_MAIN_DIR>$dir</CLICON_YANG_MAIN_DIR>
|
||||||
|
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
|
||||||
|
<CLICON_CLI_DIR>/usr/local/lib/$APPNAME/cli</CLICON_CLI_DIR>
|
||||||
|
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
|
||||||
|
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
|
||||||
|
<CLICON_BACKEND_PIDFILE>/usr/local/var/$APPNAME/$APPNAME.pidfile</CLICON_BACKEND_PIDFILE>
|
||||||
|
<CLICON_XMLDB_DIR>/usr/local/var/$APPNAME</CLICON_XMLDB_DIR>
|
||||||
|
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
|
||||||
|
</clixon-config>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat <<EOF > $fyangbase
|
||||||
|
module example-base{
|
||||||
|
yang-version 1.1;
|
||||||
|
prefix base;
|
||||||
|
namespace "urn:example:base";
|
||||||
|
container system {
|
||||||
|
must "daytime or time";
|
||||||
|
leaf daytime{
|
||||||
|
type string;
|
||||||
|
}
|
||||||
|
list name-server {
|
||||||
|
key name;
|
||||||
|
leaf name {
|
||||||
|
type string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list user {
|
||||||
|
key name;
|
||||||
|
leaf name {
|
||||||
|
type string;
|
||||||
|
}
|
||||||
|
leaf type {
|
||||||
|
type string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Example from RFC 7950 Sec 7.20.3.3
|
||||||
|
cat <<EOF > $fyangdev
|
||||||
|
module $APPNAME{
|
||||||
|
yang-version 1.1;
|
||||||
|
prefix md;
|
||||||
|
namespace "urn:example:deviations";
|
||||||
|
|
||||||
|
import example-base {
|
||||||
|
prefix base;
|
||||||
|
}
|
||||||
|
|
||||||
|
deviation /base:system/base:daytime {
|
||||||
|
deviate not-supported;
|
||||||
|
}
|
||||||
|
deviation /base:system/base:user/base:type {
|
||||||
|
deviate add {
|
||||||
|
default "admin"; // new users are 'admin' by default
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deviation /base:system {
|
||||||
|
deviate delete {
|
||||||
|
must "daytime or time";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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_backend -s init -f "$cfg"
|
||||||
|
|
||||||
|
new "waiting"
|
||||||
|
wait_backend
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
stop_backend -f "$cfg"
|
||||||
|
|
||||||
|
rm -rf "$dir"
|
||||||
|
|
||||||
|
new "endtest"
|
||||||
|
endtest
|
||||||
Loading…
Add table
Add a link
Reference in a new issue