Repository: fedora-infra/bodhi

Issue:
Bodhi sends e-mails when it cannot modify private bugs
Bodhi tries to close private bugs, which it does not have permission to do. It should probably not try to do this in the first place, but more importantly it should catch the Exception that arises when it tries. Bodhi often sends error e-mails like this one:

Message
-------
[2018-06-09 20:39:48][     bodhi   ERROR]
```python
Unable to close bug #1549665
```


Process Details
---------------
- host:     bodhi-backend01.phx2.fedoraproject.org
- PID:      98853
- name:     fedmsg-hub
- command:  /usr/bin/python2 /usr/bin/fedmsg-hub
- msg_id:   

Callstack that lead to the logging statement
--------------------------------------------
```python
  File "/usr/lib64/python2.7/threading.py", line 777 in __bootstrap
    self.__bootstrap_inner()
  File "/usr/lib64/python2.7/threading.py", line 804 in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/site-packages/bodhi/server/consumers/masher.py", line 337 in run
    self.work()
  File "/usr/lib/python2.7/site-packages/bodhi/server/consumers/masher.py", line 416 in work
    self.modify_bugs()
  File "/usr/lib/python2.7/site-packages/bodhi/server/consumers/masher.py", line 70 in wrapper
    retval = method(self, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/bodhi/server/consumers/masher.py", line 717 in modify_bugs
    update.modify_bugs()
  File "/usr/lib/python2.7/site-packages/bodhi/server/models.py", line 2735 in modify_bugs
    bug.close_bug(self)
  File "/usr/lib/python2.7/site-packages/bodhi/server/models.py", line 4155 in close_bug
    bugs.bugtracker.close(self.bug_id, versions=versions, comment=self.default_message(update))
  File "/usr/lib/python2.7/site-packages/bodhi/server/bugs.py", line 222 in close
    log.exception("Unable to close bug #%d" % bug_id)
```
```
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/bodhi/server/bugs.py", line 199, in close
    bug = self.bz.getbug(bug_id)
  File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 1024, in getbug
    extra_fields=extra_fields)
  File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 1016, in _getbug
    return self._getbugs([objid], permissive=False, **kwargs)[0]
  File "/usr/lib/python2.7/site-packages/bugzilla/base.py", line 984, in _getbugs
    r = self._proxy.Bug.get(getbugdata)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1243, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/site-packages/bugzilla/transport.py", line 100, in _ServerProxy__request
    ret = ServerProxy._ServerProxy__request(self, methodname, params)
  File "/usr/lib64/python2.7/xmlrpclib.py", line 1602, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/site-packages/bugzilla/transport.py", line 195, in request
    return self._request_helper(url, request_body)
  File "/usr/lib/python2.7/site-packages/bugzilla/transport.py", line 181, in _request_helper
    raise sys.exc_info()[1]
Fault: <Fault 102: 'You are not authorized to access bug #1549665. Most likely the bug has been restricted for internal development processes and we cannot grant access. If you are a Red Hat customer with an active subscription, please visit the Red Hat Customer Portal for assistance with your issue If you are a Fedora Project user and require assistance, please consider using one of the mailing lists we host for the Fedora Project.'>
```


Discussion:

Resolving patch:
diff --git a/bodhi/server/bugs.py b/bodhi/server/bugs.py
--- a/bodhi/server/bugs.py
+++ b/bodhi/server/bugs.py
@@ -231,7 +231,7 @@ def close(self, bug_id, versions, comment):
 
             bug.close('ERRATA', **args)
         except xmlrpc_client.Fault:
-            log.exception("Unable to close bug #%d" % bug_id)
+            log.info("Unable to close bug #%d" % bug_id)
 
     def update_details(self, bug, bug_entity):
         """


Test patch:
diff --git a/bodhi/tests/server/test_bugs.py b/bodhi/tests/server/test_bugs.py
--- a/bodhi/tests/server/test_bugs.py
+++ b/bodhi/tests/server/test_bugs.py
@@ -88,9 +88,9 @@ def test_bz_with__bz_set(self, _connect):
         self.assertTrue(return_value is bz._bz)
         self.assertEqual(_connect.call_count, 0)
 
-    @mock.patch('bodhi.server.bugs.log.exception')
+    @mock.patch('bodhi.server.bugs.log.info')
     @mock.patch.dict('bodhi.server.bugs.config', {'bz_products': 'aproduct'})
-    def test_close_fault(self, exception):
+    def test_close_fault(self, info):
         """Assert that an xmlrpc Fault is caught and logged by close()."""
         bz = bugs.Bugzilla()
         bz._bz = mock.MagicMock()
@@ -101,7 +101,7 @@ def test_close_fault(self, exception):
         # This should not raise an Exception.
         bz.close(12345, {'bodhi': 'bodhi-3.1.0-1.fc27'}, 'whabam!')
 
-        exception.assert_called_once_with('Unable to close bug #12345')
+        info.assert_called_once_with('Unable to close bug #12345')
 
     @mock.patch('bodhi.server.bugs.log.exception')
     @mock.patch.dict('bodhi.server.bugs.config', {'bz_products': 'aproduct'})