Skip to content

Commit

Permalink
Allow running builds from repo_id
Browse files Browse the repository at this point in the history
Closes #50
  • Loading branch information
mizdebsk committed Apr 5, 2017
1 parent 99d40e6 commit f523aa1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config.cfg.template
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ config = {
# maximum number of items in single koji multicall. Too low values may
# cause poor performance, too high values may cause timeouts.
"multicall_chunk_size": 100,
# run scratch-builds from latest known repo_id to reduce hazard.
# Requires extra Koji privileges.
"build_from_repo_id": False,
},
# secondary koji instance configuration, leave empty if you want default
# primary mode
Expand Down
11 changes: 10 additions & 1 deletion koschei/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def db(self):
self._db = Session()
return self._db

@property
def build_from_repo_id(self):
return get_config('koji_config').get('build_from_repo_id')

def koji(self, koji_id):
"""
Returns (and creates if necessary) current koji session for given
Expand Down Expand Up @@ -112,12 +116,17 @@ def submit_build(session, package):
)
if srpm_res:
srpm, srpm_url = srpm_res
if session.build_from_repo_id:
target = None
build_opts.update({'repo_id': package.collection.latest_repo_id})
else:
target = package.collection.target
# priorities are reset after the build is done
# - the reason for that is that the build might be canceled and we want
# the priorities to be retained in that case
build.task_id = koji_util.koji_scratch_build(
session.koji('primary'),
package.collection.target,
target,
name,
srpm_url,
build_opts
Expand Down
1 change: 1 addition & 0 deletions koschei/backend/koji_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def get_last_srpm(koji_session, tag, name):


def koji_scratch_build(session, target, name, source, build_opts):
assert target or build_opts['repo_id']
build_opts = prepare_build_opts(build_opts)
log = logging.getLogger('koschei.backend.koji_util')
log.info('Intiating koji build for %(name)s:\n\tsource=%(source)s'
Expand Down
14 changes: 14 additions & 0 deletions test/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,17 @@ def test_submit_build_force_archful(self):
koji_scratch_build.assert_called_once_with(self.session.koji_mock, 'f25', 'rnv', 'the_url', {'arch_override': 'armhfp i386 x86_64'})
self.db.commit()
self.assertEqual(7541, package.last_build.task_id)

def test_submit_build_from_repo_id(self):
self.session.build_from_repo_id_override = True
package = self.prepare_packages('rnv')[0]
with patch('koschei.backend.koji_util.get_last_srpm', return_value=({'epoch': '111',
'version': '222',
'release': '333'}, 'the_url')) as get_last_srpm:
with patch('koschei.backend.koji_util.koji_scratch_build', return_value=7541) as koji_scratch_build:
backend.submit_build(self.session, package)
get_last_srpm.assert_called_once_with(self.session.sec_koji_mock, 'f25', 'rnv')
koji_scratch_build.assert_called_once_with(self.session.koji_mock, None, 'rnv', 'the_url', {'repo_id': 123})
self.db.commit()
self.assertEqual(7541, package.last_build.task_id)

5 changes: 5 additions & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def __init__(self):
self.sec_koji_mock = KojiMock()
self.repo_cache_mock = RepoCacheMock()
self.log = Mock()
self.build_from_repo_id_override = False

def koji(self, koji_id, anonymous=True):
if koji_id == 'primary':
Expand All @@ -107,6 +108,10 @@ def koji(self, koji_id, anonymous=True):
def repo_cache(self):
return self.repo_cache_mock

@property
def build_from_repo_id(self):
return self.build_from_repo_id_override


class DBTest(AbstractTest):
POSTGRES_OPTS = {
Expand Down

0 comments on commit f523aa1

Please sign in to comment.