diff --git a/runbot/models/build_config.py b/runbot/models/build_config.py index f13da2e7..55016dbe 100644 --- a/runbot/models/build_config.py +++ b/runbot/models/build_config.py @@ -288,12 +288,9 @@ class ConfigStep(models.Model): def _make_python_ctx(self, build): return { 'self': self, - # 'fields': fields, - # 'models': models, 'build': build, '_logger': _logger, 'log_path': build._path('logs', '%s.txt' % self.name), - 'glob': glob.glob, 'Command': Command, 're': ReProxy, 'grep': grep, @@ -311,15 +308,19 @@ class ConfigStep(models.Model): if run and callable(run): return run() return eval_ctx.get('docker_params') - except ValueError as e: - save_eval_value_error_re = r': "(.*)" while evaluating\n.*' + except RunbotException as e: message = e.args[0] - groups = re.match(save_eval_value_error_re, message) - if groups: - build._log("run", groups[1], level='ERROR') - build._kill(result='ko') - else: - raise + build._log("run", f'A runbot exception occured:\n{message}', level='ERROR') + build._kill(result='ko') + #except ValueError as e: + # save_eval_value_error_re = r''': "(.*)" while evaluating\n.*''' + # message = e.args[0] + # groups = re.match(save_eval_value_error_re, message) + # if groups: + # build._log("run", groups[1], level='ERROR') + # build._kill(result='ko') + # else: + # raise def _is_docker_step(self): if not self: diff --git a/runbot/tests/test_build.py b/runbot/tests/test_build.py index 767d2b69..66df0b9c 100644 --- a/runbot/tests/test_build.py +++ b/runbot/tests/test_build.py @@ -388,7 +388,8 @@ class TestBuildResult(RunbotCase): self.assertEqual('waiting', build1.global_state) self.assertEqual('testing', build1_1.global_state) - # with self.assertQueries([]): # write the same value, no update should be triggered + #with self.assertQueries(['''UPDATE "runbot_build" SET "global_state" = %s, "write_date" = %s, "write_uid" = %s WHERE id IN %s''']): + build1.local_state = 'done' build1.flush_recordset() diff --git a/runbot/tests/test_build_config_step.py b/runbot/tests/test_build_config_step.py index 389a1c66..589a445f 100644 --- a/runbot/tests/test_build_config_step.py +++ b/runbot/tests/test_build_config_step.py @@ -588,6 +588,28 @@ def run(): retult = config_step._run_python(self.parent_build) self.assertEqual(retult, {'a': 'b'}) + @patch('odoo.addons.runbot.models.build.BuildResult._checkout') + def test_run_python_exception(self, mock_checkout): + """minimal test for python steps. Also test that `-d` in cmd creates a database""" + + def raise_runbot_exception(): + raise RunbotException('Nope') + + mock_checkout.side_effect = raise_runbot_exception + test_code = """ +def run(): + build._checkout() +""" + config_step = self.ConfigStep.create({ + 'name': 'default', + 'job_type': 'python', + 'python_code': test_code, + }) + + config_step._run_python(self.parent_build) + self.assertEqual(self.parent_build.log_ids.mapped('message'), ['A runbot exception occured:\nNope']) + self.assertEqual(self.parent_build.log_ids.mapped('level'), ['ERROR']) + @patch('odoo.addons.runbot.models.build.BuildResult._checkout') def test_sub_command(self, mock_checkout): config_step = self.ConfigStep.create({