Skip to content

Commit efa599b

Browse files
committed
testing: enable cleanup; establish context
1 parent 53f5d14 commit efa599b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

test/namespace_admin_test.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def run_test(self):
3535
try:
3636
os.chdir(self.tmpdir)
3737
self.log.info(f"Running test in: {self.tmpdir}")
38+
self.establish_initial_context()
3839
self.establish_names()
3940
self.setup_namespaces()
40-
self.initial_context = get_kubeconfig_value("{.current-context}")
4141
self.setup_service_accounts()
4242
self.deploy_network_in_team_namespaces()
4343
self.authenticate_and_become_bob()
@@ -46,9 +46,13 @@ def run_test(self):
4646
try:
4747
self.cleanup_kubeconfig()
4848
except K8sError as e:
49-
self.log.info(e)
49+
self.log.info(f"KUBECONFIG cleanup error: {e}")
5050
self.cleanup()
5151

52+
def establish_initial_context(self):
53+
self.initial_context = get_kubeconfig_value("{.current-context}")
54+
self.log.info(f"Initial context: {self.initial_context}")
55+
5256
def establish_names(self):
5357
self.bob_user = "bob-warnettest"
5458
self.bob_auth_file = "bob-warnettest-wargames-red-team-warnettest-kubeconfig"
@@ -80,6 +84,7 @@ def setup_service_accounts(self):
8084
self.log.info("Creating service accounts...")
8185
self.log.info(self.warnet("admin create-kubeconfigs"))
8286
self.wait_for_predicate(self.service_accounts_are_validated)
87+
self.log.info("Service accounts have been set up and validated")
8388

8489
def deploy_network_in_team_namespaces(self):
8590
self.log.info("Deploy networks to team namespaces")
@@ -91,7 +96,7 @@ def deploy_network_in_team_namespaces(self):
9196
def authenticate_and_become_bob(self):
9297
self.log.info("Authenticating and becoming bob...")
9398
assert get_kubeconfig_value("{.current-context}") == self.initial_context
94-
self.log.info(self.warnet(f"auth kubeconfigs/{self.bob_auth_file}"))
99+
self.warnet(f"auth kubeconfigs/{self.bob_auth_file}")
95100
assert get_kubeconfig_value("{.current-context}") == self.bob_context
96101

97102
def service_accounts_are_validated(self) -> bool:
@@ -136,14 +141,11 @@ def two_namespaces_are_validated(self) -> bool:
136141
maybe_namespaces = self.get_namespaces()
137142
if maybe_namespaces is None:
138143
return False
139-
if len(maybe_namespaces) != 2:
140-
return False
141144
if self.blue_namespace not in maybe_namespaces:
142145
return False
143146
return self.red_namespace in maybe_namespaces
144147

145148
def cleanup_kubeconfig(self):
146-
pass
147149
try:
148150
kubeconfig_data = open_kubeconfig(KUBECONFIG)
149151
except K8sError as e:

0 commit comments

Comments
 (0)