diff --git a/test/lib.sh b/test/lib.sh index bff8df09..16944d81 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -206,6 +206,27 @@ if [ ! -z ${YANG_STANDARD_DIR} ]; then : ${IETFRFC=$YANG_STANDARD_DIR/ietf/RFC} fi +: ${SNMPCHECK:=true} + +if $SNMPCHECK; then + if [ "${WITH_NETSNMP}" == "yes" ]; then + if [ ! -f /var/run/snmpd.pid ]; then + echo -e "\e[31m\nenable-netsnmp set but snmpd not running, start with:" + echo "systemctl start snmpd" + echo "" + echo "snmpd must be configured to use a Unix socket for agent communication" + echo "and have a rwcommunity configured, make sure the following lines are" + echo "added to /etc/snmp/snmpd.conf:" + echo "" + echo " rwcommunity public localhost" + echo " agentXSocket unix:/var/run/snmp.sock" + echo " agentxperms 777 777" + echo -e "\e[0m" + exit -1 + fi + fi +fi + # Check sanity between --with-restconf setting and if nginx is started by systemd or not # This check is optional because some installs, such as vagrant make a non-systemd/direct # start diff --git a/test/test_snmp.sh b/test/test_snmp.sh index 8d8b99d6..84990629 100755 --- a/test/test_snmp.sh +++ b/test/test_snmp.sh @@ -11,14 +11,14 @@ if [ ${WITH_NETSNMP} != "yes" ]; then fi snmpd=$(type -p snmpd) -snmpget="$(type -p snmpget) -On -c public -v2c localhost:1161 " -snmpset="$(type -p snmpset) -On -c public -v2c localhost:1161 " +snmpget="$(type -p snmpget) -On -c public -v2c localhost " +snmpset="$(type -p snmpset) -On -c public -v2c localhost " cfg=$dir/conf_startup.xml fyang=$dir/clixon-example.yang # AgentX unix socket -SOCK=/tmp/clixon_snmp.sock +SOCK=/var/run/snmp.sock cat < $cfg @@ -46,24 +46,6 @@ module clixon-example{ EOF function testinit(){ - # Kill old snmp daemon and start a new ones - new "kill old snmp daemons" - sudo killall snmpd - - new "Starting $snmpd -C --rwcommunity=public --master=agentx --agentXSocket=unix:/tmp/clixon_snmp.sock udp:127.0.0.1:1161" - - # Dirty workaround for snmpd in Alpine - if [ -f /.dockerenv ]; then - $snmpd -C --rwcommunity=public --master=agentx --agentXSocket=unix:$SOCK udp:127.0.0.1:1161 - else - $snmpd --rwcommunity=public --master=agentx --agentXSocket=unix:$SOCK udp:127.0.0.1:1161 - fi - - pgrep snmpd - if [ $? != 0 ]; then - err "Failed to start snmpd" - fi - new "test params: -f $cfg" # Kill old backend and start a new one new "kill old backend" @@ -89,8 +71,7 @@ function testinit(){ } function testexit(){ - sudo killall snmpd - stop_snmp + sudo killall clixon_snmp } new "SNMP tests" diff --git a/test/test_snmp_table.sh b/test/test_snmp_table.sh index 4ba41dd0..34acfc5f 100755 --- a/test/test_snmp_table.sh +++ b/test/test_snmp_table.sh @@ -13,15 +13,15 @@ if [ ${WITH_NETSNMP} != "yes" ]; then fi snmpd=$(type -p snmpd) -snmpget="$(type -p snmpget) -On -c public -v2c localhost:1161 " -snmpset="$(type -p snmpset) -On -c public -v2c localhost:1161 " -snmptable="$(type -p snmptable) -c public -v2c localhost:1161 " +snmpget="$(type -p snmpget) -On -c public -v2c localhost:161 " +snmpset="$(type -p snmpset) -On -c public -v2c localhost:161 " +snmptable="$(type -p snmptable) -c public -v2c localhost:161 " cfg=$dir/conf_startup.xml fyang=$dir/clixon-example.yang # AgentX unix socket -SOCK=/tmp/clixon_snmp.sock +SOCK=/var/run/snmp.sock # OID # .netSnmpExampleTables.netSnmpIETFWGTable @@ -56,24 +56,6 @@ module clixon-example{ EOF function testinit(){ - # Kill old snmp daemon and start a new ones - new "kill old snmp daemons" - sudo killall snmpd - - new "Starting $snmpd --rwcommunity=public --master=agentx --agentXSocket=unix:/tmp/clixon_snmp.sock udp:127.0.0.1:1161" - - # Dirty workaround for snmpd in Alpine - if [ -f /.dockerenv ]; then - $snmpd -C --rwcommunity=public --master=agentx --agentXSocket=unix:$SOCK udp:127.0.0.1:1161 - else - $snmpd --rwcommunity=public --master=agentx --agentXSocket=unix:$SOCK udp:127.0.0.1:1161 - fi - - pgrep snmpd - if [ $? != 0 ]; then - err "Failed to start snmpd" - fi - new "test params: -f $cfg" # Kill old backend and start a new one new "kill old backend" @@ -99,8 +81,7 @@ function testinit(){ } function testexit(){ - sudo killall snmpd - stop_snmp + sudo killall clixon_snmp } new "SNMP table tests"