* Corrected client session handling to make internal IPC socket persistent

* Applies to cli/netconf/restconf/client-api code
  * Previous behaviour:
    * Close socket after each rpc, but now keeps the socket open until the client terminates
    * Kept locks over socket life-cycle, but according to RFC 6241 7.5 a lock should be relaeased when session ends
This commit is contained in:
Olof hagsand 2021-01-27 15:07:27 +01:00
parent b41f68b677
commit f5f013c739
18 changed files with 371 additions and 145 deletions

View file

@ -15,6 +15,7 @@ fyang=$dir/example-client.yang
cfile=$dir/example-client.c
pdir=$dir/plugin
app=$dir/clixon-app
debug=0
if [ ! -d $pdir ]; then
mkdir $pdir
@ -68,19 +69,21 @@ cat<<EOF > $cfile
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include <syslog.h> // debug
#include <clixon/clixon_log.h>
#include <clixon/clixon_log.h> // debug
#include <clixon/clixon_client.h>
int
main(int argc,
char **argv)
{
int retval = -1;
clixon_handle h = NULL; /* clixon handle */
clixon_client_handle ch = NULL; /* clixon client handle */
// clicon_log_init("client", LOG_DEBUG, CLICON_LOG_STDERR); // debug
// clicon_debug_init(1, NULL); // debug
clicon_log_init("client", LOG_DEBUG, CLICON_LOG_STDERR); // debug
clicon_debug_init($debug, NULL); // debug
/* Provide a clixon config-file, get a clixon handle */
if ((h = clixon_client_init("$cfg")) == NULL)
@ -94,12 +97,15 @@ main(int argc,
{
uint32_t u = 0;
if (clixon_client_get_uint32(ch, &u, "urn:example:clixon-client", "/table/parameter[name='a']/value") < 0)
return -1;
goto done;
printf("%u\n", u); /* for test output */
}
retval = 0;
done:
clixon_client_disconnect(ch);
clixon_client_terminate(h);
return 0;
printf("done\n"); /* for test output */
return retval;
}
EOF

View file

@ -236,6 +236,9 @@ expecteof "$clixon_netconf -qf $cfg" 0 "<xx:rpc xmlns:xx=\"urn:ietf:params:xml:n
new "netconf lock/unlock"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><lock><target><candidate/></target></lock></rpc>]]>]]><rpc $DEFAULTNS><unlock><target><candidate/></target></unlock></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
new "netconf lock/unlock/lock"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><lock><target><candidate/></target></lock></rpc>]]>]]><rpc $DEFAULTNS><unlock><target><candidate/></target></unlock></rpc>]]>]]><rpc $DEFAULTNS><lock><target><candidate/></target></lock></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]>$"
new "netconf lock/lock"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc $DEFAULTNS><lock><target><candidate/></target></lock></rpc>]]>]]><rpc $DEFAULTNS><lock><target><candidate/></target></lock></rpc>]]>]]>" "^<rpc-reply $DEFAULTNS><ok/></rpc-reply>]]>]]><rpc-reply $DEFAULTNS><rpc-error><error-type>protocol</error-type><error-tag>lock-denied</error-tag><error-info><session-id>"

View file

@ -167,7 +167,7 @@ expectpart "$(curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' http:
# Negative
new "restconf get config on wrong port in netns:$netns"
expectpart "$(sudo ip netns exec $netns curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://$vaddr:8888/restconf/data/clixon-example:table)" 7
expectpart "$(sudo ip netns exec $netns curl $CURLOPTS -X GET -H 'Accept: application/yang-data+xml' $RCPROTO://$vaddr:8888/restconf/data/clixon-example:table 2> /dev/null)" 7
if [ $RC -ne 0 ]; then
new "Kill restconf daemon"
@ -192,4 +192,3 @@ new "endtest"
endtest
rm -rf $dir