Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #820

Draft
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Draft

wip #820

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions runbot/models/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,9 @@ def _run_create_build(self, build):
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,
Expand All @@ -311,15 +308,19 @@ def _run_python(self, build, force=False):
if run and callable(run):
return run()
return eval_ctx.get('docker_params')
except ValueError as e:
save_eval_value_error_re = r'<class \'odoo.addons.runbot.models.repo.RunbotException\'>: "(.*)" 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'''<class 'odoo.addons.runbot.commona.RunbotException'>: "(.*)" 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:
Expand Down
3 changes: 2 additions & 1 deletion runbot/tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ def test_children(self):
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()

Expand Down
22 changes: 22 additions & 0 deletions runbot/tests/test_build_config_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down