Skip to content

Commit 5807a22

Browse files
committed
[jump_ci] testing: add multi-test support
1 parent cd01fa8 commit 5807a22

File tree

2 files changed

+60
-37
lines changed

2 files changed

+60
-37
lines changed

projects/jump_ci/testing/config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ exec_list:
3333
prepare_ci: null
3434
test_ci: null
3535
post_cleanup_ci: null
36+
multi_run:
37+
args: []
38+
stop_on_error: false

projects/jump_ci/testing/test.py

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ def rewrite_variables_overrides(variable_overrides_dict):
2424
new_args_str = new_variable_overrides[f"PR_POSITIONAL_ARGS"] = " ".join(new_args)
2525
new_variable_overrides["PR_POSITIONAL_ARGS"] = variable_overrides_dict["PR_POSITIONAL_ARG_0"]
2626
logging.info(f"New args to execute on the jump host: {new_args_str}")
27+
28+
idx = 0
2729
for idx, value in enumerate(new_args):
2830
new_variable_overrides[f"PR_POSITIONAL_ARG_{idx+1}"] = value
31+
next_pr_positional_arg_count = idx + 2
2932

3033
for k, v in variable_overrides_dict.items():
3134
if k.startswith("PR_POSITIONAL_ARG"): continue
@@ -44,7 +47,7 @@ def rewrite_variables_overrides(variable_overrides_dict):
4447
new_variable_overrides[k] = v
4548
logging.info(f"Passing '{k}: {v}' to the new variables overrides")
4649

47-
return new_variable_overrides
50+
return new_variable_overrides, next_pr_positional_arg_count
4851

4952

5053
def jump_ci(command):
@@ -72,8 +75,6 @@ def do_jump_ci(cluster=None, project=None, test_args=None):
7275
TOPSAIL_JUMP_CI="true",
7376
TOPSAIL_JUMP_CI_INSIDE_JUMP_HOST="true",
7477
)
75-
if step_dir := os.environ.get("TOPSAIL_OPENSHIFT_CI_STEP_DIR"):
76-
extra_env["TOPSAIL_OPENSHIFT_CI_STEP_DIR"] = f"{step_dir}/test-artifacts" # see "jump_ci retrieve_artifacts" below
7778

7879
env_pass_lists = config.project.get_config("env.pass_lists", print=False)
7980

@@ -112,51 +113,70 @@ def do_jump_ci(cluster=None, project=None, test_args=None):
112113
variables_overrides_dict[f"PR_POSITIONAL_ARG_{idx+1}"] = arg
113114

114115
config.project.set_config("overrides", variables_overrides_dict)
115-
116+
next_pr_positional_arg_count = idx + 2
116117
else:
117118
if not os.environ.get("OPENSHIFT_CI") == "true":
118119
logging.fatal("Not running in OpenShift CI. Don't know how to rewrite the variable_overrides_file. Aborting.")
119120
raise SystemExit(1)
120121

121122
project = config.project.get_config("overrides.PR_POSITIONAL_ARG_2")
122123

