From 2d7e34545398c55850e3e7736d0de593fd92e20c Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Feb 14 2018 05:25:03 +0000 Subject: Do not check bodhi-client version So far, EL6 is still needed to be considered for fedpkg, so bodhi-client 1.x must be supported as well. This patch does not check bodhi-client version to select proper version of bodhi-client. Instead, if current system is EL6, version 1.x is selected, otherwise bodhi command line will be constructed in the 2.x format. This avoids fedpkg to be updated and released when each time a new version of bodhi-client with increased major version is released. Fixes #171 Signed-off-by: Chenxiong Qi --- diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py index dd1c2d9..59a1dd9 100644 --- a/fedpkg/__init__.py +++ b/fedpkg/__init__.py @@ -14,11 +14,11 @@ import os import git import re import platform -import subprocess from . import cli # noqa from .lookaside import FedoraLookasideCache from pyrpkg.utils import cached_property +from .utils import is_el6_system class Commands(pyrpkg.Commands): @@ -228,42 +228,22 @@ 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_version()[0] - if bodhi_major_version < 2: + if is_el6_system(): 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. + else: 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) self._run_command(cmd, shell=True) -def _get_bodhi_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, 1, 9]. - """ - bodhi = subprocess.Popen(['bodhi', '--version'], stdout=subprocess.PIPE) - version = bodhi.communicate()[0].strip() - return [int(component) for component in version.split('.')] - - if __name__ == "__main__": from fedpkg.__main__ import main main() diff --git a/fedpkg/utils.py b/fedpkg/utils.py index d241308..6d91944 100644 --- a/fedpkg/utils.py +++ b/fedpkg/utils.py @@ -11,6 +11,7 @@ # the full text of the license. import re +import rpm import json from datetime import datetime @@ -196,6 +197,15 @@ def is_epel(branch): return bool(re.match(r'^(?:el|epel)\d+$', branch)) +def is_el6_system(): + """Check if current system is EL6 + + :return: True if current system is EL6. Otherwise False is returned. + :rtype: bool + """ + return '.el6' == rpm.expandMacro('%{dist}') + + def assert_valid_epel_package(name, branch): """ Determines if the package is allowed to have an EPEL branch. If it can't, diff --git a/test/test_cli.py b/test/test_cli.py index 047b962..97596f7 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -43,9 +43,9 @@ 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_version_patcher = patch('fedpkg._get_bodhi_version', - return_value=[2, 11, 0]) - self.mock_get_bodhi_version = self.get_bodhi_version_patcher.start() + self.is_el6_system_patcher = patch('fedpkg.is_el6_system', + return_value=False) + self.mock_is_el6_system = self.is_el6_system_patcher.start() # Not write clog actually. Instead, file object will be mocked and # return fake clog content for tests. @@ -64,7 +64,7 @@ class TestUpdate(CliTestCase): def tearDown(self): self.os_environ_patcher.stop() self.clog_patcher.stop() - self.get_bodhi_version_patcher.stop() + self.is_el6_system_patcher.stop() self.run_command_patcher.stop() self.nvr_patcher.stop() super(TestUpdate, self).tearDown() @@ -151,28 +151,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