From 5d25a9186842c0a67fea3557dfda571f8eceef4f Mon Sep 17 00:00:00 2001 From: Chenxiong Qi Date: Jan 11 2017 15:08:28 +0000 Subject: Move tag inheritance check into a separate method Tag inheritance check may not be required by all downstream package tools built on top of rpkg. Moving this check into a separate method would be easy for downstream tools to customize the behavior. By default, tag inheritance check happens when doing a chain build. Once some tool does not need the check, it can be disabled in derived Commands class. Signed-off-by: Chenxiong Qi --- diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3b0031c..b25a4db 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ ChangeLog ========= +NEXT +---- + +- Move tag inheritance check into a separate method (cqi) + v1.48 (2016-12-22) ------------------ diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 61907a2..61039f3 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -1822,6 +1822,14 @@ class Commands(object): if self.repo.git.rev_list('%s...%s' % (merge, branch)): raise rpkgError('There are unpushed changes in your repo') + def check_inheritance(self, build_target, dest_tag): + """Check if build tag inherits from dest tag""" + ancestors = self.kojisession.getFullInheritance(build_target['build_tag']) + ancestors = [ancestor['parent_id'] for ancestor in ancestors] + if dest_tag['id'] not in [build_target['build_tag']] + ancestors: + raise rpkgError('Packages in destination tag %(dest_tag_name)s are not inherited by' + ' build tag %(build_tag_name)s' % build_target) + def build(self, skip_tag=False, scratch=False, background=False, url=None, chain=None, arches=None, sets=False, nvr_check=True): """Initiate a build of the module. Available options are: @@ -1876,17 +1884,10 @@ class Commands(object): % build_target['dest_tag_name']) if dest_tag['locked'] and not scratch: raise rpkgError('Destination tag %s is locked' % dest_tag['name']) - # If we're chain building, make sure inheritance works if chain: cmd.append('chain-build') - ancestors = self.kojisession.getFullInheritance( - build_target['build_tag']) - ancestors = [ancestor['parent_id'] for ancestor in ancestors] - if dest_tag['id'] not in [build_target['build_tag']] + ancestors: - raise rpkgError('Packages in destination tag ' - '%(dest_tag_name)s are not inherited by' - 'build tag %(build_tag_name)s' % - build_target) + # We're chain building, make sure inheritance works + self.check_inheritance(build_target, dest_tag) else: cmd.append('build') # define our dictionary for options diff --git a/tests/test_commands.py b/tests/test_commands.py index 0d08eb1..9765d6d 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -7,6 +7,7 @@ import tempfile import git import rpm from mock import patch +from mock import Mock from pyrpkg import rpkgError @@ -504,3 +505,39 @@ class TestGetLatestCommit(CommandTestCase): self.assertEqual(str(git.Repo(self.repo_path).iter_commits().next()), cmd.get_latest_commit(os.path.basename(self.repo_path), 'eng-rhel-6')) + + +def load_kojisession(self): + self._kojisession = Mock() + self._kojisession.getFullInheritance.return_value = [ + {'child_id': 342, 'currdepth': 1, 'filter': [], 'intransitive': False, + 'maxdepth': None, 'name': 'f25-override', 'nextdepth': None, 'noconfig': False, + 'parent_id': 341, 'pkg_filter': '', 'priority': 0}, + {'child_id': 341, 'currdepth': 2, 'filter': [], 'intransitive': False, + 'maxdepth': None, 'name': 'f25-updates', 'nextdepth': None, 'noconfig': False, + 'parent_id': 336, 'pkg_filter': '', 'priority': 0}, + {'child_id': 336, 'currdepth': 3, 'filter': [], 'intransitive': False, + 'maxdepth': None, 'name': 'f25', 'nextdepth': None, 'noconfig': False, + 'parent_id': 335, 'pkg_filter': '', 'priority': 0}, + ] + + +class TestTagInheritanceTag(CommandTestCase): + + @patch('pyrpkg.Commands.load_kojisession', new=load_kojisession) + def test_error_if_not_inherit(self): + build_target = { + 'build_tag': 342, 'build_tag_name': 'f25-build', + 'dest_tag': 337, 'dest_tag_name': 'f25-updates-candidate', + 'id': 167, 'name': 'f25-candidate', + } + dest_tag = { + 'arches': None, 'extra': {}, + 'id': 337, 'locked': False, + 'maven_include_all': False, 'maven_support': False, + 'name': 'f25-updates-candidate', + 'perm': None, 'perm_id': None, + } + + cmd = self.make_commands() + self.assertRaises(rpkgError, cmd.check_inheritance, build_target, dest_tag)