#!/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 # 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 "^$" new "cli show config" expectpart "$($clixon_cli -1 -f $cfg show config)" 0 "hello" "world" new "netconf edit-config" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "netconf commit" expecteof "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO]]>]]>" "^]]>]]>$" new "restconf GET" expectpart "$(curl $CURLOPTS -X GET $RCPROTO://localhost/restconf/data/clixon-hello:hello)" 0 "HTTP/$HVER 200" "{\"clixon-hello:hello\":{\"world\":{}}}" 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 rm -rf $dir RCPROTO= # This is sh not bash undef new "endtest" endtest