diff --git a/.travis.yml b/.travis.yml index fd07fe2..98abb04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,16 +8,12 @@ env: - "LUA=lua5.1 TRANSPORT=uloop" install: - - "sudo apt-get install -y $LUA $lib$LUA-0-dev" - - "sudo apt-get install -y python-pexpect python-pip" - - "sudo apt-get install -y snmp" - - "sudo apt-get install -y luarocks" - - "sudo pip install PyYAML" - - "sudo pip install cpp-coveralls" + - "sudo apt-get install -yq $LUA $lib$LUA-0-dev python-pexpect snmp luarocks" + - "sudo pip -q install PyYAML cpp-coveralls" - "sudo luarocks install Lua-cURL" - "sudo luarocks install luacov-coveralls" - "if [ $TRANSPORT = 'libevent' ]; then - sudo apt-get install -y libevent-dev; + sudo apt-get install -yq libevent-dev; fi" - "if [ $TRANSPORT = 'uloop' ]; then ( @@ -38,7 +34,8 @@ install: cp libubox.so .. ); fi" - - ./tests/netsnmp_build.sh + - "wget -q https://raw.githubusercontent.com/credosemi/pub/master/net-snmp-pre-built.tar.gz" + - "tar xzf net-snmp-pre-built.tar.gz" script: - "if [ $TRANSPORT = 'uloop' ]; then @@ -50,14 +47,13 @@ script: else scons --transport=$TRANSPORT --gcov=yes; fi" - - "sudo TRAVIS_JOB_ID=$TRAVIS_JOB_ID LUACOV=1 SYS_LUA_PATH=`$LUA -e 'print(package.path)'` LUA=$LUA python ./tests/test_all.py" + - "sudo LUACOV=1 SYS_LUA_PATH=`$LUA -e 'print(package.path)'` LUA=$LUA python ./tests/test_all.py" after_success: - "cpp-coveralls -b . -e. -e .sconf_temp `ls core/*.gcno | sed 's/\\.gcno$/.c/' | sed 's/^/-i /'` --dump c.report.json" - "luacov-coveralls -j c.report.json -i bin/smartsnmpd -i lualib/smartsnmp/init.lua -i lualib/smartsnmp/utils.lua" after_failure: + - "cat config.log" - "cat tests/test.log" -after_script: cat config.log - diff --git a/bin/smartsnmpd b/bin/smartsnmpd index 2b59272..039f0e8 100755 --- a/bin/smartsnmpd +++ b/bin/smartsnmpd @@ -177,4 +177,10 @@ end mib_modules = nil mib_mod_refs = nil +if protocol == 'snmp' then + print("SmartSNMP (Mode: SNMP Agent)") +else + print("SmartSNMP (Mode: AgentX Sub-Agent)") +end + snmpd.start() diff --git a/tests/smartsnmp_testframework.py b/tests/smartsnmp_testframework.py index 19be225..ae49cd3 100644 --- a/tests/smartsnmp_testframework.py +++ b/tests/smartsnmp_testframework.py @@ -209,30 +209,66 @@ def snmpset_expect(self, oid, setting, expect, **kwargs): def snmpwalk_expect(self, oid, **kwargs): results = self.snmpwalk(oid, **kwargs) + print('Checking walk results (total = %d) ...' % len(results)), for i in range(len(results)): - print(results[i]) self.snmpwalk_result_check(results[i], len(results), i) + print('Done.') def snmp_setup(self, config_file): print "Starting Smart-SNMP Agent (Master Mode)..." self.snmp = pexpect.spawn(r"%s %s ./bin/smartsnmpd -c %s" % (lua_exe, luacov, config_file), env = env) self.snmp.logfile_read = sys.stderr - time.sleep(1) + self.snmp.expect("SmartSNMP .+\r\n") def snmp_teardown(self): - self.snmp.close() - time.sleep(1) + import signal + + wait_time = 60 * 60 * 3 # 3 hours + + for i in range(wait_time): + print 'Try to kill SmartSNMP Agent (%d)...' % i + self.snmp.kill(signal.SIGINT) + time.sleep(0.1) + if self.snmp.isalive() is True: + time.sleep(0.9) + else: + break + + if i == wait_time - 1: + raise Exception("Can't Stop SmartSNMP Agent") def agentx_setup(self, config_file): print "Starting NET-SNMP Agent (Master Mode)..." self.netsnmp = pexpect.spawn(r"./tests/net-snmp-release/sbin/snmpd -f -Lo -m "" -C -c tests/snmpd.conf", env = env) - time.sleep(1) + self.netsnmp.expect("NET-SNMP version [\d\.]+\r\n") + print "Starting SmartSNMP SubAgent (AgentX Mode)..." self.agentx = pexpect.spawn(r"%s %s ./bin/smartsnmpd -c %s" % (lua_exe, luacov, config_file), env = env) self.agentx.logfile_read = sys.stderr - time.sleep(1) + self.agentx.expect("SmartSNMP .+\r\n") def agentx_teardown(self): - self.agentx.close() - self.netsnmp.close(force = True) - time.sleep(1) + import signal + wait_time = 60 * 60 * 3 # 3 hours + + for i in range(wait_time): + print 'Try to kill SmartSNMP Sub-Agent (%d)...' % i + self.agentx.kill(signal.SIGINT) + time.sleep(0.1) + if self.agentx.isalive() is True: + time.sleep(0.9) + else: + break + if i == wait_time - 1: + raise Exception("Can't Stop SmartSNMP Sub-Agent") + + for i in range(wait_time): + print 'Try to kill Net-SNMP Agent (%d)...' % i + self.netsnmp.kill(signal.SIGKILL) + time.sleep(0.1) + if self.netsnmp.isalive() is True: + time.sleep(0.9) + else: + break + if i == wait_time - 1: + raise Exception("Can't Stop Net-SNMP Agent")