librenms/tests/OSModulesTest.php
Tony Murray 11147d3bbf
Major Processors rewrite (#8066)
* Extract DiscoveryItem and move some things to better places.
Extract model class
Fix up model construction.  I have problem with construction...
Makeshift model working.  Switch constructor to factory.  discover() and create()
Support legacy discovery.
Remove uneeded custom pollers
Remove netonix custom detection as we try ucd on all os now.
Add a few yaml procs.  Fix a couple things.
More processor discovery conversions
Move Calix e7 to standard hrProcessorLoad, but it doesn't fully implement the HR-MIB, move things around to make it work.
Add a few yaml procs.  Fix a couple things. Correct some stupid mib stuff.
Move more, drop php 5.3
Add netscaler which uses string indexes.  Port fiberhome to yaml and use skip_values
More conversions.  BroadcomProcessorUsage Trait
Serveriron and Ironware share some mibs.  Create a common abstract os for them.
Add yaml support for mib specification in each data entry
Make legacy discover_processor() set 0 for hrDeviceIndex

Untangle Dell switch OS processors

Use use shared OS for groups if they don't have a specific group.
fix silly mib mistake

Make index optional

Move HR and UCD to Traits and out of Processor.

* forgot to update the fortiswitch index

* Make sgos and avaya-ers match the old index.

* fix comware test data

* fix merge errors

* fix dsm and remove pointless empty modules

* file not found exception is in the wrong place.

* Updated processor development docs
2018-02-05 07:39:13 -06:00

100 lines
3.3 KiB
PHP

<?php
/**
* OSModulesTest.php
*
* Test discovery and poller modules
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link http://librenms.org
* @copyright 2017 Tony Murray
* @author Tony Murray <murraytony@gmail.com>
*/
namespace LibreNMS\Tests;
use LibreNMS\Config;
use LibreNMS\Exceptions\FileNotFoundException;
use LibreNMS\Util\ModuleTestHelper;
class OSModulesTest extends DBTestCase
{
/**
* Test all modules for a particular OS
*
* @group os
* @dataProvider dumpedDataProvider
* @param string $target_os name of the (and variant) to test
* @param string $filename file name of the json data
* @param array $modules modules to test for this os
*/
public function testOS($os, $variant, $modules)
{
$this->requreSnmpsim(); // require snmpsim for tests
global $snmpsim;
try {
$helper = new ModuleTestHelper($modules, $os, $variant);
$helper->setQuiet();
$filename = $helper->getJsonFilepath(true);
$expected_data = $helper->getTestData();
$results = $helper->generateTestData($snmpsim, true);
} catch (FileNotFoundException $e) {
$this->fail($e->getMessage());
}
if (is_null($results)) {
$this->fail("$os: Failed to collect data.");
}
foreach ($modules as $module) {
$expected = $expected_data[$module]['discovery'];
$actual = $results[$module]['discovery'];
$this->assertEquals(
$expected,
$actual,
"OS $os: Discovered $module data does not match that found in $filename\n"
. print_r(array_diff($expected, $actual), true)
. $helper->getLastDiscoveryOutput()
. "\nOS $os: Polled $module data does not match that found in $filename"
);
$expected = $expected_data[$module]['poller'] == 'matches discovery' ? $expected_data[$module]['discovery'] : $expected_data[$module]['poller'];
$actual = $results[$module]['poller'];
$this->assertEquals(
$expected,
$actual,
"OS $os: Polled $module data does not match that found in $filename\n"
. print_r(array_diff($expected, $actual), true)
. $helper->getLastPollerOutput()
. "\nOS $os: Polled $module data does not match that found in $filename"
);
}
}
public function dumpedDataProvider()
{
$modules = array();
if (getenv('TEST_MODULES')) {
$modules = explode(',', getenv('TEST_MODULES'));
}
return ModuleTestHelper::findOsWithData($modules);
}
}