debug print of backend state, split test-stream into a netconf and restconf part, change restconf yang auth-type from leaf-list to leaf

This commit is contained in:
Olof hagsand 2021-01-27 14:40:34 +01:00
parent a5f32fbedf
commit b41f68b677
13 changed files with 244 additions and 63 deletions

View file

@ -147,6 +147,7 @@ backend_client_rm(clicon_handle h,
clixon_event_unreg_fd(ce->ce_s, from_client);
close(ce->ce_s);
ce->ce_s = 0;
xmldb_unlock_all(h, ce->ce_id);
}
break;
}
@ -1308,8 +1309,8 @@ from_client_kill_session(clicon_handle h,
}
/* may or may not be in active client list, probably not */
if ((ce = ce_find_byid(backend_client_list(h), id)) != NULL){
xmldb_unlock_all(h, id);
backend_client_rm(h, ce);
xmldb_unlock_all(h, id); /* Removes locks on all databases */
backend_client_rm(h, ce); /* Removes client struct */
}
if (xmldb_islocked(h, db) == id)
xmldb_unlock(h, db);

View file

@ -54,4 +54,6 @@ struct client_entry *backend_client_list(clicon_handle h);
int backend_client_delete(clicon_handle h, struct client_entry *ce);
int backend_client_print(clicon_handle h, FILE *f);
#endif /* _BACKEND_HANDLE_H_ */

View file

@ -188,3 +188,25 @@ backend_client_delete(clicon_handle h,
return 0;
}
/*! Debug print backend clients
* @param[in] h Clicon handle
* @param[in] f UNIX output stream
*/
int
backend_client_print(clicon_handle h,
FILE *f)
{
struct backend_handle *bh = handle(h);
struct client_entry *ce;
for (ce = bh->bh_ce_list; ce; ce = ce->ce_next){
fprintf(f, "Client: %d\n", ce->ce_nr);
fprintf(f, " Session: %d\n", ce->ce_id);
fprintf(f, " Socket: %d\n", ce->ce_s);
fprintf(f, " Msgs in: %d\n", ce->ce_stat_in);
fprintf(f, " Msgs out: %d\n", ce->ce_stat_out);
fprintf(f, " Username: %s\n", ce->ce_username);
}
return 0;
}

View file

@ -946,7 +946,7 @@ cx_evhtp_init(clicon_handle h,
/* If at least one socket has ssl then enable global ssl_enable */
ssl_enable = xpath_first(xrestconf, nsc, "socket[ssl='true']") != NULL;
/* get common fields */
if ((x = xpath_first(xrestconf, nsc, "auth-type")) != NULL) /* XXX: leaf-list? */
if ((x = xpath_first(xrestconf, nsc, "auth-type")) != NULL)
auth_type = xml_body(x);
if (auth_type && strcmp(auth_type, "client-certificate") == 0)
auth_type_client_certificate = 1;

View file

@ -148,7 +148,7 @@ Merge a branch back:
## Use of constants etc
Use MAXPATHLEN (not PATH_MAX)
Use MAXPATHLEN (not PATH_MAX) in sys/param.h
## Emulating a serial console

View file

@ -66,7 +66,7 @@
#include <clixon/clixon_backend.h>
/* Command line options to be passed to getopt(3) */
#define BACKEND_EXAMPLE_OPTS "rsS:iuUt:v:n:"
#define BACKEND_EXAMPLE_OPTS "rsS:iuUt:v:"
/*! Variable to control if reset code is run.
* The reset code inserts "extra XML" which assumes ietf-interfaces is
@ -119,11 +119,6 @@ static int _transaction_log = 0;
static char *_validate_fail_xpath = NULL;
static int _validate_fail_toggle = 0; /* fail at validate and commit */
/* -n <ns>
* Network namespace for starting restconf process in another namespace
*/
static char *_proc_netns = NULL;
/* forward */
static int example_stream_timer_setup(clicon_handle h);
@ -1087,9 +1082,6 @@ clixon_plugin_init(clicon_handle h)
case 'v': /* validate fail */
_validate_fail_xpath = optarg;
break;
case 'n': /* process restconf namespace*/
_proc_netns = optarg;
break;
}
/* Example stream initialization:

View file

@ -75,5 +75,6 @@ int xmldb_modified_get(clicon_handle h, const char *db);
int xmldb_modified_set(clicon_handle h, const char *db, int value);
int xmldb_empty_get(clicon_handle h, const char *db);
int xmldb_dump(clicon_handle h, FILE *f, cxobj *xt);
int xmldb_print(clicon_handle h, FILE *f);
#endif /* _CLIXON_DATASTORE_H */

