1
1
import pymongo
2
2
import 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
4
5
from kubetester .certs import create_mongodb_tls_certs , create_tls_certs
5
6
from kubetester .kubetester import KubernetesTester
6
7
from kubetester .kubetester import fixture as yaml_fixture
@@ -163,12 +164,13 @@ def test_create_users(
163
164
namespace , name = admin_user ["spec" ]["passwordSecretKeyRef" ]["name" ], data = {"password" : ADMIN_USER_PASSWORD }
164
165
)
165
166
admin_user .update ()
166
- admin_user .assert_reaches_phase (Phase .Updated , timeout = 300 )
167
167
168
168
create_or_update_secret (
169
169
namespace , name = user ["spec" ]["passwordSecretKeyRef" ]["name" ], data = {"password" : USER_PASSWORD }
170
170
)
171
171
user .update ()
172
+
173
+ admin_user .assert_reaches_phase (Phase .Updated , timeout = 300 )
172
174
user .assert_reaches_phase (Phase .Updated , timeout = 300 )
173
175
174
176
create_or_update_secret (
@@ -192,6 +194,9 @@ def test_wait_for_database_resource_ready(mdb: MongoDB):
192
194
193
195
@mark .e2e_search_enterprise_tls
194
196
def 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.
195
200
def check_mongod_parameters ():
196
201
parameters_are_set = True
197
202
pod_parameters = []
@@ -209,7 +214,7 @@ def check_mongod_parameters():
209
214
210
215
return parameters_are_set , f'Not all pods have mongot parameters set:\n { "\n " .join (pod_parameters )} '
211
216
212
- run_periodically (lambda : check_mongod_parameters () , timeout = 200 )
217
+ run_periodically (check_mongod_parameters , timeout = 200 )
213
218
214
219
215
220
@mark .e2e_search_enterprise_tls
@@ -233,13 +238,24 @@ def test_search_assert_search_query(mdb: MongoDB):
233
238
234
239
235
240
@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.
236
246
class TestUpgradeMongod :
237
247
def test_check_polyfilled_role_in_ac (self , mdb : MongoDB ):
238
248
custom_roles = mdb .get_automation_config_tester ().automation_config .get ("roles" , [])
239
249
assert len (custom_roles ) > 0
240
250
assert "searchCoordinator" in [role ["role" ] for role in custom_roles ]
241
251
242
252
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.
243
259
mdb .tester (ca_path = get_issuer_ca_filepath (), use_ssl = True ).assert_version (MDB_VERSION_WITHOUT_BUILT_IN_ROLE )
244
260
245
261
def test_upgrade_to_mongo_8_2 (self , mdb : MongoDB ):
@@ -257,13 +273,10 @@ def test_mongod_version_after_upgrade(self, mdb: MongoDB):
257
273
mdb_tester .assert_scram_sha_authentication (
258
274
ADMIN_USER_NAME , ADMIN_USER_PASSWORD , "SCRAM-SHA-256" , 1 , ssl = True , tlsCAFile = get_issuer_ca_filepath ()
259
275
)
260
- # TODO check why assert version works without auth for 8.0 and not for 8.2
261
276
mdb_tester .assert_version (MDB_VERSION_WITH_BUILT_IN_ROLE )
262
277
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 )
267
280
268
281
269
282
def get_connection_string (mdb : MongoDB , user_name : str , user_password : str ) -> str :
0 commit comments