From 4a6bbcbedb65c713334c09733672b1b6cc54cbf7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 14 2020 08:38:18 +0000 Subject: Ignore invalid messages sent by the CI system We have recently ran into at least two messages sent by the CI system that did not conform to the specifications and thus breaking toddlers. These two messages are: https://apps.fedoraproject.org/datagrepper/id?is_raw=true&size=extra-large&id=2020-7ae2f4fd-98a1-4c3b-9c43-f966f4699776 and https://apps.fedoraproject.org/datagrepper/id?is_raw=true&size=extra-large&id=2020-fbb9e244-0ab4-4cf1-b5cc-d9a8485a5e84 So we'll be ignoring them but still log it so we can potentially figure out what happened. Signed-off-by: Pierre-Yves Chibon --- diff --git a/tests/plugins/test_flag_ci_pr.py b/tests/plugins/test_flag_ci_pr.py index 768e6ae..2961ac6 100644 --- a/tests/plugins/test_flag_ci_pr.py +++ b/tests/plugins/test_flag_ci_pr.py @@ -115,6 +115,37 @@ class TestFlagCIPRToddler: caplog.records[-1].message == "Request to https://pagure.io returned: 401" ) + def test_process_msg_no_result(self, toddler, caplog): + toddler.requests_session.request.return_value = MagicMock( + ok=True, status_code=200, text="invalid" + ) + + caplog.set_level(logging.INFO) + msg = fedora_messaging.api.Message() + msg.id = 123 + msg.topic = "org.centos.stg.ci.dist-git-pr.test.error" + msg.body = { + "version": "0.2.1", + "test": {}, + "artifact": { + "id": 456, + "commit_hash": "abcdefghijklmnopqrst", + "repository": "https://host.c/namespace/name", + }, + "run": {"url": "https://example.com/testing"}, + } + config = { + "dist_git_token_seed": "example_seed", + "dist_git_url": "https://pagure.io", + "dist_git_token": "ahah", + } + + assert toddler.process(config=config, message=msg) is None + assert ( + caplog.records[-1].message + == "Invalid message send, no `result` in the `test` section, ignoring - id: 123" + ) + def test_process_valid(self, toddler, caplog): toddler.requests_session.request.return_value = MagicMock( ok=True, status_code=200, text="invalid" diff --git a/toddlers/plugins/flag_ci_pr.py b/toddlers/plugins/flag_ci_pr.py index e2f37d5..9ea551c 100644 --- a/toddlers/plugins/flag_ci_pr.py +++ b/toddlers/plugins/flag_ci_pr.py @@ -67,6 +67,13 @@ class FlagCIPR(ToddlerBase): _log.info("Unsupported msg version, ignoring") return + if "result" not in msg["test"]: + _log.info( + "Invalid message send, no `result` in the `test` section, ignoring - id: %s", + message.id, + ) + return + # test complete messages if pipeline_state == "complete": state = msg["test"]["result"]