From caac9797084db127453ddb95edd79b50a131e5cf Mon Sep 17 00:00:00 2001 From: Jan Kaluža Date: Apr 26 2019 09:01:48 +0000 Subject: Merge #270 `Log Pungi stderr/stdout to logs in compose directory.` --- diff --git a/server/odcs/server/pungi.py b/server/odcs/server/pungi.py index 8adbf6c..83039ee 100644 --- a/server/odcs/server/pungi.py +++ b/server/odcs/server/pungi.py @@ -426,8 +426,15 @@ class Pungi(object): self._write_cfgs(td) compose_dir = self._prepare_compose_dir(td, conf.target_dir) pungi_cmd = self.get_pungi_cmd(td, conf.target_dir, compose_dir) - odcs.server.utils.execute_cmd(pungi_cmd, cwd=td, - timeout=conf.pungi_timeout) + + log_out_path = os.path.join(compose_dir, "pungi-stdout.log") + log_err_path = os.path.join(compose_dir, "pungi-stderr.log") + + with open(log_out_path, "w") as log_out: + with open(log_err_path, "w") as log_err: + odcs.server.utils.execute_cmd( + pungi_cmd, cwd=td, timeout=conf.pungi_timeout, + stdout=log_out, stderr=log_err) finally: try: if td is not None: diff --git a/server/odcs/server/views.py b/server/odcs/server/views.py index b5627bc..524869b 100644 --- a/server/odcs/server/views.py +++ b/server/odcs/server/views.py @@ -176,7 +176,7 @@ class ODCSAPI(MethodView): db.session.commit() if CELERY_AVAILABLE and conf.celery_broker_url: - if source_type == PungiSourceType.PULP: + if compose.source_type == PungiSourceType.PULP: generate_pulp_compose.delay(compose.id) else: generate_pungi_compose.delay(compose.id) diff --git a/server/tests/test_pungi.py b/server/tests/test_pungi.py index 3608e53..414f939 100644 --- a/server/tests/test_pungi.py +++ b/server/tests/test_pungi.py @@ -369,7 +369,9 @@ class TestPungi(unittest.TestCase): execute_cmd.assert_called_once_with( ['pungi-koji', AnyStringWith('pungi.conf'), AnyStringWith('--compose-dir='), '--nightly'], - cwd=AnyStringWith('/tmp/'), timeout=3600) + 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): diff --git a/server/tests/utils.py b/server/tests/utils.py index 44e1f81..5840048 100644 --- a/server/tests/utils.py +++ b/server/tests/utils.py @@ -36,7 +36,7 @@ from mock import patch class AnyStringWith(str): def __eq__(self, other): - return self in other + return self in str(other) class ConfigPatcher(object):