1
- from typing import Dict , Optional
1
+ from typing import Dict
2
2
3
3
import pytest
4
- from kubeobject import CustomObject
5
- from kubernetes import client
6
- from kubetester import create_or_update_configmap , read_configmap
7
- from kubetester .certs import create_sharded_cluster_certs
8
- from kubetester .kubetester import ensure_nested_objects
4
+ from kubetester import read_configmap , try_load
5
+ from kubetester .certs import create_mongodb_tls_certs , create_sharded_cluster_certs
9
6
from kubetester .kubetester import fixture as yaml_fixture
10
7
from kubetester .mongodb import MongoDB
11
- from kubetester .mongotester import ShardedClusterTester
12
- from kubetester .operator import Operator
8
+ from kubetester .mongotester import ReplicaSetTester , ShardedClusterTester
13
9
from kubetester .phase import Phase
14
10
from tests import test_logger
15
11
from tests .conftest import (
16
12
LEGACY_OPERATOR_NAME ,
17
13
OPERATOR_NAME ,
18
- get_central_cluster_client ,
19
14
get_default_operator ,
20
15
install_legacy_deployment_state_meko ,
21
16
log_deployments_info ,
22
17
)
23
18
from tests .upgrades import downscale_operator_deployment
24
19
25
20
MDB_RESOURCE = "sh001-base"
21
+ MDB_RS_RESOURCE = "rs"
26
22
CERT_PREFIX = "prefix"
27
23
28
24
logger = test_logger .get_test_logger (__name__ )
41
37
If the sharded cluster resource correctly reconciles after upgrade/downgrade and scaling steps, we assume it works
42
38
correctly.
43
39
"""
40
+
41
+
44
42
# TODO CLOUDP-318100: this test should eventually be updated and not pinned to 1.27 anymore
45
43
46
44
@@ -68,7 +66,7 @@ def server_certs(issuer: str, namespace: str) -> str:
68
66
)
69
67
70
68
71
- @pytest .fixture (scope = "module " )
69
+ @pytest .fixture (scope = "function " )
72
70
def sharded_cluster (
73
71
issuer_ca_configmap : str ,
74
72
namespace : str ,
@@ -81,14 +79,44 @@ def sharded_cluster(
81
79
name = MDB_RESOURCE ,
82
80
).configure (om = None , project_name = MDB_RESOURCE )
83
81
82
+ if try_load (resource ):
83
+ return resource
84
+
84
85
resource .set_version (custom_mdb_version )
85
86
resource ["spec" ]["mongodsPerShardCount" ] = 2
86
87
resource ["spec" ]["configServerCount" ] = 2
87
88
resource ["spec" ]["mongosCount" ] = 1
88
89
resource ["spec" ]["persistent" ] = True
89
90
resource .configure_custom_tls (issuer_ca_configmap , CERT_PREFIX )
90
91
91
- return resource .update ()
92
+ return resource
93
+
94
+
95
+ @pytest .fixture (scope = "module" )
96
+ def replica_set_certs (issuer : str , namespace : str ):
97
+ return create_mongodb_tls_certs (issuer , namespace , MDB_RS_RESOURCE , f"prefix-{ MDB_RS_RESOURCE } -cert" )
98
+
99
+
100
+ @pytest .fixture (scope = "module" )
101
+ def replica_set (
102
+ issuer_ca_configmap : str ,
103
+ namespace : str ,
104
+ replica_set_certs : str ,
105
+ custom_mdb_version : str ,
106
+ ):
107
+ resource = MongoDB .from_yaml (
108
+ yaml_fixture ("replica-set-basic.yaml" ),
109
+ namespace = namespace ,
110
+ name = MDB_RS_RESOURCE ,
111
+ ).configure (om = None , project_name = f"{ MDB_RS_RESOURCE } " )
112
+
113
+ if try_load (resource ):
114
+ return resource
115
+
116
+ resource .set_version (custom_mdb_version )
117
+ resource .configure_custom_tls (issuer_ca_configmap , CERT_PREFIX )
118
+
119
+ return resource
92
120
93
121
94
122
@pytest .mark .e2e_sharded_cluster_operator_upgrade_v1_27_to_mck
@@ -102,16 +130,23 @@ def test_install_legacy_deployment_state_meko(
102
130
install_legacy_deployment_state_meko (namespace , managed_security_context , operator_installation_config )
103
131
104
132
def test_create_sharded_cluster (self , sharded_cluster : MongoDB ):
133
+ sharded_cluster .update ()
105
134
sharded_cluster .assert_reaches_phase (phase = Phase .Running , timeout = 350 )
106
135
107
136
def test_scale_up_sharded_cluster (self , sharded_cluster : MongoDB ):
108
- sharded_cluster .load ()
109
137
sharded_cluster ["spec" ]["mongodsPerShardCount" ] = 3
110
138
sharded_cluster ["spec" ]["configServerCount" ] = 3
111
139
sharded_cluster .update ()
112
140
sharded_cluster .assert_reaches_phase (phase = Phase .Running , timeout = 300 )
113
141
114
142
143
+ @pytest .mark .e2e_sharded_cluster_operator_upgrade_v1_27_to_mck
144
+ class TestReplicaSetDeployment :
145
+ def test_create_replica_set (self , replica_set : MongoDB ):
146
+ replica_set .update ()
147
+ replica_set .assert_reaches_phase (phase = Phase .Running , timeout = 350 )
148
+
149
+
115
150
@pytest .mark .e2e_sharded_cluster_operator_upgrade_v1_27_to_mck
116
151
class TestOperatorUpgrade :
117
152
@@ -138,6 +173,12 @@ def test_sharded_cluster_reconciled(self, sharded_cluster: MongoDB, namespace: s
138
173
def test_assert_connectivity (self , ca_path : str ):
139
174
ShardedClusterTester (MDB_RESOURCE , 1 , ssl = True , ca_path = ca_path ).assert_connectivity ()
140
175
176
+ def test_replica_set_reconciled (self , replica_set : MongoDB ):
177
+ replica_set .assert_reaches_phase (phase = Phase .Running , timeout = 850 , ignore_errors = True )
178
+
179
+ def test_assert_connectivity_replica_set (self , ca_path : str ):
180
+ ReplicaSetTester (MDB_RS_RESOURCE , 3 , ssl = True , ca_path = ca_path ).assert_connectivity ()
181
+
141
182
def test_scale_down_sharded_cluster (self , sharded_cluster : MongoDB , namespace : str ):
142
183
sharded_cluster .load ()
143
184
# Scale down both by 1
@@ -169,6 +210,12 @@ def test_sharded_cluster_reconciled(self, sharded_cluster: MongoDB):
169
210
def test_assert_connectivity (self , ca_path : str ):
170
211
ShardedClusterTester (MDB_RESOURCE , 1 , ssl = True , ca_path = ca_path ).assert_connectivity ()
171
212
213
+ def test_replica_set_reconciled (self , replica_set : MongoDB ):
214
+ replica_set .assert_reaches_phase (phase = Phase .Running , timeout = 850 , ignore_errors = True )
215
+
216
+ def test_assert_connectivity_replica_set (self , ca_path : str ):
217
+ ReplicaSetTester (MDB_RS_RESOURCE , 3 , ssl = True , ca_path = ca_path ).assert_connectivity ()
218
+
172
219
def test_scale_up_sharded_cluster (self , sharded_cluster : MongoDB ):
173
220
sharded_cluster .load ()
174
221
sharded_cluster ["spec" ]["mongodsPerShardCount" ] = 3
0 commit comments