[FIX] runbot: make python jobs usable and improve logs

This commit is contained in:
Xavier-Do 2019-05-21 15:50:26 +02:00
parent d3e3f75224
commit 519f50790d
4 changed files with 17 additions and 6 deletions

View File

@ -19,7 +19,7 @@ class runbot_branch(models.Model):
branch_name = fields.Char(compute='_get_branch_infos', string='Branch', readonly=1, store=True)
branch_url = fields.Char(compute='_get_branch_url', string='Branch url', readonly=1)
pull_head_name = fields.Char(compute='_get_branch_infos', string='PR HEAD name', readonly=1, store=True)
target_branch_name = fields.Char(compute='_get_branch_infos', string='PR target branch', readonly=1, store=True)
target_branch_name = fields.Char(compute='_get_branch_infos', string='PR target branch', store=True)
sticky = fields.Boolean('Sticky')
coverage_result = fields.Float(compute='_compute_coverage_result', type='Float', string='Last coverage', store=False) # non optimal search in loop, could we store this result ? or optimise
state = fields.Char('Status')

View File

@ -100,7 +100,7 @@ class runbot_build(models.Model):
log_list = fields.Char('Comma separted list of step_ids names with logs', compute="_compute_log_list", store=True)
@api.depends('config_id')
def _compute_log_list(self): # storing this field beacause it will be access trhoug repo viewn and keep track of the list at create
def _compute_log_list(self): # storing this field because it will be access trhoug repo viewn and keep track of the list at create
for build in self:
build.log_list = ','.join({step.name for step in build.config_id.step_ids() if step._has_log()})
@ -113,6 +113,7 @@ class runbot_build(models.Model):
waiting_score = record._get_state_score('waiting')
if record._get_state_score(record.local_state) > waiting_score and record.children_ids: # if finish, check children
children_state = record._get_youngest_state([child.global_state for child in record.children_ids])
# if all children are in running/done state (children could't be a duplicate I guess?)
if record._get_state_score(children_state) > waiting_score:
record.global_state = record.local_state
@ -238,6 +239,7 @@ class runbot_build(models.Model):
# ('build_type', '!=', 'indirect'), # in case of performance issue, this little fix may improve performance a little but less duplicate will be detected when pushing an empty branch on repo with duplicates
'|', ('local_result', '=', False), ('local_result', '!=', 'skipped'), # had to reintroduce False posibility for selections
('config_id', '=', build_id.config_id.id),
('extra_params', '=', build_id.extra_params),
]
candidates = self.search(domain)
if candidates and nb_deps:
@ -576,9 +578,9 @@ class runbot_build(models.Model):
pid = build.active_step._run(build) # run should be on build?
build.write({'pid': pid}) # no really usefull anymore with dockers
except Exception as e:
message = '%s failed running step %s' % (build.dest, build.job)
message = '%s failed running step %s:\n %s' % (build.dest, build.job, str(e).replace('\\n', '\n').replace("\\'", "'"))
_logger.exception(message)
build._log("run", message)
build._log("run", message, level='ERROR')
build._kill(result='ko')
continue
@ -881,6 +883,14 @@ class runbot_build(models.Model):
new_step = step_ids[next_index] # job to do, state is job_state (testing or running)
return {'active_step': new_step.id, 'local_state': new_step._step_state()}
def read_file(self, file):
file_path = self._path(file)
try:
with open(file_path, 'r') as f:
return f.read()
except:
return False
def build_type_label(self):
self.ensure_one()
return dict(self.fields_get('build_type', 'selection')['build_type']['selection']).get(self.build_type, self.build_type)

View File

@ -209,8 +209,8 @@ class ConfigStep(models.Model):
build._log('create_build', 'created with config %s' % create_config.name, log_type='subbuild', path=str(children.id))
def _run_python(self, build, log_path):
eval_ctx = {'self': self, 'build': build, 'log_path': log_path}
return safe_eval(self.sudo().code.strip(), eval_ctx, mode="exec", nocopy=True)
eval_ctx = {'self': self, 'build': build, 'log_path': log_path, 'docker_run': docker_run, 'glob': glob, '_logger': _logger, 'build_odoo_cmd': build_odoo_cmd}
return safe_eval(self.sudo().python_code.strip(), eval_ctx, mode="exec", nocopy=True)
def _run_odoo_run(self, build, log_path):
# adjust job_end to record an accurate job_20 job_time

View File

@ -14,6 +14,7 @@
<field name="branch_name"/>
<field name="branch_url"/>
<field name="pull_head_name"/>
<field name="target_branch_name"/>
<field name="sticky"/>
<field name="priority"/>
<field name="state"/>