[image-build] Allow running image build scratch tasks
Issue #130 Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
dc4d502f2a
commit
a698c7cc0a
@ -680,6 +680,8 @@ Image Build Settings
|
|||||||
If ``ksurl`` ends with ``#HEAD``, Pungi will figure out the SHA1 hash of
|
If ``ksurl`` ends with ``#HEAD``, Pungi will figure out the SHA1 hash of
|
||||||
current HEAD and use that instead.
|
current HEAD and use that instead.
|
||||||
|
|
||||||
|
Setting ``scratch`` to ``True`` will run the koji tasks as scratch builds.
|
||||||
|
|
||||||
|
|
||||||
Example
|
Example
|
||||||
-------
|
-------
|
||||||
|
@ -127,7 +127,8 @@ class ImageBuildPhase(PhaseBase):
|
|||||||
"relative_image_dir": self.compose.paths.compose.image_dir(
|
"relative_image_dir": self.compose.paths.compose.image_dir(
|
||||||
variant, relative=True
|
variant, relative=True
|
||||||
),
|
),
|
||||||
"link_type": self.compose.conf.get("link_type", "hardlink-or-copy")
|
"link_type": self.compose.conf.get("link_type", "hardlink-or-copy"),
|
||||||
|
"scratch": image_conf.pop('scratch', False),
|
||||||
}
|
}
|
||||||
self.pool.add(CreateImageBuildThread(self.pool))
|
self.pool.add(CreateImageBuildThread(self.pool))
|
||||||
self.pool.queue_put((self.compose, cmd))
|
self.pool.queue_put((self.compose, cmd))
|
||||||
@ -174,7 +175,8 @@ class CreateImageBuildThread(WorkerThread):
|
|||||||
self.pool.log_info("Writing image-build config for %s.%s into %s" % (
|
self.pool.log_info("Writing image-build config for %s.%s into %s" % (
|
||||||
cmd["image_conf"]["variant"], '-'.join(arches), cmd["conf_file"]))
|
cmd["image_conf"]["variant"], '-'.join(arches), cmd["conf_file"]))
|
||||||
koji_cmd = koji_wrapper.get_image_build_cmd(cmd['image_conf'],
|
koji_cmd = koji_wrapper.get_image_build_cmd(cmd['image_conf'],
|
||||||
conf_file_dest=cmd["conf_file"])
|
conf_file_dest=cmd["conf_file"],
|
||||||
|
scratch=cmd['scratch'])
|
||||||
|
|
||||||
# avoid race conditions?
|
# avoid race conditions?
|
||||||
# Kerberos authentication failed: Permission denied in replay cache code (-1765328215)
|
# Kerberos authentication failed: Permission denied in replay cache code (-1765328215)
|
||||||
|
@ -117,6 +117,7 @@ class TestImageBuildPhase(unittest.TestCase):
|
|||||||
"image_dir": '/image_dir/Client/%(arch)s',
|
"image_dir": '/image_dir/Client/%(arch)s',
|
||||||
"relative_image_dir": 'image_dir/Client/%(arch)s',
|
"relative_image_dir": 'image_dir/Client/%(arch)s',
|
||||||
"link_type": 'hardlink-or-copy',
|
"link_type": 'hardlink-or-copy',
|
||||||
|
"scratch": False,
|
||||||
}
|
}
|
||||||
server_args = {
|
server_args = {
|
||||||
"format": [('docker', 'tar.xz')],
|
"format": [('docker', 'tar.xz')],
|
||||||
@ -138,6 +139,7 @@ class TestImageBuildPhase(unittest.TestCase):
|
|||||||
"image_dir": '/image_dir/Server/%(arch)s',
|
"image_dir": '/image_dir/Server/%(arch)s',
|
||||||
"relative_image_dir": 'image_dir/Server/%(arch)s',
|
"relative_image_dir": 'image_dir/Server/%(arch)s',
|
||||||
"link_type": 'hardlink-or-copy',
|
"link_type": 'hardlink-or-copy',
|
||||||
|
"scratch": False,
|
||||||
}
|
}
|
||||||
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
|
self.assertItemsEqual(phase.pool.queue_put.mock_calls,
|
||||||
[mock.call((compose, client_args)),
|
[mock.call((compose, client_args)),
|
||||||
@ -225,6 +227,7 @@ class TestImageBuildPhase(unittest.TestCase):
|
|||||||
"image_dir": '/image_dir/Server/%(arch)s',
|
"image_dir": '/image_dir/Server/%(arch)s',
|
||||||
"relative_image_dir": 'image_dir/Server/%(arch)s',
|
"relative_image_dir": 'image_dir/Server/%(arch)s',
|
||||||
"link_type": 'hardlink-or-copy',
|
"link_type": 'hardlink-or-copy',
|
||||||
|
"scratch": False,
|
||||||
})
|
})
|
||||||
|
|
||||||
@mock.patch('pungi.phases.image_build.ThreadPool')
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
||||||
@ -280,6 +283,7 @@ class TestImageBuildPhase(unittest.TestCase):
|
|||||||
"image_dir": '/image_dir/Server/%(arch)s',
|
"image_dir": '/image_dir/Server/%(arch)s',
|
||||||
"relative_image_dir": 'image_dir/Server/%(arch)s',
|
"relative_image_dir": 'image_dir/Server/%(arch)s',
|
||||||
"link_type": 'hardlink-or-copy',
|
"link_type": 'hardlink-or-copy',
|
||||||
|
"scratch": False,
|
||||||
})
|
})
|
||||||
|
|
||||||
@mock.patch('pungi.phases.image_build.ThreadPool')
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
||||||
@ -316,6 +320,39 @@ class TestImageBuildPhase(unittest.TestCase):
|
|||||||
self.assertEqual(args[0][1].get('image_conf', {}).get('release'),
|
self.assertEqual(args[0][1].get('image_conf', {}).get('release'),
|
||||||
'20151203.0')
|
'20151203.0')
|
||||||
|
|
||||||
|
@mock.patch('pungi.phases.image_build.ThreadPool')
|
||||||
|
def test_image_build_scratch_build(self, ThreadPool):
|
||||||
|
compose = _DummyCompose({
|
||||||
|
'image_build': {
|
||||||
|
'^Server$': [
|
||||||
|
{
|
||||||
|
'format': [('docker', 'tar.xz')],
|
||||||
|
'name': 'Fedora-Docker-Base',
|
||||||
|
'target': 'f24',
|
||||||
|
'version': 'Rawhide',
|
||||||
|
'ksurl': 'git://git.fedorahosted.org/git/spin-kickstarts.git',
|
||||||
|
'kickstart': "fedora-docker-base.ks",
|
||||||
|
'distro': 'Fedora-20',
|
||||||
|
'disk_size': 3,
|
||||||
|
'arches': ['x86_64'],
|
||||||
|
'scratch': True,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'koji_profile': 'koji',
|
||||||
|
})
|
||||||
|
|
||||||
|
phase = ImageBuildPhase(compose)
|
||||||
|
|
||||||
|
phase.run()
|
||||||
|
|
||||||
|
# assert at least one thread was started
|
||||||
|
self.assertTrue(phase.pool.add.called)
|
||||||
|
|
||||||
|
self.assertTrue(phase.pool.queue_put.called_once)
|
||||||
|
args, kwargs = phase.pool.queue_put.call_args
|
||||||
|
self.assertTrue(args[0][1].get('scratch'))
|
||||||
|
|
||||||
|
|
||||||
class TestCreateImageBuildThread(unittest.TestCase):
|
class TestCreateImageBuildThread(unittest.TestCase):
|
||||||
|
|
||||||
@ -347,6 +384,7 @@ class TestCreateImageBuildThread(unittest.TestCase):
|
|||||||
"image_dir": '/image_dir/Client/%(arch)s',
|
"image_dir": '/image_dir/Client/%(arch)s',
|
||||||
"relative_image_dir": 'image_dir/Client/%(arch)s',
|
"relative_image_dir": 'image_dir/Client/%(arch)s',
|
||||||
"link_type": 'hardlink-or-copy',
|
"link_type": 'hardlink-or-copy',
|
||||||
|
"scratch": False,
|
||||||
}
|
}
|
||||||
koji_wrapper = KojiWrapper.return_value
|
koji_wrapper = KojiWrapper.return_value
|
||||||
koji_wrapper.run_create_image_cmd.return_value = {
|
koji_wrapper.run_create_image_cmd.return_value = {
|
||||||
|
Loading…
Reference in New Issue
Block a user