1- from typing import Dict , Optional
1+ from typing import Dict
22
33import 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
96from kubetester .kubetester import fixture as yaml_fixture
107from kubetester .mongodb import MongoDB
11- from kubetester .mongotester import ShardedClusterTester
12- from kubetester .operator import Operator
8+ from kubetester .mongotester import ReplicaSetTester , ShardedClusterTester
139from kubetester .phase import Phase
1410from tests import test_logger
1511from tests .conftest import (
1612 LEGACY_OPERATOR_NAME ,
1713 OPERATOR_NAME ,
18- get_central_cluster_client ,
1914 get_default_operator ,
2015 install_legacy_deployment_state_meko ,
2116 log_deployments_info ,
2217)
2318from tests .upgrades import downscale_operator_deployment
2419
2520MDB_RESOURCE = "sh001-base"
21+ MDB_RS_RESOURCE = "rs"
2622CERT_PREFIX = "prefix"
2723
2824logger = test_logger .get_test_logger (__name__ )
4137If the sharded cluster resource correctly reconciles after upgrade/downgrade and scaling steps, we assume it works
4238correctly.
4339"""
40+
41+
4442# TODO CLOUDP-318100: this test should eventually be updated and not pinned to 1.27 anymore
4543
4644
@@ -68,7 +66,7 @@ def server_certs(issuer: str, namespace: str) -> str:
6866 )
6967
7068
71- @pytest .fixture (scope = "module " )
69+ @pytest .fixture (scope = "function " )
7270def sharded_cluster (
7371 issuer_ca_configmap : str ,
7472 namespace : str ,
@@ -79,15 +77,46 @@ def sharded_cluster(
7977 yaml_fixture ("sharded-cluster.yaml" ),
8078 namespace = namespace ,
8179 name = MDB_RESOURCE ,
82- )
80+ ).configure (om = None , project_name = MDB_RESOURCE )
81+
82+ if try_load (resource ):
83+ return resource
84+
8385 resource .set_version (custom_mdb_version )
8486 resource ["spec" ]["mongodsPerShardCount" ] = 2
8587 resource ["spec" ]["configServerCount" ] = 2
8688 resource ["spec" ]["mongosCount" ] = 1
8789 resource ["spec" ]["persistent" ] = True
8890 resource .configure_custom_tls (issuer_ca_configmap , CERT_PREFIX )
8991
90- 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
91120
92121
93122@pytest .mark .e2e_sharded_cluster_operator_upgrade_v1_27_to_mck
@@ -101,16 +130,23 @@ def test_install_legacy_deployment_state_meko(
101130 install_legacy_deployment_state_meko (namespace , managed_security_context , operator_installation_config )
102131
103132 def test_create_sharded_cluster (self , sharded_cluster : MongoDB ):
133+ sharded_cluster .update ()
104134 sharded_cluster .assert_reaches_phase (phase = Phase .Running , timeout = 350 )
105135
106136 def test_scale_up_sharded_cluster (self , sharded_cluster : MongoDB ):
107- sharded_cluster .load ()
108137 sharded_cluster ["spec" ]["mongodsPerShardCount" ] = 3
109138 sharded_cluster ["spec" ]["configServerCount" ] = 3
110139 sharded_cluster .update ()
111140 sharded_cluster .assert_reaches_phase (phase = Phase .Running , timeout = 300 )
112141
113142
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+
114150@pytest .mark .e2e_sharded_cluster_operator_upgrade_v1_27_to_mck
115151class TestOperatorUpgrade :
116152
@@ -137,6 +173,12 @@ def test_sharded_cluster_reconciled(self, sharded_cluster: MongoDB, namespace: s
137173 def test_assert_connectivity (self , ca_path : str ):
138174 ShardedClusterTester (MDB_RESOURCE , 1 , ssl = True , ca_path = ca_path ).assert_connectivity ()
139175
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+
140182 def test_scale_down_sharded_cluster (self , sharded_cluster : MongoDB , namespace : str ):
141183 sharded_cluster .load ()
142184 # Scale down both by 1
@@ -168,6 +210,12 @@ def test_sharded_cluster_reconciled(self, sharded_cluster: MongoDB):
168210 def test_assert_connectivity (self , ca_path : str ):
169211 ShardedClusterTester (MDB_RESOURCE , 1 , ssl = True , ca_path = ca_path ).assert_connectivity ()
170212
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+
171219 def test_scale_up_sharded_cluster (self , sharded_cluster : MongoDB ):
172220 sharded_cluster .load ()
173221 sharded_cluster ["spec" ]["mongodsPerShardCount" ] = 3
0 commit comments