@@ -42,6 +42,11 @@ Examples:
42
42
4. Run the ldap test(s) from the openshift test suite and keep namespace:
43
43
44
44
./scripts/run-tests --skip-release --skip-delete --test-suite openshift --test ldap
45
+
46
+ 5. Run the smoke test suite in the namespace "smoke". The namespace will be
47
+ created if it doesn't exist and will not be deleted when the tests end.
48
+
49
+ ./scripts/run-tests --test-suite smoke-latest --namespace smoke
45
50
"""
46
51
47
52
@@ -111,6 +116,13 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
111
116
default = logging .INFO ,
112
117
)
113
118
119
+ parser .add_argument (
120
+ "--namespace" ,
121
+ help = "Namespace to run the tests in. It will be created if it doesn't already exist." ,
122
+ type = str ,
123
+ required = False ,
124
+ )
125
+
114
126
return parser .parse_args (argv )
115
127
116
128
@@ -254,9 +266,9 @@ def maybe_install_release(skip_release: bool, release_file: str) -> None:
254
266
logging .error ("stackablectl failed" )
255
267
raise TestRunnerException ()
256
268
257
- except subprocess .CalledProcessError :
269
+ except subprocess .CalledProcessError as e :
258
270
# in case stackablectl starts returning non-zero exit codes
259
- logging .error (stackablectl_err )
271
+ logging .error (e . stderr . decode ( "utf-8" ) )
260
272
logging .error ("stackablectl failed" )
261
273
raise TestRunnerException ()
262
274
@@ -287,7 +299,7 @@ def gen_tests(test_suite: str) -> None:
287
299
raise TestRunnerException ()
288
300
289
301
290
- def run_tests (test : str , parallel : int , skip_delete : bool ) -> None :
302
+ def run_tests (test : str , parallel : int , namespace : str , skip_delete : bool ) -> None :
291
303
try :
292
304
kuttl_cmd = ["kubectl-kuttl" , "test" ]
293
305
if test :
@@ -296,6 +308,25 @@ def run_tests(test: str, parallel: int, skip_delete: bool) -> None:
296
308
kuttl_cmd .extend (["--parallel" , str (parallel )])
297
309
if skip_delete :
298
310
kuttl_cmd .extend (["--skip-delete" ])
311
+ if namespace :
312
+ kuttl_cmd .extend (["--namespace" , namespace ])
313
+ # kuttl doesn't create the namespace so we need to do it ourselves
314
+ create_ns_cmd = ["kubectl" , "create" , "namespace" , namespace ]
315
+ try :
316
+ logging .debug (f"Running : { create_ns_cmd } " )
317
+ subprocess .run (
318
+ create_ns_cmd ,
319
+ check = True ,
320
+ capture_output = True ,
321
+ )
322
+ except subprocess .CalledProcessError as e :
323
+ stderr = e .stderr .decode ("utf-8" )
324
+ # If the namespace already exists, this will fail and we ignore the
325
+ # error. If it fails for any other reason, we raise an exception.
326
+ if "already exists" not in stderr :
327
+ logging .error (stderr )
328
+ logging .error ("namespace creation failed" )
329
+ raise TestRunnerException ()
299
330
300
331
logging .debug (f"Running : { kuttl_cmd } " )
301
332
@@ -318,7 +349,7 @@ def main(argv) -> int:
318
349
gen_tests (opts .test_suite )
319
350
with release_file (opts .operator ) as f :
320
351
maybe_install_release (opts .skip_release , f )
321
- run_tests (opts .test , opts .parallel , opts .skip_delete )
352
+ run_tests (opts .test , opts .parallel , opts .namespace , opts . skip_delete )
322
353
except TestRunnerException :
323
354
ret = 1
324
355
return ret
0 commit comments