Merge #554 osbs: write manifest for scratch osbs
This commit is contained in:
commit
fa3d94bae3
@ -75,25 +75,38 @@ class OSBSThread(WorkerThread):
|
||||
raise RuntimeError('OSBS: task %s failed: see %s for details'
|
||||
% (task_id, log_file))
|
||||
|
||||
# Only real builds get the metadata.
|
||||
if not config.get('scratch', False):
|
||||
self._add_metadata(koji.koji_proxy, variant, task_id)
|
||||
scratch = config.get('scratch', False)
|
||||
self._add_metadata(koji.koji_proxy, variant, task_id, compose, scratch)
|
||||
|
||||
self.pool.log_info('[DONE ] %s' % msg)
|
||||
|
||||
def _add_metadata(self, koji_proxy, variant, task_id):
|
||||
def _add_metadata(self, koji_proxy, variant, task_id, compose, is_scratch):
|
||||
# Create metadata
|
||||
metadata = {
|
||||
'compose_id': compose.compose_id,
|
||||
'koji_task': task_id,
|
||||
}
|
||||
|
||||
result = koji_proxy.getTaskResult(task_id)
|
||||
if is_scratch:
|
||||
metadata.update({
|
||||
'repositories': result['repositories'],
|
||||
})
|
||||
# add a fake arch of 'scratch', so we can construct the metadata
|
||||
# in same data structure as real builds.
|
||||
self.pool.metadata.setdefault(
|
||||
variant.uid, {}).setdefault('scratch', []).append(metadata)
|
||||
else:
|
||||
build_id = int(result['koji_builds'][0])
|
||||
buildinfo = koji_proxy.getBuild(build_id)
|
||||
archives = koji_proxy.listArchives(build_id)
|
||||
|
||||
metadata = {
|
||||
metadata.update({
|
||||
'name': buildinfo['name'],
|
||||
'version': buildinfo['version'],
|
||||
'release': buildinfo['release'],
|
||||
'creation_time': buildinfo['creation_time'],
|
||||
}
|
||||
})
|
||||
for archive in archives:
|
||||
data = {
|
||||
'filename': archive['filename'],
|
||||
|
@ -147,6 +147,22 @@ METADATA = {
|
||||
}]}
|
||||
}
|
||||
|
||||
SCRATCH_TASK_RESULT = {
|
||||
'koji_builds': [],
|
||||
'repositories': [
|
||||
'registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632',
|
||||
]
|
||||
}
|
||||
|
||||
SCRATCH_METADATA = {
|
||||
"Server": {'scratch': [{
|
||||
"koji_task": 12345,
|
||||
"repositories": [
|
||||
'registry.example.com:8888/rcm/buildroot:f24-docker-candidate-20160617141632',
|
||||
]
|
||||
}]}
|
||||
}
|
||||
|
||||
|
||||
class OSBSThreadTest(helpers.PungiTestCase):
|
||||
|
||||
@ -161,10 +177,13 @@ class OSBSThreadTest(helpers.PungiTestCase):
|
||||
]
|
||||
})
|
||||
|
||||
def _setupMock(self, KojiWrapper, resolve_git_url):
|
||||
def _setupMock(self, KojiWrapper, resolve_git_url, scratch=False):
|
||||
resolve_git_url.return_value = 'git://example.com/repo?#BEEFCAFE'
|
||||
self.wrapper = KojiWrapper.return_value
|
||||
self.wrapper.koji_proxy.buildContainer.return_value = 12345
|
||||
if scratch:
|
||||
self.wrapper.koji_proxy.getTaskResult.return_value = SCRATCH_TASK_RESULT
|
||||
else:
|
||||
self.wrapper.koji_proxy.getTaskResult.return_value = TASK_RESULT
|
||||
self.wrapper.koji_proxy.getBuild.return_value = BUILD_INFO
|
||||
self.wrapper.koji_proxy.listArchives.return_value = ARCHIVES
|
||||
@ -172,17 +191,26 @@ class OSBSThreadTest(helpers.PungiTestCase):
|
||||
self.wrapper.koji_proxy.getNextRelease.return_value = 3
|
||||
self.wrapper.watch_task.return_value = 0
|
||||
|
||||
def _assertCorrectMetadata(self):
|
||||
def _assertCorrectMetadata(self, scratch=False):
|
||||
self.maxDiff = None
|
||||
self.assertEqual(self.pool.metadata, METADATA)
|
||||
if scratch:
|
||||
metadata = copy.deepcopy(SCRATCH_METADATA)
|
||||
metadata['Server']['scratch'][0]['compose_id'] = self.compose.compose_id
|
||||
metadata['Server']['scratch'][0]['koji_task'] = 12345
|
||||
else:
|
||||
metadata = copy.deepcopy(METADATA)
|
||||
metadata['Server']['x86_64'][0]['compose_id'] = self.compose.compose_id
|
||||
metadata['Server']['x86_64'][0]['koji_task'] = 12345
|
||||
self.assertEqual(self.pool.metadata, metadata)
|
||||
|
||||
def _assertCorrectCalls(self, opts, setupCalls=None):
|
||||
def _assertCorrectCalls(self, opts, setupCalls=None, scratch=False):
|
||||
setupCalls = setupCalls or []
|
||||
options = {'yum_repourls': ['http://root/work/global/tmp-Server/compose-rpms-1.repo']}
|
||||
if scratch:
|
||||
options['scratch'] = True
|
||||
options.update(opts)
|
||||
self.assertEqual(
|
||||
self.wrapper.mock_calls,
|
||||
[mock.call.login()] + setupCalls + [
|
||||
expect_calls = [mock.call.login()] + setupCalls
|
||||
expect_calls.extend([
|
||||
mock.call.koji_proxy.buildContainer(
|
||||
'git://example.com/repo?#BEEFCAFE',
|
||||
'f24-docker-candidate',
|
||||
@ -190,9 +218,12 @@ class OSBSThreadTest(helpers.PungiTestCase):
|
||||
priority=None),
|
||||
mock.call.watch_task(
|
||||
12345, self.topdir + '/logs/global/osbs/Server-1-watch-task.log'),
|
||||
mock.call.koji_proxy.getTaskResult(12345),
|
||||
mock.call.koji_proxy.getBuild(54321),
|
||||
mock.call.koji_proxy.getTaskResult(12345)])
|
||||
|
||||
if not scratch:
|
||||
expect_calls.extend([mock.call.koji_proxy.getBuild(54321),
|
||||
mock.call.koji_proxy.listArchives(54321)])
|
||||
self.assertEqual(self.wrapper.mock_calls, expect_calls)
|
||||
|
||||
def _assertRepoFile(self, variants=None, gpgkey=None):
|
||||
variants = variants or ['Server']
|
||||
@ -414,19 +445,20 @@ class OSBSThreadTest(helpers.PungiTestCase):
|
||||
|
||||
@mock.patch('pungi.util.resolve_git_url')
|
||||
@mock.patch('pungi.phases.osbs.kojiwrapper.KojiWrapper')
|
||||
def test_scratch_has_no_metadata(self, KojiWrapper, resolve_git_url):
|
||||
def test_scratch_metadata(self, KojiWrapper, resolve_git_url):
|
||||
cfg = {
|
||||
'url': 'git://example.com/repo?#HEAD',
|
||||
'target': 'fedora-24-docker-candidate',
|
||||
'target': 'f24-docker-candidate',
|
||||
'scratch': True,
|
||||
}
|
||||
self._setupMock(KojiWrapper, resolve_git_url, scratch=True)
|
||||
self._assertConfigCorrect(cfg)
|
||||
self._setupMock(KojiWrapper, resolve_git_url)
|
||||
|
||||
self.t.process((self.compose, self.compose.variants['Server'], cfg), 1)
|
||||
|
||||
self.assertEqual(self.pool.metadata, {})
|
||||
|
||||
self._assertCorrectCalls({}, scratch=True)
|
||||
self._assertCorrectMetadata(scratch=True)
|
||||
self._assertRepoFile()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user