Skip to content

Commit 157e288

Browse files
Generated commit to update templated files based on rev 1819d08 in stackabletech/operator-templating repo. (#168)
Triggered by: Manual run triggered by: razvan with message [run-tests --namespace]
1 parent f3e3fc5 commit 157e288

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

scripts/run-tests

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ Examples:
4242
4. Run the ldap test(s) from the openshift test suite and keep namespace:
4343
4444
./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
4550
"""
4651

4752

@@ -111,6 +116,13 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
111116
default=logging.INFO,
112117
)
113118

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+
114126
return parser.parse_args(argv)
115127

116128

@@ -254,9 +266,9 @@ def maybe_install_release(skip_release: bool, release_file: str) -> None:
254266
logging.error("stackablectl failed")
255267
raise TestRunnerException()
256268

257-
except subprocess.CalledProcessError:
269+
except subprocess.CalledProcessError as e:
258270
# in case stackablectl starts returning non-zero exit codes
259-
logging.error(stackablectl_err)
271+
logging.error(e.stderr.decode("utf-8"))
260272
logging.error("stackablectl failed")
261273
raise TestRunnerException()
262274

@@ -287,7 +299,7 @@ def gen_tests(test_suite: str) -> None:
287299
raise TestRunnerException()
288300

289301

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:
291303
try:
292304
kuttl_cmd = ["kubectl-kuttl", "test"]
293305
if test:
@@ -296,6 +308,25 @@ def run_tests(test: str, parallel: int, skip_delete: bool) -> None:
296308
kuttl_cmd.extend(["--parallel", str(parallel)])
297309
if skip_delete:
298310
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()
299330

300331
logging.debug(f"Running : {kuttl_cmd}")
301332

@@ -318,7 +349,7 @@ def main(argv) -> int:
318349
gen_tests(opts.test_suite)
319350
with release_file(opts.operator) as f:
320351
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)
322353
except TestRunnerException:
323354
ret = 1
324355
return ret

0 commit comments

Comments
 (0)