| |
@@ -0,0 +1,167 @@
|
| |
+ import copy
|
| |
+ import json
|
| |
+ import logging
|
| |
+
|
| |
+ import pytest
|
| |
+ import fedora_messaging.api
|
| |
+ import fedora_messaging.config
|
| |
+
|
| |
+ from compose_tracker import Consumer
|
| |
+
|
| |
+
|
| |
+ EXAMPLE_MESSAGE_BODY = json.loads(
|
| |
+ """
|
| |
+ {
|
| |
+ "status": "DOOMED",
|
| |
+ "release_type": "ga",
|
| |
+ "compose_label": null,
|
| |
+ "compose_respin": 0,
|
| |
+ "compose_date": "20190619",
|
| |
+ "release_version": "Rawhide",
|
| |
+ "location": "https://kojipkgs.fedoraproject.org/compose/rawhide/Fedora-Rawhide-20190619.n.0/compose",
|
| |
+ "compose_type": "nightly",
|
| |
+ "release_is_layered": false,
|
| |
+ "release_name": "Fedora",
|
| |
+ "release_short": "Fedora",
|
| |
+ "compose_id": "Fedora-Rawhide-20190619.n.0"
|
| |
+ }
|
| |
+ """
|
| |
+ )
|
| |
+
|
| |
+ EXAMPLE_PUNGI_LOG_DOOMED = """2020-02-04 06:15:09 [INFO ] [BEGIN] ---------- PHASE: INIT ----------
|
| |
+ 2020-02-04 06:15:19 [INFO ] [DONE ] ---------- PHASE: INIT ----------
|
| |
+ 2020-02-04 06:15:20 [INFO ] [BEGIN] ---------- PHASE: WEAVER ----------
|
| |
+ 2020-02-04 06:15:21 [INFO ] [DONE ] ---------- PHASE: WEAVER ----------
|
| |
+ 2020-02-04 06:15:21 [INFO ] [BEGIN] ---------- PHASE: CREATEISO ----------
|
| |
+ 2020-02-04 06:35:39 [ERROR ] Compose run failed: ImageBuild task failed: 41350838. See /mnt/koji/compose/cloud/Fedora-Cloud-30-20200204.0/logs/aarch64-ppc64le-s390x-x86_64/imagebuild-Cloud-Cloud_Base-qcow2-raw-xz.aarch64-ppc64le-s390x-x86_64.log for more details.
|
| |
+ 2020-02-04 06:35:39 [ERROR ] Extended traceback in: /mnt/koji/compose/cloud/Fedora-Cloud-30-20200204.0/logs/global/traceback.global.log
|
| |
+ """
|
| |
+
|
| |
+ EXAMPLE_PUNGI_LOG_INCOMPLETE = """2020-02-04 05:59:24 [INFO ] [BEGIN] ---------- PHASE: OSTREE ----------
|
| |
+ 2020-02-04 06:03:08 [ERROR ] [FAIL] Ostree (variant Silverblue, arch x86_64) failed, but going on anyway.
|
| |
+ 2020-02-04 06:03:08 [ERROR ] Runroot task failed: 41350821. See /mnt/koji/compose/rawhide/Fedora-Rawhide-20200204.n.0/logs/x86_64/Silverblue/ostree-1/runroot.log for more details.
|
| |
+ 2020-02-04 06:03:40 [ERROR ] [FAIL] Ostree (variant Silverblue, arch ppc64le) failed, but going on anyway.
|
| |
+ 2020-02-04 06:03:40 [ERROR ] Runroot task failed: 41350822. See /mnt/koji/compose/rawhide/Fedora-Rawhide-20200204.n.0/logs/ppc64le/Silverblue/ostree-2/runroot.log for more details.
|
| |
+ 2020-02-04 06:04:44 [INFO ] [DONE ] ---------- PHASE: OSTREE ----------
|
| |
+ """
|
| |
+
|
| |
+
|
| |
+ def test_consumer_message_process(mocker, caplog):
|
| |
+ "Test that we can successfully process a message"
|
| |
+ mocker.patch("compose_tracker.PagureService")
|
| |
+ req = mocker.patch("compose_tracker.requests.get", autospec=True)
|
| |
+ text_mock = mocker.MagicMock()
|
| |
+ text_mock.text.splitlines.return_value = EXAMPLE_PUNGI_LOG_DOOMED.splitlines()
|
| |
+ req.return_value = text_mock
|
| |
+ mocker.patch(
|
| |
+ "compose_tracker.fedora_messaging.config.conf",
|
| |
+ fedora_messaging.config.conf.load_config("compose-tracker.toml"),
|
| |
+ )
|
| |
+ con = Consumer()
|
| |
+ msg = fedora_messaging.api.Message(
|
| |
+ topic="org.fedoraproject.prod.pungi.compose.status.change", body=EXAMPLE_MESSAGE_BODY,
|
| |
+ )
|
| |
+ con.process(msg)
|
| |
+ assert "Fedora-Rawhide-20190619.n.0 DOOMED" in caplog.text
|
| |
+
|
| |
+
|
| |
+ def test_consumer_settings_ignore_compose(mocker, caplog):
|
| |
+ "Test that we ignore the composes specified in the settings"
|
| |
+ mocker.patch("compose_tracker.PagureService")
|
| |
+ mocker.patch("compose_tracker.requests")
|
| |
+ mocker.patch(
|
| |
+ "compose_tracker.fedora_messaging.config.conf",
|
| |
+ {"consumer_config": {"composes_to_skip": ["IoT"]}},
|
| |
+ )
|
| |
+ con = Consumer()
|
| |
+ body = copy.copy(EXAMPLE_MESSAGE_BODY)
|
| |
+ body["compose_id"] = "Fedora-IoT-20190619.n.0"
|
| |
+ msg = fedora_messaging.api.Message(
|
| |
+ topic="org.fedoraproject.prod.pungi.compose.status.change", body=body,
|
| |
+ )
|
| |
+ con.process(msg)
|
| |
+ assert "Skipping filing issues for IoT composes" in caplog.text
|
| |
+
|
| |
+
|
| |
+ def test_consumer_settings_ignore_compose_2_values(mocker, caplog):
|
| |
+ "Test that we ignore the composes specified in the settings with 2 values"
|
| |
+ mocker.patch("compose_tracker.PagureService")
|
| |
+ mocker.patch("compose_tracker.requests")
|
| |
+ mocker.patch(
|
| |
+ "compose_tracker.fedora_messaging.config.conf",
|
| |
+ {"consumer_config": {"composes_to_skip": ["IoT", "Rawhide"]}},
|
| |
+ )
|
| |
+ con = Consumer()
|
| |
+ msg = fedora_messaging.api.Message(
|
| |
+ topic="org.fedoraproject.prod.pungi.compose.status.change", body=EXAMPLE_MESSAGE_BODY,
|
| |
+ )
|
| |
+ con.process(msg)
|
| |
+ assert "Skipping filing issues for Rawhide composes" in caplog.text
|
| |
+
|
| |
+
|
| |
+ def test_consumer_ignore_good_composes(mocker, caplog):
|
| |
+ "Test that we ignore the composes that finished correctly"
|
| |
+ mocker.patch("compose_tracker.PagureService")
|
| |
+ mocker.patch("compose_tracker.requests")
|
| |
+ mocker.patch(
|
| |
+ "compose_tracker.fedora_messaging.config.conf",
|
| |
+ fedora_messaging.config.conf.load_config("compose-tracker.toml"),
|
| |
+ )
|
| |
+ con = Consumer()
|
| |
+ body = copy.copy(EXAMPLE_MESSAGE_BODY)
|
| |
+ body["status"] = "FINISHED"
|
| |
+ msg = fedora_messaging.api.Message(
|
| |
+ topic="org.fedoraproject.prod.pungi.compose.status.change", body=body,
|
| |
+ )
|
| |
+ con.process(msg)
|
| |
+ assert "Fedora-Rawhide-20190619.n.0" not in caplog.text
|
| |
+
|
| |
+
|
| |
+ def test_consumer_logfile_time_parsing(mocker, caplog):
|
| |
+ "Test that the consumer correctly parses the time a compose takes"
|
| |
+
|
| |
+ mocker.patch("compose_tracker.PagureService")
|
| |
+
|
| |
+ # set logs at DEBUG and capture this level
|
| |
+ caplog.set_level(logging.DEBUG)
|
| |
+ mocker.patch("compose_tracker.logger.level", logging.DEBUG)
|
| |
+
|
| |
+ # mock the pungi.global.log file
|
| |
+ req = mocker.patch("compose_tracker.requests.get", autospec=True)
|
| |
+ text_mock = mocker.MagicMock()
|
| |
+ text_mock.text.splitlines.return_value = EXAMPLE_PUNGI_LOG_DOOMED.splitlines()
|
| |
+ req.return_value = text_mock
|
| |
+
|
| |
+ con = Consumer()
|
| |
+ msg = fedora_messaging.api.Message(
|
| |
+ topic="org.fedoraproject.prod.pungi.compose.status.change", body=EXAMPLE_MESSAGE_BODY,
|
| |
+ )
|
| |
+ con.process(msg)
|
| |
+ assert "- Compose run failed because: - [41350838]" in caplog.text
|
| |
+ assert "Compose Total time: 0:20:30" in caplog.text
|
| |
+ assert "Compose phase INIT time: 0:00:10." in caplog.text
|
| |
+ assert "Compose phase CREATEISO: FAILED." in caplog.text
|
| |
+
|
| |
+
|
| |
+ def test_consumer_logfile_parsing_failures(mocker, caplog):
|
| |
+ "Test that the consumer correctly parses the failures of a compose"
|
| |
+
|
| |
+ mocker.patch("compose_tracker.PagureService")
|
| |
+
|
| |
+ # set logs at DEBUG and capture this level
|
| |
+ caplog.set_level(logging.DEBUG)
|
| |
+ mocker.patch("compose_tracker.logger.level", logging.DEBUG)
|
| |
+
|
| |
+ # mock the pungi.global.log file
|
| |
+ req = mocker.patch("compose_tracker.requests.get", autospec=True)
|
| |
+ text_mock = mocker.MagicMock()
|
| |
+ text_mock.text.splitlines.return_value = EXAMPLE_PUNGI_LOG_INCOMPLETE.splitlines()
|
| |
+ req.return_value = text_mock
|
| |
+
|
| |
+ con = Consumer()
|
| |
+ msg = fedora_messaging.api.Message(
|
| |
+ topic="org.fedoraproject.prod.pungi.compose.status.change", body=EXAMPLE_MESSAGE_BODY,
|
| |
+ )
|
| |
+ con.process(msg)
|
| |
+ assert "Ostree (variant Silverblue, arch x86_64) failed, but going on anyway." in caplog.text
|
| |
+ assert "Ostree (variant Silverblue, arch ppc64le) failed, but going on anyway." in caplog.text
|
| |
This commits add the total time of a compose and the time for each phases of a compose in the ticket created.
This is committed on top of #28 since it introduced the unit test framework