From e3d87b5b5dd086a7184824baf8dd690ccd94fdc1 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Tue, 4 Apr 2023 14:33:49 +0200 Subject: [PATCH] [IMP] runbot: improve test-tags support The current post_install build mecanism is using extra params to give test-tags. Unfortunately this disables the support for auto tags and this have to be done manually. This means that auto tags are in the build extra-params and not dynamic at rebuild of a post_install. Also, using extraparams in the post install creation was removing extra_params comming from custom trigger. With this commit, the test-tags can be given inside config_data and will be combined with config step test-tags and auto-tags. This was an opportunity to simplify the logic. This commit also fixes the test_install_tags that was broken. --- runbot/models/build_config.py | 36 +++++++++--------- runbot/tests/test_build_config_step.py | 51 +++++++++++++++++--------- 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/runbot/models/build_config.py b/runbot/models/build_config.py index 9e6fb1eb..402cbf82 100644 --- a/runbot/models/build_config.py +++ b/runbot/models/build_config.py @@ -435,25 +435,27 @@ class ConfigStep(models.Model): cmd.extend(['--test-enable']) else: build._log('test_all', 'Installing modules without testing', level='WARNING') + test_tags_in_extra = '--test-tags' in extra_params - disable_auto_tags = build.params_id.config_data.get('disable_auto_tags', False) - if self.test_tags or test_tags_in_extra: - if "--test-tags" in available_options: - if not test_tags_in_extra: - test_tags = self.test_tags.replace(' ', '') - if self.enable_auto_tags and not disable_auto_tags: - auto_tags = self.env['runbot.build.error'].disabling_tags() - test_tags = ','.join(test_tags.split(',') + auto_tags) - cmd.extend(['--test-tags', test_tags]) - else: - build._log('test_all', 'Test tags given but not supported') - elif self.enable_auto_tags and self.test_enable and not disable_auto_tags: - if grep(config_path, "[/module][:class]"): - auto_tags = self.env['runbot.build.error'].disabling_tags() - if auto_tags: - test_tags = ','.join(auto_tags) - cmd.extend(['--test-tags', test_tags]) + if (self.test_enable or self.test_tags) and "--test-tags" in available_options and not test_tags_in_extra: + test_tags = [] + custom_tags = build.params_id.config_data.get('test_tags') + if custom_tags: + test_tags += custom_tags.replace(' ', '').split(',') + if self.test_tags: + test_tags += self.test_tags.replace(' ', '').split(',') + if self.enable_auto_tags and not build.params_id.config_data.get('disable_auto_tags', False): + if grep(config_path, "[/module][:class]"): + auto_tags = self.env['runbot.build.error'].disabling_tags() + if auto_tags: + test_tags += auto_tags + + test_tags = [test_tag for test_tag in test_tags if test_tag] + if test_tags: + cmd.extend(['--test-tags', ','.join(test_tags)]) + elif test_tags_in_extra or self.test_tags and "--test-tags" not in available_options: + build._log('test_all', 'Test tags given but not supported') if "--screenshots" in available_options: cmd.add_config_tuple('screenshots', '/data/build/tests') diff --git a/runbot/tests/test_build_config_step.py b/runbot/tests/test_build_config_step.py index 6b7c588b..09fe6da2 100644 --- a/runbot/tests/test_build_config_step.py +++ b/runbot/tests/test_build_config_step.py @@ -404,8 +404,15 @@ class TestBuildConfigStep(TestBuildConfigStepCommon): config_step._run_install_odoo(self.parent_build, 'dev/null/logpath') + def get_test_tags(self, params): + cmds = params['cmd'].build().split(' && ') + self.assertEqual(cmds[1].split(' server/server.py')[0], 'python3') + return cmds[1].split('--test-tags ')[1].split(' ')[0] + + @patch('odoo.addons.runbot.models.build.BuildResult.parse_config') @patch('odoo.addons.runbot.models.build.BuildResult._checkout') - def test_install_tags(self, mock_checkout): + def test_install_tags(self, mock_checkout, parse_config): + parse_config.return_value = {'--test-enable', '--test-tags'} config_step = self.ConfigStep.create({ 'name': 'all', 'job_type': 'install_odoo', @@ -417,26 +424,36 @@ class TestBuildConfigStep(TestBuildConfigStepCommon): 'random': True, 'test_tags': ':otherclass.othertest' }) - - def docker_run(cmd, *args, **kwargs): - cmds = cmd.build().split(' && ') - self.assertEqual(cmds[1].split(' server/server.py')[0], 'python3') - tags = cmds[1].split('--test-tags ')[1].split(' ')[0] - self.assertEqual(tags, '/module,:class.method') - - self.patchers['docker_run'].side_effect = docker_run - config_step._run_install_odoo(self.parent_build, 'dev/null/logpath') + params = config_step._run_install_odoo(self.parent_build, 'dev/null/logpath') + tags = self.get_test_tags(params) + self.assertEqual(tags, '/module,:class.method') config_step.enable_auto_tags = True + params = config_step._run_install_odoo(self.parent_build, 'dev/null/logpath') + tags = self.get_test_tags(params) + self.assertEqual(tags, '/module,:class.method,-:otherclass.othertest') - def docker_run2(cmd, *args, **kwargs): - cmds = cmd.build().split(' && ') - self.assertEqual(cmds[1].split(' server/server.py')[0], 'python3') - tags = cmds[1].split('--test-tags ')[1].split(' ')[0] - self.assertEqual(tags, '/module,:class.method,-:otherclass.othertest') + @patch('odoo.addons.runbot.models.build.BuildResult.parse_config') + @patch('odoo.addons.runbot.models.build.BuildResult._checkout') + def test_install_custom_tags(self, mock_checkout, parse_config): + parse_config.return_value = {'--test-enable', '--test-tags'} + config_step = self.ConfigStep.create({ + 'name': 'all', + 'job_type': 'install_odoo', + 'enable_auto_tags': True, + }) + self.env['runbot.build.error'].create({ + 'content': 'foo', + 'random': True, + 'test_tags': ':otherclass.othertest' + }) + + child = self.parent_build._add_child({'config_data': {'test_tags': '-at_install,/module1,/module2'}}) + + params = config_step._run_install_odoo(child, 'dev/null/logpath') + tags = self.get_test_tags(params) + self.assertEqual(tags, '-at_install,/module1,/module2,-:otherclass.othertest') - self.patchers['docker_run'].side_effect = docker_run2 - config_step._run_install_odoo(self.parent_build, 'dev/null/logpath') @patch('odoo.addons.runbot.models.build.BuildResult._checkout') def test_db_name(self, mock_checkout):