Repository: fedora-infra/bodhi

Issue:
Include the releases in the message schema of updates
For the CI pipeline it would be helpful if `bodhi.update.status.testing` messages were to include the release information.

I was surprised that this was not already the case and I saw on datagrepper that quite a few messages actually already include this information (for example: https://apps.fedoraproject.org/datagrepper/id?id=2019-0612255c-501f-40e1-91b5-6026044cbea3&is_raw=true&size=extra-large) but I'm not seeing it in the message schema.

Could we either fix the message schema in all places or at least for `bodhi.update.status.testing` messages?

Thanks


Discussion:
@abompard Is this something you could look into?
All the update messages include the Update model, so if a release is defined for an update, it is typically included.

In fact, bodhi.update.status.testing (i.e. UpdateReadyForTestingV1) actually includes this information, this is the message that is returned by the test_models.py:test_set_status_testing test:

```
{
  'update': {
    'autokarma': True,
    'autotime': True,
    'stable_karma': 3,
    'stable_days': 0,
    'unstable_karma': -3,
    'requirements': None,
    'require_bugs': False,
    'require_testcases': False,
    'display_name': '',
    'notes': 'foobar',
    'type': 'security',
    'status': 'testing',
    'request': 'testing',
    'severity': 'medium',
    'suggest': 'reboot',
    'locked': False,
    'pushed': False,
    'critpath': False,
    'close_bugs': True,
    'date_submitted': '2019-10-03 23:41:15',
    'date_modified': None,
    'date_approved': None,
    'date_pushed': None,
    'date_testing': None,
    'date_stable': None,
    'alias': 'FEDORA-2019-e7ea91bf16',
    'test_gating_status': None,
    'from_tag': None,
    'meets_testing_requirements': False,
    'url': 'http://0.0.0.0:6543/updates/FEDORA-2019-e7ea91bf16',
    'title': 'TurboGears-1.0.8-3.fc11',
    'release': {
      'name': 'F11',
      'long_name': 'Fedora 11',
      'version': '11',
      'id_prefix': 'FEDORA',
      'branch': 'f11',
      'dist_tag': 'dist-f11',
      'stable_tag': 'dist-f11-updates',
      'testing_tag': 'dist-f11-updates-testing',
      'candidate_tag': 'dist-f11-updates-candidate',
      'pending_signing_tag': 'dist-f11-updates-testing-signing',
      'pending_testing_tag': 'dist-f11-updates-testing-pending',
      'pending_stable_tag': 'dist-f11-updates-pending',
      'override_tag': 'dist-f11-override',
      'mail_template': 'fedora_errata_template',
      'state': 'current',
      'composed_by_bodhi': True,
      'create_automatic_updates': False,
      'package_manager': 'yum',
      'testing_repository': 'updates-testing',
      'composes': []
    },
    'comments': [],
    'builds': [{
      'nvr': 'TurboGears-1.0.8-3.fc11',
      'release_id': 1,
      'signed': False,
      'type': 'rpm',
      'epoch': 0
    }],
    'compose': None,
    'bugs': [{
      'bug_id': 1,
      'title': None,
      'security': False,
      'parent': False,
      'feedback': []
    }, {
      'bug_id': 2,
      'title': None,
      'security': False,
      'parent': False,
      'feedback': []
    }],
    'user': {
      'id': 1,
      'name': 'lmacken',
      'email': None,
      'avatar': None,
      'openid': None,
      'groups': []
    },
    'updateid': 'FEDORA-2019-e7ea91bf16',
    'karma': 0,
    'content_type': 'rpm',
    'test_cases': []
  },
  'agent': 'bodhi',
  're-trigger': False
}
```


Resolving patch:
diff --git a/bodhi/messages/schemas/base.py b/bodhi/messages/schemas/base.py
--- a/bodhi/messages/schemas/base.py
+++ b/bodhi/messages/schemas/base.py
@@ -173,6 +173,32 @@ def schema() -> dict:
         }
 
 
