]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Add explicit test to verify json.loads is not called with empty string
authorcopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Tue, 17 Feb 2026 15:08:59 +0000 (15:08 +0000)
committercopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Tue, 17 Feb 2026 15:08:59 +0000 (15:08 +0000)
Co-authored-by: epuertat <37327689+epuertat@users.noreply.github.com>
src/pybind/mgr/prometheus/test_module.py

index 59835776a847739a2bbd06f7674bf1af18baa63f..7f894c9a47d05f9ae2220b5e43bec077df25ec39 100644 (file)
@@ -95,6 +95,30 @@ ceph_disk_occupation_display{ceph_daemon="osd.5+osd.6",device="/dev/dm-1",instan
 
 
 class ConfigureTest(TestCase):
+    @patch('prometheus.module.json.loads')
+    def test_configure_with_empty_security_config_no_json_parse(self, mock_json_loads):
+        """Test that json.loads is NOT called when output is empty string"""
+        module = Mock(spec=Module)
+        module.log = Mock()
+
+        # Mock mon_command to return empty string (the problematic case)
+        module.mon_command = Mock(return_value=(0, "", ""))
+
+        # Mock setup_default_config
+        module.setup_default_config = Mock()
+
+        # Call the actual configure method with our mocks
+        Module.configure(module, "127.0.0.1", 9283)
+
+        # Verify that json.loads was NOT called (this is the fix!)
+        mock_json_loads.assert_not_called()
+
+        # Verify that setup_default_config was called (fallback behavior)
+        module.setup_default_config.assert_called_once_with("127.0.0.1", 9283)
+
+        # Verify no exception was raised and log was not called with exception
+        module.log.exception.assert_not_called()
+
     def test_configure_with_empty_security_config(self):
         """Test that configure handles empty string from orch get-security-config"""
         module = Mock(spec=Module)