mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +07:00
[IMP] runbot: custom db_names for install and run jobs.
When creating a subbuild from a custom python job/cron, some data can be given through config_data or extra_params to change another step behaviour. An example is to give a specific -i to an install job in order to install different modules from the parent build. Anyway since we are using the same install step in this case, all databases will have the same name, and the name may not be correct in regard to the database content. This commit allows to give a config_param on build giving the default db_name to use in an install step.
This commit is contained in:
parent
ef7029668a
commit
6b88cb7688
@ -297,7 +297,7 @@ class ConfigStep(models.Model):
|
||||
# not sure, to avoid old server to check other dbs
|
||||
cmd += ["--max-cron-threads", "0"]
|
||||
|
||||
db_name = [step.db_name for step in build.config_id.step_ids() if step.job_type == 'install_odoo'][-1]
|
||||
db_name = build.config_data.get('db_name') or [step.db_name for step in build.config_id.step_ids() if step.job_type == 'install_odoo'][-1]
|
||||
# we need to have at least one job of type install_odoo to run odoo, take the last one for db_name.
|
||||
cmd += ['-d', '%s-%s' % (build.dest, db_name)]
|
||||
|
||||
@ -336,7 +336,8 @@ class ConfigStep(models.Model):
|
||||
python_params = ['-m', 'flamegraph', '-o', self._perfs_data_path()]
|
||||
cmd = build._cmd(python_params, py_version)
|
||||
# create db if needed
|
||||
db_name = "%s-%s" % (build.dest, self.db_name)
|
||||
db_suffix = build.config_data.get('db_name') or self.db_name
|
||||
db_name = "%s-%s" % (build.dest, db_suffix)
|
||||
if self.create_db:
|
||||
build._local_pg_createdb(db_name)
|
||||
cmd += ['-d', db_name]
|
||||
@ -407,7 +408,8 @@ class ConfigStep(models.Model):
|
||||
kwargs = dict(message='Step %s finished in %s' % (self.name, s2human(build.job_time)))
|
||||
if self.job_type == 'install_odoo':
|
||||
kwargs['message'] += ' $$fa-download$$'
|
||||
kwargs['path'] = '%s%s-%s.zip' % (build.http_log_url(), build.dest, self.db_name)
|
||||
db_suffix = build.config_data.get('db_name') or self.db_name
|
||||
kwargs['path'] = '%s%s-%s.zip' % (build.http_log_url(), build.dest, db_suffix)
|
||||
kwargs['log_type'] = 'link'
|
||||
build._log('', **kwargs)
|
||||
|
||||
|
@ -40,6 +40,8 @@ class RunbotCase(TransactionCase):
|
||||
self.start_patcher('docker_build', 'odoo.addons.runbot.models.build.docker_build')
|
||||
self.start_patcher('docker_ps', 'odoo.addons.runbot.models.repo.docker_ps', [])
|
||||
self.start_patcher('docker_stop', 'odoo.addons.runbot.models.repo.docker_stop')
|
||||
self.start_patcher('docker_ps', 'odoo.addons.runbot.models.build_config.docker_get_gateway_ip', None)
|
||||
|
||||
self.start_patcher('cr_commit', 'odoo.sql_db.Cursor.commit', None)
|
||||
self.start_patcher('repo_commit', 'odoo.addons.runbot.models.repo.runbot_repo._commit', None)
|
||||
self.start_patcher('_local_cleanup_patcher', 'odoo.addons.runbot.models.build.runbot_build._local_cleanup')
|
||||
|
@ -158,6 +158,33 @@ class TestBuildConfigStep(RunbotCase):
|
||||
config_step._run_odoo_install(self.parent_build, 'dev/null/logpath')
|
||||
|
||||
|
||||
@patch('odoo.addons.runbot.models.build.runbot_build._checkout')
|
||||
def test_db_name(self, mock_checkout):
|
||||
config_step = self.ConfigStep.create({
|
||||
'name': 'default',
|
||||
'job_type': 'install_odoo',
|
||||
'custom_db_name': 'custom',
|
||||
})
|
||||
call_count = 0
|
||||
assert_db_name = 'custom'
|
||||
def docker_run(cmd, log_path, *args, **kwargs):
|
||||
db_sufgfix = cmd.cmd[cmd.index('-d')+1].split('-')[-1]
|
||||
self.assertEqual(db_sufgfix, assert_db_name)
|
||||
nonlocal call_count
|
||||
call_count += 1
|
||||
|
||||
self.patchers['docker_run'].side_effect = docker_run
|
||||
|
||||
config_step._run_odoo_install(self.parent_build, 'dev/null/logpath')
|
||||
|
||||
assert_db_name = 'custom_build'
|
||||
self.parent_build.config_data = {'db_name': 'custom_build'}
|
||||
config_step._run_odoo_install(self.parent_build, 'dev/null/logpath')
|
||||
|
||||
config_step._run_odoo_run(self.parent_build, 'dev/null/logpath')
|
||||
|
||||
self.assertEqual(call_count, 3)
|
||||
|
||||
class TestMakeResult(RunbotCase):
|
||||
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user