Skip to content

Commit f76fc3a

Browse files
committed
E2E test
1 parent 9a587d6 commit f76fc3a

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

docker/mongodb-kubernetes-tests/tests/multicluster/multi_cluster_scale_up_cluster.py

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import List
1+
from typing import List
22

33
import kubernetes
44
import pytest
5+
from kubetester import create_or_update_configmap, read_configmap, try_load
56
from kubetester.automation_config_tester import AutomationConfigTester
67
from kubetester.certs_mongodb_multi import create_multi_cluster_mongodb_tls_certs
78
from kubetester.kubetester import fixture as yaml_fixture
@@ -17,6 +18,23 @@
1718
BUNDLE_SECRET_NAME = f"prefix-{RESOURCE_NAME}-cert"
1819

1920

21+
@pytest.fixture(scope="module")
22+
def new_project_configmap(
23+
namespace: str,
24+
) -> str:
25+
cm = read_configmap(namespace=namespace, name="my-project")
26+
project_name = "new-project"
27+
return create_or_update_configmap(
28+
namespace=namespace,
29+
name=project_name,
30+
data={
31+
"baseUrl": cm["baseUrl"],
32+
"projectName": project_name,
33+
"orgId": cm["orgId"],
34+
},
35+
)
36+
37+
2038
@pytest.fixture(scope="module")
2139
def mongodb_multi_unmarshalled(
2240
namespace: str,
@@ -28,7 +46,7 @@ def mongodb_multi_unmarshalled(
2846
resource = MongoDBMulti.from_yaml(yaml_fixture("mongodb-multi.yaml"), RESOURCE_NAME, namespace)
2947
resource.set_version(custom_mdb_version)
3048
# ensure certs are created for the members during scale up
31-
resource["spec"]["clusterSpecList"] = cluster_spec_list(member_cluster_names, [2, 1, 2])
49+
resource["spec"]["clusterSpecList"] = cluster_spec_list(member_cluster_names, [3, 1, 2])
3250
resource["spec"]["security"] = {
3351
"certsSecretPrefix": "prefix",
3452
"tls": {
@@ -58,9 +76,14 @@ def server_certs(
5876

5977
@pytest.fixture(scope="module")
6078
def mongodb_multi(mongodb_multi_unmarshalled: MongoDBMulti, server_certs: str) -> MongoDBMulti:
79+
if try_load(mongodb_multi_unmarshalled):
80+
return mongodb_multi_unmarshalled
81+
6182
# remove the last element, we are only starting with 2 clusters we will scale up the 3rd one later.
6283
mongodb_multi_unmarshalled["spec"]["clusterSpecList"].pop()
63-
return mongodb_multi_unmarshalled.update()
84+
# remove one member from the first cluster to start with 2 members
85+
mongodb_multi_unmarshalled["spec"]["clusterSpecList"][0]["members"] = 2
86+
return mongodb_multi_unmarshalled
6487

6588

6689
@pytest.mark.e2e_multi_cluster_scale_up_cluster
@@ -70,6 +93,7 @@ def test_deploy_operator(multi_cluster_operator: Operator):
7093

7194
@pytest.mark.e2e_multi_cluster_scale_up_cluster
7295
def test_create_mongodb_multi(mongodb_multi: MongoDBMulti):
96+
mongodb_multi.update()
7397
mongodb_multi.assert_reaches_phase(Phase.Running, timeout=600)
7498

7599

@@ -97,7 +121,6 @@ def test_ops_manager_has_been_updated_correctly_before_scaling():
97121

98122
@pytest.mark.e2e_multi_cluster_scale_up_cluster
99123
def test_scale_mongodb_multi(mongodb_multi: MongoDBMulti, member_cluster_clients: List[MultiClusterClient]):
100-
mongodb_multi.load()
101124
mongodb_multi["spec"]["clusterSpecList"].append(
102125
{"members": 2, "clusterName": member_cluster_clients[2].cluster_name}
103126
)
@@ -139,3 +162,42 @@ def test_ops_manager_has_been_updated_correctly_after_scaling():
139162
def test_replica_set_is_reachable(mongodb_multi: MongoDBMulti, ca_path: str):
140163
tester = mongodb_multi.tester()
141164
tester.assert_connectivity(opts=[with_tls(use_tls=True, ca_path=ca_path)])
165+
166+
167+
# From here on, the tests are for verifying that we can change the project of the MongoDBMulti resource even with
168+
# non-sequential member ids in the replicaset.
169+
170+
171+
@pytest.mark.e2e_multi_cluster_scale_up_cluster
172+
def test_scale_up_first_cluster(
173+
mongodb_multi: MongoDBMulti,
174+
member_cluster_clients: List[MultiClusterClient],
175+
):
176+
# Scale up the first cluster to 3 members. This will lead to non-sequential member ids in the replicaset.
177+
# multi-replica-set-0-0 : 0
178+
# multi-replica-set-0-1 : 1
179+
# multi-replica-set-0-2 : 5
180+
# multi-replica-set-1-0 : 2
181+
# multi-replica-set-2-0 : 3
182+
# multi-replica-set-2-1 : 4
183+
184+
mongodb_multi["spec"]["clusterSpecList"][0]["members"] = 3
185+
mongodb_multi.update()
186+
mongodb_multi.assert_abandons_phase(Phase.Running, timeout=120)
187+
mongodb_multi.assert_reaches_phase(Phase.Running, timeout=1800)
188+
189+
190+
@pytest.mark.e2e_multi_cluster_scale_up_cluster
191+
def test_change_project(mongodb_multi: MongoDBMulti, new_project_configmap: str):
192+
oldRsMembers = mongodb_multi.get_automation_config_tester().get_replica_set_members(mongodb_multi.name)
193+
194+
mongodb_multi["spec"]["opsManager"]["configMapRef"]["name"] = new_project_configmap
195+
mongodb_multi.update()
196+
197+
mongodb_multi.assert_abandons_phase(phase=Phase.Running, timeout=300)
198+
mongodb_multi.assert_reaches_phase(phase=Phase.Running, timeout=600)
199+
200+
newRsMembers = mongodb_multi.get_automation_config_tester().get_replica_set_members(mongodb_multi.name)
201+
202+
# Assert that the replica set member ids have not changed after changing the project.
203+
assert oldRsMembers == newRsMembers

0 commit comments

Comments
 (0)