@@ -155,10 +155,36 @@ def main(args):
155155 except SkipJob :
156156 continue
157157
158+ # Create run archive directory if not already created and
159+ # job's archive directory
160+ job_archive_path = job_config ['archive_path' ]
161+ log .info ('Creating job\' s archive dir %s' , job_archive_path )
162+ safepath .makedirs ('/' , job_archive_path )
163+
164+ orig_job_config_path = os .path .join (job_archive_path , 'orig.config.yaml' )
165+ # Write initial job config in job archive dir
166+ with open (orig_job_config_path , 'w' ) as f :
167+ yaml .safe_dump (job_config , f , default_flow_style = False )
168+
169+
170+ run_args = [
171+ os .path .join (teuth_bin_path , 'teuthology-supervisor' ),
172+ '-v' ,
173+ '--bin-path' , teuth_bin_path ,
174+ '--archive-dir' , archive_dir ,
175+ ]
176+
158177 # lock machines but do not reimage them
159178 if 'roles' in job_config :
160179 try :
161- job_config = lock_machines (job_config )
180+ targets_job_config = lock_machines (job_config )
181+ job_config_path = os .path .join (job_archive_path , 'targets.config.yaml' )
182+
183+ with open (job_config_path , 'w' ) as f :
184+ yaml .safe_dump (targets_job_config , f , default_flow_style = False )
185+
186+ run_args .extend (["--job-config" , job_config_path ])
187+
162188 except LoopExit as e :
163189 log .critical (
164190 "Caught gevent LoopExit exception during lock_machines for job %s. "
@@ -186,27 +212,10 @@ def main(args):
186212 )
187213 )
188214 continue
215+ else :
216+ run_args .extend (["--job-config" , orig_job_config_path ])
189217
190- run_args = [
191- os .path .join (teuth_bin_path , 'teuthology-supervisor' ),
192- '-v' ,
193- '--bin-path' , teuth_bin_path ,
194- '--archive-dir' , archive_dir ,
195- ]
196-
197- # Create run archive directory if not already created and
198- # job's archive directory
199- create_job_archive (job_config ['name' ],
200- job_config ['archive_path' ],
201- archive_dir )
202- job_config_path = os .path .join (job_config ['archive_path' ], 'orig.config.yaml' )
203-
204- # Write initial job config in job archive dir
205- with open (job_config_path , 'w' ) as f :
206- yaml .safe_dump (job_config , f , default_flow_style = False )
207-
208- run_args .extend (["--job-config" , job_config_path ])
209-
218+ report .try_push_job_info (job_config , dict (status = 'running' ))
210219 try :
211220 # Use start_new_session=True to ensure child processes are isolated
212221 # from the dispatcher's process group. This prevents accidental
@@ -222,8 +231,8 @@ def main(args):
222231 except Exception :
223232 error_message = "Saw error while trying to spawn supervisor."
224233 log .exception (error_message )
225- if 'targets' in job_config :
226- node_names = job_config ["targets" ].keys ()
234+ if targets_job_config and 'targets' in targets_job_config :
235+ node_names = targets_job_config ["targets" ].keys ()
227236 lock_ops .unlock_safe (
228237 node_names ,
229238 job_config ["owner" ],
@@ -420,7 +429,6 @@ def check_job_expiration(job_config):
420429
421430
422431def lock_machines (job_config ):
423- report .try_push_job_info (job_config , dict (status = 'running' ))
424432 fake_ctx = supervisor .create_fake_context (job_config , block = True )
425433 machine_type = job_config ["machine_type" ]
426434 count = len (job_config ['roles' ])
@@ -435,14 +443,4 @@ def lock_machines(job_config):
435443 tries = - 1 ,
436444 reimage = False ,
437445 )
438- job_config = fake_ctx .config
439- return job_config
440-
441-
442- def create_job_archive (job_name , job_archive_path , archive_dir ):
443- log .info ('Creating job\' s archive dir %s' , job_archive_path )
444- safe_archive = safepath .munge (job_name )
445- run_archive = os .path .join (archive_dir , safe_archive )
446- if not os .path .exists (run_archive ):
447- safepath .makedirs ('/' , run_archive )
448- safepath .makedirs ('/' , job_archive_path )
446+ return fake_ctx .config
0 commit comments