11import pymongo
22import yaml
3- from kubetester import create_or_update_secret , run_periodically , try_load
3+ from kubernetes import client
4+ from kubetester import create_or_update_secret , run_periodically , try_load , wait_until
45from kubetester .certs import create_mongodb_tls_certs , create_tls_certs
56from kubetester .kubetester import KubernetesTester
67from kubetester .kubetester import fixture as yaml_fixture
@@ -163,12 +164,13 @@ def test_create_users(
163164 namespace , name = admin_user ["spec" ]["passwordSecretKeyRef" ]["name" ], data = {"password" : ADMIN_USER_PASSWORD }
164165 )
165166 admin_user .update ()
166- admin_user .assert_reaches_phase (Phase .Updated , timeout = 300 )
167167
168168 create_or_update_secret (
169169 namespace , name = user ["spec" ]["passwordSecretKeyRef" ]["name" ], data = {"password" : USER_PASSWORD }
170170 )
171171 user .update ()
172+
173+ admin_user .assert_reaches_phase (Phase .Updated , timeout = 300 )
172174 user .assert_reaches_phase (Phase .Updated , timeout = 300 )
173175
174176 create_or_update_secret (
@@ -192,6 +194,9 @@ def test_wait_for_database_resource_ready(mdb: MongoDB):
192194
193195@mark .e2e_search_enterprise_tls
194196def test_wait_for_mongod_parameters (mdb : MongoDB ):
197+ # After search CR is deployed, MongoDB controller will pick it up
198+ # and start adding searchCoordinator role and search-related
199+ # parameters to the automation config.
195200 def check_mongod_parameters ():
196201 parameters_are_set = True
197202 pod_parameters = []
@@ -209,7 +214,7 @@ def check_mongod_parameters():
209214
210215 return parameters_are_set , f'Not all pods have mongot parameters set:\n { "\n " .join (pod_parameters )} '
211216
212- run_periodically (lambda : check_mongod_parameters () , timeout = 200 )
217+ run_periodically (check_mongod_parameters , timeout = 200 )
213218
214219
215220@mark .e2e_search_enterprise_tls
@@ -233,13 +238,24 @@ def test_search_assert_search_query(mdb: MongoDB):
233238
234239
235240@mark .e2e_search_enterprise_tls
241+ # This test class verifies if mongodb <8.2 can be upgraded to mongodb >=8.2
242+ # For mongod <8.2 the operator is automatically creating searchCoordinator customRole.
243+ # We test here that the role exists before upgrade, because
244+ # after mongodb is upgraded, the role should be removed from AC
245+ # From 8.2 searchCoordinator role is a built-in role.
236246class TestUpgradeMongod :
237247 def test_check_polyfilled_role_in_ac (self , mdb : MongoDB ):
238248 custom_roles = mdb .get_automation_config_tester ().automation_config .get ("roles" , [])
239249 assert len (custom_roles ) > 0
240250 assert "searchCoordinator" in [role ["role" ] for role in custom_roles ]
241251
242252 def test_mongod_version (self , mdb : MongoDB ):
253+ # This test is redundant when looking at the context of the full test file,
254+ # as we deploy MDB_VERSION_WITHOUT_BUILT_IN_ROLE initially
255+ # But it makes sense if we take into consideration TestUpgradeMongod test class alone.
256+ # This checks the most important prerequisite for this test class to work.
257+ # We check the version in case the test class is reused in another place
258+ # or executed again when running locally.
243259 mdb .tester (ca_path = get_issuer_ca_filepath (), use_ssl = True ).assert_version (MDB_VERSION_WITHOUT_BUILT_IN_ROLE )
244260
245261 def test_upgrade_to_mongo_8_2 (self , mdb : MongoDB ):
@@ -257,13 +273,10 @@ def test_mongod_version_after_upgrade(self, mdb: MongoDB):
257273 mdb_tester .assert_scram_sha_authentication (
258274 ADMIN_USER_NAME , ADMIN_USER_PASSWORD , "SCRAM-SHA-256" , 1 , ssl = True , tlsCAFile = get_issuer_ca_filepath ()
259275 )
260- # TODO check why assert version works without auth for 8.0 and not for 8.2
261276 mdb_tester .assert_version (MDB_VERSION_WITH_BUILT_IN_ROLE )
262277
263-
264- @mark .e2e_search_enterprise_tlssh
265- def test_search_assert_search_query_2 (mdb : MongoDB ):
266- get_user_sample_movies_helper (mdb ).assert_search_query (retry_timeout = 60 )
278+ def test_search_assert_search_query_after_upgrade (self , mdb : MongoDB ):
279+ get_user_sample_movies_helper (mdb ).assert_search_query (retry_timeout = 60 )
267280
268281
269282def get_connection_string (mdb : MongoDB , user_name : str , user_password : str ) -> str :
0 commit comments