@@ -295,6 +295,7 @@ def VARS(vars, path):
295295 'max_builds' : OPTIONAL (INT ),
296296 'if' : OPTIONAL (DYNAMIC_VALUE ),
297297 'log' : OPTIONAL (DYNAMIC_VALUE ),
298+ 'use_parent' : OPTIONAL (BOOL ),
298299 }
299300 valid_steps ['restore' ] = {
300301 'name' : REQUIRED (NAME ),
@@ -371,6 +372,18 @@ def _check_recursion(self, visited=None):
371372 for create_config in step .create_config_ids :
372373 create_config ._check_recursion (visited [:])
373374
375+ def _default_uses_parent (self , param_values ):
376+ if param_values .get ('dump_db' ):
377+ return False
378+ config_data = param_values .get ('config_data' , {}) or {}
379+ if config_data .get ('dump_url' ):
380+ return False
381+ if config_data .get ('restore_build_id' ):
382+ return False
383+ if config_data .get ('dump_trigger_id' ):
384+ return False
385+ return any (step .job_type == 'restore' for step in self .step_ids )
386+
374387
375388class ConfigStepUpgradeDb (models .Model ):
376389 _name = 'runbot.config.step.upgrade.db'
@@ -589,7 +602,7 @@ def _run_step(self, build, **kwargs):
589602 return build ._docker_run (self , ** docker_params )
590603 return True
591604
592- def _run_create_build (self , build , config_data = None , max_build = 200 ):
605+ def _run_create_build (self , build , config_data = None , max_build = 200 , use_parent = ... ):
593606 if config_data :
594607 config_data = {** config_data , ** build .params_id .config_data }
595608 else :
@@ -613,7 +626,7 @@ def _run_create_build(self, build, config_data=None, max_build=200):
613626 build ._log ('create_build' , f'More than { max_build } build created, stopping' , level = 'WARNING' )
614627 return
615628 config_name = config_name or create_config .name
616- child = build ._add_child (child_data_values , orphan = self .make_orphan , description = description or config_name )
629+ child = build ._add_child (child_data_values , orphan = self .make_orphan , description = description or config_name , use_parent = use_parent )
617630 build ._log ('create_build' , 'created with config %s' % config_name , log_type = 'subbuild' , path = str (child .id ))
618631
619632 def _make_python_ctx (self , build ):
@@ -1122,7 +1135,7 @@ def _run_restore(self, build, config_data=None):
11221135 dump_build = dump_db .build_id
11231136 else :
11241137 download_db_suffix = config_data .get ('dump_suffix' , self .restore_download_db_suffix or 'all' )
1125- dump_build = build .parent_id
1138+ dump_build = params . reference_build_id or build .parent_id # TODO cleanup parent_id
11261139 assert download_db_suffix and dump_build
11271140 download_db_name = '%s-%s' % (dump_build .dest , download_db_suffix )
11281141 zip_name = '%s.zip' % download_db_name
@@ -1604,11 +1617,15 @@ def _run_dynamic(self, build):
16041617 'config_name' : config_name ,
16051618 'description' : description ,
16061619 }
1620+ if current_step .get ('use_parent' ) or (current_step .get ('use_parent' ) is None and any (step .get ('job_type' ) == 'restore' for step in child .get ('steps' , []))):
1621+ # TODO improve, not needed is other restore params are given
1622+ child_data ['reference_build_id' ] = build .id
16071623 child_data_list .append (child_data )
16081624 return self ._run_create_build (
16091625 build ,
16101626 {'child_data' : child_data_list , 'number_build' : current_step .get ('number_builds' , 1 )},
16111627 max_build = min (current_step .get ('max_builds' , 20 ), 200 ),
1628+ use_parent = current_step .get ('use_parent' , ...)
16121629 )
16131630
16141631 if current_step ['job_type' ] == 'restore' :
0 commit comments