[IMP] runbot: add subcommand support

This commit is contained in:
Xavier-Do 2020-02-28 14:59:33 +01:00 committed by Christophe Monniez
parent 745f385dd3
commit 2379318b0c
4 changed files with 37 additions and 4 deletions

View File

@ -965,7 +965,7 @@ class runbot_build(models.Model):
_logger.error('None of %s found in commit, actual commit content:\n %s' % (commit.repo.server_files, os.listdir(commit._source_path())))
raise RunbotException('No server found in %s' % commit)
def _cmd(self, python_params=None, py_version=None, local_only=True):
def _cmd(self, python_params=None, py_version=None, local_only=True, sub_command=None):
"""Return a list describing the command to start the build
"""
self.ensure_one()
@ -984,7 +984,10 @@ class runbot_build(models.Model):
server_dir = self._docker_source_folder(server_commit)
# commandline
cmd = ['python%s' % py_version] + python_params + [os.path.join(server_dir, server_file), '--addons-path', ",".join(addons_paths)]
cmd = ['python%s' % py_version] + python_params + [os.path.join(server_dir, server_file)]
if sub_command:
cmd += [sub_command]
cmd += ['--addons-path', ",".join(addons_paths)]
# options
config_path = build._server("tools/config.py")
if grep(config_path, "no-xmlrpcs"): # move that to configs ?

View File

@ -113,6 +113,7 @@ class ConfigStep(models.Model):
test_enable = fields.Boolean('Test enable', default=True, track_visibility='onchange')
test_tags = fields.Char('Test tags', help="comma separated list of test tags", track_visibility='onchange')
enable_auto_tags = fields.Boolean('Allow auto tag', default=False, track_visibility='onchange')
sub_command = fields.Char('Subcommand', track_visibility='onchange')
extra_params = fields.Char('Extra cmd args', track_visibility='onchange')
additionnal_env = fields.Char('Extra env', help='Example: foo="bar",bar="foo". Cannot contains \' ', track_visibility='onchange')
# python
@ -149,6 +150,13 @@ class ConfigStep(models.Model):
else:
self.force_build = False
@api.onchange('sub_command')
def _onchange_number_builds(self):
if self.sub_command:
self.install_modules = '-*'
self.test_enable = False
self.create_db = False
@api.depends('name', 'custom_db_name')
def _compute_db_name(self):
for step in self:
@ -334,7 +342,7 @@ class ConfigStep(models.Model):
python_params = ['-m', 'coverage', 'run', '--branch', '--source', '/data/build'] + coverage_extra_params
elif self.flamegraph:
python_params = ['-m', 'flamegraph', '-o', self._perfs_data_path()]
cmd = build._cmd(python_params, py_version)
cmd = build._cmd(python_params, py_version, sub_command=self.sub_command)
# create db if needed
db_suffix = build.config_data.get('db_name') or self.db_name
db_name = "%s-%s" % (build.dest, db_suffix)

View File

@ -185,6 +185,27 @@ class TestBuildConfigStep(RunbotCase):
self.assertEqual(call_count, 3)
@patch('odoo.addons.runbot.models.build.runbot_build._checkout')
def test_sub_command(self, mock_checkout):
config_step = self.ConfigStep.create({
'name': 'default',
'job_type': 'install_odoo',
'sub_command': 'subcommand',
})
call_count = 0
def docker_run(cmd, log_path, *args, **kwargs):
nonlocal call_count
sub_command = cmd.cmd[cmd.index('bar/server.py')+1]
self.assertEqual(sub_command, 'subcommand')
call_count += 1
self.patchers['docker_run'].side_effect = docker_run
config_step._run_odoo_install(self.parent_build, 'dev/null/logpath')
self.assertEqual(call_count, 1)
class TestMakeResult(RunbotCase):
def setUp(self):

View File

@ -64,7 +64,8 @@
<field name="test_enable"/>
<field name="test_tags"/>
<field name="enable_auto_tags"/>
<field name="extra_params"/>
<field name="sub_command"/>
<field name="extra_params" groups="base.group_no_one"/>
<field name="additionnal_env"/>
</group>
<group string="Create settings" attrs="{'invisible': [('job_type', 'not in', ('python', 'create_build'))]}">