From c2c97914843a61ccb472fe32f51cd1e1011136cc Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Jun 01 2018 06:09:00 +0000 Subject: [PATCH 1/3] Drop support of bodhi-client 0.9 Fixes #223 Signed-off-by: Chenxiong Qi --- diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py index d058ba1..3d36d8c 100644 --- a/fedpkg/__init__.py +++ b/fedpkg/__init__.py @@ -14,7 +14,7 @@ import os import git import re import platform -import subprocess +import pkg_resources from . import cli # noqa from .lookaside import FedoraLookasideCache @@ -228,43 +228,24 @@ class Commands(pyrpkg.Commands): def update(self, bodhi_config, template='bodhi.template', bugs=[]): """Submit an update to bodhi using the provided template.""" - - # build up the bodhi arguments, based on which version of bodhi is - # installed - bodhi_major_version = _get_bodhi_major_version() - if bodhi_major_version < 2: - cmd = ['bodhi', '--bodhi-url', bodhi_config['url'], - '--new', '--release', self.branch_merge, - '--file', 'bodhi.template', self.nvr, '--username', - self.user] - elif bodhi_major_version < 4: - # Version 3 is compatible with 2, it was bumped for server side - # reasons. - cmd = ['bodhi', 'updates', 'new', '--file', 'bodhi.template', - '--user', self.user] - if bodhi_config['staging']: - cmd.append('--staging') - cmd.append(self.nvr) - else: - msg = 'This system has bodhi v{0}, which is unsupported.' - msg = msg.format(bodhi_major_version) - raise Exception(msg) + check_bodhi_version() + cmd = ['bodhi', 'updates', 'new', '--file', 'bodhi.template', + '--user', self.user] + if bodhi_config['staging']: + cmd.append('--staging') + cmd.append(self.nvr) self._run_command(cmd, shell=True) -def _get_bodhi_major_version(): - """ - Use bodhi --version to determine the version of the Bodhi CLI that's - installed on the system, then return a list of the version components. - For example, if bodhi --version returns "2.1.9", this function will return - 2. - """ - bodhi = subprocess.Popen(['bodhi', '--version'], - stdout=subprocess.PIPE, - universal_newlines=True) - version = bodhi.communicate()[0].strip() - major, _ = version.split('.', 1) - return int(major) +def check_bodhi_version(): + try: + dist = pkg_resources.get_distribution('bodhi_client') + except pkg_resources.DistributionNotFound: + raise pyrpkg.rpkgError('bodhi-client < 2.0 is not supported.') + major = int(dist.version.split('.', 1)) + if major >= 4: + raise pyrpkg.rpkgError( + 'This system has bodhi v{0}, which is unsupported.'.format(major)) if __name__ == "__main__": diff --git a/test/test_cli.py b/test/test_cli.py index 9ac0a4b..103a4ca 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -45,10 +45,8 @@ class TestUpdate(CliTestCase): self.mock_run_command = self.run_command_patcher.start() # Let's always use the bodhi 2 command line to test here - self.get_bodhi_major_version_patcher = patch( - 'fedpkg._get_bodhi_major_version', return_value=2) - self.mock_get_bodhi_major_version = \ - self.get_bodhi_major_version_patcher.start() + self.check_bodhi_version_patcher = patch('fedpkg.check_bodhi_version') + self.mock_check_bodhi_version = self.check_bodhi_version_patcher.start() # Not write clog actually. Instead, file object will be mocked and # return fake clog content for tests. @@ -74,7 +72,7 @@ class TestUpdate(CliTestCase): os.unlink(os.path.join(self.cloned_repo_path, 'clog')) self.os_environ_patcher.stop() self.clog_patcher.stop() - self.get_bodhi_major_version_patcher.stop() + self.check_bodhi_version_patcher.stop() self.run_command_patcher.stop() self.nvr_patcher.stop() super(TestUpdate, self).tearDown() @@ -168,28 +166,10 @@ class TestUpdate(CliTestCase): @patch('os.path.isfile', return_value=True) @patch('hashlib.new') @patch('fedpkg.lookaside.FedoraLookasideCache.hash_file') - def test_fail_if_bodhi_version_is_not_supported( - self, hash_file, hashlib_new, isfile): - # As of writing this test, only supports version v3, v2, and Date: Jun 01 2018 07:44:09 +0000 Subject: [PATCH 2/3] Check bodhi version earlier Unsupported bodhi version will be reported before user does anything for a new update. Signed-off-by: Chenxiong Qi --- diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py index 3d36d8c..683a1a8 100644 --- a/fedpkg/__init__.py +++ b/fedpkg/__init__.py @@ -14,7 +14,6 @@ import os import git import re import platform -import pkg_resources from . import cli # noqa from .lookaside import FedoraLookasideCache @@ -228,7 +227,6 @@ class Commands(pyrpkg.Commands): def update(self, bodhi_config, template='bodhi.template', bugs=[]): """Submit an update to bodhi using the provided template.""" - check_bodhi_version() cmd = ['bodhi', 'updates', 'new', '--file', 'bodhi.template', '--user', self.user] if bodhi_config['staging']: @@ -237,17 +235,6 @@ class Commands(pyrpkg.Commands): self._run_command(cmd, shell=True) -def check_bodhi_version(): - try: - dist = pkg_resources.get_distribution('bodhi_client') - except pkg_resources.DistributionNotFound: - raise pyrpkg.rpkgError('bodhi-client < 2.0 is not supported.') - major = int(dist.version.split('.', 1)) - if major >= 4: - raise pyrpkg.rpkgError( - 'This system has bodhi v{0}, which is unsupported.'.format(major)) - - if __name__ == "__main__": from fedpkg.__main__ import main main() diff --git a/fedpkg/cli.py b/fedpkg/cli.py index ff7f18d..7c83028 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -18,6 +18,7 @@ import io import os import re import json +import pkg_resources import six import textwrap @@ -34,6 +35,17 @@ from fedpkg.utils import ( RELEASE_BRANCH_REGEX = r'^(f\d+|el\d+|epel\d+)$' +def check_bodhi_version(): + try: + dist = pkg_resources.get_distribution('bodhi_client') + except pkg_resources.DistributionNotFound: + raise rpkgError('bodhi-client < 2.0 is not supported.') + major = int(dist.version.split('.', 1)) + if major >= 4: + raise rpkgError( + 'This system has bodhi v{0}, which is unsupported.'.format(major)) + + class fedpkgClient(cliClient): def __init__(self, config, name=None): self.DEFAULT_CLI_NAME = 'fedpkg' @@ -243,6 +255,8 @@ and created: return lines[0], "\n".join(log) def update(self): + check_bodhi_version() + try: section = '%s.bodhi' % self.name bodhi_config = { diff --git a/test/test_cli.py b/test/test_cli.py index 103a4ca..3de4bd5 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -14,6 +14,9 @@ import io import os import sys import json +import pkg_resources +import unittest + from datetime import datetime, timedelta from tempfile import mkdtemp from os import rmdir @@ -26,6 +29,7 @@ from six.moves import StringIO from pyrpkg.errors import rpkgError from utils import CliTestCase from fedpkg.bugzilla import BugzillaClient +from fedpkg.cli import check_bodhi_version from mock import call, patch, PropertyMock, Mock @@ -45,7 +49,7 @@ class TestUpdate(CliTestCase): self.mock_run_command = self.run_command_patcher.start() # Let's always use the bodhi 2 command line to test here - self.check_bodhi_version_patcher = patch('fedpkg.check_bodhi_version') + self.check_bodhi_version_patcher = patch('fedpkg.cli.check_bodhi_version') self.mock_check_bodhi_version = self.check_bodhi_version_patcher.start() # Not write clog actually. Instead, file object will be mocked and @@ -1106,3 +1110,15 @@ class TestRequestTestsRepo(CliTestCase): assert False, 'rpkgError not raised' except rpkgError as error: self.assertEqual(str(error), expected_error) + + +class TestCheckBodhiVersion(unittest.TestCase): + """Test check_bodhi_version""" + + @patch('pkg_resources.get_distribution') + def test_no_2_x_version_installed(self, get_distribution): + get_distribution.side_effect = pkg_resources.DistributionNotFound + + six.assertRaisesRegex( + self, rpkgError, r'bodhi-client < 2\.0 is not supported\.', + check_bodhi_version) diff --git a/test/test_commands.py b/test/test_commands.py index 2ec869d..835ba00 100644 --- a/test/test_commands.py +++ b/test/test_commands.py @@ -9,12 +9,7 @@ # option) any later version. See http://www.gnu.org/copyleft/gpl.html for # the full text of the license. -import pkg_resources -import six -import unittest - from pyrpkg.errors import rpkgError -from fedpkg import check_bodhi_version from utils import CommandTestCase from mock import call, patch, Mock, PropertyMock, mock_open from six.moves import builtins @@ -329,15 +324,3 @@ class TestOverrideBuildURL(CommandTestCase): self.assertEqual( 'git+{0}'.format(super_construct_build_url.return_value), overrided_url) - - -class TestCheckBodhiVersion(unittest.TestCase): - """Test check_bodhi_version""" - - @patch('pkg_resources.get_distribution') - def test_no_2_x_version_installed(self, get_distribution): - get_distribution.side_effect = pkg_resources.DistributionNotFound - - six.assertRaisesRegex( - self, rpkgError, r'bodhi-client < 2\.0 is not supported\.', - check_bodhi_version) From 59e978923b177a4f6445aeadef5c93e30ea6e675 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Jun 01 2018 09:44:37 +0000 Subject: [PATCH 3/3] Also remove bodhi url from config Bodhi URL was added for switching to staging server, which is required by old versions <2.0. Since, bodhi client 2.0, command line option --staging is for that and no need to provide URL explicitly. Signed-off-by: Chenxiong Qi --- diff --git a/conf/etc/rpkg/fedpkg-stage.conf b/conf/etc/rpkg/fedpkg-stage.conf index 5a82141..0d8d25e 100644 --- a/conf/etc/rpkg/fedpkg-stage.conf +++ b/conf/etc/rpkg/fedpkg-stage.conf @@ -19,7 +19,6 @@ kerberos_realms = STG.FEDORAPROJECT.ORG [fedpkg-stage.bodhi] # Refer to fedpkg.conf -url = https://bodhi.stg.fedoraproject.org/ staging = True [fedpkg-stage.mbs] diff --git a/conf/etc/rpkg/fedpkg.conf b/conf/etc/rpkg/fedpkg.conf index 4e45ebc..c656fe5 100644 --- a/conf/etc/rpkg/fedpkg.conf +++ b/conf/etc/rpkg/fedpkg.conf @@ -18,10 +18,6 @@ lookaside_namespaced = True kerberos_realms = FEDORAPROJECT.ORG [fedpkg.bodhi] -# This is for the bodhi-client 1.x. that accepts --bodhi-dir option to switch -# to different instances including the production and stage. -url = https://bodhi.fedoraproject.org/ - # This is for the bodhi-client 2.x, that do not require an option to switch to # different instance. Instead, --staging is available to switch to the stage # bodhi, and production is used without providing --staging. diff --git a/fedpkg/cli.py b/fedpkg/cli.py index 7c83028..2b21719 100644 --- a/fedpkg/cli.py +++ b/fedpkg/cli.py @@ -260,7 +260,6 @@ and created: try: section = '%s.bodhi' % self.name bodhi_config = { - 'url': self.config.get(section, 'url'), 'staging': self.config.getboolean(section, 'staging'), } except (ValueError, NoOptionError, NoSectionError) as e: diff --git a/test/fedpkg-stage.conf b/test/fedpkg-stage.conf index 3c09ebc..c72a29b 100644 --- a/test/fedpkg-stage.conf +++ b/test/fedpkg-stage.conf @@ -11,7 +11,6 @@ distgit_namespaced = True kerberos_realms = STG.FEDORAPROJECT.ORG [fedpkg-stage.bodhi] -url = https://bodhi.stg.example.com/ staging = True [fedpkg-stage.bugzilla] diff --git a/test/fedpkg-test.conf b/test/fedpkg-test.conf index 2173f0e..997eebb 100644 --- a/test/fedpkg-test.conf +++ b/test/fedpkg-test.conf @@ -11,7 +11,6 @@ distgit_namespaced = True kerberos_realms = FEDORAPROJECT.ORG [fedpkg.bodhi] -url = https://bodhi.dummy.example.com/ staging = False [fedpkg.bugzilla]