Skip to content

Commit 8398705

Browse files
committed
wip
1 parent afd1d01 commit 8398705

File tree

2 files changed

+17
-31
lines changed

2 files changed

+17
-31
lines changed

docker/mongodb-kubernetes-tests/kubetester/mongodb.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from typing import Dict, List, Optional
88

99
import semver
10+
from kubernetes.client import ApiException
11+
1012
from kubeobject import CustomObject
1113
from kubernetes import client
1214
from kubetester import create_or_update_configmap, read_configmap
@@ -37,9 +39,6 @@
3739

3840

3941
class MongoDB(CustomObject, MongoDBCommon):
40-
# project name set when configure method is called
41-
om_project_name: Optional[str]
42-
4342
def __init__(self, *args, **kwargs):
4443
with_defaults = {
4544
"plural": "mongodb",
@@ -48,7 +47,6 @@ def __init__(self, *args, **kwargs):
4847
"version": "v1",
4948
}
5049
with_defaults.update(kwargs)
51-
self.om_project_name = None
5250
super(MongoDB, self).__init__(*args, **with_defaults)
5351

5452
@classmethod
@@ -261,14 +259,12 @@ def configure_ops_manager(
261259
# then the secret needs to be copied there manually
262260
self["spec"]["credentials"] = om.api_key_secret(self.namespace, api_client=api_client)
263261

264-
self.om_project_name = project_name
265-
266262
return self
267263

268264
def configure_cloud_qa(
269265
self,
270266
project_name,
271-
src_project_config_map_name: str = None,
267+
src_project_config_map_name: Optional[str] = None,
272268
api_client: Optional[client.ApiClient] = None,
273269
) -> MongoDB:
274270
if "opsManager" in self["spec"]:
@@ -280,27 +276,16 @@ def configure_cloud_qa(
280276
ensure_nested_objects(self, ["spec", "cloudManager", "configMapRef"])
281277
self["spec"]["cloudManager"]["configMapRef"]["name"] = new_project_config_map_name
282278

279+
# we update the project name by adding a namespace prefix to ensure uniqueness in shared cloud-qa projects
280+
# the namespace prefix is not added if we run the test against
283281
src_cm.update({"projectName": f"{self.namespace}-{project_name}"})
284282
create_or_update_configmap(self.namespace, new_project_config_map_name, src_cm, api_client=api_client)
285283

286284
return self
287285

288-
def get_project_config_map(self, api_client, src_project_config_map_name):
289-
if src_project_config_map_name is None and "cloudManager" in self["spec"]:
290-
src_project_config_map_name = self["spec"]["cloudManager"]["configMapRef"]["name"]
291-
else:
292-
# my-project cm and my-credentials secret are created by scripts/evergreen/e2e/configure_operator.sh
293-
src_project_config_map_name = "my-project"
294-
try:
295-
src_cm = read_configmap(self.namespace, src_project_config_map_name, api_client=api_client)
296-
except client.ApiException as e:
297-
if e.status == 404:
298-
logger.debug("project config map is not specified, trying my-project as the source")
299-
src_cm = read_configmap(self.namespace, "my-project", api_client=api_client)
300-
else:
301-
raise e
302-
303-
return src_cm
286+
def get_om_project_name(self) -> str:
287+
project_cm = self.read_configmap()
288+
return project_cm["projectName"]
304289

305290
def configure_backup(self, mode: str = "enabled") -> MongoDB:
306291
ensure_nested_objects(self, ["spec", "backup"])
@@ -488,8 +473,8 @@ def get_om_tester(self) -> OMTester:
488473

489474
def get_automation_config_tester(self, **kwargs):
490475
"""This is just a shortcut for getting automation config tester for replica set"""
491-
if "group_name" not in kwargs and self.om_project_name is not None:
492-
kwargs["group_name"] = self.om_project_name
476+
if "group_name" not in kwargs:
477+
kwargs["group_name"] = self.get_om_project_name()
493478
return self.get_om_tester().get_automation_config_tester(**kwargs)
494479

495480
def get_external_domain(self):

docker/mongodb-kubernetes-tests/kubetester/opsmanager.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -687,17 +687,18 @@ def get_or_create_mongodb_connection_config_map(
687687
api_client: Optional[kubernetes.client.ApiClient] = None,
688688
) -> str:
689689
"""Creates the configmap containing the information needed to connect to OM"""
690-
config_map_name = f"{mongodb_name}-config"
691-
data = {
692-
"baseUrl": self.om_status().get_url(),
693-
"projectName": project_name,
694-
"orgId": "",
695-
}
690+
config_map_name = f"{mongodb_name}-project-config"
696691

697692
# the namespace can be different from OM one if the MongoDB is created in a separate namespace
698693
if namespace is None:
699694
namespace = self.namespace
700695

696+
data = {
697+
"baseUrl": self.om_status().get_url(),
698+
"projectName": f"{namespace}-{project_name}",
699+
"orgId": "",
700+
}
701+
701702
try:
702703
create_configmap(namespace, config_map_name, data, api_client=api_client)
703704
except ApiException as e:

0 commit comments

Comments
 (0)