View file

@ -560,3 +560,32 @@ xmldb_modified_set(clicon_handle h,
de->de_modified = value;
return 0;
}
/* Print the datastore meta-info to file
*/
int
xmldb_print(clicon_handle h,
FILE *f)
{
int retval = -1;
db_elmnt *de = NULL;
char **keys = NULL;
size_t klen;
int i;
if (clicon_hash_keys(clicon_db_elmnt(h), &keys, &klen) < 0)
goto done;
for (i = 0; i < klen; i++){
/* XXX name */
if ((de = clicon_db_elmnt_get(h, keys[i])) == NULL)
continue;
fprintf(f, "Datastore: %s\n", keys[i]);
fprintf(f, " Session: %u\n", de->de_id);
fprintf(f, " XML: %p\n", de->de_xml);
fprintf(f, " Modified: %d\n", de->de_modified);
fprintf(f, " Empty: %d\n", de->de_empty);
}
retval = 0;
done:
return retval;
}

View file

@ -334,6 +334,7 @@ stop_restconf(){
# Wait for restconf to stop sending 502 Bad Gateway
# @see start_restconf
# Reasons for not working: if you run evhtp is nginx running?
# @note assumes port=80 if RCPROTO=http and port=443 if RCPROTO=https
wait_restconf(){
# echo "curl $CURLOPTS $* $RCPROTO://localhost/restconf"
hdr=$(curl $CURLOPTS $* $RCPROTO://localhost/restconf) 2> /dev/null

View file

@ -0,0 +1,157 @@
#!/usr/bin/env bash
# Tests for Netconf event streams using notifications
# See RFC5277 NETCONF Event Notifications
#
# Testing of streams is quite complicated.
# Here are some testing dimensions in restconf alone:
# - start/stop subscription
# - start-time/stop-time in subscription
# - stream retention time
# - native vs nchan implementation
# Focussing on 1-3
# 2a) start sub 8s - expect 2 notifications
# 2b) start sub 8s - stoptime after 5s - expect 1 notifications
# 2c) start sub 8s - replay from start -8s - expect 4 notifications
# 2d) start sub 8s - replay from start -8s to stop +4s - expect 3 notifications
# 2e) start sub 8s - replay from -90s w retention 60s - expect 10 notifications
# Note the sleeps are mainly for valgrind usage
# 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
NCWAIT=10 # Wait (netconf valgrind may need more time)
# Ensure UTC
DATE=$(date -u +"%Y-%m-%d")
cfg=$dir/conf.xml
fyang=$dir/stream.yang
xml=$dir/xml.xml
# <CLICON_YANG_MODULE_MAIN>example</CLICON_YANG_MODULE_MAIN>
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>$IETFRFC</CLICON_YANG_DIR>
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
<CLICON_RESTCONF_PRETTY>false</CLICON_RESTCONF_PRETTY>
<CLICON_SOCK>/usr/local/var/$APPNAME/$APPNAME.sock</CLICON_SOCK>
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
<CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP>
<CLICON_BACKEND_PIDFILE>$dir/restconf.pidfile</CLICON_BACKEND_PIDFILE>
<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>
<CLICON_CLI_MODE>$APPNAME</CLICON_CLI_MODE>
<CLICON_MODULE_LIBRARY_RFC7895>true</CLICON_MODULE_LIBRARY_RFC7895>
<CLICON_STREAM_DISCOVERY_RFC5277>true</CLICON_STREAM_DISCOVERY_RFC5277>
<CLICON_STREAM_PATH>streams</CLICON_STREAM_PATH>
<CLICON_STREAM_RETENTION>60</CLICON_STREAM_RETENTION>
</clixon-config>
EOF
# For nchan testing add this line to above config
# <CLICON_STREAM_PUB>http://localhost/pub</CLICON_STREAM_PUB>
# RFC5277 NETCONF Event Notifications
# using reportingEntity (rfc5277) not reporting-entity (rfc8040)
cat <<EOF > $fyang
module example {
namespace "urn:example:clixon";
prefix ex;
organization "Example, Inc.";
contact "support at example.com";
description "Example Notification Data Model Module.";
revision "2016-07-07" {
description "Initial version.";
reference "example.com document 2-9976.";
}
notification event {
description "Example notification event.";
leaf event-class {
type string;
description "Event class identifier.";
}
container reportingEntity {
description "Event specific information.";
leaf card {
type string;
description "Line card identifier.";
}
}
leaf severity {
type string;
description "Event severity description.";
}
}
container state {
config false;
description "state data for the example application (must be here for example get operation)";
leaf-list op {
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
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
fi
new "waiting"
wait_backend
#
# 1. Netconf RFC5277 stream testing
new "1. Netconf RFC5277 stream testing"
# 1.1 Stream discovery
new "netconf event stream discovery RFC5277 Sec 3.2.5"
expecteof "$clixon_netconf -D $DBG -qf $cfg" 0 "<rpc $DEFAULTNS><get><filter type=\"xpath\" select=\"n:netconf/n:streams\" xmlns:n=\"urn:ietf:params:xml:ns:netmod:notification\"/></get></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><data><netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><streams><stream><name>EXAMPLE</name><description>Example event stream</description><replay-support>true</replay-support></stream></streams></netconf></data></rpc-reply>]]>]]>"
new "netconf EXAMPLE subscription"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>20" $NCWAIT
new "netconf subscription with empty startTime"
expecteof "$clixon_netconf -D $DBG -qf $cfg" 0 "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><startTime/></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>startTime</bad-element></error-info><error-severity>error</error-severity><error-message>regexp match fail:"
new "netconf EXAMPLE subscription with simple filter"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><filter type=\"xpath\" select=\"event\"/></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>20" $NCWAIT
new "netconf EXAMPLE subscription with filter classifier"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><filter type=\"xpath\" select=\"event[event-class='fault']\"/></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>20" $NCWAIT
new "netconf NONEXIST subscription"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>NONEXIST</stream></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>invalid-value</error-tag><error-severity>error</error-severity><error-message>No such stream</error-message></rpc-error></rpc-reply>]]>]]>$" $NCWAIT
new "netconf EXAMPLE subscription with wrong date"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><startTime>kallekaka</startTime></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>startTime</bad-element></error-info><error-severity>error</error-severity><error-message>regexp match fail:" 0
#new "netconf EXAMPLE subscription with replay"
#NOW=$(date +"%Y-%m-%dT%H:%M:%S")
#sleep 10
#expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><startTime>$NOW</startTime></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>20" 10
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
rm -rf $dir

View file

@ -1,5 +1,7 @@
#!/usr/bin/env bash
# Tests for event streams using notifications
# See RFC5277 NETCONF Event Notifications
# RFC8040 Sec 6.2
# Assumptions:
# 1. http server setup, such as nginx described in apps/restconf/README.md
# especially SSE - ngchan setup
@ -134,43 +136,13 @@ if [ $RC -ne 0 ]; then
wait_restconf
fi
#
# 1. Netconf RFC5277 stream testing
new "1. Netconf RFC5277 stream testing"
# 1.1 Stream discovery
new "netconf event stream discovery RFC5277 Sec 3.2.5"
expecteof "$clixon_netconf -D $DBG -qf $cfg" 0 "<rpc $DEFAULTNS><get><filter type=\"xpath\" select=\"n:netconf/n:streams\" xmlns:n=\"urn:ietf:params:xml:ns:netmod:notification\"/></get></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><data><netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><streams><stream><name>EXAMPLE</name><description>Example event stream</description><replay-support>true</replay-support></stream></streams></netconf></data></rpc-reply>]]>]]>"
new "netconf event stream discovery RFC8040 Sec 6.2"
expecteof "$clixon_netconf -D $DBG -qf $cfg" 0 "<rpc $DEFAULTNS><get><filter type=\"xpath\" select=\"r:restconf-state/r:streams\" xmlns:r=\"urn:ietf:params:xml:ns:yang:ietf-restconf-monitoring\"/></get></rpc>]]>]]>" "<rpc-reply $DEFAULTNS><data><restconf-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf-monitoring\"><streams><stream><name>EXAMPLE</name><description>Example event stream</description><replay-support>true</replay-support><access><encoding>xml</encoding><location>https://localhost/streams/EXAMPLE</location></access></stream></streams></restconf-state></data></rpc-reply>]]>]]>"
#
# 1.2 Netconf stream subscription
new "netconf EXAMPLE subscription"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>20" $NCWAIT
new "netconf subscription with empty startTime"
expecteof "$clixon_netconf -D $DBG -qf $cfg" 0 "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><startTime/></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>startTime</bad-element></error-info><error-severity>error</error-severity><error-message>regexp match fail:"
new "netconf EXAMPLE subscription with simple filter"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><filter type=\"xpath\" select=\"event\"/></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>20" $NCWAIT
new "netconf EXAMPLE subscription with filter classifier"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><filter type=\"xpath\" select=\"event[event-class='fault']\"/></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>20" $NCWAIT
new "netconf NONEXIST subscription"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>NONEXIST</stream></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>invalid-value</error-tag><error-severity>error</error-severity><error-message>No such stream</error-message></rpc-error></rpc-reply>]]>]]>$" $NCWAIT
new "netconf EXAMPLE subscription with wrong date"
expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><startTime>kallekaka</startTime></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>startTime</bad-element></error-info><error-severity>error</error-severity><error-message>regexp match fail:" 0
#new "netconf EXAMPLE subscription with replay"
#NOW=$(date +"%Y-%m-%dT%H:%M:%S")
#sleep 10
#expectwait "$clixon_netconf -D $DBG -qf $cfg" "<rpc $DEFAULTNS><create-subscription xmlns=\"urn:ietf:params:xml:ns:netmod:notification\"><stream>EXAMPLE</stream><startTime>$NOW</startTime></create-subscription></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><notification xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\"><eventTime>20" 10
sleep 1
#
# 2. Restconf RFC8040 stream testing
new "2. Restconf RFC8040 stream testing"
# 2.1 Stream discovery
@ -261,8 +233,8 @@ if [ -z "$match" ]; then
fi
nr=$(echo "$ret" | grep -c "data:")
if [ $nr -lt 9 -o $nr -gt 14 ]; then
err "9-14" "$nr"
if [ $nr -lt 8 -o $nr -gt 14 ]; then
err "8-14" "$nr"
fi
sleep 1
@ -300,10 +272,7 @@ if [ $RC -ne 0 ]; then
stop_restconf
fi
if [ $BE -eq 0 ]; then
exit # BE
fi
if [ $BE -ne 0 ]; then
new "Kill backend"
# Check if premature kill
pid=$(pgrep -u root -f clixon_backend)
@ -312,6 +281,7 @@ if [ -z "$pid" ]; then
fi
# kill backend
stop_backend -f $cfg
fi
rm -rf $dir

View file

@ -300,9 +300,11 @@ module clixon-config {
enum IPv4 {
description "IPv4";
}
enum IPv6 {
description "IPv6";
}
}
}
container clixon-config {
container restconf {
uses clrc:clixon-restconf;
@ -629,8 +631,12 @@ module clixon-config {
type string;
mandatory true;
description
"If family above is AF_UNIX: Unix socket for communicating
with clixon_backend. If family is AF_INET: IPv4 address";
"String description of Clixon Internal (IPC) socket that connects a clixon
client to the clixon backend. This string is dependent on family.
If CLICON_SOCK_FAMILY is:
- UNIX: The value is a Unix socket path
- IPv4: IPv4 address string
- IPv6: IPv6 address string (NYI)";
}
leaf CLICON_SOCK_PORT {
type int32;

View file

@ -78,7 +78,7 @@ module clixon-restconf {
For example, if the restconf daemon is under systemd management, the restconf
daemon will only start if enable=true.";
}
leaf-list auth-type {
leaf auth-type {
type http-auth-type;
description
"The authentication type.