Skip to content

Commit ad1da30

Browse files
committed
E2E testing
1 parent a92a591 commit ad1da30

File tree

10 files changed

+556
-164
lines changed

10 files changed

+556
-164
lines changed

.evergreen-tasks.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ tasks:
254254
commands:
255255
- func: "e2e_test"
256256

257+
- name: e2e_mongodb_custom_roles
258+
tags: [ "patch-run" ]
259+
commands:
260+
- func: "e2e_test"
261+
257262
- name: e2e_replica_set_recovery
258263
tags: [ "patch-run" ]
259264
commands:
@@ -644,7 +649,7 @@ tasks:
644649
commands:
645650
- func: "e2e_test"
646651

647-
- name: e2e_replica_set_custom_roles
652+
- name: e2e_replica_set_ldap_custom_roles
648653
tags: [ "patch-run" ]
649654
commands:
650655
- func: "e2e_test"

.evergreen.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ task_groups:
729729
- e2e_replica_set_ldap_user_to_dn_mapping
730730
# e2e_replica_set_ldap_agent_auth
731731
- e2e_replica_set_ldap_agent_client_certs
732-
- e2e_replica_set_custom_roles
732+
- e2e_replica_set_ldap_custom_roles
733733
- e2e_replica_set_update_roles_no_privileges
734734
- e2e_replica_set_ldap_group_dn
735735
- e2e_replica_set_ldap_group_dn_with_x509_agent
@@ -906,6 +906,7 @@ task_groups:
906906
- e2e_tls_x509_configure_all_options_sc
907907
- e2e_tls_x509_sc
908908
- e2e_meko_mck_upgrade
909+
- e2e_mongodb_custom_roles
909910

910911
<<: *teardown_group
911912

docker/mongodb-kubernetes-tests/kubeobject/customobject.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _reload_if_needed(self):
145145
self.reload()
146146

147147
@classmethod
148-
def from_yaml(cls, yaml_file, name=None, namespace=None):
148+
def from_yaml(cls, yaml_file, name=None, namespace=None, cluster_scoped=False):
149149
"""Creates a `CustomObject` from a yaml file. In this case, `name` and
150150
`namespace` are optional in this function's signature, because they
151151
might be passed as part of the `yaml_file` document.
@@ -161,22 +161,23 @@ def from_yaml(cls, yaml_file, name=None, namespace=None):
161161
"or exist in the `metadata` section of the yaml document."
162162
)
163163

164-
if (namespace is None or namespace == "") and "namespace" not in doc["metadata"]:
165-
raise ValueError(
166-
"`namespace` needs to be passed as part of the function call "
167-
"or exist in the `metadata` section of the yaml document."
168-
)
164+
if not cluster_scoped:
165+
if (namespace is None or namespace == "") and "namespace" not in doc["metadata"]:
166+
raise ValueError(
167+
"`namespace` needs to be passed as part of the function call "
168+
"or exist in the `metadata` section of the yaml document."
169+
)
170+
171+
if namespace is None:
172+
namespace = doc["metadata"]["namespace"]
173+
else:
174+
doc["metadata"]["namespace"] = namespace
169175

170176
if name is None:
171177
name = doc["metadata"]["name"]
172178
else:
173179
doc["metadata"]["name"] = name
174180

175-
if namespace is None:
176-
namespace = doc["metadata"]["namespace"]
177-
else:
178-
doc["metadata"]["namespace"] = namespace
179-
180181
kind = doc["kind"]
181182
api_version = doc["apiVersion"]
182183
if "/" in api_version:
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from typing import Optional
2+
3+
from kubeobject import CustomObject
4+
from kubetester.mongodb import MongoDBCommon, Phase, in_desired_state
5+
6+
ClusterMongoDBRoleKind = "ClusterMongoDBRole"
7+
8+
9+
class ClusterMongoDBRole(CustomObject, MongoDBCommon):
10+
def __init__(self, *args, **kwargs):
11+
with_defaults = {
12+
"plural": "clustermongodbroles",
13+
"kind": "ClusterMongoDBRole",
14+
"group": "mongodb.com",
15+
"version": "v1",
16+
}
17+
with_defaults.update(kwargs)
18+
super(ClusterMongoDBRole, self).__init__(*args, **with_defaults)
19+
20+
def assert_reaches_phase(self, phase: Phase, msg_regexp=None, timeout=None, ignore_errors=False):
21+
return self.wait_for(
22+
lambda s: in_desired_state(
23+
current_state=self.get_status_phase(),
24+
desired_state=phase,
25+
current_generation=self.get_generation(),
26+
observed_generation=self.get_status_observed_generation(),
27+
current_message=self.get_status_message(),
28+
msg_regexp=msg_regexp,
29+
ignore_errors=ignore_errors,
30+
),
31+
timeout,
32+
should_raise=True,
33+
)
34+
35+
def get_name(self) -> str:
36+
return self["metadata"]["name"]
37+
38+
def get_role_name(self):
39+
return self["spec"]["role"]
40+
41+
def get_role(self):
42+
return self["spec"]
43+
44+
def get_status_phase(self) -> Optional[Phase]:
45+
try:
46+
return Phase[self["status"]["phase"]]
47+
except KeyError:
48+
return None
49+
50+
def get_status_message(self) -> Optional[str]:
51+
try:
52+
return self["status"]["msg"]
53+
except KeyError:
54+
return None
55+
56+
def get_status_observed_generation(self) -> Optional[int]:
57+
try:
58+
return self["status"]["observedGeneration"]
59+
except KeyError:
60+
return None
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: mongodb.com/v1
2+
kind: ClusterMongoDBRole
3+
metadata:
4+
name: test-customrole
5+
spec:
6+
role: "test-customrole"
7+
db: "admin"
8+
roles:
9+
- db: "admin"
10+
role: "root"
11+
privileges:
12+
- resource:
13+
db: "admin"
14+
collection: "system.users"
15+
actions:
16+
- "find"
17+
- "update"
18+
- resource:
19+
db: "admin"
20+
collection: "system.roles"
21+
actions:
22+
- "find"
23+
- "update"
24+
authenticationRestrictions:
25+
- clientSource:
26+
- "127.0.0.0/8"
27+
serverAddress:
28+
- "10.0.0.0/8"

0 commit comments

Comments
 (0)