createiso: Refactor code into smaller functions

This way some parts of the code will be reusable. This should have no
effects on the outcome, the tests still pass without any changes needed.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2018-05-11 10:38:56 +02:00
parent fc78a3cbb3
commit 48d0f2f643

View File

@ -201,16 +201,63 @@ class CreateIsoThread(WorkerThread):
arch, variant, os.path.basename(cmd["iso_path"])) arch, variant, os.path.basename(cmd["iso_path"]))
self.pool.log_info("[BEGIN] %s" % msg) self.pool.log_info("[BEGIN] %s" % msg)
try:
run_createiso_command(runroot, num, compose, bootable, arch,
cmd['cmd'], mounts, log_file)
except Exception:
self.fail(compose, cmd, variant, arch)
raise
add_iso_to_metadata(compose, variant, arch, cmd["iso_path"],
cmd["bootable"], cmd["disc_num"], cmd["disc_count"])
self.pool.log_info("[DONE ] %s" % msg)
if compose.notifier:
compose.notifier.send('createiso-imagedone',
file=cmd['iso_path'],
arch=arch,
variant=str(variant))
def add_iso_to_metadata(compose, variant, arch, iso_path, bootable, disc_num, disc_count):
img = Image(compose.im)
img.path = iso_path.replace(compose.paths.compose.topdir(), '').lstrip('/')
img.mtime = get_mtime(iso_path)
img.size = get_file_size(iso_path)
img.arch = arch
# XXX: HARDCODED
img.type = "dvd"
img.format = "iso"
img.disc_number = disc_num
img.disc_count = disc_count
img.bootable = bootable
img.subvariant = variant.uid
img.implant_md5 = iso.get_implanted_md5(iso_path, logger=compose._logger)
setattr(img, 'can_fail', compose.can_fail(variant, arch, 'iso'))
setattr(img, 'deliverable', 'iso')
try:
img.volume_id = iso.get_volume_id(iso_path)
except RuntimeError:
pass
if arch == "src":
for variant_arch in variant.arches:
compose.im.add(variant.uid, variant_arch, img)
else:
compose.im.add(variant.uid, arch, img)
def run_createiso_command(runroot, num, compose, bootable, arch, cmd, mounts,
log_file, with_jigdo=True):
if runroot: if runroot:
# run in a koji build root # run in a koji build root
packages = ["coreutils", "genisoimage", "isomd5sum"] packages = ["coreutils", "genisoimage", "isomd5sum"]
if compose.conf['create_jigdo']: if with_jigdo and compose.conf['create_jigdo']:
packages.append('jigdo') packages.append('jigdo')
if bootable:
extra_packages = { extra_packages = {
'lorax': ['lorax'], 'lorax': ['lorax'],
'buildinstall': ['anaconda'], 'buildinstall': ['anaconda'],
} }
if bootable:
packages.extend(extra_packages[compose.conf["buildinstall_method"]]) packages.extend(extra_packages[compose.conf["buildinstall_method"]])
runroot_channel = compose.conf.get("runroot_channel") runroot_channel = compose.conf.get("runroot_channel")
@ -234,63 +281,25 @@ class CreateIsoThread(WorkerThread):
build_arch = random.choice(tag_arches) build_arch = random.choice(tag_arches)
koji_cmd = koji_wrapper.get_runroot_cmd( koji_cmd = koji_wrapper.get_runroot_cmd(
runroot_tag, build_arch, cmd["cmd"], runroot_tag, build_arch, cmd,
channel=runroot_channel, use_shell=True, task_id=True, channel=runroot_channel, use_shell=True, task_id=True,
packages=packages, mounts=mounts, packages=packages, mounts=mounts,
weight=compose.conf['runroot_weights'].get('createiso') weight=compose.conf['runroot_weights'].get('createiso')
) )
# avoid race conditions? # This should avoid a possible race condition with multiple processes
# trying to get a kerberos ticket at the same time.
# Kerberos authentication failed: Permission denied in replay cache code (-1765328215) # Kerberos authentication failed: Permission denied in replay cache code (-1765328215)
time.sleep(num * 3) time.sleep(num * 3)
output = koji_wrapper.run_runroot_cmd(koji_cmd, log_file=log_file) output = koji_wrapper.run_runroot_cmd(koji_cmd, log_file=log_file)
if output["retcode"] != 0: if output["retcode"] != 0:
self.fail(compose, cmd, variant, arch)
raise RuntimeError("Runroot task failed: %s. See %s for more details." raise RuntimeError("Runroot task failed: %s. See %s for more details."
% (output["task_id"], log_file)) % (output["task_id"], log_file))
else: else:
# run locally # run locally
try: run(cmd, show_cmd=True, logfile=log_file)
run(cmd["cmd"], show_cmd=True, logfile=log_file)
except:
self.fail(compose, cmd, variant, arch)
raise
img = Image(compose.im)
img.path = cmd["iso_path"].replace(compose.paths.compose.topdir(), '').lstrip('/')
img.mtime = get_mtime(cmd["iso_path"])
img.size = get_file_size(cmd["iso_path"])
img.arch = arch
# XXX: HARDCODED
img.type = "dvd"
img.format = "iso"
img.disc_number = cmd["disc_num"]
img.disc_count = cmd["disc_count"]
img.bootable = cmd["bootable"]
img.subvariant = variant.uid
img.implant_md5 = iso.get_implanted_md5(cmd["iso_path"], logger=compose._logger)
setattr(img, 'can_fail', compose.can_fail(variant, arch, 'iso'))
setattr(img, 'deliverable', 'iso')
try:
img.volume_id = iso.get_volume_id(cmd["iso_path"])
except RuntimeError:
pass
if arch == "src":
for variant_arch in variant.arches:
compose.im.add(variant.uid, variant_arch, img)
else:
compose.im.add(variant.uid, arch, img)
# TODO: supported_iso_bit
# add: boot.iso
self.pool.log_info("[DONE ] %s" % msg)
if compose.notifier:
compose.notifier.send('createiso-imagedone',
file=cmd['iso_path'],
arch=arch,
variant=str(variant))
def split_iso(compose, arch, variant, no_split=False, logger=None): def split_iso(compose, arch, variant, no_split=False, logger=None):