From 9b571e52732fc5c1007ce75962074a5a019bb3a1 Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Dec 09 2019 12:49:33 +0000 Subject: verrel command on master asks Koji first `fedpkg verrel` on master branch could return wrong result in some cases. Now running order is: asks active Koji session, asks anonymous Koji session and then if there is still no result, tries to determine release offline. Fedpkg ability to work offline is still desirable. JIRA: COMPOSE-3876 Fixes: #357 Signed-off-by: Ondrej Nosek --- diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py index 769ee36..24d9f9e 100644 --- a/fedpkg/__init__.py +++ b/fedpkg/__init__.py @@ -202,7 +202,6 @@ class Commands(pyrpkg.Commands): """ get the '26' part of 'f26-foo' string """ return dest_tag.split('-')[0].replace('f', '') - # New functionality def _findmasterbranch(self): """Find the right "fedora" for master""" @@ -211,6 +210,15 @@ class Commands(pyrpkg.Commands): rawhidetarget = self.kojisession.getBuildTarget('rawhide') return self._tag2version(rawhidetarget['dest_tag_name']) + # Try connect Koji once more, this time with anonymous session. + try: + rawhidetarget = self.anon_kojisession.getBuildTarget('rawhide') + except Exception: + # We couldn't hit Koji. Continue, because fedpkg may work offline. + self.log.debug('Unable to query Koji to find rawhide target. Continue offline.') + else: + return self._tag2version(rawhidetarget['dest_tag_name']) + # Create a list of "fedoras" fedoras = [] @@ -234,15 +242,7 @@ class Commands(pyrpkg.Commands): # Start with the last item, strip the f, add 1, return it. return(int(fedoras[-1].strip('f')) + 1) else: - # We may not have Fedoras. Find out what rawhide target does. - try: - rawhidetarget = self.anon_kojisession.getBuildTarget( - 'rawhide') - except Exception: - # We couldn't hit koji, bail. - raise pyrpkg.rpkgError( - 'Unable to query koji to find rawhide target') - return self._tag2version(rawhidetarget['dest_tag_name']) + raise pyrpkg.rpkgError('Unable to find rawhide target') def _determine_runtime_env(self): """Need to know what the runtime env is, so we can unset anything diff --git a/test/test_commands.py b/test/test_commands.py index 4a47f02..752a5dd 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -323,12 +323,21 @@ class TestFindMasterBranch(CommandTestCase): repo.return_value.refs = ['rhel', 'private-branch'] koji_session = anon_kojisession.return_value - koji_session.getBuildTarget.return_value = {'dest_tag_name': 'f28'} + koji_session.getBuildTarget.return_value = {'dest_tag_name': 'f29'} result = self.cmd._findmasterbranch() koji_session.getBuildTarget.assert_called_once_with('rawhide') - self.assertEqual('28', result) + self.assertEqual('29', result) + + @patch('pyrpkg.Commands.anon_kojisession', new_callable=PropertyMock) + def test_if_koji_api_is_offline(self, anon_kojisession): + koji_session = anon_kojisession.return_value + # As the code shows, any error will be caught + koji_session.getBuildTarget.side_effect = ValueError + + result = self.cmd._findmasterbranch() + self.assertEqual(28, result) @patch('pyrpkg.Commands.anon_kojisession', new_callable=PropertyMock) @patch('pyrpkg.Commands.repo', new_callable=PropertyMock) @@ -341,7 +350,7 @@ class TestFindMasterBranch(CommandTestCase): koji_session.getBuildTarget.side_effect = ValueError six.assertRaisesRegex( - self, rpkgError, 'Unable to query koji to find rawhide target', + self, rpkgError, 'Unable to find rawhide target', self.cmd._findmasterbranch)