Skip to content

Commit 7b1682f

Browse files
committed
Fix e2e search test naming alignment issues
- Fix try_load() by removing the FIXME early-return that was causing get_ops_manager() to return unloaded resources (empty status), resulting in empty baseUrl in OpsManager connection ConfigMaps on om80 variant - Fix endpoint template in search-sharded-external-lb.yaml - Fix username mismatch in enterprise_tls sample_movies_helper - Fix CRD field name sharded→shardedCluster in sharded_enterprise_external_mongod - Fix CA configmap and mongodbResourceRef overrides in sharded_enterprise_managed_lb - Fix username mismatches in sharded_external_mongod_single_mongot
1 parent c92d81e commit 7b1682f

9 files changed

Lines changed: 62 additions & 35 deletions

docker/mongodb-kubernetes-tests/kubetester/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@ def try_load(resource: CustomObject) -> bool:
458458
Tries to load the resource without raising an exception when the resource does not exist.
459459
Returns False if the resource does not exist.
460460
"""
461-
# FIXME DELETE THIS
462-
return False
463461
try:
464462
resource.load()
465463
except kubernetes.client.ApiException as e:

docker/mongodb-kubernetes-tests/tests/common/mongodb_tools_pod/mongodb_tools_pod.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
TOOLS_POD_NAME = "mongodb-tools-pod"
1212
# pinning to specific hash as there was a regression in recently published images
13-
TOOLS_POD_IMAGE = "quay.io/mongodb/mongodb-community-server@sha256:4be3e7a6568e467a21c093f34ddedf0a7d35c244ead410d687e9eb50ac46be25"
13+
TOOLS_POD_IMAGE = (
14+
"quay.io/mongodb/mongodb-community-server@sha256:4be3e7a6568e467a21c093f34ddedf0a7d35c244ead410d687e9eb50ac46be25"
15+
)
1416

1517

1618
class ToolsPod:

docker/mongodb-kubernetes-tests/tests/common/search/search_resource_names.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Go source: api/v1/search/mongodbsearch_types.go
88
"""
99

10-
1110
# ============================================================================
1211
# Replica Set resources
1312
# ============================================================================

docker/mongodb-kubernetes-tests/tests/search/fixtures/search-sharded-external-lb.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ spec:
1818
mode: Unmanaged
1919
# Endpoint template with {shardName} placeholder
2020
# NAMESPACE placeholder is replaced with actual namespace by the test fixture
21-
endpoint: "mdb-sh-mongot-{shardName}-proxy-svc.NAMESPACE.svc.cluster.local:27029"
21+
endpoint: "mdb-sh-search-0-{shardName}-proxy-svc.NAMESPACE.svc.cluster.local:27029"

docker/mongodb-kubernetes-tests/tests/search/search_enterprise_tls.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ def mdbs(namespace: str) -> MongoDBSearch:
5454
if "spec" not in resource:
5555
resource["spec"] = {}
5656
resource["spec"]["security"] = {"tls": {"certificateKeySecretRef": {"name": MDBS_TLS_SECRET_NAME}}}
57-
resource["spec"]["source"] = {
58-
"passwordSecretRef": {
59-
"name": f"{resource.name}-{MONGOT_USER_NAME}-password"
60-
}
61-
}
57+
resource["spec"]["source"] = {"passwordSecretRef": {"name": f"{resource.name}-{MONGOT_USER_NAME}-password"}}
6258
try_load(resource)
6359
return resource
6460

@@ -81,7 +77,9 @@ def admin_user(namespace: str) -> MongoDBUser:
8177

