diff --git a/run_kraken.py b/run_kraken.py index e8ddda27..b78491f9 100644 --- a/run_kraken.py +++ b/run_kraken.py @@ -206,6 +206,7 @@ def main(options, command: Optional[str], out: Optional[dict] = None) -> int: check_critical_alerts = get_yaml_item_value( config["performance_monitoring"], "check_critical_alerts", False ) + config["telemetry"] = get_yaml_item_value(config, "telemetry", {}) telemetry_api_url = config["telemetry"].get("api_url", "") telemetry_enabled = config["telemetry"].get("enabled", True) diff --git a/tests/test_run_kraken.py b/tests/test_run_kraken.py new file mode 100644 index 00000000..98aab312 --- /dev/null +++ b/tests/test_run_kraken.py @@ -0,0 +1,32 @@ +import unittest +from unittest.mock import patch, mock_open +from types import SimpleNamespace + +from run_kraken import main + + +class TestRunKraken(unittest.TestCase): + + @patch('run_kraken.yaml.safe_load') + @patch('run_kraken.os.path.isfile') + @patch('builtins.open', new_callable=mock_open) + def test_main_without_telemetry_config(self, mock_file, mock_isfile, mock_yaml_load): + """ + Test that main() doesn't crash when config has no telemetry section + """ + mock_isfile.side_effect = lambda p: p == "/fake/config.yaml" + mock_yaml_load.return_value = { + "kraken": {"rollback_versions_directory": "/tmp/krkn-test-rollback"}, + "tunings": {}, + "performance_monitoring": {}, + "elastic": {}, + } + + options = SimpleNamespace(cfg="/fake/config.yaml") + result = main(options, None) + + self.assertEqual(result, -1) + + +if __name__ == "__main__": + unittest.main()