diff --git a/krkn/cerberus/setup.py b/krkn/cerberus/setup.py index 5b132613d..cee535282 100644 --- a/krkn/cerberus/setup.py +++ b/krkn/cerberus/setup.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# # Copyright 2025 The Krkn Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import logging import requests import sys @@ -31,15 +34,26 @@ def set_url(config): global cerberus_url 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","") + # Read correct key first; fall back to legacy misspelled key for older configs + check_application_routes = get_yaml_item_value( + config["cerberus"], "check_application_routes", "" + ) + if not check_application_routes: + legacy = get_yaml_item_value( + config["cerberus"], "check_applicaton_routes", "" + ) + if legacy: + logging.warning( + "Config key 'check_applicaton_routes' is deprecated and will be " + "removed in a future release. Please rename it to 'check_application_routes'." + ) + check_application_routes = legacy def get_status(start_time, end_time): """ Get cerberus status """ cerberus_status = True - check_application_routes = False application_routes_status = True if cerberus_enabled: if not cerberus_url: @@ -55,7 +69,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 ) @@ -96,26 +109,12 @@ def publish_kraken_status( start_time, end_time): if not cerberus_status: if exit_on_failure: logging.info( - "Cerberus status is not healthy and post action scenarios " - "are still failing, exiting kraken run" - ) - sys.exit(1) - else: - logging.info( - "Cerberus status is not healthy and post action scenarios " - "are still failing" - ) - else: - if exit_on_failure: - logging.info( - "Cerberus status is healthy but post action scenarios " - "are still failing, exiting kraken run" + "Cerberus status is not healthy, exiting kraken run" ) sys.exit(1) else: logging.info( - "Cerberus status is healthy but post action scenarios " - "are still failing" + "Cerberus status is not healthy" ) diff --git a/krkn/prometheus/client.py b/krkn/prometheus/client.py index 41727e640..d4be59217 100644 --- a/krkn/prometheus/client.py +++ b/krkn/prometheus/client.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# # Copyright 2025 The Krkn Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + from __future__ import annotations import datetime @@ -178,8 +181,10 @@ def critical_alerts( if not firing_alerts: logging.info("No critical alerts are firing!!") - - + + return firing_alerts + + def metrics( prom_cli: KrknPrometheus, elastic: KrknElastic, diff --git a/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py b/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py index eb1a52451..24b2c9722 100644 --- a/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py +++ b/krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py @@ -74,7 +74,6 @@ def run( targets = random.sample( targets, network_chaos_config.instance_count ) - if network_chaos_config.execution == "parallel": self.run_parallel(targets, network_chaos) else: diff --git a/krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py b/krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py index 094d0bedd..2413331d8 100644 --- a/krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py +++ b/krkn/scenario_plugins/zone_outage/zone_outage_scenario_plugin.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# # Copyright 2025 The Krkn Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,10 +13,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + import base64 import json import logging import time +import base64 +import json import yaml diff --git a/krkn/utils/HealthChecker.py b/krkn/utils/HealthChecker.py index c095db085..f0fcc0870 100644 --- a/krkn/utils/HealthChecker.py +++ b/krkn/utils/HealthChecker.py @@ -65,6 +65,7 @@ def run_health_check(self, health_check_config, health_check_telemetry_queue: qu "status_code": response["status_code"], "start_timestamp": start_timestamp } + if response["status_code"] != 200: if response["status_code"] != 200: if response_tracker[config["url"]] is not False: response_tracker[config["url"]] = False @@ -106,3 +107,4 @@ def run_health_check(self, health_check_config, health_check_telemetry_queue: qu else: logging.info("health checks config is not defined, skipping them") return self.ret_value + return self.ret_value diff --git a/tests/test_cerberus_setup.py b/tests/test_cerberus_setup.py index 45102021f..4f1e9e439 100644 --- a/tests/test_cerberus_setup.py +++ b/tests/test_cerberus_setup.py @@ -1,3 +1,19 @@ +#!/usr/bin/env python +# +# Copyright 2025 The Krkn Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + """ Test suite for krkn/cerberus/setup.py @@ -33,7 +49,7 @@ def test_set_url_with_cerberus_enabled(self): "cerberus": { "cerberus_enabled": True, "cerberus_url": "http://cerberus.example.com", - "check_applicaton_routes": "route1,route2" + "check_application_routes": "route1,route2" } } @@ -178,12 +194,28 @@ def test_publish_kraken_status_healthy_exit_on_failure_true(self, mock_get_statu cerberus_setup.exit_on_failure = True mock_get_status.return_value = True - with self.assertRaises(SystemExit) as cm: - cerberus_setup.publish_kraken_status(0, 100) - - self.assertEqual(cm.exception.code, 1) + # Healthy cluster should NOT exit regardless of exit_on_failure + cerberus_setup.publish_kraken_status(0, 100) + mock_get_status.assert_called_once_with(0, 100) + def test_set_url_legacy_misspelled_key_fallback(self): + """Test set_url falls back to legacy misspelled key check_applicaton_routes""" + config = { + "kraken": {"exit_on_failure": False}, + "cerberus": { + "cerberus_enabled": True, + "cerberus_url": "http://cerberus.example.com", + "check_applicaton_routes": "legacy-route" # old misspelled key + } + } + + with self.assertLogs(level="WARNING") as log: + cerberus_setup.set_url(config) + + self.assertEqual(cerberus_setup.check_application_routes, "legacy-route") + self.assertTrue(any("deprecated" in msg for msg in log.output)) + @patch('krkn.cerberus.setup.get_status') def test_publish_kraken_status_unhealthy_exit_on_failure_false(self, mock_get_status): """Test publish_kraken_status when cluster is unhealthy and exit_on_failure is False"""