From f5e5d0677b31cbf619d01e5fbbfe479662afce3a Mon Sep 17 00:00:00 2001 From: Netram Faran Date: Wed, 13 May 2026 23:18:51 +0530 Subject: [PATCH] fix(cerberus): fix config key typo and shadowed global in get_status (#1303) * fix(cerberus): fix config key typo and shadowed global in get_status Fixes #1302 - Fix typo in set_url(): read 'check_application_routes' instead of 'check_applicaton_routes' so the correct config key is used - Remove local 'check_application_routes = False' in get_status() and declare global instead, so the value set by set_url() is actually read - Update test config key and remove the workaround comment that acknowledged the shadowed global Signed-off-by: netram75 * fix(cerberus): remove extra cerberus_url arg from application_status call application_status(start_time, end_time) takes two parameters but was being called with three (cerberus_url, start_time, end_time), which would raise a TypeError whenever check_application_routes is enabled. Remove the stale argument since the function already reads cerberus_url from the module global. Signed-off-by: netram75 --------- Signed-off-by: netram75 Co-authored-by: Paige Patton <64206430+paigerube14@users.noreply.github.com> --- krkn/cerberus/setup.py | 5 ++--- tests/test_cerberus_setup.py | 14 +++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/krkn/cerberus/setup.py b/krkn/cerberus/setup.py index 5b132613..c32d2153 100644 --- a/krkn/cerberus/setup.py +++ b/krkn/cerberus/setup.py @@ -32,14 +32,14 @@ def set_url(config): cerberus_url = get_yaml_item_value(config["cerberus"],"cerberus_url", "") global check_application_routes check_application_routes = \ - get_yaml_item_value(config["cerberus"],"check_applicaton_routes","") + get_yaml_item_value(config["cerberus"],"check_application_routes","") def get_status(start_time, end_time): """ Get cerberus status """ + global check_application_routes cerberus_status = True - check_application_routes = False application_routes_status = True if cerberus_enabled: if not cerberus_url: @@ -55,7 +55,6 @@ def get_status(start_time, end_time): # experience downtime during the chaos if check_application_routes: application_routes_status, unavailable_routes = application_status( - cerberus_url, start_time, end_time ) diff --git a/tests/test_cerberus_setup.py b/tests/test_cerberus_setup.py index 45102021..b48ab20f 100644 --- a/tests/test_cerberus_setup.py +++ b/tests/test_cerberus_setup.py @@ -33,7 +33,7 @@ class TestCerberusSetup(unittest.TestCase): "cerberus": { "cerberus_enabled": True, "cerberus_url": "http://cerberus.example.com", - "check_applicaton_routes": "route1,route2" + "check_application_routes": "route1,route2" } } @@ -125,26 +125,22 @@ class TestCerberusSetup(unittest.TestCase): """Test get_status with application routes check when routes are healthy""" cerberus_setup.cerberus_enabled = True cerberus_setup.cerberus_url = "http://cerberus.example.com" - - # Mock both cerberus status check and history endpoint + cerberus_setup.check_application_routes = "route1,route2" + def mock_get_side_effect(url, timeout): mock_response = MagicMock() if "/history?" in url: - # History endpoint - no failures mock_response.content = json.dumps({"history": {"failures": []}}).encode() else: - # Status endpoint mock_response.content = b"True" return mock_response - + mock_get.side_effect = mock_get_side_effect - # Note: check_application_routes is set to False locally in get_status() - # so we can't test the full flow without modifying the function - # This test verifies cerberus status returns True result = cerberus_setup.get_status(0, 100) self.assertTrue(result) + self.assertEqual(mock_get.call_count, 2) @patch('krkn.cerberus.setup.requests.get') def test_get_status_with_application_routes_check_failure(self, mock_get):