Repository: fedora-infra/bodhi

Issue:
Greenwave consumer should not process the compose results
Currently the greenwave consumer consumes all the messages from `topic=org.fedoraproject.prod.greenwave.decision.update` but some messages on this topic are related to compose results and not koji build.

The consumer should filter the messages based on the `subject_type`, and only process `koji_build` type.

See a koji_build example https://apps.fedoraproject.org/datagrepper/id?id=2019-efb310ed-6acf-4742-809f-90a40c2a5855&is_raw=true&size=extra-large

And a compose example https://apps.fedoraproject.org/datagrepper/id?id=2019-33002e05-241c-4180-8953-5a29cea4443d&is_raw=true&size=extra-large

This is currently raising the following exception in production : 
``` 2019-07-26 15:16:55,501 ERROR [bodhi.server][PoolThread-twisted.internet.reactor-0] Bodhi failed to send POST request to Greenwave at the following URL "https://greenwave-web-greenwave.app.os.fedoraproject.org/api/v1.0/decision". The status code was "502". The error was "{'message': 'Failed to retrieve SCM URL from Koji build "Fedora-Workstation-Rawhide-20190726.n.0" at "https://koji.fedoraproject.org/kojihub" (expected SCM URL in "source" attribute)'}". ```


Discussion:
Definitely :+1:  on the idea
We may need to be careful (ie: double-check) on the impact this may have. It seems it is still not 100% clear if some fields are required or not, cf:
- https://src.fedoraproject.org/rpms/python-virtualenv/pull-request/10
- https://pagure.io/fedora-ci/docs/issue/30

Resolving patch:
diff --git a/bodhi/server/consumers/greenwave.py b/bodhi/server/consumers/greenwave.py
--- a/bodhi/server/consumers/greenwave.py
+++ b/bodhi/server/consumers/greenwave.py
@@ -56,6 +56,11 @@ def __call__(self, message: fedora_messaging.api.Message):
             log.debug("Couldn't find subject_identifier in Greenwave message")
             return
 
+        subject_type = msg.get("subject_type")
+        if subject_type == "compose":
+            log.debug("Not requesting a decision for a compose")
+            return
+
         with self.db_factory():
 
             build = Build.get(subject_identifier)


Test patch:
diff --git a/bodhi/tests/server/consumers/test_greenwave.py b/bodhi/tests/server/consumers/test_greenwave.py
--- a/bodhi/tests/server/consumers/test_greenwave.py
+++ b/bodhi/tests/server/consumers/test_greenwave.py
@@ -34,7 +34,7 @@ def setUp(self):
         super().setUp()
         self.sample_message = Message(
             topic="org.fedoraproject.prod.greenwave.decision.update",
-            body={"subject_identifier": "bodhi-2.0-1.fc17"},
+            body={"subject_identifier": "bodhi-2.0-1.fc17", "subject_type": "koji_build"},
         )
         self.handler = greenwave.GreenwaveHandler()
 
@@ -94,3 +94,12 @@ def test_greenwave_wrong_build_nvr(self, mock_log):
         self.handler(self.sample_message)
         self.assertEqual(mock_log.debug.call_count, 1)
         mock_log.debug.assert_called_with("Couldn't find build notapackage-2.0-1.fc17 in DB")
+
+    @mock.patch('bodhi.server.consumers.greenwave.log')
+    def test_greenwave_compose_subject_type(self, mock_log):
+        """ Assert that the consumer ignores messages with subject_type equal to compose """
+
+        self.sample_message.body["subject_type"] = "compose"
+        self.handler(self.sample_message)
+        self.assertEqual(mock_log.debug.call_count, 1)
+        mock_log.debug.assert_called_with("Not requesting a decision for a compose")