Feature: Generic discovery and poller tests (#7873)

* Processor Tests!

* Capture data from live devices easily.

* fix up some stuff, remove powerconnect things as they seem to be just broken.

* formatting, fix missing assignment
add netonix processor data

* fix multi-line, always add sysDescr and sysObjectID
ios cpm test file

* revert composer change and fix whitespace issues

* add help text

* missed help text

* tighter debug output

* handle empty strings properly and mibs with numbers

* use keys for sorting as intended

* fix type with empty data

* oops :)

* whitespace fix

* try installing fping

* Fix TestCase collision + cleanup

* mark TestCase as abstract
don't run two instances of snmpsim

* better database dumps, improved capture

* style fixes

* fix quotes add a few more tables

* add --prefer-new, properly merge data

* Support separate discovery and poller data. But don't waste space if they aren't needed.

* refactor to use class
collects all code in one place for reusability

* reorganize

* Print out when not saving.

* Support for running multiple (or all) modules at once.

* tidy

* Change unit test to a generic name and test all modules we have data for.

* Add documentation and a few more tidies

* whitespace fixes

* Fix tests, add a couple more modules, more docs

* More docs updates

* Fix scrutinizer issues

* add bgp-peers
This commit is contained in:
Tony Murray
2017-12-20 08:36:49 -06:00
committed by GitHub
parent 56561aa4dc
commit fff66d3c00
50 changed files with 1950 additions and 84 deletions

View File

@@ -1,8 +1,6 @@
#!/usr/bin/env php
<?php
use LibreNMS\Proc;
$filename = basename(__FILE__);
$install_dir = realpath(__DIR__ . '/..');
chdir($install_dir);
@@ -17,6 +15,7 @@ $long_opts = array(
'fail-fast',
'passthru',
'snmpsim',
'db',
'commands',
'help',
);
@@ -30,7 +29,8 @@ Running $filename without options runs all checks.
-u, --unit Run phpunit tests
-f, --fail-fast Quit when any failure is encountered
-p, --passthru Display output from checks as it comes
--snmpsim Use snmpsim on 127.0.0.1:11161 for unit tests
--db Run unit tests that require a database
--snmpsim Use snmpsim for unit tests
-c, --commands Print commands only, no checks
-h, --help Show this help text.\n";
exit();
@@ -39,7 +39,6 @@ Running $filename without options runs all checks.
// set up some variables
$passthru = check_opt($options, 'p', 'passthru');
$command_only = check_opt($options, 'c', 'commands');
$snmpsim = check_opt($options, 'snmpsim');
$fail_fast = check_opt($options, 'f', 'fail-fast');
$return = 0;
$completed_tests = array(
@@ -54,6 +53,14 @@ if ($all) {
$options += array('u' => false, 's' => false, 'l' => false);
}
if (check_opt($options, 'snmpsim')) {
putenv('SNMPSIM=1');
}
if (check_opt($options, 'db')) {
putenv('DBTEST=1');
}
// run tests in the order they were specified
foreach (array_keys($options) as $opt) {
$ret = 0;
@@ -62,7 +69,7 @@ foreach (array_keys($options) as $opt) {
} elseif ($opt == 's' || $opt == 'style') {
$ret = run_check('style', $passthru, $command_only);
} elseif ($opt == 'u' || $opt == 'unit') {
$ret = run_check('unit', $passthru, $command_only, $fail_fast, $snmpsim);
$ret = run_check('unit', $passthru, $command_only, $fail_fast);
}
if ($fail_fast && $ret !== 0 && $ret !== 250) {
@@ -202,40 +209,23 @@ function check_style($passthru = false, $command_only = false)
* @param bool $passthru display the output as comes in
* @param bool $command_only only display the intended command, no checks
* @param bool $fail_fast Stop when any error or failure is encountered
* @param bool $snmpsim send snmp requests to snmpsim listening on 127.0.0.1:11161
* @return int the return value from phpunit (0 = success)
*/
function check_unit($passthru = false, $command_only = false, $fail_fast = false, $snmpsim = false)
function check_unit($passthru = false, $command_only = false, $fail_fast = false)
{
$phpunit_bin = check_exec('phpunit');
if ($snmpsim) {
$phpunit_cmd = "SNMPSIM=1 $phpunit_bin --colors=always";
$snmpsim_cmd = "snmpsimd.py --data-dir=./tests/snmpsim --agent-udpv4-endpoint=127.0.0.1:11161 --logging-method=file:/tmp/snmpsimd.log";
} else {
$phpunit_cmd = "$phpunit_bin --colors=always";
$snmpsim_cmd = '';
}
$phpunit_cmd = "$phpunit_bin --colors=always";
if ($fail_fast) {
$phpunit_cmd .= ' --stop-on-error --stop-on-failure';
}
if ($command_only) {
echo $phpunit_cmd . PHP_EOL;
if ($snmpsim) {
echo $snmpsim_cmd . PHP_EOL;
}
return 250;
}
$proc_snmpsimd = null;
if ($snmpsim) {
echo 'Starting snmpsimd...' . PHP_EOL;
$proc_snmpsimd = new Proc($snmpsim_cmd);
}
echo 'Running unit tests... ';
if ($passthru) {
echo PHP_EOL;