diff --git a/atomic_reactor/plugins/pre_bump_release.py b/atomic_reactor/plugins/pre_bump_release.py index 7f2e2cc16..292ab1950 100644 --- a/atomic_reactor/plugins/pre_bump_release.py +++ b/atomic_reactor/plugins/pre_bump_release.py @@ -60,7 +60,14 @@ def run(self): target_info = self.xmlrpc.getBuildTarget(self.target) self.log.debug('target info: %s', target_info) + if not target_info: + raise RuntimeError("no such target: %s" % self.target) + tag_id = target_info['dest_tag'] + if not self.xmlrpc.checkTagPackage(tag_id, component): + raise RuntimeError( + "package %s is not in the list for target %s" % (component, self.target)) + latest = self.xmlrpc.getLatestBuilds(tag_id, package=component) self.log.debug('latest builds: %s', latest) try: diff --git a/tests/plugins/test_bump_release.py b/tests/plugins/test_bump_release.py index 205ac3ed5..f9a002049 100644 --- a/tests/plugins/test_bump_release.py +++ b/tests/plugins/test_bump_release.py @@ -83,14 +83,22 @@ def test_release_label_already_set(self, tmpdir, caplog, labels): ([{}], '2', '2'), ]) @pytest.mark.parametrize('release_label', ['release', 'Release']) + @pytest.mark.parametrize(('component', 'tag', 'throws_exception'), [ + ('comp', 'dest_tag', False), + ('comp', 'wrong_tag', True), + ('wrong_comp', 'dest_tag', True), + ]) def test_increment(self, tmpdir, release_label, latest_builds, next_release, - expected): + expected, component, tag, throws_exception): class MockedClientSession(object): def __init__(self): pass def getBuildTarget(self, target): - return {'dest_tag': 'dest_tag'} + if target == 'dest_tag': + return {'dest_tag': 'dest_tag'} + else: + return None def getLatestBuilds(self, target, package=None): return latest_builds @@ -98,9 +106,16 @@ def getLatestBuilds(self, target, package=None): def getNextRelease(self, build_info): return next_release + def checkTagPackage(self, tag, package): + return package == 'comp' and tag == 'dest_tag' + session = MockedClientSession() flexmock(koji, ClientSession=session) - plugin = self.prepare(tmpdir, labels={'com.redhat.component': 'comp'}) - plugin.run() - parser = DockerfileParser(plugin.workflow.builder.df_path) - assert parser.labels[release_label] == expected + plugin = self.prepare(tmpdir, labels={'com.redhat.component': component}, target=tag) + if throws_exception: + with pytest.raises(RuntimeError): + plugin.run() + else: + plugin.run() + parser = DockerfileParser(plugin.workflow.builder.df_path) + assert parser.labels[release_label] == expected