refactor: OS discovery tests are now dynamic (#6555)

* refactor: OS discovery tests are now dynamic
All that needs to be done now is supply snmprec files with the proper name. os.snmprec or os_description.snmprec
I also tweaked the loading of yaml files to speed up the tests substantially.
Verifies all os have at least one test and all snmprec files are tested.

* fix typo
This commit is contained in:
Tony Murray
2017-05-03 15:52:53 +01:00
committed by Neil Lathwood
parent c772a36142
commit 4dbab407bb
269 changed files with 99 additions and 1884 deletions
+5 -19
View File
@@ -2,28 +2,15 @@ source: Developing/os/Test-Units.md
We have a testing unit for new OS', please ensure you add a test for any new OS' or updates to existing OS discovery.
The OS test unit file is located `tests/OSDiscoveryTest.php`. An example of this is as follows:
```php
public function testPulse()
{
$this->checkOS('pulse');
$this->checkOS('pulse', 'pulse-mag2600');
$this->checkOS('pulse', 'pulse-sa2500');
$this->checkOS('pulse', 'pulse-sa6500');
$this->checkOS('pulse', 'pulse-vaspe');
$this->checkOS('pulse', 'pulse-sa');
}
```
The above example has multiple test files, the first argument in the function call is the os name we expect the test
to pass as, the second argument is the filename to use for the test. If not filename is passed then the os name is used
for the file.
All that you need to do is create an snmprec file in tests/snmpsim with the proper name. If adding the first test for
this os, simply use the os name `pulse.snmprec` for example. If you need to add multiple test files, you can add an
underscore after the os name followed by a description, typically a model name. For example: `pulse_mag2600.snmprec`.
You can copy `skel.snmprec` to your intended name and fill in the data to make things a little easier.
We utilise [snmpsim](http://snmpsim.sourceforge.net/) to do unit testing for OS discovery. For this to work you need
to supply an snmprec file. This is pretty simple and using pulse as the example again this would look like:
`tests/snmpsim/pulse-mag2600.snmprec`
`tests/snmpsim/pulse_mag2600.snmprec`
```
1.3.6.1.2.1.1.1.0|4|Pulse Secure,LLC,MAG-2600,8.0R14 (build 41869)
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.12532.254.1.1
@@ -46,7 +33,6 @@ Common OIDs used in discovery:
| SNMPv2-MIB::sysObjectID.0 | 1.3.6.1.2.1.1.2.0 |
| ENTITY-MIB::entPhysicalDescr.1 | 1.3.6.1.2.1.47.1.1.1.1.2.1 |
| ENTITY-MIB::entPhysicalMfgName.1 | 1.3.6.1.2.1.47.1.1.1.1.12.1 |
| SML-MIB::product-Name.0 | 1.3.6.1.4.1.2.6.182.3.3.1.0 |
List of SNMP data types:
+5
View File
@@ -1584,7 +1584,12 @@ function load_all_os($restricted = array())
$list = $restricted;
} else {
$list = glob($config['install_dir'].'/includes/definitions/*.yaml');
if (count($list) == count($config['os'])) {
// already fully loaded
return;
}
}
foreach ($list as $file) {
$tmp = Symfony\Component\Yaml\Yaml::parse(
file_get_contents($file)
+8 -3
View File
@@ -100,9 +100,14 @@ function getHostOS($device)
// check yaml files
$pattern = $config['install_dir'] . '/includes/definitions/*.yaml';
foreach (glob($pattern) as $file) {
$tmp = Symfony\Component\Yaml\Yaml::parse(
file_get_contents($file)
);
$os = basename($file, '.yaml');
if (isset($config['os'][$os])) {
$tmp = $config['os'][$os];
} else {
$tmp = Symfony\Component\Yaml\Yaml::parse(
file_get_contents($file)
);
}
if (isset($tmp['discovery']) && is_array($tmp['discovery'])) {
foreach ($tmp['discovery'] as $item) {
// check each item individually, if all the conditions in that item are true, we have a match
+80 -1862
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -47,6 +47,7 @@ chdir($install_dir);
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_WARNING);
load_all_os(); // pre-load OS so we don't keep loading them
if (getenv('DBTEST')) {
global $schema, $sql_mode;

Some files were not shown because too many files have changed in this diff Show More