From 13543dd88bbd0933809409d6ee649871f808a31e Mon Sep 17 00:00:00 2001 From: Robert Chacon Date: Wed, 11 Mar 2026 17:10:29 -0600 Subject: [PATCH] changes --- src/scheduler.py | 10 ++++--- src/test_scheduler.py | 67 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/scheduler.py b/src/scheduler.py index 5ca74684..eb7b3158 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -23,6 +23,11 @@ ads = BlockingScheduler(executors={'default': ThreadPoolExecutor(1)}) network_hash = 0 +def clear_scheduler_error(): + """Clear the scheduler error status shown in the Web UI.""" + scheduler_error("") + + def get_integration_affinity_cpus(): """Return efficiency-core CPU IDs to prefer for integration subprocesses.""" try: @@ -108,7 +113,6 @@ def capture_output_and_run(func): output = captured_output.getvalue() if output: print(output) - scheduler_error(output) def run_python_integration(module_name: str, func_name: str, label: str = ""): @@ -129,7 +133,6 @@ def run_python_integration(module_name: str, func_name: str, label: str = ""): output = (result.stdout or "") + (result.stderr or "") if output: print(output) - scheduler_error(output) if result.returncode != 0: # Non-zero exit shouldn't stop scheduling; log and continue msg = f"Integration {friendly} exited with code {result.returncode}. Continuing." @@ -141,6 +144,7 @@ def run_python_integration(module_name: str, func_name: str, label: str = ""): scheduler_error(err) def importFromCRM(): + clear_scheduler_error() # CRM Hooks if automatic_import_uisp(): try: @@ -155,8 +159,6 @@ def importFromCRM(): output = (result.stdout or "") + (result.stderr or "") if output: print(output) - # Report UISP output to error channel regardless of return code. - scheduler_error(output) if result.returncode != 0: msg = f"UISP integration exited with code {result.returncode}. Continuing." print(msg) diff --git a/src/test_scheduler.py b/src/test_scheduler.py index 3dcaf41f..42b7d890 100644 --- a/src/test_scheduler.py +++ b/src/test_scheduler.py @@ -30,9 +30,9 @@ def install_scheduler_stubs(): lqlib.efficiency_core_ids = lambda: [] lqlib.scheduler_alive = Mock() lqlib.scheduler_error = Mock() - lqlib.overrides_persistent_devices = lambda: [] + lqlib.overrides_persistent_devices_effective = lambda: [] lqlib.overrides_circuit_adjustments = lambda: [] - lqlib.overrides_network_adjustments = lambda: [] + lqlib.overrides_network_adjustments_effective = lambda: [] sys.modules["liblqos_python"] = lqlib apscheduler_pkg = types.ModuleType("apscheduler") @@ -150,5 +150,68 @@ class TestSchedulerAffinity(unittest.TestCase): ) +class TestSchedulerErrorReporting(unittest.TestCase): + def test_python_integration_output_does_not_set_scheduler_error(self): + result = types.SimpleNamespace(returncode=0, stdout="normal info\n", stderr="") + + with patch.object(scheduler, "run_integration_subprocess", return_value=result): + with patch.object(scheduler, "scheduler_error") as mock_scheduler_error: + with patch("builtins.print"): + scheduler.run_python_integration( + "integrationExample", + "importExample", + label="Example", + ) + + mock_scheduler_error.assert_not_called() + + def test_python_integration_nonzero_exit_sets_scheduler_error(self): + result = types.SimpleNamespace(returncode=2, stdout="normal info\n", stderr="") + + with patch.object(scheduler, "run_integration_subprocess", return_value=result): + with patch.object(scheduler, "scheduler_error") as mock_scheduler_error: + with patch("builtins.print"): + scheduler.run_python_integration( + "integrationExample", + "importExample", + label="Example", + ) + + mock_scheduler_error.assert_called_once_with( + "Integration Example exited with code 2. Continuing." + ) + + def test_import_from_crm_clears_error_and_keeps_success_output_non_error(self): + result = types.SimpleNamespace(returncode=0, stdout="uisp info\n", stderr="") + + with patch.object(scheduler, "automatic_import_uisp", return_value=True): + with patch.object(scheduler, "get_libreqos_directory", return_value="/tmp/libreqos"): + with patch.object(scheduler, "run_integration_subprocess", return_value=result): + with patch.object(scheduler, "apply_lqos_overrides"): + with patch.object(scheduler.os.path, "isfile", return_value=False): + with patch.object(scheduler, "scheduler_error") as mock_scheduler_error: + with patch("builtins.print"): + scheduler.importFromCRM() + + self.assertEqual(mock_scheduler_error.call_args_list, [(( "",),)]) + + def test_import_from_crm_reports_nonzero_exit(self): + result = types.SimpleNamespace(returncode=1, stdout="uisp info\n", stderr="") + + with patch.object(scheduler, "automatic_import_uisp", return_value=True): + with patch.object(scheduler, "get_libreqos_directory", return_value="/tmp/libreqos"): + with patch.object(scheduler, "run_integration_subprocess", return_value=result): + with patch.object(scheduler, "apply_lqos_overrides"): + with patch.object(scheduler.os.path, "isfile", return_value=False): + with patch.object(scheduler, "scheduler_error") as mock_scheduler_error: + with patch("builtins.print"): + scheduler.importFromCRM() + + self.assertEqual( + mock_scheduler_error.call_args_list, + [(( "",),), (("UISP integration exited with code 1. Continuing.",),)], + ) + + if __name__ == "__main__": unittest.main() -- knotmirror 0.0.1