88
99from warnet .k8s import get_kubeconfig_value
1010from warnet .process import stream_command
11+ from warnet .status import _get_deployed_scenarios as scenarios_deployed
1112
1213
1314class WargamesTest (TestBase ):
@@ -19,6 +20,7 @@ def __init__(self):
1920 Path (os .path .dirname (__file__ )).parent / "resources" / "scenarios" / "test_scenarios"
2021 )
2122 self .initial_context = get_kubeconfig_value ("{.current-context}" )
23+ self .kconfigdir = self .tmpdir / "kubeconfigs"
2224
2325 def run_test (self ):
2426 try :
@@ -61,8 +63,10 @@ def check_scenario_permissions(self):
6163 assert self .warnet ("bitcoin rpc miner getblockcount" ) == "5"
6264
6365 self .log .info ("Switch to wargames player context" )
64- self .log .info (self .warnet ("admin create-kubeconfigs" ))
65- clicker = pexpect .spawn ("warnet auth kubeconfigs/warnet-user-wargames-red-kubeconfig" )
66+ self .log .info (self .warnet (f"admin create-kubeconfigs --kubeconfig-dir={ self .kconfigdir } " ))
67+ clicker = pexpect .spawn (
68+ f"warnet auth { self .kconfigdir } /warnet-user-wargames-red-kubeconfig"
69+ )
6670 while clicker .expect (["Overwrite" , "Updated kubeconfig" ]) == 0 :
6771 print (clicker .before , clicker .after )
6872 clicker .sendline ("y" )
@@ -82,16 +86,24 @@ def check_scenario_permissions(self):
8286 # Nothing was accesible
8387 assert self .warnet ("bitcoin rpc armada getblockcount" ) == "6"
8488
89+ self .log .info ("Check pod limit per namespace" )
90+ for _ in range (10 ):
91+ stream_command (
92+ f"warnet run { self .scen_test_dir / 'nothing.py' } --source_dir={ self .scen_src_dir } "
93+ )
94+ assert len (scenarios_deployed ()) == 2 , (
95+ f"Unexpected scenarios deployed:{ scenarios_deployed ()} "
96+ )
97+
8598 self .log .info ("Restore admin context" )
8699 stream_command (f"kubectl config use-context { self .initial_context } " )
87100 # Sanity check
88101 assert self .warnet ("bitcoin rpc miner getblockcount" ) == "6"
89102
90103 self .log .info ("Re-generate kubeconfigs after a scenario has been run" )
91- self .log .info (self .warnet ("admin create-kubeconfigs" ))
92- kubeconfig_dir = Path ("kubeconfigs/" )
104+ self .log .info (self .warnet (f"admin create-kubeconfigs --kubeconfig-dir={ self .kconfigdir } " ))
93105 count = 0
94- for p in kubeconfig_dir .iterdir ():
106+ for p in self . kconfigdir .iterdir ():
95107 if p .is_file ():
96108 print (p )
97109 assert "warnet-user" in str (p )
0 commit comments