Skip to content

Commit

Permalink
Test: make streams optional, remove dependency on main example
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Sep 20, 2022
1 parent e532543 commit fcc9245
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ e`

### Corrected Bugs

* [Replace operation](https://github.com/clicon/clixon/issues/350)
* Fixed: [When multiple lists have same key name, need more elaborate error message in case of configuration having duplicate keys](https://github.com/clicon/clixon/issues/362)
* Solved by implementing RFC7950 Sec 5.1 correctly
* Fixed: [All values in list don't appear when writing "show <list>" in cli](https://github.com/clicon/clixon/issues/359)
Expand Down
49 changes: 30 additions & 19 deletions example/main/example_backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
* The example have the following optional arguments that you can pass as
* argc/argv after -- in clixon_backend:
* -a <..> Register callback for this yang action
* -n Notification streams example
* -r enable the reset function
* -s enable the state function
* -S <file> read state data from file, otherwise construct it programmatically (requires -s)
Expand Down Expand Up @@ -67,7 +68,7 @@
#include <clixon/clixon_backend.h>

/* Command line options to be passed to getopt(3) */
#define BACKEND_EXAMPLE_OPTS "a:rsS:x:iuUtV:"
#define BACKEND_EXAMPLE_OPTS "a:nrsS:x:iuUtV:"

/*! Yang action
* Start backend with -- -a <instance-id>
Expand All @@ -76,6 +77,12 @@
*/
static char *_action_instanceid = NULL;

/*! Notification stream
* Enable notification streams for netconf/restconf
* Start backend with -- -n
*/
static int _notification_stream = 0;

/*! Variable to control if reset code is run.
* The reset code inserts "extra XML" which assumes ietf-interfaces is
* loaded, and this is not always the case.
Expand Down Expand Up @@ -1314,6 +1321,9 @@ clixon_plugin_init(clicon_handle h)
case 'a':
_action_instanceid = optarg;
break;
case 'n':
_notification_stream = 1;
break;
case 'r':
_reset = 1;
break;
Expand Down Expand Up @@ -1355,24 +1365,25 @@ clixon_plugin_init(clicon_handle h)
}
}

/* Example stream initialization:
* 1) Register EXAMPLE stream
* 2) setup timer for notifications, so something happens on stream
* 3) setup stream callbacks for notification to push channel
*/
if (clicon_option_exists(h, "CLICON_STREAM_RETENTION"))
retention.tv_sec = clicon_option_int(h, "CLICON_STREAM_RETENTION");
if (stream_add(h, "EXAMPLE", "Example event stream", 1, &retention) < 0)
goto done;
/* Enable nchan pub/sub streams
* assumes: CLIXON_PUBLISH_STREAMS, eg configure --enable-publish
*/
if (clicon_option_exists(h, "CLICON_STREAM_PUB") &&
stream_publish(h, "EXAMPLE") < 0)
goto done;
if (example_stream_timer_setup(h) < 0)
goto done;

if (_notification_stream){
/* Example stream initialization:
* 1) Register EXAMPLE stream
* 2) setup timer for notifications, so something happens on stream
* 3) setup stream callbacks for notification to push channel
*/
if (clicon_option_exists(h, "CLICON_STREAM_RETENTION"))
retention.tv_sec = clicon_option_int(h, "CLICON_STREAM_RETENTION");
if (stream_add(h, "EXAMPLE", "Example event stream", 1, &retention) < 0)
goto done;
/* Enable nchan pub/sub streams
* assumes: CLIXON_PUBLISH_STREAMS, eg configure --enable-publish
*/
if (clicon_option_exists(h, "CLICON_STREAM_PUB") &&
stream_publish(h, "EXAMPLE") < 0)
goto done;
if (example_stream_timer_setup(h) < 0)
goto done;
}
/* Register callback for routing rpc calls
*/
/* From example.yang (clicon) */
Expand Down
1 change: 0 additions & 1 deletion test/config.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ CLIXON_AUTOCLI_REV="2022-02-11"
CLIXON_LIB_REV="2021-12-05"
CLIXON_CONFIG_REV="2022-03-21"
CLIXON_RESTCONF_REV="2022-08-01"
CLIXON_EXAMPLE_REV="2020-12-01"

# Length of TSL RSA key
# Problem with small key such as 1024 not allowed in centos8 for example (why is this)
Expand Down
99 changes: 98 additions & 1 deletion test/test_netconf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ APPNAME=example

cfg=$dir/conf_yang.xml
tmp=$dir/tmp.x
fyang=$dir/clixon-example.yang

# Use yang in example

Expand All @@ -19,9 +20,10 @@ cat <<EOF > $cfg
<CLICON_CONFIGFILE>$cfg</CLICON_CONFIGFILE>
<CLICON_FEATURE>ietf-netconf:startup</CLICON_FEATURE>
<CLICON_MODULE_SET_ID>42</CLICON_MODULE_SET_ID>
<CLICON_YANG_DIR>$dir</CLICON_YANG_DIR>
<CLICON_YANG_DIR>${YANG_INSTALLDIR}</CLICON_YANG_DIR>
<CLICON_YANG_DIR>$IETFRFC</CLICON_YANG_DIR>
<CLICON_YANG_MODULE_MAIN>clixon-example</CLICON_YANG_MODULE_MAIN>
<CLICON_YANG_MAIN_FILE>$fyang</CLICON_YANG_MAIN_FILE>
<CLICON_CLISPEC_DIR>/usr/local/lib/$APPNAME/clispec</CLICON_CLISPEC_DIR>
<CLICON_BACKEND_DIR>/usr/local/lib/$APPNAME/backend</CLICON_BACKEND_DIR>
<CLICON_BACKEND_REGEXP>example_backend.so$</CLICON_BACKEND_REGEXP>
Expand All @@ -36,6 +38,101 @@ cat <<EOF > $cfg
</clixon-config>
EOF

cat <<EOF > $fyang
module clixon-example{
yang-version 1.1;
namespace "urn:example:clixon";
prefix ex;
import ietf-interfaces {
prefix if;
}
import ietf-ip {
prefix ip;
}
/* Example interface type for tests, local callbacks, etc */
identity eth {
base if:interface-type;
}
/* Generic config data */
container table{
list parameter{
key name;
leaf name{
type string;
}
}
}
/* State data (not config) for the example application*/
container state {
config false;
description "state data for the example application (must be here for example get operation)";
leaf-list op {
type string;
}
}
augment "/if:interfaces/if:interface" {
container my-status {
config false;
description "For testing augment+state";
leaf int {
type int32;
}
leaf str {
type string;
}
}
}
rpc client-rpc {
description "Example local client-side RPC that is processed by the
the netconf/restconf and not sent to the backend.
This is a clixon implementation detail: some rpc:s
are better processed by the client for API or perf reasons";
input {
leaf x {
type string;
}
}
output {
leaf x {
type string;
}
}
}
rpc empty {
description "Smallest possible RPC with no input or output sections";
}
rpc example {
description "Some example input/output for testing RFC7950 7.14.
RPC simply echoes the input for debugging.";
input {
leaf x {
description
"If a leaf in the input tree has a 'mandatory' statement with
the value 'true', the leaf MUST be present in an RPC invocation.";
type string;
mandatory true;
}
leaf y {
description
"If a leaf in the input tree has a 'mandatory' statement with the
value 'true', the leaf MUST be present in an RPC invocation.";
type string;
default "42";
}
}
output {
leaf x {
type string;
}
leaf y {
type string;
}
}
}
}
EOF

new "test params: -f $cfg -- -s"
# Bring your own backend
if [ $BE -ne 0 ]; then
Expand Down
4 changes: 2 additions & 2 deletions test/test_netconf_notifications.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ if [ $BE -ne 0 ]; then
if [ $? -ne 0 ]; then
err
fi
new "start backend -s init -f $cfg"
start_backend -s init -f $cfg
new "start backend -s init -f $cfg -- -n"
start_backend -s init -f $cfg -- -n # create example notification stream
fi

new "waiting"
Expand Down
Loading

0 comments on commit fcc9245

Please sign in to comment.