Skip to content

Commit 219e880

Browse files
committed
improvments
1 parent 58f831d commit 219e880

File tree

5 files changed

+138
-236
lines changed

5 files changed

+138
-236
lines changed

.evergreen-tasks.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,11 @@ tasks:
590590
commands:
591591
- func: "e2e_test"
592592

593+
- name: e2e_replica_set_scram_sha_256_switch_project
594+
tags: [ "patch-run" ]
595+
commands:
596+
- func: "e2e_test"
597+
593598
- name: e2e_sharded_cluster_scram_sha_1_user_connectivity
594599
tags: [ "patch-run" ]
595600
commands:

.evergreen.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ task_groups:
711711
- e2e_sharded_cluster_scram_sha_1_upgrade
712712
- e2e_sharded_cluster_scram_sha_256_user_connectivity
713713
- e2e_sharded_cluster_scram_sha_256_switch_project
714+
- e2e_replica_set_scram_sha_256_switch_project
714715
- e2e_sharded_cluster_scram_sha_1_user_connectivity
715716
- e2e_sharded_cluster_scram_x509_ic_manual_certs
716717
- e2e_sharded_cluster_external_access
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
apiVersion: mongodb.com/v1
3+
kind: MongoDB
4+
metadata:
5+
name: replica-set-scram-sha-256-switch-project
6+
spec:
7+
members: 3
8+
version: 4.4.0
9+
type: ReplicaSet
10+
opsManager:
11+
configMapRef:
12+
name: my-project
13+
credentials: my-credentials
14+
logLevel: DEBUG
15+
persistent: false
16+
security:
17+
authentication:
18+
enabled: true
19+
modes: ["SCRAM"]
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import pytest
2+
3+
from kubetester.kubetester import KubernetesTester
4+
from kubetester.kubetester import fixture as load_fixture
5+
from kubetester.mongodb import MongoDB
6+
from kubetester.mongotester import ReplicaSetTester
7+
from kubetester.phase import Phase
8+
9+
from kubetester import (
10+
random_k8s_name,
11+
create_or_update_configmap,
12+
read_configmap
13+
)
14+
15+
# Constants
16+
MDB_RESOURCE_NAME = "replica-set-scram-sha-256-switch-project"
17+
MDB_FIXTURE_NAME = MDB_RESOURCE_NAME
18+
19+
CONFIG_MAP_KEYS = {
20+
"BASE_URL": "baseUrl",
21+
"PROJECT_NAME": "projectName",
22+
"ORG_ID": "orgId",
23+
}
24+
25+
26+
27+
@pytest.fixture(scope="module")
28+
def replica_set(namespace: str) -> MongoDB:
29+
"""
30+
Fixture to initialize the MongoDB resource for the replica set.
31+
32+
Dynamically updates the resource configuration based on the test context.
33+
"""
34+
resource = MongoDB.from_yaml(load_fixture(f"{MDB_FIXTURE_NAME}.yaml"), namespace=namespace)
35+
return resource
36+
37+
38+
@pytest.fixture(scope="module")
39+
def project_name_prefix(namespace: str) -> str:
40+
"""
41+
Generates a random Kubernetes project name prefix based on the namespace.
42+
43+
Ensures test isolation in a multi-namespace test environment.
44+
"""
45+
return random_k8s_name(f"{namespace}-project-")
46+
47+
48+
@pytest.mark.e2e_replica_set_scram_sha_256_switch_project
49+
class TestReplicaSetCreationAndProjectSwitch(KubernetesTester):
50+
"""
51+
E2E test suite for replica set creation and user connectivity with SCRAM-SHA-256 authentication.
52+
"""
53+
54+
def test_create_replica_set(self, custom_mdb_version: str, replica_set: MongoDB):
55+
"""
56+
Test replica set creation ensuring resources are applied correctly and set reaches Running phase.
57+
"""
58+
replica_set.set_version(custom_mdb_version)
59+
replica_set.update()
60+
replica_set.assert_reaches_phase(Phase.Running, timeout=600)
61+
62+
def test_replica_set_connectivity(self):
63+
"""
64+
Verify connectivity to the original replica set.
65+
"""
66+
ReplicaSetTester(MDB_RESOURCE_NAME, 3).assert_connectivity() # Adjust node count as appropriate
67+
68+
def test_ops_manager_state_correctly_updated_in_initial_replica_set(self, replica_set: MongoDB):
69+
"""
70+
Ensure Ops Manager state is correctly updated in the original replica set.
71+
"""
72+
tester = replica_set.get_automation_config_tester()
73+
tester.assert_authentication_mechanism_enabled("SCRAM-SHA-256")
74+
tester.assert_authentication_enabled()
75+
76+
def test_switch_replica_set_project(
77+
self, custom_mdb_version: str, replica_set: MongoDB, namespace: str, project_name_prefix: str
78+
):
79+
"""
80+
Modify the replica set to switch its Ops Manager reference to a new project and verify lifecycle.
81+
"""
82+
original_configmap = read_configmap(namespace=namespace, name="my-project")
83+
new_project_name = f"{project_name_prefix}-second"
84+
new_project_configmap = create_or_update_configmap(
85+
namespace=namespace,
86+
name=new_project_name,
87+
data={
88+
CONFIG_MAP_KEYS["BASE_URL"]: original_configmap[CONFIG_MAP_KEYS["BASE_URL"]],
89+
CONFIG_MAP_KEYS["PROJECT_NAME"]: new_project_name,
90+
CONFIG_MAP_KEYS["ORG_ID"]: original_configmap[CONFIG_MAP_KEYS["ORG_ID"]],
91+
},
92+
)
93+
94+
replica_set.load()
95+
replica_set["spec"]["opsManager"]["configMapRef"]["name"] = new_project_configmap
96+
replica_set.set_version(custom_mdb_version)
97+
replica_set.update()
98+
99+
replica_set.assert_reaches_phase(Phase.Running, timeout=600)
100+
101+
def test_moved_replica_set_connectivity(self):
102+
"""
103+
Verify connectivity to the replica set after switching projects.
104+
"""
105+
ReplicaSetTester(MDB_RESOURCE_NAME, 3).assert_connectivity() # Adjust node count as appropriate
106+
107+
def test_ops_manager_state_correctly_updated_in_moved_replica_set(self, replica_set: MongoDB):
108+
"""
109+
Ensure Ops Manager state is correctly updated in the moved replica set after the project switch.
110+
"""
111+
tester = replica_set.get_automation_config_tester()
112+
tester.assert_authentication_mechanism_enabled("SCRAM-SHA-256")
113+
tester.assert_authentication_enabled()

public/samples/community/setup

Lines changed: 0 additions & 236 deletions
This file was deleted.

0 commit comments

Comments
 (0)