From 5e2643c382a94e0380139f6baffa9985cba941f7 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sat, 3 Sep 2022 13:07:26 +0200 Subject: [PATCH] Test: remove testdir also if skip test --- test/README.md | 5 +++- test/lib.sh | 4 +-- test/test_autocli_listkey_compress.sh | 1 + test/test_http_data.sh | 1 + test/test_netconf_ssh_callhome.sh | 2 ++ test/test_openconfig.sh | 1 + test/test_openconfig_interfaces.sh | 1 + test/test_openconfig_network_instance.sh | 1 + test/test_pagination_config.sh | 2 ++ test/test_privileges.sh | 1 + test/test_restconf_basic_auth.sh | 1 + test/test_restconf_continue.sh | 1 + test/test_restconf_err.sh | 1 + test/test_restconf_http_upgrade.sh | 2 ++ test/test_restconf_internal.sh | 1 + test/test_restconf_internal_usecases.sh | 1 + test/test_restconf_netns.sh | 4 +++ test/test_restconf_notifications.sh | 6 ++++- test/test_restconf_yang_patch_json.sh | 1 + test/test_restconf_yang_patch_xml.sh | 1 + test/test_snmp_entity.sh | 5 +++- test/test_snmp_get.sh | 3 +++ test/test_snmp_ifmib.sh | 31 +++++++++++++++--------- test/test_snmp_rowstatus.sh | 3 +++ test/test_snmp_set.sh | 4 ++- test/test_snmp_system.sh | 3 +++ 26 files changed, 69 insertions(+), 18 deletions(-) diff --git a/test/README.md b/test/README.md index 5f9f85af..8ba1210d 100644 --- a/test/README.md +++ b/test/README.md @@ -164,7 +164,10 @@ Clixon snmp frontend tests require a running netsnmpd and converted YANG files f Netsnmpd is 5.9 or later and can be started via systemd. For the tests to run, the systems IFMIB should be disabled: `-I -ifTable,ifNumber,ifXTable,`, etc. -One way to start snmpd on Ubuntu, known to be working for the tests are: snmpd -Lo -p /var/run/snmpd.pid -I -ifXTable -I -ifTable -I -system_mib -I -sysORTable -I -snmpNotifyFilterTable -I -snmpNotifyTable -I -snmpNotifyFilterProfileTable +One way to start snmpd on Ubuntu, known to be working for the tests is: +``` +snmpd -c /etc/snmp/snmpd.conf -Lo -p /var/run/snmpd.pid -I -ifXTable -I -ifTable -I -system_mib -I -sysORTable -I -snmpNotifyFilterTable -I -snmpNotifyTable -I -snmpNotifyFilterProfileTable +``` Converted YANG files are available at `https://github.com/clicon/mib-yangs` or alternatively use `smidump` version 0.5 or later. Clixon expects them to be at `/usr/local/share/mib-yangs/` by default, or configured by `--with-mib-generated-yang-dir=DIR`. diff --git a/test/lib.sh b/test/lib.sh index f0a6a615..56f1513c 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -661,7 +661,7 @@ function wait_snmp() done } -# End of test, final tests before normal exit of test +# End of single test, final tests before normal exit of test # Note this is a single test started by new, not a total test suite function endtest() { @@ -679,7 +679,7 @@ function new(){ >&2 echo "Test $testi($testnr) [$1]" } -# End of complete test-suite, eg a test file +# End of complete test-suite, eg a test file, mem.sh function endsuite() { unset CURLOPTS diff --git a/test/test_autocli_listkey_compress.sh b/test/test_autocli_listkey_compress.sh index 2805476e..db0fe0ba 100755 --- a/test/test_autocli_listkey_compress.sh +++ b/test/test_autocli_listkey_compress.sh @@ -27,6 +27,7 @@ fi if [ ! -d "$OPENCONFIG" ]; then # err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?" echo "...skipped: OPENCONFIG not set" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi OCDIR=$OPENCONFIG/release/models diff --git a/test/test_http_data.sh b/test/test_http_data.sh index 699c3f1d..b8a9d6ea 100755 --- a/test/test_http_data.sh +++ b/test/test_http_data.sh @@ -19,6 +19,7 @@ mkdir $dir/www/data # Does not work with fcgi if [ "${WITH_RESTCONF}" = "fcgi" ]; then echo "...skipped: Must run with --with-restconf=native" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_netconf_ssh_callhome.sh b/test/test_netconf_ssh_callhome.sh index 43f7fb8d..1d5b5314 100755 --- a/test/test_netconf_ssh_callhome.sh +++ b/test/test_netconf_ssh_callhome.sh @@ -7,12 +7,14 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Skip it if no openssh if ! [ -x "$(command -v ssh)" ]; then echo "...ssh not installed" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip fi # Dont run this test with valgrind if [ $valgrindtest -ne 0 ]; then echo "...skipped " + rm -rf $dir return 0 # skip fi diff --git a/test/test_openconfig.sh b/test/test_openconfig.sh index 28b5c374..4b6f7ee8 100755 --- a/test/test_openconfig.sh +++ b/test/test_openconfig.sh @@ -20,6 +20,7 @@ new "openconfig" if [ ! -d "$OPENCONFIG" ]; then # err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?" echo "...skipped: OPENCONFIG not set" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_openconfig_interfaces.sh b/test/test_openconfig_interfaces.sh index 98714da5..c15d1eed 100755 --- a/test/test_openconfig_interfaces.sh +++ b/test/test_openconfig_interfaces.sh @@ -14,6 +14,7 @@ new "openconfig" if [ ! -d "$OPENCONFIG" ]; then # err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?" echo "...skipped: OPENCONFIG not set" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_openconfig_network_instance.sh b/test/test_openconfig_network_instance.sh index 3a543b51..6f4a7d0f 100755 --- a/test/test_openconfig_network_instance.sh +++ b/test/test_openconfig_network_instance.sh @@ -14,6 +14,7 @@ new "openconfig" if [ ! -d "$OPENCONFIG" ]; then # err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?" echo "...skipped: OPENCONFIG not set" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_pagination_config.sh b/test/test_pagination_config.sh index 5c764e52..0234de5c 100755 --- a/test/test_pagination_config.sh +++ b/test/test_pagination_config.sh @@ -10,12 +10,14 @@ APPNAME=example if [ -z "$(type expect 2> /dev/null)" ]; then echo "...skipped: Expect not installed" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi # Skip test if valgrind if [ $valgrindtest -ne 0 ]; then echo "...skipped for valgrind " + rm -rf $dir return 0 # skip fi diff --git a/test/test_privileges.sh b/test/test_privileges.sh index bd3f0615..17c5af0e 100755 --- a/test/test_privileges.sh +++ b/test/test_privileges.sh @@ -13,6 +13,7 @@ APPNAME=example # Dont run this test with valgrind if [ $valgrindtest -ne 0 ]; then echo "...skipped " + rm -rf $dir return 0 # skip fi diff --git a/test/test_restconf_basic_auth.sh b/test/test_restconf_basic_auth.sh index 10394892..6c386447 100755 --- a/test/test_restconf_basic_auth.sh +++ b/test/test_restconf_basic_auth.sh @@ -16,6 +16,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi if ! ${HAVE_HTTP1}; then echo "...skipped: Must run with http/1" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_restconf_continue.sh b/test/test_restconf_continue.sh index 0cbf76d3..fb6a180a 100755 --- a/test/test_restconf_continue.sh +++ b/test/test_restconf_continue.sh @@ -8,6 +8,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi if ! ${HAVE_HTTP1}; then echo "...skipped: Must run with http/1" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_restconf_err.sh b/test/test_restconf_err.sh index 1a3b6705..9025a377 100755 --- a/test/test_restconf_err.sh +++ b/test/test_restconf_err.sh @@ -29,6 +29,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi if [ "${WITH_RESTCONF}" = "native" -a ${HAVE_HTTP1} = false ]; then #if ! ${HAVE_HTTP1}; then echo "...skipped: must run with http/1" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_restconf_http_upgrade.sh b/test/test_restconf_http_upgrade.sh index 20e16d86..20bafc9d 100755 --- a/test/test_restconf_http_upgrade.sh +++ b/test/test_restconf_http_upgrade.sh @@ -12,12 +12,14 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Only works with native if [ "${WITH_RESTCONF}" != "native" ]; then + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip fi # Cant make it work in sum.sh... if ! ${HAVE_HTTP1}; then echo "...skipped: must run with http/1" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_restconf_internal.sh b/test/test_restconf_internal.sh index 7f5ddd0f..3c44ec1f 100755 --- a/test/test_restconf_internal.sh +++ b/test/test_restconf_internal.sh @@ -17,6 +17,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Does not work with native http/2-only if [ "${WITH_RESTCONF}" = "native" -a ${HAVE_HTTP1} = false ]; then echo "...skipped: Must run with http/1" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_restconf_internal_usecases.sh b/test/test_restconf_internal_usecases.sh index 7a1c9d85..c7c94392 100755 --- a/test/test_restconf_internal_usecases.sh +++ b/test/test_restconf_internal_usecases.sh @@ -28,6 +28,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Does not work with native http/2-only if [ "${WITH_RESTCONF}" = "native" -a ${HAVE_HTTP1} = false ]; then echo "...skipped: Must run with http/1" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi diff --git a/test/test_restconf_netns.sh b/test/test_restconf_netns.sh index eff7a7af..d74dcda4 100755 --- a/test/test_restconf_netns.sh +++ b/test/test_restconf_netns.sh @@ -13,16 +13,19 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Skip if other than native if [ "${WITH_RESTCONF}" != "native" ]; then + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip fi if ! ${HAVE_HTTP1}; then echo "...skipped: HAVE_HTTP1 is false, must run with http/1" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi # Skip if valgrind restconf (actually valgrind version < 3.16 27 May 2020) if [ $valgrindtest -eq 3 ]; then + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip fi @@ -30,6 +33,7 @@ fi ip netns 2> /dev/null if [ $? -ne 0 ]; then echo "...ip netns does not work" + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip fi diff --git a/test/test_restconf_notifications.sh b/test/test_restconf_notifications.sh index ef66a854..ce2f1aa6 100755 --- a/test/test_restconf_notifications.sh +++ b/test/test_restconf_notifications.sh @@ -29,11 +29,15 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Skip it other than fcgi and http if [ "${WITH_RESTCONF}" != "fcgi" -o "$RCPROTO" = https ]; then + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip fi # Skip regardless, broken in 5.7 -if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip +if true; then + rm -rf $dir + if [ "$s" = $0 ]; then exit 0; else return 0; fi # skip +fi : ${SLEEP2:=1} SLEEP5=.5 APPNAME=example diff --git a/test/test_restconf_yang_patch_json.sh b/test/test_restconf_yang_patch_json.sh index db2bcfdd..8dcb342f 100755 --- a/test/test_restconf_yang_patch_json.sh +++ b/test/test_restconf_yang_patch_json.sh @@ -9,6 +9,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi # Enable if YANG_PATCH echo "...skipped: YANG_PATCH JSON NYI" +rm -rf $dir if [ -z "${CLIXON_YANG_PATCH}" -a "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example diff --git a/test/test_restconf_yang_patch_xml.sh b/test/test_restconf_yang_patch_xml.sh index 78bc0d48..1c0610b7 100755 --- a/test/test_restconf_yang_patch_xml.sh +++ b/test/test_restconf_yang_patch_xml.sh @@ -8,6 +8,7 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi echo "...skipped: YANG_PATCH XML NYI" +rm -rf $dir if [ -z "${CLIXON_YANG_PATCH}" -a "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example diff --git a/test/test_snmp_entity.sh b/test/test_snmp_entity.sh index 8864f010..7ebd7273 100755 --- a/test/test_snmp_entity.sh +++ b/test/test_snmp_entity.sh @@ -9,6 +9,7 @@ APPNAME=example if [ ${ENABLE_NETSNMP} != "yes" ]; then echo "Skipping test, Net-SNMP support not enabled." + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi @@ -510,7 +511,9 @@ expectpart "$($snmpwalk $ENTITY_OID)" 0 "SNMPv2-SMI::mib-2.47.1.1.1.1.1.1 = INTE "SNMPv2-SMI::mib-2.47.1.1.1.1.16.2 = INTEGER: 0" \ new "Cleaning up" -# testexit +testexit + +rm -rf $dir new "endtest" endtest diff --git a/test/test_snmp_get.sh b/test/test_snmp_get.sh index 37eee83c..bb1a38d5 100755 --- a/test/test_snmp_get.sh +++ b/test/test_snmp_get.sh @@ -9,6 +9,7 @@ APPNAME=example if [ ${ENABLE_NETSNMP} != "yes" ]; then echo "Skipping test, Net-SNMP support not enabled." + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi @@ -282,5 +283,7 @@ expectpart "$($snmpgetnext $OID19)" 0 "$OID20 = INTEGER: 1" new "Cleaning up" testexit +rm -rf $dir + new "endtest" endtest diff --git a/test/test_snmp_ifmib.sh b/test/test_snmp_ifmib.sh index e62ca159..8ae00c0c 100755 --- a/test/test_snmp_ifmib.sh +++ b/test/test_snmp_ifmib.sh @@ -9,6 +9,7 @@ APPNAME=example if [ ${ENABLE_NETSNMP} != "yes" ]; then echo "Skipping test, Net-SNMP support not enabled." + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi @@ -162,19 +163,21 @@ EOF function testinit(){ new "test params: -f $cfg -- -sS $fstate" if [ $BE -ne 0 ]; then - # Kill old backend and start a new one - new "kill old backend" - sudo clixon_backend -zf $cfg - if [ $? -ne 0 ]; then - err "Failed to start backend" + # Kill old backend and start a new one + new "kill old backend" + sudo clixon_backend -zf $cfg + if [ $? -ne 0 ]; then + err "Failed to start backend" + fi + sudo pkill -f clixon_backend + + new "Starting backend" + start_backend -s init -f $cfg -- -sS $fstate fi - - sudo pkill -f clixon_backend - - new "Starting backend" - start_backend -s init -f $cfg -- -sS $fstate - fi - +if true; then + rm -rf $dir + if [ "$s" = $0 ]; then exit 0; else return 0; fi +fi new "wait backend" wait_backend @@ -195,9 +198,11 @@ function testexit(){ stop_snmp } + new "SNMP tests" testinit + # IF-MIB::interfaces MIB=".1.3.6.1.2.1" for (( i=1; i<23; i++ )); do @@ -465,5 +470,7 @@ expectpart "$($snmpwalk IF-MIB::ifRcvAddressTable)" 0 "IF-MIB::ifRcvAddressAddre testexit +rm -rf $dir + new "endtest" endtest diff --git a/test/test_snmp_rowstatus.sh b/test/test_snmp_rowstatus.sh index 1abf0924..e92776d5 100755 --- a/test/test_snmp_rowstatus.sh +++ b/test/test_snmp_rowstatus.sh @@ -9,6 +9,7 @@ APPNAME=example # XXX skip for now if [ ${ENABLE_NETSNMP} != "yes" ]; then echo "Skipping test, Net-SNMP support not enabled." + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi @@ -222,5 +223,7 @@ testrun_removeRows new "Cleaning up" testexit +rm -rf $dir + new "endtest" endtest diff --git a/test/test_snmp_set.sh b/test/test_snmp_set.sh index 651f5a73..f57ff676 100755 --- a/test/test_snmp_set.sh +++ b/test/test_snmp_set.sh @@ -8,9 +8,9 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi APPNAME=example -# XXX skip for now if [ ${ENABLE_NETSNMP} != "yes" ]; then echo "Skipping test, Net-SNMP support not enabled." + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi @@ -244,5 +244,7 @@ expectpart "$($clixon_cli -1 -f $cfg show config xml)" 0 "<$name>active" new "Cleaning up" testexit +rm -rf $dir + new "endtest" endtest diff --git a/test/test_snmp_system.sh b/test/test_snmp_system.sh index 563df5d7..922dbaf6 100755 --- a/test/test_snmp_system.sh +++ b/test/test_snmp_system.sh @@ -9,6 +9,7 @@ APPNAME=example if [ ${ENABLE_NETSNMP} != "yes" ]; then echo "Skipping test, Net-SNMP support not enabled." + rm -rf $dir if [ "$s" = $0 ]; then exit 0; else return 0; fi fi @@ -235,5 +236,7 @@ expectpart "$($snmpwalkstr system)" 0 "SNMPv2-MIB::sysDescr = STRING: System des new "Cleaning up" testexit +rm -rf $dir + new "endtest" endtest