+class ReleaseV1(typing.NamedTuple):
+    """
+    A model for referencing a Release.
+
+    Attributes:
+        name: The name of the release.
+    """
+
+    name: str
+
+    @staticmethod
+    def schema() -> dict:
+        """Return a schema snippet for a Build."""
+        return {
+            'type': 'object',
+            'description': 'A release',
+            'properties': {
+                'name': {
+                    'type': 'string',
+                    'description': 'The name of the release e.g. F32'
+                },
+            },
+            'required': ['name']
+        }
+
+
 class UpdateV1(typing.NamedTuple):
     """
     A model for referencing an Update object.
@@ -187,6 +213,7 @@ class UpdateV1(typing.NamedTuple):
     user: 'UserV1'
     status: str
     request: typing.Union[None, str]
+    release: 'ReleaseV1'
 
     @property
     def packages(self) -> typing.Iterable[str]:
@@ -209,6 +236,7 @@ def schema() -> dict:
                     'description': 'A list of builds included in this update',
                     'items': {'$ref': '#/definitions/build'}
                 },
+                'release': ReleaseV1.schema(),
                 'request': {
                     'type': ['null', 'string'],
                     'description': 'The request of the update, if any',
@@ -222,7 +250,7 @@ def schema() -> dict:
                 },
                 'user': UserV1.schema(),
             },
-            'required': ['alias', 'builds', 'request', 'status', 'user']
+            'required': ['alias', 'builds', 'release', 'request', 'status', 'user']
         }
 
 
diff --git a/bodhi/messages/schemas/errata.py b/bodhi/messages/schemas/errata.py
--- a/bodhi/messages/schemas/errata.py
+++ b/bodhi/messages/schemas/errata.py
@@ -23,7 +23,7 @@
 
 import typing
 
-from .base import BodhiMessage, BuildV1, SCHEMA_URL, UpdateV1, UserV1
+from .base import BodhiMessage, BuildV1, ReleaseV1, SCHEMA_URL, UpdateV1, UserV1
 
 
 class ErrataPublishV1(BodhiMessage):
@@ -109,5 +109,5 @@ def update(self) -> UpdateV1:
                 self.body['update']['alias'],
                 [BuildV1(b['nvr']) for b in self.body['update']['builds']],
                 UserV1(self.body['update']['user']['name']), self.body['update']['status'],
-                self.body['update']['request'])
+                self.body['update']['request'], ReleaseV1(self.body['update']['release']['name']))
         return self._update
diff --git a/bodhi/messages/schemas/update.py b/bodhi/messages/schemas/update.py
--- a/bodhi/messages/schemas/update.py
+++ b/bodhi/messages/schemas/update.py
@@ -23,7 +23,7 @@
 
 import typing
 
-from .base import BodhiMessage, BuildV1, SCHEMA_URL, UpdateV1, UserV1
+from .base import BodhiMessage, BuildV1, ReleaseV1, SCHEMA_URL, UpdateV1, UserV1
 from ..utils import truncate
 
 
@@ -48,7 +48,7 @@ def update(self) -> UpdateV1:
             self._update_obj = UpdateV1(
                 self._update['alias'], [BuildV1(b['nvr']) for b in self._update['builds']],
                 UserV1(self._update['user']['name']), self._update['status'],
-                self._update['request'])
+                self._update['request'], ReleaseV1(self._update['release']['name']))
         return self._update_obj
 
     @property


Test patch:
diff --git a/bodhi/tests/messages/schemas/test_errata.py b/bodhi/tests/messages/schemas/test_errata.py
--- a/bodhi/tests/messages/schemas/test_errata.py
+++ b/bodhi/tests/messages/schemas/test_errata.py
@@ -17,7 +17,7 @@
 
 import unittest
 
-from bodhi.messages.schemas.errata import BuildV1, ErrataPublishV1, UpdateV1, UserV1
+from bodhi.messages.schemas.errata import BuildV1, ErrataPublishV1, ReleaseV1, UpdateV1, UserV1
 from bodhi.tests.messages.utils import check_message
 
 
@@ -40,7 +40,8 @@ def test_publish_v1(self):
             'agent': 'test_submitter',
             'update': UpdateV1(
                 "FEDORA-2019-4cc36fafbb",
-                [BuildV1('tzdata-2014i-1.fc19')], UserV1('test_submitter'), 'pending', 'testing'),
+                [BuildV1('tzdata-2014i-1.fc19')], UserV1('test_submitter'),
+                'pending', 'testing', ReleaseV1('F19')),
         }
         msg = ErrataPublishV1(
             body={
diff --git a/bodhi/tests/messages/schemas/test_update.py b/bodhi/tests/messages/schemas/test_update.py
--- a/bodhi/tests/messages/schemas/test_update.py
+++ b/bodhi/tests/messages/schemas/test_update.py
@@ -17,7 +17,7 @@
 
 import unittest
 
-from bodhi.messages.schemas.base import BuildV1, UpdateV1, UserV1
+from bodhi.messages.schemas.base import BuildV1, ReleaseV1, UpdateV1, UserV1
 from bodhi.messages.schemas.update import (
     UpdateCommentV1,
     UpdateCompleteStableV1,
@@ -57,7 +57,7 @@ def test_eject_v1(self):
             "packages": ["xstream"],
             'repo': 'test_repo',
             'update': UpdateV1('FEDORA-2019-2b055f8870', [BuildV1('xstream-1.4.11.1-2.fc30')],
-                               UserV1('mbooth'), 'testing', None)
+                               UserV1('mbooth'), 'testing', None, ReleaseV1('F30'))
         }
         msg = UpdateEjectV1(
             body={
@@ -69,6 +69,7 @@ def test_eject_v1(self):
                         "epoch": 0, "ci_url": None, "type": "rpm"}],
                     "locked": True,
                     "title": "xstream-1.4.11.1-2.fc30",
+                    "release": {"name": "F30"},
                     'request': None,
                     "status": "testing",
                     'user': {'name': 'mbooth'}
@@ -105,7 +106,7 @@ def test_complete_stable_v1(self):
                 'FEDORA-2019-d64d0caab3',
                 [BuildV1('golang-github-SAP-go-hdb-0.14.1-1.fc29'),
                  BuildV1('texworks-0.6.3-1.fc29')],
-                UserV1('eclipseo'), 'stable', None)
+                UserV1('eclipseo'), 'stable', None, ReleaseV1('F29'))
         }
         msg = UpdateCompleteStableV1(
             body={
@@ -114,6 +115,7 @@ def test_complete_stable_v1(self):
                     "builds": [{"nvr": "golang-github-SAP-go-hdb-0.14.1-1.fc29"},
                                {'nvr': 'texworks-0.6.3-1.fc29'}],
                     "title": "fedmsg-0.2.7-2.el6",
+                    'release': {"name": "F29"},
                     'request': None,
                     "status": "stable",
                     "user": {"name": "eclipseo"}
@@ -143,7 +145,7 @@ def test_complete_testing_v1(self):
                 'FEDORA-2019-d64d0caab3',
                 [BuildV1('golang-github-SAP-go-hdb-0.14.1-1.fc29'),
                  BuildV1('texworks-0.6.3-1.fc29')],
-                UserV1('eclipseo'), 'testing', None)
+                UserV1('eclipseo'), 'testing', None, ReleaseV1('F29'))
         }
         msg = UpdateCompleteTestingV1(
             body={
@@ -152,6 +154,7 @@ def test_complete_testing_v1(self):
                     "builds": [{"nvr": "golang-github-SAP-go-hdb-0.14.1-1.fc29"},
                                {'nvr': 'texworks-0.6.3-1.fc29'}],
                     "title": "fedmsg-0.2.7-2.el6",
+                    'release': {"name": "F29"},
                     'request': None,
                     "status": "testing",
                     "user": {"name": "eclipseo"}
@@ -181,7 +184,7 @@ def test_ready_for_testing_v1(self):
                 'FEDORA-2019-d64d0caab3',
                 [BuildV1('golang-github-SAP-go-hdb-0.14.1-1.fc29'),
                  BuildV1('texworks-0.6.3-1.fc29')],
-                UserV1('eclipseo'), 'testing', None)
+                UserV1('eclipseo'), 'testing', None, ReleaseV1('F29'))
         }
         msg = UpdateReadyForTestingV1(
             body={
@@ -190,6 +193,7 @@ def test_ready_for_testing_v1(self):
                     "builds": [{"nvr": "golang-github-SAP-go-hdb-0.14.1-1.fc29"},
                                {'nvr': 'texworks-0.6.3-1.fc29'}],
                     "title": "fedmsg-0.2.7-2.el6",
+                    'release': {"name": "F29"},
                     'request': None,
                     "status": "testing",
                     "user": {"name": "eclipseo"}
@@ -216,7 +220,7 @@ def test_request_testing_v1_multiple(self):
                 'FEDORA-2019-f1ca3c00e5',
                 [BuildV1('gnome-settings-daemon-3.6.1-1.fc18'),
                  BuildV1('control-center-3.6.1-1.fc18')],
-                UserV1('hadess'), 'pending', 'testing')
+                UserV1('hadess'), 'pending', 'testing', ReleaseV1('F18'))
         }
         msg = UpdateRequestTestingV1(
             body={
@@ -328,7 +332,7 @@ def test_request_unpush_v1(self):
             "packages": ["python-operator-courier"],
             'update': UpdateV1(
                 'FEDORA-2019-8da6360454', [BuildV1('python-operator-courier-1.2.0-1.fc28')],
-                UserV1('ralph'), 'unpushed', None)
+                UserV1('ralph'), 'unpushed', None, ReleaseV1('F28'))
         }
         msg = UpdateRequestUnpushV1(
             body={
@@ -336,6 +340,7 @@ def test_request_unpush_v1(self):
                 'update': {
                     "alias": "FEDORA-2019-8da6360454",
                     "builds": [{'nvr': 'python-operator-courier-1.2.0-1.fc28'}],
+                    "release": {"name": "F28"},
                     'request': None,
                     "status": "unpushed",
                     "user": {"name": "ralph"}
@@ -359,7 +364,7 @@ def test_request_obsolete_v1(self):
             "packages": ["golang-github-SAP-go-hdb"],
             'update': UpdateV1(
                 'FEDORA-2019-d64d0caab3', [BuildV1('golang-github-SAP-go-hdb-0.14.1-1.fc29')],
-                UserV1('eclipseo'), 'testing', None)
+                UserV1('eclipseo'), 'testing', None, ReleaseV1('F29'))
         }
         msg = UpdateRequestObsoleteV1(
             body={
@@ -368,6 +373,7 @@ def test_request_obsolete_v1(self):
                     "alias": "FEDORA-2019-d64d0caab3",
                     "builds": [{"nvr": "golang-github-SAP-go-hdb-0.14.1-1.fc29"}],
                     "title": "golang-github-SAP-go-hdb-0.14.1-1.fc29",
+                    'release': {"name": "F29"},
                     'request': None,
                     "status": "testing",
                     "user": {"name": "eclipseo"}
@@ -391,7 +397,7 @@ def test_request_stable_v1(self):
             "packages": ["golang-github-SAP-go-hdb"],
             'update': UpdateV1(
                 'FEDORA-2019-d64d0caab3', [BuildV1('golang-github-SAP-go-hdb-0.14.1-1.fc29')],
-                UserV1('eclipseo'), 'testing', 'stable')
+                UserV1('eclipseo'), 'testing', 'stable', ReleaseV1('F29'))
         }
         msg = UpdateRequestStableV1(
             body={
@@ -399,6 +405,7 @@ def test_request_stable_v1(self):
                 'update': {
                     "alias": "FEDORA-2019-d64d0caab3",
                     "builds": [{"nvr": "golang-github-SAP-go-hdb-0.14.1-1.fc29"}],
+                    "release": {"name": "F29"},
                     'request': 'stable',
                     "status": "testing",
                     "user": {"name": "eclipseo"}
@@ -422,7 +429,7 @@ def test_request_revoke_v1(self):
             "packages": ["golang-github-SAP-go-hdb"],
             'update': UpdateV1(
                 'FEDORA-2019-d64d0caab3', [BuildV1('golang-github-SAP-go-hdb-0.14.1-1.fc29')],
-                UserV1('eclipseo'), 'testing', None)
+                UserV1('eclipseo'), 'testing', None, ReleaseV1('F29'))
         }
         msg = UpdateRequestRevokeV1(
             body={
@@ -430,6 +437,7 @@ def test_request_revoke_v1(self):
                 'update': {
                     "alias": "FEDORA-2019-d64d0caab3",
                     "builds": [{"nvr": "golang-github-SAP-go-hdb-0.14.1-1.fc29"}],
+                    "release": {"name": "F29"},
                     'request': None,
                     "status": "testing",
                     "user": {"name": "eclipseo"}
@@ -454,7 +462,7 @@ def test_request_testing_v1(self):
             'update': UpdateV1(
                 'FEDORA-2019-f1ca3c00e5',
                 [BuildV1('golang-github-Masterminds-semver-2.0.0-0.1.20190319git3c92f33.fc29')],
-                UserV1('eclipseo'), 'pending', 'testing')
+                UserV1('eclipseo'), 'pending', 'testing', ReleaseV1('F29'))
         }
         msg = UpdateRequestTestingV1(
             body={
@@ -464,6 +472,7 @@ def test_request_testing_v1(self):
                     "builds": [{
                         "nvr": "golang-github-Masterminds-semver-2.0.0-0.1.20190319git3c92f33.fc29"
                     }],
+                    "release": {"name": "F29"},
                     'request': 'testing',
                     "status": "pending",
                     "user": {"name": "eclipseo"}
@@ -484,7 +493,7 @@ def test_requirements_met_stable_v1(self):
             'update': UpdateV1(
                 'FEDORA-2019-f1ca3c00e5',
                 [BuildV1('golang-github-Masterminds-semver-2.0.0-0.1.20190319git3c92f33.fc29')],
-                UserV1('eclipseo'), 'pending', 'testing')
+                UserV1('eclipseo'), 'pending', 'testing', ReleaseV1('F29'))
         }
         msg = UpdateRequirementsMetStableV1(
             body={
@@ -493,6 +502,7 @@ def test_requirements_met_stable_v1(self):
                     "builds": [{
                         "nvr": "golang-github-Masterminds-semver-2.0.0-0.1.20190319git3c92f33.fc29"
                     }],
+                    "release": {"name": "F29"},
                     'request': 'testing',
                     "status": "pending",
                     "user": {"name": "eclipseo"}
@@ -524,7 +534,7 @@ def test_comment_v1(self):
             'update': UpdateV1(
                 'FEDORA-EPEL-2019-f2d195dada',
                 [BuildV1("abrt-addon-python3-2.1.11-50.el7"), BuildV1("asciinema-1.4.0-2.el7")],
-                UserV1('tdawson'), 'pending', 'testing'),
+                UserV1('tdawson'), 'pending', 'testing', ReleaseV1('F29')),
             'agent': 'ralph',
         }
         msg = UpdateCommentV1(
@@ -540,6 +550,7 @@ def test_comment_v1(self):
                         'builds': [{'nvr': 'abrt-addon-python3-2.1.11-50.el7'},
                                    {'nvr': 'asciinema-1.4.0-2.el7'}],
                         'status': 'pending',
+                        "release": {"name": "F29"},
                         'request': 'testing',
                         'user': {"name": "tdawson"}},
                     'user': {'name': 'ralph'}
@@ -563,7 +574,7 @@ def test_edit_v1(self):
             "usernames": ["ralph"],
             "packages": ["tzdata"],
             'update': UpdateV1('FEDORA-2019-7dbbb74a13', [BuildV1('tzdata-2014i-1.fc19')],
-                               UserV1('ralph'), 'pending', 'testing')
+                               UserV1('ralph'), 'pending', 'testing', ReleaseV1('F19'))
         }
         msg = UpdateEditV1(
             body={
@@ -654,7 +665,7 @@ def test_karma_threshold_v1(self):
             "usernames": ['ralph'],
             "packages": ["tzdata"],
             'update': UpdateV1('FEDORA-EPEL-2015-0238', [BuildV1('tzdata-2014i-1.fc19')],
-                               UserV1('ralph'), 'pending', 'testing'),
+                               UserV1('ralph'), 'pending', 'testing', ReleaseV1('F19')),
             'status': 'stable'
         }
         msg = UpdateKarmaThresholdV1(
diff --git a/bodhi/tests/server/test_models.py b/bodhi/tests/server/test_models.py
--- a/bodhi/tests/server/test_models.py
+++ b/bodhi/tests/server/test_models.py
@@ -4250,6 +4250,7 @@ def test_set_status_testing(self):
             msg = self.db.info['messages'][0]
             self.db.commit()
         assert msg.body["update"]["status"] == "testing"
+        assert msg.body["update"]["release"]["name"] == "F11"
 
     def test_create_with_status_testing(self):
         """Test that creating an update with the status set to testing sends a message."""
@@ -4263,6 +4264,7 @@ def test_create_with_status_testing(self):
             msg = self.db.info['messages'][0]
             self.db.commit()
         assert msg.body["update"]["status"] == "testing"
+        assert msg.body["update"]["release"]["name"] == "F11"
 
 
 class TestUser(ModelTest):