Skip to content

Commit ae774a7

Browse files
nammnclaude
andcommitted
Add explicit tests to verify TLS params in monitoring config
CLOUDP-351614: Added two new tests that explicitly verify the fix: 1. test_monitoring_config_has_tls_params_when_tls_enabled: - Verifies that when TLS is enabled, the monitoring config contains TLS additionalParams (useSslForAllConnections, sslTrustedServerCertificates) - This confirms the starting state before disabling TLS 2. test_monitoring_config_tls_params_cleared_after_tls_disabled: - THE KEY TEST FOR THE BUG FIX - Verifies that after TLS is disabled, the additionalParams are CLEARED - This test would have FAILED before the fix because stale TLS params would remain in the monitoring config, causing monitoring agents to fail when trying to use certificate files that are no longer valid 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent eb0dd7e commit ae774a7

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

docker/mongodb-kubernetes-tests/tests/opsmanager/withMonitoredAppDB/om_appdb_tls_disable.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@
1616
from tests.conftest import is_multi_cluster
1717
from tests.opsmanager.withMonitoredAppDB.conftest import enable_multi_cluster_deployment
1818

19+
20+
def get_monitoring_tls_params(ops_manager: MongoDBOpsManager) -> dict:
21+
"""
22+
Extract TLS-related additionalParams from monitoring config.
23+
24+
Returns a dict with the additionalParams for all monitoring agents,
25+
keyed by hostname. An empty dict means no TLS params are present.
26+
"""
27+
ac = ops_manager.get_automation_config_tester()
28+
monitoring_versions = ac.automation_config.get("monitoringVersions", [])
29+
30+
tls_params_by_host = {}
31+
for mv in monitoring_versions:
32+
hostname = mv.get("hostname", "unknown")
33+
additional_params = mv.get("additionalParams", {})
34+
if additional_params:
35+
tls_params_by_host[hostname] = additional_params
36+
37+
return tls_params_by_host
38+
1939
OM_NAME = "om-tls-disable-test"
2040
APPDB_NAME = f"{OM_NAME}-db"
2141

@@ -69,6 +89,32 @@ def test_appdb_monitoring_works_with_tls(ops_manager: MongoDBOpsManager):
6989
ops_manager.assert_monitoring_data_exists(timeout=600, all_hosts=False)
7090

7191

92+
@mark.e2e_om_appdb_tls_disable
93+
def test_monitoring_config_has_tls_params_when_tls_enabled(ops_manager: MongoDBOpsManager):
94+
"""
95+
CLOUDP-351614: Verify that monitoring config contains TLS params when TLS is enabled.
96+
97+
When TLS is enabled on AppDB, the monitoring agents should be configured with
98+
TLS parameters in additionalParams, including:
99+
- useSslForAllConnections: "true"
100+
- sslTrustedServerCertificates: path to CA file
101+
- sslClientCertificate: path to client certificate (for x509 auth)
102+
"""
103+
tls_params = get_monitoring_tls_params(ops_manager)
104+
105+
# Monitoring agents should have TLS params configured
106+
assert len(tls_params) > 0, "Expected TLS params in monitoring config when TLS is enabled"
107+
108+
# Verify TLS params contain expected keys
109+
for hostname, params in tls_params.items():
110+
assert params.get("useSslForAllConnections") == "true", (
111+
f"Expected useSslForAllConnections=true for {hostname}, got {params}"
112+
)
113+
assert "sslTrustedServerCertificates" in params, (
114+
f"Expected sslTrustedServerCertificates in params for {hostname}"
115+
)
116+
117+
72118
@mark.e2e_om_appdb_tls_disable
73119
def test_disable_tls_on_appdb(ops_manager: MongoDBOpsManager):
74120
"""
@@ -95,6 +141,30 @@ def test_disable_tls_on_appdb(ops_manager: MongoDBOpsManager):
95141
ops_manager.appdb_status().assert_reaches_phase(Phase.Running, timeout=1800)
96142

97143

144+
@mark.e2e_om_appdb_tls_disable
145+
def test_monitoring_config_tls_params_cleared_after_tls_disabled(ops_manager: MongoDBOpsManager):
146+
"""
147+
CLOUDP-351614: Verify that TLS params are CLEARED from monitoring config after TLS is disabled.
148+
149+
THIS IS THE KEY TEST FOR THE BUG FIX:
150+
Before the fix in CLOUDP-351614, the operator would leave stale TLS params
151+
(useSslForAllConnections, sslClientCertificate, etc.) in the monitoring config
152+
even after TLS was disabled. This caused monitoring agents to fail because they
153+
would try to use TLS certificate files that are no longer valid for authentication.
154+
155+
After the fix, the operator correctly clears these params by calling:
156+
delete(monitoringVersion, "additionalParams")
157+
"""
158+
tls_params = get_monitoring_tls_params(ops_manager)
159+
160+
# After TLS is disabled, monitoring config should NOT have TLS params
161+
# This assertion would have FAILED before the fix because stale TLS params remained
162+
assert len(tls_params) == 0, (
163+
f"CLOUDP-351614 BUG: TLS params should be cleared from monitoring config after "
164+
f"TLS is disabled, but found stale params: {tls_params}"
165+
)
166+
167+
98168
@mark.e2e_om_appdb_tls_disable
99169
def test_monitoring_works_after_tls_disable(ops_manager: MongoDBOpsManager):
100170
"""

0 commit comments

Comments
 (0)