@@ -24,8 +24,11 @@ def rewrite_variables_overrides(variable_overrides_dict):
24
24
new_args_str = new_variable_overrides [f"PR_POSITIONAL_ARGS" ] = " " .join (new_args )
25
25
new_variable_overrides ["PR_POSITIONAL_ARGS" ] = variable_overrides_dict ["PR_POSITIONAL_ARG_0" ]
26
26
logging .info (f"New args to execute on the jump host: { new_args_str } " )
27
+
28
+ idx = 0
27
29
for idx , value in enumerate (new_args ):
28
30
new_variable_overrides [f"PR_POSITIONAL_ARG_{ idx + 1 } " ] = value
31
+ next_pr_positional_arg_count = idx + 2
29
32
30
33
for k , v in variable_overrides_dict .items ():
31
34
if k .startswith ("PR_POSITIONAL_ARG" ): continue
@@ -44,7 +47,7 @@ def rewrite_variables_overrides(variable_overrides_dict):
44
47
new_variable_overrides [k ] = v
45
48
logging .info (f"Passing '{ k } : { v } ' to the new variables overrides" )
46
49
47
- return new_variable_overrides
50
+ return new_variable_overrides , next_pr_positional_arg_count
48
51
49
52
50
53
def jump_ci (command ):
@@ -67,26 +70,28 @@ def do_jump_ci(cluster=None, project=None, test_args=None):
67
70
68
71
secrets_path_env_key = config .project .get_config ("secrets.dir.env_key" )
69
72
70
- env_fd_path , env_file = utils .get_tmp_fd ()
71
73
extra_env = dict (
72
74
TOPSAIL_JUMP_CI = "true" ,
73
75
TOPSAIL_JUMP_CI_INSIDE_JUMP_HOST = "true" ,
74
76
)
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
77
77
78
- env_pass_lists = config .project .get_config ("env.pass_lists" , print = False )
78
+ def prepare_env_file (_extra_env ):
79
+ env_fd_path , env_file = utils .get_tmp_fd ()
80
+
81
+ env_pass_lists = config .project .get_config ("env.pass_lists" , print = False )
79
82
80
- env_pass_list = set ()
81
- for _ , pass_list in (env_pass_lists or {}).items ():
82
- env_pass_list .update (pass_list )
83
+ env_pass_list = set ()
84
+ for _ , pass_list in (env_pass_lists or {}).items ():
85
+ env_pass_list .update (pass_list )
83
86
84
- for k , v in (os .environ | extra_env ).items ():
85
- if k not in (env_pass_list | extra_env .keys ()): continue
87
+ for k , v in (os .environ | _extra_env ).items ():
88
+ if k not in (env_pass_list | _extra_env .keys ()): continue
86
89
87
- print (f"{ k } ={ shlex .quote (v )} " , file = env_file )
90
+ print (f"{ k } ={ shlex .quote (v )} " , file = env_file )
88
91
89
- env_file .flush ()
92
+ env_file .flush ()
93
+
94
+ return env_fd_path , env_file
90
95
91
96
variable_overrides_file = pathlib .Path (os .environ .get ("ARTIFACT_DIR" )) / "variable_overrides.yaml"
92
97
@@ -100,6 +105,8 @@ def do_jump_ci(cluster=None, project=None, test_args=None):
100
105
101
106
run .run_toolbox ("jump_ci" , "ensure_lock" , cluster = cluster , owner = utils .get_lock_owner ())
102
107
108
+ cluster_lock_dir = f" /tmp/topsail_{ cluster } "
109
+
103
110
if test_args is not None :
104
111
variables_overrides_dict = dict (
105
112
PR_POSITIONAL_ARGS = test_args ,
@@ -110,55 +117,86 @@ def do_jump_ci(cluster=None, project=None, test_args=None):
110
117
variables_overrides_dict [f"PR_POSITIONAL_ARG_{ idx + 1 } " ] = arg
111
118
112
119
config .project .set_config ("overrides" , variables_overrides_dict )
113
-
120
+ next_pr_positional_arg_count = idx + 2
114
121
else :
115
122
if not os .environ .get ("OPENSHIFT_CI" ) == "true" :
116
123
logging .fatal ("Not running in OpenShift CI. Don't know how to rewrite the variable_overrides_file. Aborting." )
117
124
raise SystemExit (1 )
118
125
119
126
project = config .project .get_config ("overrides.PR_POSITIONAL_ARG_2" )
120
127
121
- variables_overrides_dict = rewrite_variables_overrides (
128
+ variables_overrides_dict , next_pr_positional_arg_count = rewrite_variables_overrides (
122
129
config .project .get_config ("overrides" )
123
130
)
124
131
125
- run .run_toolbox (
126
- "jump_ci" , "prepare_step" ,
127
- cluster = cluster ,
128
- lock_owner = utils .get_lock_owner (),
129
- project = project ,
130
- step = command ,
131
- env_file = env_fd_path ,
132
- variables_overrides_dict = variables_overrides_dict ,
133
- secrets_path_env_key = secrets_path_env_key ,
134
- )
135
-
136
- try :
137
- tunnelling .run_with_ansible_ssh_conf (f"bash /tmp/{ cluster } /test/{ command } /entrypoint.sh" )
138
- logging .info (f"Test step '{ command } ' on cluster '{ cluster } ' succeeded." )
139
- failed = False
140
- except subprocess .CalledProcessError as e :
141
- logging .fatal (f"Test step '{ command } ' on cluster '{ cluster } ' FAILED." )
142
- failed = True
143
- except run .SignalError as e :
144
- logging .error (f"Caught signal { e .sig } . Aborting." )
145
- raise
146
- finally :
147
- # always run the cleanup to be sure that the container doesn't stay running
148
- tunnelling .run_with_ansible_ssh_conf (f"bash /tmp/{ cluster } /test/{ command } /entrypoint.sh cleanup" )
149
-
150
- run .run_toolbox (
151
- "jump_ci" , "retrieve_artifacts" ,
152
- cluster = cluster ,
153
- lock_owner = utils .get_lock_owner (),
154
- remote_dir = f"test/{ command } /artifacts" ,
155
- local_dir = f"../test-artifacts" , # copy to the main artifact directory
156
- mute_stdout = True ,
157
- )
132
+ for idx , multi_run_args in enumerate ((config .project .get_config ("multi_run.args" ) or [...])):
133
+ multi_run_args_dict = {}
134
+ multi_run_dirname = None
135
+ test_artifacts_dirname = "test-artifacts"
136
+
137
+ if multi_run_args is not ...:
138
+
139
+ multi_run_args_lst = multi_run_args if isinstance (multi_run_args , list ) else [multi_run_args ]
140
+ multi_run_dirname = f"multi_run__{ '_' .join (multi_run_args_lst )} "
141
+
142
+ with open (env .ARTIFACT_DIR / "multi_run_args.list" , "a+" ) as f :
143
+ print (f"{ multi_run_dirname } : { multi_run_args } " )
144
+
145
+ for idx , multi_run_arg in enumerate (multi_run_args_lst ):
146
+ variables_overrides_dict [f"PR_POSITIONAL_ARG_{ next_pr_positional_arg_count + idx } " ] = multi_run_arg
147
+
148
+ with env .NextArtifactDir (multi_run_dirname ) if multi_run_dirname else open ("/dev/null" ):
149
+
150
+ if multi_run_dirname :
151
+ test_artifacts_dirname = f"{ env .ARTIFACT_DIR .name } /{ test_artifacts_dirname } "
152
+
153
+ if step_dir := os .environ .get ("TOPSAIL_OPENSHIFT_CI_STEP_DIR" ):
154
+ # see "jump_ci retrieve_artifacts" below
155
+ extra_env ["TOPSAIL_OPENSHIFT_CI_STEP_DIR" ] = f"{ step_dir } /{ test_artifacts_dirname } "
156
+
157
+ env_fd_path , env_file = prepare_env_file (extra_env )
158
+
159
+ run .run_toolbox (
160
+ "jump_ci" , "prepare_step" ,
161
+ cluster = cluster ,
162
+ lock_owner = utils .get_lock_owner (),
163
+ project = project ,
164
+ step = command ,
165
+ env_file = env_fd_path ,
166
+ variables_overrides_dict = (variables_overrides_dict | multi_run_args_dict ),
167
+ secrets_path_env_key = secrets_path_env_key ,
168
+ )
169
+ env_file .close ()
170
+
171
+ try :
172
+ tunnelling .run_with_ansible_ssh_conf (f"bash { cluster_lock_dir } /test/{ command } /entrypoint.sh" )
173
+ logging .info (f"Test step '{ command } ' on cluster '{ cluster } ' succeeded." )
174
+ failed = False
175
+ except subprocess .CalledProcessError as e :
176
+ logging .fatal (f"Test step '{ command } ' on cluster '{ cluster } ' FAILED." )
177
+ failed = True
178
+ except run .SignalError as e :
179
+ logging .error (f"Caught signal { e .sig } . Aborting." )
180
+ raise
181
+ finally :
182
+ # always run the cleanup to be sure that the container doesn't stay running
183
+ tunnelling .run_with_ansible_ssh_conf (f"bash { cluster_lock_dir } /test/{ command } /entrypoint.sh cleanup" )
184
+
185
+ run .run_toolbox (
186
+ "jump_ci" , "retrieve_artifacts" ,
187
+ cluster = cluster ,
188
+ lock_owner = utils .get_lock_owner (),
189
+ remote_dir = f"test/{ command } /artifacts" ,
190
+ local_dir = f"../{ pathlib .Path (test_artifacts_dirname ).name } " , # copy to the main artifact directory
191
+ mute_stdout = True ,
192
+ )
193
+
194
+ if failed and config .project .get_config ("multi_run.stop_on_error" ):
195
+ break
158
196
159
197
jump_ci_artifacts = env .ARTIFACT_DIR / "jump-ci-artifacts"
160
198
jump_ci_artifacts .mkdir (parents = True , exist_ok = True )
161
- run .run (f'mv { env .ARTIFACT_DIR } /0 * { jump_ci_artifacts } /' )
199
+ run .run (f'mv { env .ARTIFACT_DIR } /*__jump_ci_ * { jump_ci_artifacts } /' )
162
200
163
201
if failed :
164
202
raise SystemExit (1 )
0 commit comments