Repository: fedora-infra/bodhi

Issue:
Update emails still include boilerplate info for "yum" rather than "dnf"
Scott Dowdle [reported in Red Hat's Bugzilla](https://bugzilla.redhat.com/show_bug.cgi?id=1375701) that Fedora update e-mails still reference `yum` instead of `dnf`:

```
I wasn't sure which Component to file against as I did not notice email mentioned anywhere.

Here's a sample email I got today to illustrate the issue:

- - - - - start - - - - 

--------------------------------------------------------------------------------
Fedora Update Notification
FEDORA-2016-5e40d80b1c
2016-09-13 18:03:12.623848
--------------------------------------------------------------------------------

Name        : livecd-tools
Product     : Fedora 25
Version     : 23.4
Release     : 1.fc25
URL         : https://github.com/rhinstaller/livecd-tools
Summary     : Tools for building live CDs
Description :
Tools for generating live CDs on Fedora based systems including
derived distributions such as RHEL, CentOS and others. See
http://fedoraproject.org/wiki/FedoraLiveCD for more details.

--------------------------------------------------------------------------------
Update Information:

- Version 23.4 (bcl) - yuminst.LiveCDYum.runInstall: import yum.Errors
(sandro.bonazzola) - Wrap all parted calls in LC_ALL=C (#1350253) (bcl) - Fix
calling livecd-iso-to-pxeboot with a full path (cadegenn) - Stop truncating
/etc/resolv.conf in SELinux module -- fixes #31 (torrancew) - litp: Copy
ldlinux.c32 to tftpboot for PXE live setup. (bcl) - Always use rsync to copy
Packages (#1343645) (bcl) - Fix extended regular expression [0-9] (fgrose) -
Enable loop device as installation target (fgrose)
--------------------------------------------------------------------------------
References:

  [ 1 ] Bug #1350253 - livecd-iso-to-disk fails using a non English locale
        https://bugzilla.redhat.com/show_bug.cgi?id=1350253
  [ 2 ] Bug #1343645 - livecd-iso-to-disk states "/Packages found, will copy source packages to target", but does not
        https://bugzilla.redhat.com/show_bug.cgi?id=1343645
--------------------------------------------------------------------------------

This update can be installed with the "yum" update program. Use
su -c 'yum update livecd-tools' at the command line.
For more information, refer to "Managing Software with yum",
available at https://docs.fedoraproject.org/yum/.

All packages are signed with the Fedora Project GPG key.  More details on the
GPG keys used by the Fedora Project can be found at
https://fedoraproject.org/keys
--------------------------------------------------------------------------------

- - - - - end - - - - -
```

We should fix this, but we should also make sure that EPEL <= 7 updates continue to reference `yum` when we fix it.



Discussion:
I would like to try to fix this, as I was about to take a look around and try to fix #882 and this could be done both together.

That would be fantastic @k3rn3l3rr0r. Would you mind making sure they are fixed in two separate commits so they are each atomic? Thanks!

@bowlofeggs I will do my best... And will try to remember your passion for atomic commits. :)

@k3rn3l3rr0r haha, thanks!


Resolving patch:
diff --git a/bodhi/server/mail.py b/bodhi/server/mail.py
--- a/bodhi/server/mail.py
+++ b/bodhi/server/mail.py
@@ -252,12 +252,12 @@
 
 --------------------------------------------------------------------------------
 %(notes)s%(changelog)s%(references)s
-This update can be installed with the "yum" update program. Use
-su -c 'yum%(yum_repository)s update %(name)s' at the command line.
-For more information, refer to "Managing Software with yum",
-available at https://docs.fedoraproject.org/yum/.
+This update can be installed with the "dnf" update program. Use
+su -c 'dnf%(yum_repository)s upgrade %(name)s' at the command line.
+For more information, refer to the dnf documentation available at
+http://dnf.readthedocs.io/en/latest/command_ref.html#upgrade-command-label
 
-All packages are signed with the Fedora Project GPG key.  More details on the
+All packages are signed with the Fedora Project GPG key. More details on the
 GPG keys used by the Fedora Project can be found at
 https://fedoraproject.org/keys
 --------------------------------------------------------------------------------
@@ -279,12 +279,43 @@
 Description :
 %(description)s
 
