#!/usr/bin/env bash # Hello world smoketest test # A minimal test for backend/cli/netconf/restconf # See clixon-example/hello # but this test is (more or less) self-contained for as little external dependencies as possible # The test is free of plugins because that would require compilation, or pre-built plugins # Restconf is internal native http port 80 # The minimality extends to the test macros that use advanced grep, and therefore more # primitive pattern macthing is made # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi cfg=$dir/hello.xml fyang=$dir/clixon-hello.yang clispec=$dir/clispec test -d $clispec || mkdir $clispec RCPROTO=http cat < $cfg $cfg clixon-restconf:allow-auth-none ${YANG_INSTALLDIR} $fyang $clispec hello $dir/hello.sock /var/run/helloworld.pid $dir init false clicon www-data drop_perm true true none false 0 file default
0.0.0.0
80 false
false include hello yang enable clixon-hello*
EOF cat < $fyang module clixon-hello { yang-version 1.1; namespace "urn:example:hello"; prefix he; revision 2019-04-17 { description "Clixon hello world example"; } container hello{ container world{ presence true; } } } EOF # XXX remove unecessary commands cat < $clispec/hello_cli.cli CLICON_MODE="hello"; CLICON_PROMPT="cli> "; # Reference generated data model set @datamodel, cli_set(); merge @datamodel, cli_merge(); create @datamodel, cli_create(); delete("Delete a configuration item") @datamodel, cli_del(); validate("Validate changes"), cli_validate(); commit("Commit the changes"), cli_commit(); quit("Quit"), cli_quit(); show("Show a particular state of the system") configuration("Show configuration"), cli_show_config("candidate", "text", "/"); EOF new "test params: -f $cfg" # Bring your own backend if [ $BE -ne 0 ]; then # kill old backend (if any) 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 "wait backend" wait_backend if [ $RC -ne 0 ]; then new "kill old restconf daemon" stop_restconf_pre new "start restconf daemon" start_restconf -f $cfg fi new "wait restconf" wait_restconf new "cli configure" #expectpart "$($clixon_cli -1 -f $cfg set hello world)" 0 "^$" ret=$($clixon_cli -1 -f $cfg set hello world) if [ $? -ne 0 ]; then err 0 $r fi new "cli show config" ret=$($clixon_cli -1 -f $cfg show config) if [ $? -ne 0 ]; then err 0 $r fi if [ "$ret" != "hello world;" ]; then err "$ret" "hello world;" fi new "netconf edit-config" rpc=$(chunked_framing "") ret=$(echo "$DEFAULTHELLO$rpc" | $clixon_netconf -qf $cfg) if [ $? -ne 0 ]; then err 0 $r fi reply=$(chunked_framing "") if [ "$ret" != "$reply" ]; then err "$ret" "$reply" fi new "netconf commit" rpc=$(chunked_framing "") ret=$(echo "$DEFAULTHELLO$rpc" | $clixon_netconf -qf $cfg) if [ $? -ne 0 ]; then err 0 $r fi if [ "$ret" != "$reply" ]; then err "$ret" "$reply" fi new "restconf GET" ret=$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/clixon-hello:hello) if [ $? -ne 0 ]; then err 0 $r fi res=$(echo "$ret"|grep "HTTP/$HVER 200") if [ -z "$res" ]; then err "$ret" "HTTP/$HVER 200" fi res=$(echo "$ret"|grep '{"clixon-hello:hello":{"world":{}}}') if [ -z "$res" ]; then err "$ret" "{"clixon-hello:hello":{"world":{}}}" fi 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 -f clixon_backend) if [ -z "$pid" ]; then err "backend already dead" fi # kill backend stop_backend -f $cfg fi rm -rf $dir RCPROTO= # This is sh not bash undef new "endtest" endtest