From 969159f77a078367a0df80ca34f32d7ce7ba484a Mon Sep 17 00:00:00 2001 From: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com> Date: Fri, 26 Aug 2022 22:29:14 +0200 Subject: [PATCH] Save-test-data to refresh all variants of an OS (#14231) * per OS per OS per OS fixTest fixTest * fix empty variant --- LibreNMS/Util/ModuleTestHelper.php | 6 +++++- scripts/save-test-data.php | 21 ++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/LibreNMS/Util/ModuleTestHelper.php b/LibreNMS/Util/ModuleTestHelper.php index e45e2b1ae5..57778ff4bb 100644 --- a/LibreNMS/Util/ModuleTestHelper.php +++ b/LibreNMS/Util/ModuleTestHelper.php @@ -259,7 +259,7 @@ class ModuleTestHelper * * @throws InvalidModuleException */ - public static function findOsWithData($modules = []) + public static function findOsWithData($modules = [], string $os_filter = null) { $os_list = []; @@ -267,6 +267,10 @@ class ModuleTestHelper $base_name = basename($file, '.json'); [$os, $variant] = self::extractVariant($file); + if ($os_filter != '' && $os_filter != $os) { + continue; + } + // calculate valid modules $decoded = json_decode(file_get_contents($file), true); diff --git a/scripts/save-test-data.php b/scripts/save-test-data.php index 16e553e9f2..14940b1180 100755 --- a/scripts/save-test-data.php +++ b/scripts/save-test-data.php @@ -40,19 +40,19 @@ if (isset($options['snmpsim'])) { if (isset($options['h']) || isset($options['help']) - || (isset($options['o']) || isset($options['os'])) && ! (isset($options['v']) || isset($options['variant'])) || ! (isset($options['o']) || isset($options['os']) || isset($options['m']) || isset($options['modules'])) ) { echo "Script to update test data. Database data is saved in tests/data. Usage: - You must specify a valid OS (and variant) and/or module(s). + - This script can process new test data (by specifying both OS and VARIANT). + - This script can refresh test data. + -> if an OS is specified, only this OS will be refreshed. + -> if MODULES are specified, only these modules will be refreshed. -Required: - -o, --os Name of the OS to save test data for - -v, --variant The variant of the OS to use, usually the device model - -Optional: +Parameters: + -o, --os Name of the OS to save test data for. + -v, --variant The variant of the OS to use, usually the device model. -m, --modules The discovery/poller module(s) to collect data for, comma delimited. Use -m 'all' for all modules. -n, --no-save Don't save database entries, print them out instead @@ -89,7 +89,8 @@ if ((isset($options['m']) && $options['m'] == 'all') || (isset($options['modules } $full_os_name = $os_name; -$variant = ''; +$variant = null; + if (isset($options['v'])) { $variant = $options['v']; $full_os_name = $os_name . '_' . $variant; @@ -100,8 +101,10 @@ if (isset($options['v'])) { $os_list = []; -if ($os_name) { +if (isset($os_name) && isset($variant)) { $os_list = [$full_os_name => [$os_name, $variant]]; +} elseif (isset($os_name)) { + $os_list = ModuleTestHelper::findOsWithData($modules, $os_name); } else { $os_list = ModuleTestHelper::findOsWithData($modules); }