+--------------------------------------------------------------------------------
+%(notes)s%(changelog)s%(references)s
+This update can be installed with the "dnf" update programs.  Use
+su -c 'dnf%(yum_repository)s upgrade %(name)s' at the command line.
+For more information, refer to the dnf documentation available at
+http://dnf.readthedocs.io/en/latest/command_ref.html#upgrade-command-label
+
+All packages are signed with the Fedora EPEL GPG key. More details on the
+GPG keys used by the Fedora Project can be found at
+https://fedoraproject.org/keys
+--------------------------------------------------------------------------------
+"""
+
+# message template for legacy systems, still pointing users to use "yum"
+fedora_epel_legacy_errata_template = u"""\
+--------------------------------------------------------------------------------
+Fedora EPEL%(testing)s Update Notification
+%(updateid)s
+%(date)s
+--------------------------------------------------------------------------------
+
+Name        : %(name)s
+Product     : %(product)s
+Version     : %(version)s
+Release     : %(release)s
+URL         : %(url)s
+Summary     : %(summary)s
+Description :
+%(description)s
+
 --------------------------------------------------------------------------------
 %(notes)s%(changelog)s%(references)s
 This update can be installed with the "yum" update programs.  Use
 su -c 'yum%(yum_repository)s update %(name)s' at the command line.
-For more information, refer to "Managing Software with yum",
-available at https://docs.fedoraproject.org/yum/.
+For more information, refer to "YUM", available at
+https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7\
+/html/System_Administrators_Guide/ch-yum.html
 
 All packages are signed with the Fedora EPEL GPG key.  More details on the
 GPG keys used by the Fedora Project can be found at
diff --git a/bodhi/server/models/models.py b/bodhi/server/models/models.py
--- a/bodhi/server/models/models.py
+++ b/bodhi/server/models/models.py
@@ -1247,7 +1247,13 @@ def send_update_notice(self):
             mailinglist = config.get('%s_announce_list' % release_name)
         elif self.status is UpdateStatus.testing:
             mailinglist = config.get('%s_test_announce_list' % release_name)
-        templatetype = '%s_errata_template' % release_name
+        
+        # switch email template to legacy if update aims to EPEL <= 7
+        if release_name == 'fedora_epel' and self.release.version_int <= 7:
+            templatetype = '%s_errata_legacy_template' % release_name
+        else:
+            templatetype = '%s_errata_template' % release_name
+
         if mailinglist:
             for subject, body in mail.get_template(self, templatetype):
                 mail.send_mail(sender, mailinglist, subject, body)
@@ -1257,6 +1263,7 @@ def send_update_notice(self):
             log.error("Cannot find mailing list address for update notice")
             log.error("release_name = %r", release_name)
 
+
     def get_url(self):
         """ Return the relative URL to this update """
         path = ['updates']


Test patch:
diff --git a/bodhi/tests/server/models/test_models.py b/bodhi/tests/server/models/test_models.py
--- a/bodhi/tests/server/models/test_models.py
+++ b/bodhi/tests/server/models/test_models.py
@@ -598,6 +598,44 @@ def test_expand_messages(self):
         for value in mail.MESSAGES.values():
             value['body'] % value['fields']('guest', self.obj)
 
+    @mock.patch('bodhi.server.mail.get_template')
+    def test_send_update_notice_message_template(self, get_template):
+        """Ensure update message template reflects aimed distribution"""
+        update = self.obj
+        update.status = UpdateStatus.stable
+        update.send_update_notice()
+        get_template.assert_called_with(update, u'fedora_errata_template')
+
+        update = self.get_update(name=u'TurboGears-3.1-1.el7')
+        release = model.Release(name=u'EL-7', long_name=u'Fedora EPEL 7',
+                          id_prefix=u'FEDORA-EPEL', dist_tag=u'dist-7E-epel',
+                          stable_tag=u'dist-7E-epel',
+                          testing_tag=u'dist-7E-epel-testing',
+                          candidate_tag=u'dist-7E-epel-testing-candidate',
+                          pending_testing_tag=u'dist-7E-epel-testing-pending',
+                          pending_stable_tag=u'dist-7E-epel-pending',
+                          override_tag=u'dist-7E-epel-override',
+                          branch=u'el7', version=u'7')
+        update.release = release
+        update.status = UpdateStatus.stable
+        update.send_update_notice()
+        get_template.assert_called_with(update, u'fedora_epel_errata_legacy_template')
+
+        update = self.get_update(name=u'TurboGears-4.1-1.el8')
+        release = model.Release(name=u'EL-8', long_name=u'Fedora EPEL 8',
+                          id_prefix=u'FEDORA-EPEL', dist_tag=u'dist-8E-epel',
+                          stable_tag=u'dist-8E-epel',
+                          testing_tag=u'dist-8E-epel-testing',
+                          candidate_tag=u'dist-8E-epel-testing-candidate',
+                          pending_testing_tag=u'dist-8E-epel-testing-pending',
+                          pending_stable_tag=u'dist-8E-epel-pending',
+                          override_tag=u'dist-8E-epel-override',
+                          branch=u'el8', version=u'8')
+        update.release = release
+        update.status = UpdateStatus.stable
+        update.send_update_notice()
+        get_template.assert_called_with(update, u'fedora_epel_errata_template')
+
 
 class TestUser(ModelTest):
     klass = model.User