123-
variables_overrides_dict = rewrite_variables_overrides(
124+
variables_overrides_dict, next_pr_positional_arg_count = rewrite_variables_overrides(
124125
config.project.get_config("overrides")
125126
)
126127

127-
run.run_toolbox(
128-
"jump_ci", "prepare_step",
129-
cluster=cluster,
130-
lock_owner=utils.get_lock_owner(),
131-
project=project,
132-
step=command,
133-
env_file=env_fd_path,
134-
variables_overrides_dict=variables_overrides_dict,
135-
secrets_path_env_key=secrets_path_env_key,
136-
)
128+
for idx, multi_run_args in enumerate((config.project.get_config("multi_run.args") or [...])):
129+
test_artifacts_dirname = "test-artifacts"
130+
multi_run_args_dict = {}
131+
if multi_run_args is not ...:
132+
test_artifacts_dirname = f"test-artifacts-{idx:03d}"
133+
with open(env.ARTIFACTS_DIR / "multi_run_args.list", "a+") as f:
134+
print(f"{test_artifacts_dirname}: {multi_run_args}")
135+
for idx, multi_run_arg in enumerate((multi_run_args if isinstance(multi_run_args, list) else [multi_run_args])):
136+
variables_overrides_dict[f"PR_POSITIONAL_ARG_{next_pr_positional_arg_count+idx}"] = multi_run_arg
137+
else:
138+
test_artifacts_dirname = "test-artifacts"
139+
140+
if step_dir := os.environ.get("TOPSAIL_OPENSHIFT_CI_STEP_DIR"):
141+
# see "jump_ci retrieve_artifacts" below
142+
extra_env["TOPSAIL_OPENSHIFT_CI_STEP_DIR"] = f"{step_dir}/{test_artifacts_dirname}"
143+
144+
run.run_toolbox(
145+
"jump_ci", "prepare_step",
146+
cluster=cluster,
147+
lock_owner=utils.get_lock_owner(),
148+
project=project,
149+
step=command,
150+
env_file=env_fd_path,
151+
variables_overrides_dict=(variables_overrides_dict | multi_run_args_dict),
152+
secrets_path_env_key=secrets_path_env_key,
153+
)
137154

138-
try:
139-
tunnelling.run_with_ansible_ssh_conf(f"bash {cluster_lock_dir}/test/{command}/entrypoint.sh")
140-
logging.info(f"Test step '{command}' on cluster '{cluster}' succeeded.")
141-
failed = False
142-
except subprocess.CalledProcessError as e:
143-
logging.fatal(f"Test step '{command}' on cluster '{cluster}' FAILED.")
144-
failed = True
145-
except run.SignalError as e:
146-
logging.error(f"Caught signal {e.sig}. Aborting.")
147-
raise
148-
finally:
149-
# always run the cleanup to be sure that the container doesn't stay running
150-
tunnelling.run_with_ansible_ssh_conf(f"bash {cluster_lock_dir}/test/{command}/entrypoint.sh cleanup")
151-
152-
run.run_toolbox(
153-
"jump_ci", "retrieve_artifacts",
154-
cluster=cluster,
155-
lock_owner=utils.get_lock_owner(),
156-
remote_dir=f"test/{command}/artifacts",
157-
local_dir=f"../test-artifacts", # copy to the main artifact directory
158-
mute_stdout=True,
159-
)
155+
try:
156+
tunnelling.run_with_ansible_ssh_conf(f"bash {cluster_lock_dir}/test/{command}/entrypoint.sh")
157+
logging.info(f"Test step '{command}' on cluster '{cluster}' succeeded.")
158+
failed = False
159+
except subprocess.CalledProcessError as e:
160+
logging.fatal(f"Test step '{command}' on cluster '{cluster}' FAILED.")
161+
failed = True
162+
except run.SignalError as e:
163+
logging.error(f"Caught signal {e.sig}. Aborting.")
164+
raise
165+
finally:
166+
# always run the cleanup to be sure that the container doesn't stay running
167+
tunnelling.run_with_ansible_ssh_conf(f"bash {cluster_lock_dir}/test/{command}/entrypoint.sh cleanup")
168+
169+
run.run_toolbox(
170+
"jump_ci", "retrieve_artifacts",
171+
cluster=cluster,
172+
lock_owner=utils.get_lock_owner(),
173+
remote_dir=f"test/{command}/artifacts",
174+
local_dir=f"../{test_artifacts_dirname}", # copy to the main artifact directory
175+
mute_stdout=True,
176+
)
177+
178+
if failed and config.project.get_config("multi_run.stop_on_error"):
179+
break
160180

161181
jump_ci_artifacts = env.ARTIFACT_DIR / "jump-ci-artifacts"
162182
jump_ci_artifacts.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)