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 <netram.24bcs10329@sst.scaler.com>

* 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 <netram.24bcs10329@sst.scaler.com>

---------

Signed-off-by: netram75 <netram.24bcs10329@sst.scaler.com>
Co-authored-by: Paige Patton <64206430+paigerube14@users.noreply.github.com>
This commit is contained in:
Netram Faran
2026-05-13 13:48:51 -04:00
committed by GitHub
co-authored by Paige Patton
parent ebe6049be9
commit f5e5d0677b
2 changed files with 7 additions and 12 deletions
+2 -3
View File
@@ -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
)
+5 -9
View File
@@ -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):