diff --git a/bodhi/server/validators.py b/bodhi/server/validators.py index 65c39c9e81..18a4ecd473 100644 --- a/bodhi/server/validators.py +++ b/bodhi/server/validators.py @@ -217,7 +217,8 @@ def cache_nvrs(request, build): request (pyramid.util.Request): The current request. build (basestring): The NVR of the build to cache. Raises: - ValueError: If any of the name, version, or release in build are found to be ''. + ValueError: If the build could not be found in koji. + koji.GenericError: If an error was thrown by koji's getBuild() call. """ if build in request.buildinfo and 'nvr' in request.buildinfo[build]: return @@ -228,6 +229,10 @@ def cache_nvrs(request, build): # We use Koji's information to get the NVR split, because modules can have dashes in their # stream. kbinfo = request.koji.getBuild(build) + if not kbinfo: + request.buildinfo[build]['info'] = None + request.buildinfo[build]['nvr'] = None + raise ValueError('Build %s did not exist' % build) request.buildinfo[build]['info'] = kbinfo request.buildinfo[build]['nvr'] = kbinfo['name'], kbinfo['version'], kbinfo['release'] @@ -245,8 +250,13 @@ def validate_nvrs(request, **kwargs): cache_nvrs(request, build) except ValueError: request.validated['builds'] = [] - request.errors.add('body', 'builds', 'Build not in ' - 'name-version-release format: %s' % build) + request.errors.add('body', 'builds', 'Build does not exist: %s' % build) + return + except koji.GenericError: + log.exception("Error retrieving koji build for %s" % build) + request.validated['builds'] = [] + request.errors.add('body', 'builds', + 'Koji error getting build: %s' % build) return diff --git a/bodhi/tests/server/services/test_updates.py b/bodhi/tests/server/services/test_updates.py index f30225f6a2..df813b4f12 100644 --- a/bodhi/tests/server/services/test_updates.py +++ b/bodhi/tests/server/services/test_updates.py @@ -82,12 +82,6 @@ class TestNewUpdate(base.BaseTestCase): """ This class contains tests for the new_update() function. """ - @mock.patch(**mock_valid_requirements) - def test_invalid_build_name(self, *args): - res = self.app.post_json('/updates/', self.get_update(u'bodhi-2.0-1.fc17,invalidbuild-1.0'), - status=400) - assert 'Build not in name-version-release format' in res, res - @mock.patch(**mock_valid_requirements) def test_empty_build_name(self, *args): res = self.app.post_json('/updates/', self.get_update([u'']), status=400) @@ -265,6 +259,36 @@ def test_new_rpm_update(self, publish, *args): publish.assert_called_once_with( topic='update.request.testing', msg=mock.ANY) + @mock.patch.dict('bodhi.server.validators.config', {'acl_system': u'dummy'}) + @mock.patch(**mock_uuid4_version1) + @mock.patch(**mock_valid_requirements) + @mock.patch('bodhi.server.notifications.publish') + def test_new_rpm_update_unknown_build(self, publish, *args): + with mock.patch('bodhi.server.buildsys.DevBuildsys.getBuild', + return_value=None): + r = self.app.post_json('/updates/', self.get_update('bodhi-2.0.0-2.fc17'), + status=400) + up = r.json_body + + self.assertEquals(up['status'], 'error') + self.assertEquals(up['errors'][0]['description'], + "Build does not exist: bodhi-2.0.0-2.fc17") + + @mock.patch.dict('bodhi.server.validators.config', {'acl_system': u'dummy'}) + @mock.patch(**mock_uuid4_version1) + @mock.patch(**mock_valid_requirements) + @mock.patch('bodhi.server.notifications.publish') + def test_new_rpm_update_koji_error(self, publish, *args): + with mock.patch('bodhi.server.buildsys.DevBuildsys.getBuild', + side_effect=koji.GenericError()): + r = self.app.post_json('/updates/', self.get_update('bodhi-2.0.0-2.fc17'), + status=400) + up = r.json_body + + self.assertEquals(up['status'], 'error') + self.assertEquals(up['errors'][0]['description'], + "Koji error getting build: bodhi-2.0.0-2.fc17") + @mock.patch.dict('bodhi.server.validators.config', {'acl_system': u'dummy'}) @mock.patch(**mock_uuid4_version1) @mock.patch(**mock_valid_requirements)