From 84abec934bd3517f41ad28d7142155296ba92e34 Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Apr 16 2018 13:59:16 +0000 Subject: Detect Bodhi client by major version Fixes #204 Signed-off-by: Chenxiong Qi --- diff --git a/fedpkg/__init__.py b/fedpkg/__init__.py index 298064d..33eba61 100644 --- a/fedpkg/__init__.py +++ b/fedpkg/__init__.py @@ -231,7 +231,7 @@ class Commands(pyrpkg.Commands): # build up the bodhi arguments, based on which version of bodhi is # installed - bodhi_major_version = _get_bodhi_version()[0] + bodhi_major_version = _get_bodhi_major_version() if bodhi_major_version < 2: cmd = ['bodhi', '--bodhi-url', bodhi_config['url'], '--new', '--release', self.branch_merge, @@ -252,16 +252,17 @@ class Commands(pyrpkg.Commands): self._run_command(cmd, shell=True) -def _get_bodhi_version(): +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, 1, 9]. + 2. """ bodhi = subprocess.Popen(['bodhi', '--version'], stdout=subprocess.PIPE) version = bodhi.communicate()[0].strip() - return [int(component) for component in version.split('.')] + major, _ = version.split('.', 1) + return int(major) if __name__ == "__main__": diff --git a/test/test_cli.py b/test/test_cli.py index b991dd4..9c262b6 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -45,9 +45,10 @@ 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.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() # Not write clog actually. Instead, file object will be mocked and # return fake clog content for tests. @@ -73,7 +74,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_version_patcher.stop() + self.get_bodhi_major_version_patcher.stop() self.run_command_patcher.stop() self.nvr_patcher.stop() super(TestUpdate, self).tearDown() @@ -170,7 +171,7 @@ class TestUpdate(CliTestCase): 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