From 796796c5b094f27575843185eb9407c5d0086d9d Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Apr 28 2020 13:11:06 +0000 Subject: Add the --nightly/--ci/--test/--production Pungi options according to compose_type. In this commit, the --nightly, --ci, --test or --production Pungi arguments are added automatically when generating the compose based on the compose_type. It is however still possible to set them in PUNGI_KOJI_ARGS or RAW_CONFIG_PUNGI_KOJI_ARGS and in this case, they are not overriden. --- diff --git a/server/conf/config.py b/server/conf/config.py index 77a6edc..0ba91ee 100644 --- a/server/conf/config.py +++ b/server/conf/config.py @@ -143,7 +143,7 @@ class BaseConfiguration(object): # } # Command line arguments used to construct pungi-koji command. - PUNGI_KOJI_ARGS = ['--nightly'] + PUNGI_KOJI_ARGS = [] # Command line argument for raw_config source type, which overwrite # arguments listed PUNGI_KOJI_ARGS. diff --git a/server/odcs/server/pungi.py b/server/odcs/server/pungi.py index b2e8c1c..84bd0fa 100644 --- a/server/odcs/server/pungi.py +++ b/server/odcs/server/pungi.py @@ -312,7 +312,7 @@ class Pungi(object): """ self.pungi_cfg.write_config_files(topdir) - def get_pungi_cmd(self, conf_topdir, targetdir, compose_dir=None): + def get_pungi_cmd(self, conf_topdir, compose, compose_dir=None): """ Returns list with pungi command line arguments needed to generate the compose. @@ -332,7 +332,7 @@ class Pungi(object): if compose_dir: pungi_cmd.append("--compose-dir=%s" % compose_dir) else: - pungi_cmd.append("--target-dir=%s" % targetdir) + pungi_cmd.append("--target-dir=%s" % compose.target_dir) if isinstance(self.pungi_cfg, RawPungiConfig): pungi_cmd += self.pungi_cfg.pungi_koji_args @@ -341,6 +341,20 @@ class Pungi(object): else: raise RuntimeError('Unknown pungi config type to handle.') + compose_type_to_arg = { + "test": "--test", + "ci": "--ci", + "nightly": "--nightly", + "production": "--production", + } + compose_type = compose.compose_type or "test" + + # Add compose_type arg to pungi_cmd only if it's not set already + # directly in the configuration. + if not set(pungi_cmd).intersection(set(compose_type_to_arg.values())): + # For unknown compose_type, fallback to --test to be safe. + pungi_cmd.append(compose_type_to_arg.get(compose_type, "--test")) + if self.koji_event: pungi_cmd += ["--koji-event", str(self.koji_event)] if self.old_compose: @@ -402,7 +416,7 @@ class Pungi(object): self._write_cfgs(td) compose_dir = self._prepare_compose_dir(compose, td) self.pungi_cfg.validate(td, compose_dir) - pungi_cmd = self.get_pungi_cmd(td, compose.target_dir, compose_dir) + pungi_cmd = self.get_pungi_cmd(td, compose, compose_dir) # Commit the session to ensure that all the `compose` changes are # stored database before executing the compose and are not just diff --git a/server/tests/test_events.py b/server/tests/test_events.py index 55de64f..c528678 100644 --- a/server/tests/test_events.py +++ b/server/tests/test_events.py @@ -136,7 +136,7 @@ class TestFedoraMessagingSendMessageWhenComposeIsCreated(ModelsBaseTest): db.session.commit() Message.assert_called_once_with( - topic="compose.state-changed", + topic="odcs.compose.state-changed", body={'event': 'state-changed', 'compose': compose.json()}) publish.assert_called_once_with(Message.return_value) diff --git a/server/tests/test_pungi.py b/server/tests/test_pungi.py index 4bfc125..bb82b24 100644 --- a/server/tests/test_pungi.py +++ b/server/tests/test_pungi.py @@ -398,12 +398,40 @@ class TestPungi(ModelsBaseTest): execute_cmd.assert_called_once_with( ['pungi-koji', AnyStringWith('pungi.conf'), - AnyStringWith('--compose-dir='), '--nightly'], + AnyStringWith('--compose-dir='), '--test'], cwd=AnyStringWith('/tmp/'), timeout=3600, stderr=AnyStringWith("pungi-stderr.log"), stdout=AnyStringWith("pungi-stdout.log")) @patch("odcs.server.utils.execute_cmd") + def test_pungi_run_compose_type(self, execute_cmd): + for compose_type in [None, "test", "ci", "nightly", "production"]: + self.makedirs.reset_mock() + self.ci_dump.reset_mock() + execute_cmd.reset_mock() + + self.compose.compose_type = compose_type + pungi_cfg = PungiConfig("MBS-512", "1", PungiSourceType.MODULE, + "testmodule:master:1:1") + pungi = Pungi(1, pungi_cfg) + pungi.run(self.compose) + + self.makedirs.assert_called_with( + AnyStringWith("test_composes/odcs-1/")) + self.makedirs.assert_called_with( + AnyStringWith("work/global")) + self.ci_dump.assert_called_once_with( + AnyStringWith("work/global/composeinfo-base.json")) + + execute_cmd.assert_called_once_with( + ['pungi-koji', AnyStringWith('pungi.conf'), + AnyStringWith('--compose-dir='), + '--%s' % (compose_type or "test")], + cwd=AnyStringWith('/tmp/'), timeout=3600, + stderr=AnyStringWith("pungi-stderr.log"), + stdout=AnyStringWith("pungi-stdout.log")) + + @patch("odcs.server.utils.execute_cmd") def test_pungi_run_raw_config(self, execute_cmd): def mocked_execute_cmd(*args, **kwargs): topdir = kwargs["cwd"] @@ -530,7 +558,7 @@ class TestPungi(ModelsBaseTest): execute_cmd.assert_called_once_with( ['pungi-koji', AnyStringWith('pungi.conf'), - AnyStringWith('--compose-dir='), '--nightly'], + AnyStringWith('--compose-dir='), '--test'], cwd=AnyStringWith('/tmp/'), timeout=7200, stderr=AnyStringWith("pungi-stderr.log"), stdout=AnyStringWith("pungi-stdout.log"))