8278
@fixture(scope="function")
8379
def user(namespace: str) -> MongoDBUser:
84-
resource = MongoDBUser.from_yaml(yaml_fixture("mongodbuser-mdb-user.yaml"), namespace=namespace, name=f"{MDB_RESOURCE_NAME}-{USER_NAME}")
80+
resource = MongoDBUser.from_yaml(
81+
yaml_fixture("mongodbuser-mdb-user.yaml"), namespace=namespace, name=f"{MDB_RESOURCE_NAME}-{USER_NAME}"
82+
)
8583
resource["spec"]["mongodbResourceRef"]["name"] = MDB_RESOURCE_NAME
8684
resource["spec"]["username"] = resource.name
8785
resource["spec"]["passwordSecretKeyRef"]["name"] = f"{resource.name}-password"
@@ -240,7 +238,9 @@ def test_search_verify_prometheus_enabled_on_custom_port(namespace: str, mdbs: M
240238
@fixture(scope="function")
241239
def sample_movies_helper(mdb: MongoDB, namespace: str) -> movies_search_helper.SampleMoviesSearchHelper:
242240
return movies_search_helper.SampleMoviesSearchHelper(
243-
SearchTester.for_replicaset(mdb, USER_NAME, USER_PASSWORD, use_ssl=True, ca_path=get_issuer_ca_filepath()),
241+
SearchTester.for_replicaset(
242+
mdb, f"{MDB_RESOURCE_NAME}-{USER_NAME}", USER_PASSWORD, use_ssl=True, ca_path=get_issuer_ca_filepath()
243+
),
244244
tools_pod=mongodb_tools_pod.get_tools_pod(namespace),
245245
)
246246

docker/mongodb-kubernetes-tests/tests/search/search_sharded_enterprise_external_lb.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,14 @@ def create_envoy_certificates(namespace: str, issuer: str):
539539

540540
def create_per_shard_search_tls_certs(namespace: str, issuer: str, prefix: str):
541541
"""
542-
Create per-shard TLS certificates for MongoDBSearch resource.
542+
Create per-shard TLS certificates for MongoDBSearch resource.
543543
544-
For each shard, creates a certificate with DNS names for:
545-
- The mongot service: {search-name}-search-0-{shardName}-svc.{namespace}.svc.cluster.local
546-
- The proxy service: {search-name}-search-0-{shardName}-proxy-svc.{namespace}.svc.cluster.local
544+
For each shard, creates a certificate with DNS names for:
545+
- The mongot service: {search-name}-search-0-{shardName}-svc.{namespace}.svc.cluster.local
546+
- The proxy service: {search-name}-search-0-{shardName}-proxy-svc.{namespace}.svc.cluster.local
547547
548-
a Secret naming: search_resource_names.shard_tls_cert_name(MDB_RESOURCE_NAME, shardName, prefix)
549-
e.g., certs-mdb-sh-search-0-mdb-sh-0-cert
548+
a Secret naming: search_resource_names.shard_tls_cert_name(MDB_RESOURCE_NAME, shardName, prefix)
549+
e.g., certs-mdb-sh-search-0-mdb-sh-0-cert
550550
"""
551551
logger.info(f"Creating per-shard Search TLS certificates with prefix '{prefix}'...")
552552

@@ -731,7 +731,9 @@ def test_verify_per_shard_tls_secrets(namespace: str, mdbs: MongoDBSearch):
731731
shard_name = f"{MDB_RESOURCE_NAME}-{shard_idx}"
732732

733733
# Verify source secret (created by cert-manager in test_)
734-
source_secret_name = search_resource_names.shard_tls_cert_name(MDB_RESOURCE_NAME, shard_name, MDBS_TLS_CERT_PREFIX)
734+
source_secret_name = search_resource_names.shard_tls_cert_name(
735+
MDB_RESOURCE_NAME, shard_name, MDBS_TLS_CERT_PREFIX
736+
)
735737
try:
736738
source_secret = read_secret(namespace, source_secret_name)
737739
assert "tls.crt" in source_secret, f"Source secret {source_secret_name} missing tls.crt"

docker/mongodb-kubernetes-tests/tests/search/search_sharded_enterprise_external_mongod.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- Executes search queries through mongos and verifies results from all shards
1414
1515
Key difference from search_sharded_enterprise_external_lb.py:
16-
- This test uses spec.source.external.sharded (external MongoDB source)
16+
- This test uses spec.source.external.shardedCluster (external MongoDB source)
1717
- The other test uses spec.source.mongodb.name (operator-managed MongoDB source)
1818
"""
1919

@@ -139,7 +139,9 @@ def mdb(namespace: str, sharded_ca_configmap: str) -> MongoDB:
139139
for shard_idx in range(SHARD_COUNT):
140140
shard_name = f"{MDB_RESOURCE_NAME}-{shard_idx}"
141141
# Envoy proxy service name follows the pattern: <search-name>-search-0-<shard-name>-proxy-svc
142-
proxy_host = search_resource_names.shard_proxy_service_host(MDBS_RESOURCE_NAME, shard_name, namespace, ENVOY_PROXY_PORT)
142+
proxy_host = search_resource_names.shard_proxy_service_host(
143+
MDBS_RESOURCE_NAME, shard_name, namespace, ENVOY_PROXY_PORT
144+
)
143145

144146
shard_overrides.append(
145147
{
@@ -161,7 +163,9 @@ def mdb(namespace: str, sharded_ca_configmap: str) -> MongoDB:
161163

162164
# Configure mongos with search parameters pointing to first shard's Envoy proxy
163165
first_shard_name = f"{MDB_RESOURCE_NAME}-0"
164-
mongos_proxy_host = search_resource_names.shard_proxy_service_host(MDBS_RESOURCE_NAME, first_shard_name, namespace, ENVOY_PROXY_PORT)
166+
mongos_proxy_host = search_resource_names.shard_proxy_service_host(
167+
MDBS_RESOURCE_NAME, first_shard_name, namespace, ENVOY_PROXY_PORT
168+
)
165169

166170
# Initialize mongos spec if not present
167171
if "mongos" not in resource["spec"]:
@@ -185,7 +189,7 @@ def mdb(namespace: str, sharded_ca_configmap: str) -> MongoDB:
185189
def mdbs(namespace: str, mdb: MongoDB) -> MongoDBSearch:
186190
"""Fixture for MongoDBSearch with external sharded source configuration.
187191
188-
This fixture dynamically builds the spec.source.external.sharded configuration
192+
This fixture dynamically builds the spec.source.external.shardedCluster configuration
189193
based on the deployed MongoDB sharded cluster, treating it as an external source.
190194
"""
191195
resource = MongoDBSearch.from_yaml(
@@ -227,7 +231,7 @@ def mdbs(namespace: str, mdb: MongoDB) -> MongoDBSearch:
227231
"key": "password",
228232
},
229233
"external": {
230-
"sharded": {
234+
"shardedCluster": {
231235
"router": {
232236
"hosts": router_hosts,
233237
},
@@ -784,7 +788,9 @@ def test_verify_per_shard_tls_secrets(namespace: str, mdbs: MongoDBSearch):
784788
shard_name = f"{MDB_RESOURCE_NAME}-{shard_idx}"
785789

786790
# Verify source secret (created by cert-manager in test_create_search_tls_certificate)
787-
source_secret_name = search_resource_names.shard_tls_cert_name(MDBS_RESOURCE_NAME, shard_name, MDBS_TLS_CERT_PREFIX)
791+
source_secret_name = search_resource_names.shard_tls_cert_name(
792+
MDBS_RESOURCE_NAME, shard_name, MDBS_TLS_CERT_PREFIX
793+
)
788794
try:
789795
source_secret = read_secret(namespace, source_secret_name)
790796
assert "tls.crt" in source_secret, f"Source secret {source_secret_name} missing tls.crt"

docker/mongodb-kubernetes-tests/tests/search/search_sharded_enterprise_managed_lb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def mdb(namespace: str, sharded_ca_configmap: str) -> MongoDB:
120120
# Configure OpsManager/CloudManager connection
121121
resource.configure(om=get_ops_manager(namespace), project_name=MDB_RESOURCE_NAME)
122122

123+
resource["spec"]["security"]["tls"]["ca"] = CA_CONFIGMAP_NAME
124+
123125
return resource
124126

125127

@@ -139,6 +141,8 @@ def mdbs(namespace: str) -> MongoDBSearch:
139141
if try_load(resource):
140142
return resource
141143

144+
resource["spec"]["source"]["mongodbResourceRef"]["name"] = MDB_RESOURCE_NAME
145+
142146
return resource
143147

144148

@@ -488,7 +492,9 @@ def test_verify_per_shard_tls_secrets(namespace: str, mdbs: MongoDBSearch):
488492
shard_name = f"{MDB_RESOURCE_NAME}-{shard_idx}"
489493

490494
# Verify source secret (created by cert-manager in test_)
491-
source_secret_name = search_resource_names.shard_tls_cert_name(MDB_RESOURCE_NAME, shard_name, MDBS_TLS_CERT_PREFIX)
495+
source_secret_name = search_resource_names.shard_tls_cert_name(
496+
MDB_RESOURCE_NAME, shard_name, MDBS_TLS_CERT_PREFIX
497+
)
492498
try:
493499
source_secret = read_secret(namespace, source_secret_name)
494500
assert "tls.crt" in source_secret, f"Source secret {source_secret_name} missing tls.crt"

docker/mongodb-kubernetes-tests/tests/search/search_sharded_external_mongod_single_mongot.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
from pytest import fixture, mark
2525
from tests import test_logger
2626
from tests.common.mongodb_tools_pod import mongodb_tools_pod
27-
from tests.common.search import search_resource_names, movies_search_helper
28-
from tests.common.search.search_tester import SearchTester
27+
from tests.common.search import movies_search_helper, search_resource_names
2928
from tests.common.search.movies_search_helper import SampleMoviesSearchHelper
3029
from tests.common.search.search_tester import SearchTester
3130
from tests.conftest import get_default_operator, get_issuer_ca_filepath
@@ -139,7 +138,9 @@ def mdb(namespace: str, sharded_ca_configmap: str) -> MongoDB:
139138

140139
# Configure mongos with search parameters pointing to first shard's Envoy proxy
141140
first_shard_name = f"{MDB_RESOURCE_NAME}-0"
142-
mongos_proxy_host = search_resource_names.shard_service_host(MDBS_RESOURCE_NAME, first_shard_name, namespace, MONGOT_PORT)
141+
mongos_proxy_host = search_resource_names.shard_service_host(
142+
MDBS_RESOURCE_NAME, first_shard_name, namespace, MONGOT_PORT
143+
)
143144

144145
# Initialize mongos spec if not present
145146
if "mongos" not in resource["spec"]:
@@ -240,7 +241,9 @@ def admin_user(namespace: str) -> MongoDBUser:
240241

241242
@fixture(scope="function")
242243
def user(namespace: str) -> MongoDBUser:
243-
resource = MongoDBUser.from_yaml(yaml_fixture("mongodbuser-mdb-user.yaml"), namespace=namespace, name=f"{MDB_RESOURCE_NAME}-{USER_NAME}")
244+
resource = MongoDBUser.from_yaml(
245+
yaml_fixture("mongodbuser-mdb-user.yaml"), namespace=namespace, name=f"{MDB_RESOURCE_NAME}-{USER_NAME}"
246+
)
244247
resource["spec"]["mongodbResourceRef"]["name"] = MDB_RESOURCE_NAME
245248
resource["spec"]["username"] = resource.name
246249
resource["spec"]["passwordSecretKeyRef"]["name"] = f"{resource.name}-password"
@@ -407,7 +410,9 @@ def check_mongod_parameters():
407410
pod_name, namespace, ["cat", "/data/automation-mongod.conf"]
408411
)
409412
)
410-
expected_mongot_host_port = search_resource_names.shard_service_host(mdbs.name, shard_name, namespace, MONGOT_PORT)
413+
expected_mongot_host_port = search_resource_names.shard_service_host(
414+
mdbs.name, shard_name, namespace, MONGOT_PORT
415+
)
411416

412417
set_parameter = mongod_config.get("setParameter", {})
413418
mongot_host = set_parameter.get("mongotHost", "")
@@ -467,15 +472,20 @@ def test_search_deploy_tools_pod(tools_pod: mongodb_tools_pod.ToolsPod):
467472
@fixture(scope="function")
468473
def sample_movies_helper(mdb: MongoDB, namespace: str) -> movies_search_helper.SampleMoviesSearchHelper:
469474
return movies_search_helper.SampleMoviesSearchHelper(
470-
SearchTester.for_sharded(mdb, USER_NAME, USER_PASSWORD, use_ssl=True, ca_path=get_issuer_ca_filepath()),
475+
SearchTester.for_sharded(
476+
mdb, f"{MDB_RESOURCE_NAME}-{USER_NAME}", USER_PASSWORD, use_ssl=True, ca_path=get_issuer_ca_filepath()
477+
),
471478
tools_pod=mongodb_tools_pod.get_tools_pod(namespace),
472479
)
473480

474481

475482
@mark.e2e_search_sharded_external_mongod_single_mongot
476-
def test_search_restore_sample_database(mdb: MongoDB, sample_movies_helper: movies_search_helper.SampleMoviesSearchHelper):
483+
def test_search_restore_sample_database(
484+
mdb: MongoDB, sample_movies_helper: movies_search_helper.SampleMoviesSearchHelper
485+
):
477486
sample_movies_helper.restore_sample_database()
478487

488+
479489
logger.info("Sample database restored")
480490

481491

@@ -580,13 +590,17 @@ def execute_all_docs_search():
580590
def get_admin_search_tester(mdb: MongoDB, use_ssl: bool = False) -> SearchTester:
581591
"""Get SearchTester with admin credentials."""
582592
ca_path = get_issuer_ca_filepath() if use_ssl else None
583-
return SearchTester.for_sharded(mdb, ADMIN_USER_NAME, ADMIN_USER_PASSWORD, use_ssl=use_ssl, ca_path=ca_path)
593+
return SearchTester.for_sharded(
594+
mdb, f"{MDB_RESOURCE_NAME}-{ADMIN_USER_NAME}", ADMIN_USER_PASSWORD, use_ssl=use_ssl, ca_path=ca_path
595+
)
584596

585597

586598
def get_user_search_tester(mdb: MongoDB, use_ssl: bool = False) -> SearchTester:
587599
"""Get SearchTester with regular user credentials."""
588600
ca_path = get_issuer_ca_filepath() if use_ssl else None
589-
return SearchTester.for_sharded(mdb, USER_NAME, USER_PASSWORD, use_ssl=use_ssl, ca_path=ca_path)
601+
return SearchTester.for_sharded(
602+
mdb, f"{MDB_RESOURCE_NAME}-{USER_NAME}", USER_PASSWORD, use_ssl=use_ssl, ca_path=ca_path
603+
)
590604

591605

592606
def create_per_shard_search_tls_certs(namespace: str, issuer: str, prefix: str):

0 commit comments

Comments
 (0)