diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18c53565..95394dc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,8 @@ jobs: steps: - uses: actions/checkout@v2 + - name: install expect + run: sudo apt install -y expect # 1) checkout and compile natively - name: install cligen run: (git clone https://github.com/clicon/cligen.git && cd cligen && ./configure && make && sudo make install) diff --git a/lib/clixon/clixon_plugin.h b/lib/clixon/clixon_plugin.h index f950debd..5a53c777 100644 --- a/lib/clixon/clixon_plugin.h +++ b/lib/clixon/clixon_plugin.h @@ -188,6 +188,14 @@ typedef int (plgextension_t)(clicon_handle h, yang_stmt *yext, yang_stmt *ys); typedef int (plgauth_t)(clicon_handle h, void *req, clixon_auth_type_t auth_type, char **authp); /*! Reset system status + * + * Add xml or set state in backend system. + * plugin_reset in each backend plugin after all plugins have been initialized. + * This gives the application a chance to reset system state back to a base state. + * This is generally done when a system boots up to make sure the initial system state + * is well defined. + * This involves creating default configuration files for various daemons, set interface + * flags etc. * @param[in] h Clicon handle * @param[in] db Database name (eg "running") * @retval -1 Fatal error diff --git a/test/README.md b/test/README.md index f8de2d95..b8a1f96b 100644 --- a/test/README.md +++ b/test/README.md @@ -7,6 +7,9 @@ automatically run as part of the all.sh, sum.sh tests etc. The scripts need to follow some rules to work properly, please look at one or two to get the idea. +Most scripts are bash scripts using standard awk/sed etc. There is +also (at least one) expect script. + Note that some IETF yangs need to be available, by default these are in `/usr/local//share/yang/standard`. You can change this location with configure option `--with-yang-standard-dir=DIR` See also the [site.sh](#site-sh) for example for skipping tests or setting some site-specific variables. diff --git a/test/example_social.sh b/test/example_social.sh index 9fc1b977..912f96f2 100755 --- a/test/example_social.sh +++ b/test/example_social.sh @@ -58,7 +58,7 @@ cat < $fexample } leaf email-address { - type inet:email-address; + type string; mandatory true; description "The member's email address."; @@ -119,6 +119,7 @@ cat < $fexample leaf-list following { type leafref { path "/members/member/member-id"; + require-instance false; } description "Other members this members is following."; diff --git a/test/test_pagination_config.sh b/test/test_pagination_config.sh index e2efee05..1da42d5b 100755 --- a/test/test_pagination_config.sh +++ b/test/test_pagination_config.sh @@ -6,11 +6,13 @@ # Magic line must be first in script (see README.md) s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi -echo "...skipped: Must run interactvely" -if [ "$s" = $0 ]; then exit 0; else return 0; fi - APPNAME=example +if [ -z "$(type expect 2> /dev/null)" ]; then + echo "...skipped: Expect not installed" + if [ "$s" = $0 ]; then exit 0; else return 0; fi +fi + cfg=$dir/conf.xml fexample=$dir/example-social.yang @@ -29,6 +31,7 @@ cat < $cfg $cfg ietf-netconf:startup clixon-restconf:allow-auth-none + ${YANG_STANDARD_DIR}/ietf/RFC ${YANG_INSTALLDIR} $dir /usr/local/var/$APPNAME/$APPNAME.sock @@ -147,9 +150,11 @@ fi new "wait backend" wait_backend -# XXX How to run without using a terminal? -new "cli show" -$clixon_cli -f $cfg -l o -1 show pagination xpath /es:members/es:member[es:member-id=\'bob\']/es:favorites/es:uint64-numbers cli +xpath="/es:members/es:member[es:member-id=\'bob\']/es:favorites/es:uint64-numbers" +new "cli show pagination config using expect" +expect ./test_pagination_expect.exp "$cfg" "$xpath" "uint64-numbers 18" "uint64-numbers 19" + +#$clixon_cli -f $cfg -l o -1 show pagination xpath /es:members/es:member[es:member-id=\'bob\']/es:favorites/es:uint64-numbers cli if [ $BE -ne 0 ]; then new "Kill backend" @@ -164,6 +169,7 @@ fi unset validatexml unset perfnr +unset xpath rm -rf $dir diff --git a/test/test_pagination_expect.exp b/test/test_pagination_expect.exp new file mode 100755 index 00000000..2fca51e7 --- /dev/null +++ b/test/test_pagination_expect.exp @@ -0,0 +1,62 @@ +#!/usr/bin/env expect -f +# Tests of paginated state scrolling using expect. Simply that --More-- is shown and +# that first two pages scroll OK. More tests could be done. +# Arguments: +# 0: clixon configuration file +# 1: xpath +# 2: line1 should appear on first page +# 3: line2 should appear on second page (and not on first) + +set timeout 1 +#log_user 0 + +set stty_init "rows 20 cols 128" + +send_user "\nTest State paginate cli scrolling\n" + +set cfg [lindex $argv 0] +set xpath [lindex $argv 1] +set line1 [lindex $argv 2] +set line2 [lindex $argv 3] + +spawn clixon_cli -f $cfg + +send "show pagination xpath $xpath cli\n" + +expect { + timeout { send_user "\n$line1 not received.\n"; exit 1} + "$line1" { send_user "\n$line1 OK.\n";} +} + +expect { + timeout { send_user "\nmember-id $line2.\n";} + "member-id $line2" { send_user "\n$line2 not expected.\n"; exit 1} +} + +expect { + timeout { send_user "\nMore 1 not received.\n"; exit 1} + -ex "--More--" {send_user "\nMore 1 OK.\n"} +} + +send " " + +expect { + timeout { send_user "\n$line2 not received.\n"; exit 1} + "$line2" { send_user "\n$line2 OK.\n"} +} + +expect { + timeout { send_user "\nMore 2 not received.\n"; exit 1} + -ex "--More--" { send_user "\nMore 2 OK.\n"} +} + +send "q" + +expect { + -ex "--More--" { send_user "\nMore not expected.\n"; exit 1} +} + +send "\d" +close + +send_user "\nTest OK\n" diff --git a/test/test_pagination_state.sh b/test/test_pagination_state.sh index 7a179950..eaba9553 100755 --- a/test/test_pagination_state.sh +++ b/test/test_pagination_state.sh @@ -158,18 +158,17 @@ testrun_stop #---------------------------- -echo "...skipped: Must run interactively" -if false; then -testrun_start "/es:audit-logs/es:audit-log" +# Only if expect installed +if [ -n "$(type expect 2> /dev/null)" ]; then -# XXX How to run without using a terminal? Maybe use expect/unbuffer -new "cli show" -$clixon_cli -1 -f $cfg -l o show pagination xpath $xpath cli -#expectpart "$(echo -n | unbuffer -p $clixon_cli -1 -f $cfg -l o show pagination xpath $xpath cli)" 0 foo + testrun_start "/es:audit-logs/es:audit-log" + + newtest "CLI scroll test using expect" + expect ./test_pagination_expect.exp "$cfg" "$xpath" bob3 bob4 -testrun_stop + testrun_stop -fi # interactive +fi # expect unset validatexml unset perfnr diff --git a/test/vagrant/README.md b/test/vagrant/README.md index c356913b..d2a90192 100644 --- a/test/vagrant/README.md +++ b/test/vagrant/README.md @@ -24,8 +24,8 @@ You can also run a single vagrant test as follows: The current vagrant boxes are verified continuously: * ubuntu/bionic64 -* generic/centos8 -* generic/freebsd12 +# * generic/centos8 +* generic/freebsd13 For other vagrant boxes, see [search vagrant boxes](https://vagrantcloud.com/search)