Skip to content

Commit 66f541b

Browse files
committed
add admin test
However, this test is behaving in a way that I don't like. I am noticing that the predicate checks are not working like I would like them to (can they fail?). Need to revisit.
1 parent 9da45e2 commit 66f541b

File tree

5 files changed

+187
-0
lines changed

5 files changed

+187
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
users:
2+
- name: warnet-user
3+
roles:
4+
- pod-viewer
5+
- pod-manager
6+
# the pod-viewer and pod-manager roles are the default
7+
# roles defined in values.yaml for the namespaces charts
8+
#
9+
# if you need a different set of roles for a particular namespaces
10+
# deployment, you can override values.yaml by providing your own
11+
# role definitions below
12+
#
13+
# roles:
14+
# - name: my-custom-role
15+
# rules:
16+
# - apiGroups: ""
17+
# resources: ""
18+
# verbs: ""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespaces:
2+
- name: wargames-red-team
3+
users:
4+
- name: alice
5+
roles:
6+
- pod-viewer
7+
- name: bob
8+
roles:
9+
- pod-viewer
10+
- pod-manager
11+
- name: wargames-blue-team
12+
users:
13+
- name: mallory
14+
roles:
15+
- pod-viewer
16+
- name: carol
17+
roles:
18+
- pod-viewer
19+
- pod-manager
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
nodes:
2+
- name: tank-0001
3+
image:
4+
tag: "26.0"
5+
connect:
6+
- tank-0002
7+
- tank-0003
8+
- name: tank-0002
9+
resources:
10+
limits:
11+
cpu: 100m
12+
memory: 128Mi
13+
requests:
14+
cpu: 100m
15+
memory: 128Mi
16+
connect:
17+
- tank-0003
18+
- tank-0004
19+
- name: tank-0003
20+
connect:
21+
- tank-0004
22+
- tank-0005
23+
- name: tank-0004
24+
connect:
25+
- tank-0005
26+
- tank-0006
27+
- name: tank-0005
28+
connect:
29+
- tank-0006
30+
- name: tank-0006
31+
fork_observer:
32+
enabled: true
33+
caddy:
34+
enabled: true
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
chain: regtest
2+
3+
collectLogs: true
4+
metricsExport: true
5+
6+
resources: {}
7+
# We usually recommend not to specify default resources and to leave this as a conscious
8+
# choice for the user. This also increases chances charts run on environments with little
9+
# resources, such as Minikube. If you do want to specify resources, uncomment the following
10+
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
11+
# limits:
12+
# cpu: 100m
13+
# memory: 128Mi
14+
# requests:
15+
# cpu: 100m
16+
# memory: 128Mi
17+
18+
image:
19+
repository: bitcoindevproject/bitcoin
20+
pullPolicy: IfNotPresent
21+
# Overrides the image tag whose default is the chart appVersion.
22+
tag: "27.0"
23+
24+
config: |
25+
dns=1
26+
debug=rpc

test/namespace_admin_test.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
from pathlib import Path
5+
from typing import Optional
6+
7+
from test_base import TestBase
8+
9+
10+
class NamespaceAdminTest(TestBase):
11+
def __init__(self):
12+
super().__init__()
13+
self.namespace_dir = (
14+
Path(os.path.dirname(__file__))
15+
/ "data"
16+
/ "admin"
17+
/ "namespaces"
18+
/ "two_namespaces_two_users"
19+
)
20+
21+
def run_test(self):
22+
try:
23+
self.setup_namespaces()
24+
self.setup_service_accounts()
25+
except Exception as e:
26+
self.log.info(e)
27+
finally:
28+
self.cleanup()
29+
30+
def setup_namespaces(self):
31+
self.log.info("Setting up the namespaces")
32+
self.log.info(self.warnet(f"deploy {self.namespace_dir}"))
33+
self.wait_for_predicate(lambda: self.two_namespaces_are_validated)
34+
35+
def setup_service_accounts(self):
36+
self.log.info(self.warnet("admin create-kubeconfigs"))
37+
self.wait_for_predicate(lambda: self.service_accounts_are_validated)
38+
39+
def get_service_accounts(self) -> Optional[list[dict[str, str]]]:
40+
self.log.info("Setting up service accounts")
41+
resp = self.warnet("admin service-accounts list")
42+
if resp == "Could not find any matching service accounts.":
43+
return None
44+
service_accounts = {}
45+
current_namespace = ""
46+
for line in resp.splitlines():
47+
if line.startswith("Service"):
48+
current_namespace = line.split(": ")[1]
49+
service_accounts[current_namespace] = []
50+
if line.startswith("- "):
51+
sa = line.lstrip("- ")
52+
service_accounts[current_namespace].append(sa)
53+
self.log.info(f"Service accounts: {service_accounts}")
54+
return service_accounts
55+
56+
def service_accounts_are_validated(self) -> bool:
57+
maybe_service_accounts = self.get_service_accounts()
58+
expected = {
59+
"gary": [],
60+
"wargames-blue-team": ["carol", "default", "mallory"],
61+
"wargames-red-team": ["alice", "bob", "default"],
62+
}
63+
return maybe_service_accounts == expected
64+
65+
def get_namespaces(self) -> Optional[list[str]]:
66+
resp = self.warnet("warnet admin namespaces list")
67+
if resp == "No warnet namespaces found.":
68+
return None
69+
70+
namespaces = []
71+
self.log.info(namespaces)
72+
for line in resp.splitlines():
73+
namespaces.append(line.lstrip("- "))
74+
self.log.info(f"Namespaces: {namespaces}")
75+
return namespaces
76+
77+
def two_namespaces_are_validated(self) -> bool:
78+
maybe_namespaces = self.get_namespaces()
79+
if maybe_namespaces is None:
80+
return False
81+
if len(maybe_namespaces) != 2:
82+
return False
83+
if "wargames-blue-team" not in maybe_namespaces:
84+
return False
85+
return "wargames-red-team" in maybe_namespaces
86+
87+
88+
if __name__ == "__main__":
89+
test = NamespaceAdminTest()
90+
test.run_test()

0 commit comments

Comments
 (0)