Repository: fedora-infra/bodhi

Issue:
IncompleteRead while Composer polls for repomd files
It seems that Python's http library can raise a new Exception in Python 3 that we don't catch:

```
[2018-11-20 14:42:34][fedmsg.consumers    INFO]epel7-testing Polling http://download01.phx2.fedoraproject.org/pub/epel/testing/7/aarch64/repodata/repomd.xml
[2018-11-20 14:42:34][fedmsg.consumers   ERROR]epel7-testing Exception in ComposerThread(epel7-testing)
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/bodhi/server/consumers/masher.py", line 410, in work
    self._compose_updates()
  File "/usr/lib/python3.7/site-packages/bodhi/server/consumers/masher.py", line 959, in _compose_updates
    self._wait_for_sync()
  File "/usr/lib/python3.7/site-packages/bodhi/server/consumers/masher.py", line 1327, in _wait_for_sync
    newsum = hashlib.sha1(masterrepomd.read()).hexdigest()
  File "/usr/lib64/python3.7/http/client.py", line 460, in read
    s = self._safe_read(self.length)
  File "/usr/lib64/python3.7/http/client.py", line 612, in _safe_read
    raise IncompleteRead(b''.join(s), amt)
http.client.IncompleteRead: IncompleteRead(3295 bytes read, 1 more expected)
```

This one should be pretty easy to fix - we just need to catch this new Exception and retry, similar to what we do if a URLError is raised.


Discussion:
The fix for this issue is now released with Bodhi 3.11.1 and deployed to Fedora's production instance.
The fix I made for this mistakenly handled ```IncompleteRead``` on ```urlopen()``` instead of on ```read()```, so the error still happens.
I once again hotfixed this by moving the ```read()``` statement into the ```Exception``` handler.

Resolving patch:
diff --git a/bodhi/server/consumers/masher.py b/bodhi/server/consumers/masher.py
--- a/bodhi/server/consumers/masher.py
+++ b/bodhi/server/consumers/masher.py
@@ -1325,11 +1325,11 @@ def _wait_for_sync(self):
             try:
                 self.log.info('Polling %s' % master_repomd_url)
                 masterrepomd = urllib2.urlopen(master_repomd_url)
+                newsum = hashlib.sha1(masterrepomd.read()).hexdigest()
             except (IncompleteRead, URLError, HTTPError):
                 self.log.exception('Error fetching repomd.xml')
                 time.sleep(200)
                 continue
-            newsum = hashlib.sha1(masterrepomd.read()).hexdigest()
             if newsum == checksum:
                 self.log.info("master repomd.xml matches!")
                 notifications.publish(
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -63,7 +63,7 @@
 # The short X.Y version.
 version = '3.11'
 # The full version, including alpha/beta/rc tags.
-release = '3.11.1'
+release = '3.11.2'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -42,7 +42,7 @@ def get_requirements(requirements_file='requirements.txt'):
 
 here = os.path.abspath(os.path.dirname(__file__))
 README = open(os.path.join(here, 'README.rst')).read()
-VERSION = '3.11.1'
+VERSION = '3.11.2'
 # Possible options are at https://pypi.python.org/pypi?%3Aaction=list_classifiers
 CLASSIFIERS = [
     'Development Status :: 5 - Production/Stable',


Test patch:
diff --git a/bodhi/tests/server/consumers/test_masher.py b/bodhi/tests/server/consumers/test_masher.py
--- a/bodhi/tests/server/consumers/test_masher.py
+++ b/bodhi/tests/server/consumers/test_masher.py
@@ -3105,9 +3105,7 @@ def test_incompleteread(self, urlopen, sleep, publish, save):
         """
         Assert that an IncompleteRead is properly caught and logged, and that the code continues.
         """
-        fake_url = mock.MagicMock()
-        fake_url.read.return_value = b'---\nyaml: rules'
-        urlopen.side_effect = [IncompleteRead('some_data'), fake_url]
+        urlopen.return_value.read.side_effect = [IncompleteRead('some_data'), b'---\nyaml: rules']
         t = PungiComposerThread(self.semmock, self._make_msg()['body']['msg']['composes'][0],
                                 'bowlofeggs', log, self.Session, self.tempdir)
         t.compose = self.db.query(Compose).one()
@@ -3132,10 +3130,12 @@ def test_incompleteread(self, urlopen, sleep, publish, save):
         # won't be deterministic about which of arch URL gets used. However, either one of them
         # would be correct so we will just assert that the one that is used is used correctly.
         arch = 'x86_64' if 'x86_64' in urlopen.mock_calls[0][1][0] else 'aarch64'
-        expected_calls = [
-            mock.call('http://example.com/pub/fedora/linux/updates/testing/17/'
-                      '{}/repodata.repomd.xml'.format(arch))
-            for i in range(2)]
+        expected_calls = []
+        for i in range(2):
+            expected_calls.append(
+                mock.call('http://example.com/pub/fedora/linux/updates/testing/17/'
+                          '{}/repodata.repomd.xml'.format(arch)))
+            expected_calls.append(mock.call().read())
         urlopen.assert_has_calls(expected_calls)
         t.log.exception.assert_called_once_with('Error fetching repomd.xml')
         sleep.assert_called_once_with(200)