Skip to content

Commit

Permalink
Merge pull request #523 from vrutkovs/bump-release-checks
Browse files Browse the repository at this point in the history
bump_release: add several checks to avoid incorrect builds
  • Loading branch information
lcarva authored Jun 23, 2016
2 parents 6659860 + 63c13a6 commit 5e00758
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
7 changes: 7 additions & 0 deletions atomic_reactor/plugins/pre_bump_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
27 changes: 21 additions & 6 deletions tests/plugins/test_bump_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,39 @@ 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

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

0 comments on commit 5e00758

Please sign in to comment.