[IMP] runbot: add without-demo as field

Adds the without-demo flag as a field on config steps.
This commit is contained in:
William Braeckman 2024-11-29 14:26:18 +01:00 committed by xdo
parent 214ab338d5
commit fbce7ae713
4 changed files with 156 additions and 2 deletions

View File

@ -160,6 +160,10 @@ class ConfigStep(models.Model):
extra_params = fields.Char('Extra cmd args', tracking=True)
additionnal_env = fields.Char('Extra env', help='Example: foo="bar";bar="foo". Cannot contains \' ', tracking=True)
enable_log_db = fields.Boolean("Enable log db", default=True)
demo_mode = fields.Selection(
[('default', 'Default'), ('without_demo', 'Without Demo'), ('with_demo', 'With Demo')],
"Install demo data", default='default', tracking=True, required=True,
)
# python
python_code = fields.Text('Python code', tracking=True, default=PYTHON_DEFAULT)
python_result_code = fields.Text('Python code for result', tracking=True, default=PYTHON_DEFAULT)
@ -431,13 +435,23 @@ class ConfigStep(models.Model):
if self.create_db:
build._local_pg_createdb(db_name)
cmd += ['-d', db_name]
# Demo data behavior changed in 18.1 -> demo data became opt-in instead of opt-out
available_options = build._parse_config()
# True if build has demo data by default
demo_installed_by_default = '--with-demo' not in available_options
demo_mode = build.params_id.config_data.get('demo_mode', self.demo_mode)
if demo_mode == 'with_demo' and not demo_installed_by_default:
cmd.append('--with-demo')
elif demo_mode == 'without_demo' and demo_installed_by_default:
cmd.append('--without-demo=true')
# list module to install
extra_params = build.params_id.extra_params or self.extra_params or ''
if mods and '-i' not in extra_params:
cmd += ['-i', mods]
config_path = build._server("tools/config.py")
available_options = build._parse_config()
if self.test_enable:
if "--test-enable" in available_options:
cmd.extend(['--test-enable'])

View File

@ -487,6 +487,11 @@ class TestBuildConfigStep(TestBuildConfigStepCommon):
self.assertEqual(cmds[1].split(' server/server.py')[0], 'python3')
return cmds[1].split('--test-tags ')[1].split(' ')[0]
def get_odoo_cmd(self, params):
cmds = params['cmd'].build().split(' && ')
self.assertTrue(any('server/server.py' in cmd for cmd in cmds), 'did not find start command')
return next(iter(cmd for cmd in cmds if 'server/server.py' in cmd))
@patch('odoo.addons.runbot.models.build.BuildResult._parse_config')
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_install_tags(self, mock_checkout, parse_config):
@ -625,6 +630,139 @@ def run():
self.assertEqual(call_count, 1)
@patch('odoo.addons.runbot.models.build.BuildResult._parse_config')
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_install_demo_mode_default_default_without_demo(self, mock_checkout, parse_config):
# Test demo_mode = 'default' when the default is without_demo
parse_config.return_value = {'--with-demo'}
config_step = self.ConfigStep.create({
'name': 'all',
'job_type': 'install_odoo',
})
child = self.parent_build._add_child({'config_data': {}})
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
child.params_id.config_data = {'demo_mode': 'default'}
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_install_demo_mode_default_default_with_demo(self, mock_checkout):
# Test demo_mode = 'default' when the default is with_demo
config_step = self.ConfigStep.create({
'name': 'all',
'job_type': 'install_odoo',
})
child = self.parent_build._add_child({'config_data': {}})
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
child.params_id.config_data = {'demo_mode': 'default'}
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
@patch('odoo.addons.runbot.models.build.BuildResult._parse_config')
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_install_demo_mode_with_demo_default_without_demo(self, mock_checkout, parse_config):
# Test demo_mode = 'with_demo' when the default is without_demo
parse_config.return_value = {'--with-demo'}
config_step = self.ConfigStep.create({
'name': 'all',
'job_type': 'install_odoo',
'demo_mode': 'with_demo',
})
child = self.parent_build._add_child({'config_data': {}})
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
config_step.demo_mode = 'default'
child.params_id.config_data = {'demo_mode': 'with_demo'}
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_install_demo_mode_with_demo_default_with_demo(self, mock_checkout):
# Test demo_mode = 'with_demo' when the default is with_demo
config_step = self.ConfigStep.create({
'name': 'all',
'job_type': 'install_odoo',
'demo_mode': 'with_demo',
})
child = self.parent_build._add_child({'config_data': {}})
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
config_step.demo_mode = 'default'
child.params_id.config_data = {'demo_mode': 'with_demo'}
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
@patch('odoo.addons.runbot.models.build.BuildResult._parse_config')
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_install_demo_mode_without_demo_default_without_demo(self, mock_checkout, parse_config):
# Test demo_mode = 'without_demo' when the default is without_demo
parse_config.return_value = {'--with-demo'}
config_step = self.ConfigStep.create({
'name': 'all',
'job_type': 'install_odoo',
'demo_mode': 'without_demo',
})
child = self.parent_build._add_child({'config_data': {}})
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
config_step.demo_mode = 'default'
child.params_id.config_data = {'demo_mode': 'without_demo'}
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertNotIn('--without-demo', cmd)
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_install_demo_mode_without_demo_default_with_demo(self, mock_checkout):
# Test demo_mode = 'without_demo' when the default is with_demo
config_step = self.ConfigStep.create({
'name': 'all',
'job_type': 'install_odoo',
'demo_mode': 'without_demo',
})
child = self.parent_build._add_child({'config_data': {}})
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertIn('--without-demo', cmd)
config_step.demo_mode = 'default'
child.params_id.config_data = {'demo_mode': 'without_demo'}
params = config_step._run_install_odoo(child)
cmd = self.get_odoo_cmd(params)
self.assertNotIn('--with-demo', cmd)
self.assertIn('--without-demo', cmd)
class TestMakeResult(RunbotCase):

View File

@ -258,7 +258,8 @@ class TestUpgradeFlow(RunbotCase):
return builds_nigthly, builds_weekly
def test_all(self):
@patch('odoo.addons.runbot.models.build.BuildResult._parse_config')
def test_all(self, *_):
# Test setup
self.assertEqual(self.branch_server.bundle_id, self.branch_upgrade.bundle_id)
self.assertTrue(self.branch_upgrade.bundle_id.is_base)

View File

@ -64,6 +64,7 @@
<group string="Test settings" invisible="job_type not in ('python', 'install_odoo')">
<field name="create_db" groups="base.group_no_one"/>
<field name="install_modules"/>
<field name="demo_mode"/>
<field name="db_name" groups="base.group_no_one"/>
<field name="cpu_limit" groups="base.group_no_one"/>
<field name="container_cpus" groups="base.group_no_one"/>