From fbce7ae713382256e781f59274d91147a787f87f Mon Sep 17 00:00:00 2001 From: William Braeckman Date: Fri, 29 Nov 2024 14:26:18 +0100 Subject: [PATCH] [IMP] runbot: add without-demo as field Adds the without-demo flag as a field on config steps. --- runbot/models/build_config.py | 16 ++- runbot/tests/test_build_config_step.py | 138 +++++++++++++++++++++++++ runbot/tests/test_upgrade.py | 3 +- runbot/views/config_views.xml | 1 + 4 files changed, 156 insertions(+), 2 deletions(-) diff --git a/runbot/models/build_config.py b/runbot/models/build_config.py index 21b87b20..a58c6b82 100644 --- a/runbot/models/build_config.py +++ b/runbot/models/build_config.py @@ -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']) diff --git a/runbot/tests/test_build_config_step.py b/runbot/tests/test_build_config_step.py index ac96e1e8..a5e29b01 100644 --- a/runbot/tests/test_build_config_step.py +++ b/runbot/tests/test_build_config_step.py @@ -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): diff --git a/runbot/tests/test_upgrade.py b/runbot/tests/test_upgrade.py index 2f19536c..556f93f7 100644 --- a/runbot/tests/test_upgrade.py +++ b/runbot/tests/test_upgrade.py @@ -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) diff --git a/runbot/views/config_views.xml b/runbot/views/config_views.xml index c857272c..646e46c8 100644 --- a/runbot/views/config_views.xml +++ b/runbot/views/config_views.xml @@ -64,6 +64,7 @@ +