Load Balancers test

This commit is contained in:
Tony Murray 2020-06-19 13:37:36 -05:00
parent 9372074b6d
commit d44ff69b99
2 changed files with 29 additions and 9 deletions

View File

@ -26,7 +26,9 @@
namespace LibreNMS\Util;
use DeviceCache;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use LibreNMS\Component;
use LibreNMS\Config;
use LibreNMS\Exceptions\FileNotFoundException;
use LibreNMS\Exceptions\InvalidModuleException;
@ -246,7 +248,7 @@ class ModuleTestHelper
foreach (glob(Config::get('install_dir') . "/tests/data/*.json") as $file) {
$base_name = basename($file, '.json');
list($os, $variant) = self::extractVariant($file);
[$os, $variant] = self::extractVariant($file);
// calculate valid modules
$data_modules = array_keys(json_decode(file_get_contents($file), true));
@ -295,7 +297,7 @@ class ModuleTestHelper
} elseif (is_file(Config::get('install_dir') . "/includes/definitions/$full_name.yaml")) {
return [$full_name, ''];
} else {
list($rvar, $ros) = explode('_', strrev($full_name), 2);
[$rvar, $ros] = explode('_', strrev($full_name), 2);
return [strrev($ros), strrev($rvar)];
}
}
@ -359,17 +361,17 @@ class ModuleTestHelper
}
if (preg_match('/^\.[.\d]+ =/', $line)) {
list($oid, $raw_data) = explode(' =', $line, 2);
[$oid, $raw_data] = explode(' =', $line, 2);
$oid = ltrim($oid, '.');
$raw_data = trim($raw_data);
if (empty($raw_data)) {
$result[] = "$oid|4|"; // empty data, we don't know type, put string
} else {
list($raw_type, $data) = explode(':', $raw_data, 2);
[$raw_type, $data] = explode(':', $raw_data, 2);
if (Str::startsWith($raw_type, 'Wrong Type (should be ')) {
// device returned the wrong type, save the wrong type to emulate the device behavior
list($raw_type, $data) = explode(':', ltrim($data), 2);
[$raw_type, $data] = explode(':', ltrim($data), 2);
}
$data = ltrim($data, ' "');
$type = $this->getSnmprecType($raw_type);
@ -392,7 +394,7 @@ class ModuleTestHelper
// multi-line data, append to last
$last = end($result);
list($oid, $type, $data) = explode('|', $last, 3);
[$oid, $type, $data] = explode('|', $last, 3);
if ($type == '4x') {
$result[key($result)] .= bin2hex(PHP_EOL . $line);
} else {
@ -470,7 +472,7 @@ class ModuleTestHelper
foreach ($snmprec_data as $line) {
if (!empty($line)) {
list($oid,) = explode('|', $line, 2);
[$oid,] = explode('|', $line, 2);
$result[$oid] = $line;
}
}
@ -681,6 +683,15 @@ class ModuleTestHelper
// only dump data for the given modules
foreach ($modules as $module) {
foreach ($module_dump_info[$module] ?: [] as $table => $info) {
if ($table == 'component') {
if (isset($key)) {
$data[$module][$key][$table] = $this->collectComponents($device_id);
} else {
$data[$module][$table] = $this->collectComponents($device_id);
}
continue;
}
// check for custom where
$where = isset($info['custom_where']) ? $info['custom_where'] : "WHERE `$table`.`device_id`=?";
$params = [$device_id];
@ -694,8 +705,8 @@ class ModuleTestHelper
$default_select = [];
} else {
list($left, $lkey) = explode('.', $join_info['left']);
list($right, $rkey) = explode('.', $join_info['right']);
[$left, $lkey] = explode('.', $join_info['left']);
[$right, $rkey] = explode('.', $join_info['right']);
$join .= " LEFT JOIN `$right` ON (`$left`.`$lkey` = `$right`.`$rkey`)";
$default_select = ["`$right`.*"];
@ -824,6 +835,13 @@ class ModuleTestHelper
return $this->json_file;
}
private function collectComponents($device_id)
{
$components = (new Component())->getComponents($device_id)[$device_id] ?? [];
$components = Arr::sort($components, 'label');
return array_values($components);
}
private function dataIsEmpty($data)
{
foreach ($data as $table_data) {

View File

@ -26,6 +26,8 @@ fdb-table:
- { left: ports_fdb.port_id, right: ports.port_id, select: [ifIndex] }
- { left: ports_fdb.vlan_id, right: vlans.vlan_id, select: [vlan_vlan] }
order_by: ports.ifIndex, vlans.vlan_vlan, ports_fdb.mac_address
loadbalancers:
component: true
mempools:
mempools:
excluded_fields: [device_id, mempool_id]