diff --git a/pungi/createiso.py b/pungi/createiso.py index 57badaec..8014a505 100644 --- a/pungi/createiso.py +++ b/pungi/createiso.py @@ -6,7 +6,7 @@ import os import pipes from collections import namedtuple -from .wrappers.iso import IsoWrapper +from .wrappers import iso from .wrappers.jigdo import JigdoWrapper @@ -40,7 +40,7 @@ fi """.replace('\n', '') -def make_image(f, iso, opts): +def make_image(f, opts): mkisofs_kwargs = {} if opts.buildinstall_method: @@ -62,12 +62,12 @@ def make_image(f, iso, opts): emit(f, cmd) -def implant_md5(f, iso, opts): +def implant_md5(f, opts): cmd = iso.get_implantisomd5_cmd(opts.iso_name, opts.supported) emit(f, cmd) -def run_isohybrid(f, iso, opts): +def run_isohybrid(f, opts): """If the image is bootable, it should include an MBR or GPT so that it can be booted when written to USB disk. This is done by running isohybrid on the image. @@ -77,7 +77,7 @@ def run_isohybrid(f, iso, opts): emit(f, cmd) -def make_manifest(f, iso, opts): +def make_manifest(f, opts): emit(f, iso.get_manifest_cmd(opts.iso_name)) @@ -103,10 +103,9 @@ def write_script(opts, f): emit(f, "#!/bin/bash") emit(f, "set -ex") emit(f, "cd %s" % opts.output_dir) - iso = IsoWrapper() - make_image(f, iso, opts) - run_isohybrid(f, iso, opts) - implant_md5(f, iso, opts) - make_manifest(f, iso, opts) + make_image(f, opts) + run_isohybrid(f, opts) + implant_md5(f, opts) + make_manifest(f, opts) if opts.jigdo_dir: make_jigdo(f, opts) diff --git a/pungi/phases/buildinstall.py b/pungi/phases/buildinstall.py index 4c03bde0..5ad96deb 100644 --- a/pungi/phases/buildinstall.py +++ b/pungi/phases/buildinstall.py @@ -31,7 +31,7 @@ from pungi.util import get_buildroot_rpms, get_volid, get_arch_variant_data from pungi.util import get_file_size, get_mtime, failable from pungi.wrappers.lorax import LoraxWrapper from pungi.wrappers.kojiwrapper import KojiWrapper -from pungi.wrappers.iso import IsoWrapper +from pungi.wrappers import iso from pungi.wrappers.scm import get_file_from_scm from pungi.phases.base import PhaseBase @@ -312,7 +312,6 @@ def link_boot_iso(compose, arch, variant, can_fail): except OSError: shutil.copy2(boot_iso_path, new_boot_iso_path) - iso = IsoWrapper() implant_md5 = iso.get_implanted_md5(new_boot_iso_path) iso_name = os.path.basename(new_boot_iso_path) iso_dir = os.path.dirname(new_boot_iso_path) diff --git a/pungi/phases/createiso.py b/pungi/phases/createiso.py index 8f2eeca6..b05a9123 100644 --- a/pungi/phases/createiso.py +++ b/pungi/phases/createiso.py @@ -25,7 +25,7 @@ from productmd.images import Image from kobo.threads import ThreadPool, WorkerThread from kobo.shortcuts import run, relative_path -from pungi.wrappers.iso import IsoWrapper +from pungi.wrappers import iso from pungi.wrappers.createrepo import CreaterepoWrapper from pungi.wrappers.kojiwrapper import KojiWrapper from pungi.phases.base import PhaseBase @@ -246,8 +246,6 @@ class CreateIsoThread(WorkerThread): self.fail(compose, cmd, variant, arch) raise - iso = IsoWrapper() - img = Image(compose.im) img.path = cmd["iso_path"].replace(compose.paths.compose.topdir(), '').lstrip('/') img.mtime = get_mtime(cmd["iso_path"]) @@ -412,13 +410,12 @@ def prepare_iso(compose, arch, variant, disc_num=1, disc_count=None, split_iso_d new_di_path = os.path.join(iso_dir, ".discinfo") write_discinfo(new_di_path, **data) - i = IsoWrapper() if not disc_count or disc_count == 1: - data = i.get_graft_points([tree_dir, iso_dir]) + data = iso.get_graft_points([tree_dir, iso_dir]) else: - data = i.get_graft_points([i._paths_from_list(tree_dir, split_iso_data["files"]), iso_dir]) + data = iso.get_graft_points([iso._paths_from_list(tree_dir, split_iso_data["files"]), iso_dir]) # TODO: /content /graft-points gp = "%s-graft-points" % iso_dir - i.write_graft_points(gp, data, exclude=["*/lost+found", "*/boot.iso"]) + iso.write_graft_points(gp, data, exclude=["*/lost+found", "*/boot.iso"]) return gp diff --git a/pungi/phases/live_images.py b/pungi/phases/live_images.py index 4630f1bb..e2b403df 100644 --- a/pungi/phases/live_images.py +++ b/pungi/phases/live_images.py @@ -25,7 +25,7 @@ from kobo.shortcuts import run, save_to_file, force_list from productmd.images import Image from pungi.wrappers.kojiwrapper import KojiWrapper -from pungi.wrappers.iso import IsoWrapper +from pungi.wrappers import iso from pungi.phases import base from pungi.util import get_arch_variant_data, makedirs, get_mtime, get_file_size, failable from pungi.paths import translate_path @@ -268,7 +268,6 @@ class CreateLiveImageThread(WorkerThread): :param iso_path: (str) absolute path to the ISO """ dir, filename = os.path.split(iso_path) - iso = IsoWrapper() run("cd %s && %s" % (pipes.quote(dir), iso.get_manifest_cmd(filename))) def _sign_image(self, koji_wrapper, compose, cmd, koji_task_id): diff --git a/pungi/phases/ostree_installer.py b/pungi/phases/ostree_installer.py index f274e321..521a442b 100644 --- a/pungi/phases/ostree_installer.py +++ b/pungi/phases/ostree_installer.py @@ -100,8 +100,7 @@ class OstreeInstallerThread(WorkerThread): def _add_to_manifest(self, compose, variant, arch, filename): full_iso_path = compose.paths.compose.iso_path(arch, variant, filename) iso_path = compose.paths.compose.iso_path(arch, variant, filename, relative=True) - iso_wrapper = iso.IsoWrapper() - implant_md5 = iso_wrapper.get_implanted_md5(full_iso_path) + implant_md5 = iso.get_implanted_md5(full_iso_path) img = images.Image(compose.im) img.path = iso_path @@ -118,7 +117,7 @@ class OstreeInstallerThread(WorkerThread): setattr(img, 'can_fail', self.can_fail) setattr(img, 'deliverable', 'ostree-installer') try: - img.volume_id = iso_wrapper.get_volume_id(full_iso_path) + img.volume_id = iso.get_volume_id(full_iso_path) except RuntimeError: pass compose.im.add(variant.uid, arch, img) diff --git a/pungi/phases/product_img.py b/pungi/phases/product_img.py index ad974945..dc3e316f 100644 --- a/pungi/phases/product_img.py +++ b/pungi/phases/product_img.py @@ -47,7 +47,7 @@ from kobo.shortcuts import run from pungi.arch import split_name_arch from pungi.util import makedirs, pkg_is_rpm from pungi.phases.base import PhaseBase -from pungi.wrappers.iso import IsoWrapper +from pungi.wrappers import iso from pungi.wrappers.scm import get_file_from_scm, get_dir_from_scm @@ -178,8 +178,6 @@ def rebuild_boot_iso(compose, arch, variant, package_sets): compose.log_info("[BEGIN] %s" % msg) - iso = IsoWrapper() - # read the original volume id volume_id = iso.get_volume_id(boot_iso) diff --git a/pungi/util.py b/pungi/util.py index 4b81f917..a65fb992 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -380,10 +380,6 @@ def get_volid(compose, arch, variant=None, escape_spaces=False, disc_type=False) if len(volid) <= 32: break - # from wrappers.iso import IsoWrapper - # iso = IsoWrapper(logger=compose._logger) - # volid = iso._truncate_volid(volid) - if volid and len(volid) > 32: raise ValueError("Could not create volume ID <= 32 characters") diff --git a/pungi/wrappers/iso.py b/pungi/wrappers/iso.py index 774310e5..2a7640f8 100644 --- a/pungi/wrappers/iso.py +++ b/pungi/wrappers/iso.py @@ -29,309 +29,312 @@ if sys.version_info[0] == 3: return (a > b) - (a < b) -class IsoWrapper(kobo.log.LoggingBase): +def get_boot_options(arch, createfrom, efi=True): + """Checks to see what we need as the -b option for mkisofs""" - def get_boot_options(self, arch, createfrom, efi=True): - """Checks to see what we need as the -b option for mkisofs""" + if arch in ("arm", "armhfp"): + result = [] + return result - if arch in ("arm", "armhfp"): - result = [] - return result + if arch in ("aarch64", ): + result = [ + '-eltorito-alt-boot', + '-e', 'images/efiboot.img', + '-no-emul-boot', + ] + return result - if arch in ("aarch64", ): - result = [ + if arch in ("i386", "i686", "x86_64"): + result = [ + '-b', 'isolinux/isolinux.bin', + '-c', 'isolinux/boot.cat', + '-no-emul-boot', + '-boot-load-size', '4', + '-boot-info-table', + ] + + # EFI args + if arch == "x86_64": + result.extend([ '-eltorito-alt-boot', '-e', 'images/efiboot.img', '-no-emul-boot', - ] - return result + ]) + return result - if arch in ("i386", "i686", "x86_64"): - result = [ - '-b', 'isolinux/isolinux.bin', - '-c', 'isolinux/boot.cat', - '-no-emul-boot', - '-boot-load-size', '4', - '-boot-info-table', - ] + if arch == "ia64": + result = [ + '-b', 'images/boot.img', + '-no-emul-boot', + ] + return result - # EFI args - if arch == "x86_64": - result.extend([ - '-eltorito-alt-boot', - '-e', 'images/efiboot.img', - '-no-emul-boot', - ]) - return result + if arch in ("ppc", "ppc64", "ppc64le"): + result = [ + '-part', + '-hfs', + '-r', + '-l', + '-sysid', 'PPC', + '-no-desktop', + '-allow-multidot', + '-chrp-boot', + "-map", os.path.join(createfrom, 'mapping'), # -map %s/ppc/mapping + '-hfs-bless', "/ppc/mac", # must be the last + ] + return result - if arch == "ia64": - result = [ - '-b', 'images/boot.img', - '-no-emul-boot', - ] - return result + if arch == "sparc": + result = [ + '-G', '/boot/isofs.b', + '-B', '...', + '-s', '/boot/silo.conf', + '-sparc-label', '"sparc"', + ] + return result - if arch in ("ppc", "ppc64", "ppc64le"): - result = [ - '-part', - '-hfs', - '-r', - '-l', - '-sysid', 'PPC', - '-no-desktop', - '-allow-multidot', - '-chrp-boot', - "-map", os.path.join(createfrom, 'mapping'), # -map %s/ppc/mapping - '-hfs-bless', "/ppc/mac", # must be the last - ] - return result + if arch in ("s390", "s390x"): + result = [ + # "-no-emul-boot", + # "-b", "images/cdboot.img", + # "-c", "boot.cat", + ] + return result - if arch == "sparc": - result = [ - '-G', '/boot/isofs.b', - '-B', '...', - '-s', '/boot/silo.conf', - '-sparc-label', '"sparc"', - ] - return result + raise ValueError("Unknown arch: %s" % arch) - if arch in ("s390", "s390x"): - result = [ - # "-no-emul-boot", - # "-b", "images/cdboot.img", - # "-c", "boot.cat", - ] - return result - raise ValueError("Unknown arch: %s" % arch) +def _truncate_volid(volid): + if len(volid) > 32: + volid = volid.replace("-", "") - def _truncate_volid(self, volid): - if len(volid) > 32: - old_volid = volid - volid = volid.replace("-", "") - self.log_warning("Truncating volume ID from '%s' to '%s'" % (old_volid, volid)) + if len(volid) > 32: + volid = volid.replace(" ", "") - if len(volid) > 32: - old_volid = volid - volid = volid.replace(" ", "") - self.log_warning("Truncating volume ID from '%s' to '%s'" % (old_volid, volid)) + if len(volid) > 32: + volid = volid.replace("Supplementary", "Supp") - if len(volid) > 32: - old_volid = volid - volid = volid.replace("Supplementary", "Supp") - self.log_warning("Truncating volume ID from '%s' to '%s'" % (old_volid, volid)) + if len(volid) > 32: + raise ValueError("Volume ID must be less than 32 character: %s" % volid) - if len(volid) > 32: - raise ValueError("Volume ID must be less than 32 character: %s" % volid) + return volid - return volid - def get_mkisofs_cmd(self, iso, paths, appid=None, volid=None, volset=None, exclude=None, verbose=False, boot_args=None, input_charset="utf-8", graft_points=None): - # following options are always enabled - untranslated_filenames = True - translation_table = True - joliet = True - joliet_long = True - rock = True +def get_mkisofs_cmd(iso, paths, appid=None, volid=None, volset=None, exclude=None, verbose=False, boot_args=None, input_charset="utf-8", graft_points=None): + # following options are always enabled + untranslated_filenames = True + translation_table = True + joliet = True + joliet_long = True + rock = True - cmd = ["/usr/bin/genisoimage"] - if appid: - cmd.extend(["-appid", appid]) + cmd = ["/usr/bin/genisoimage"] + if appid: + cmd.extend(["-appid", appid]) - if untranslated_filenames: - cmd.append("-untranslated-filenames") + if untranslated_filenames: + cmd.append("-untranslated-filenames") - if volid: - cmd.extend(["-volid", self._truncate_volid(volid)]) + if volid: + cmd.extend(["-volid", _truncate_volid(volid)]) - if joliet: - cmd.append("-J") + if joliet: + cmd.append("-J") - if joliet_long: - cmd.append("-joliet-long") + if joliet_long: + cmd.append("-joliet-long") - if volset: - cmd.extend(["-volset", volset]) + if volset: + cmd.extend(["-volset", volset]) - if rock: - cmd.append("-rational-rock") + if rock: + cmd.append("-rational-rock") - if verbose: - cmd.append("-verbose") + if verbose: + cmd.append("-verbose") - if translation_table: - cmd.append("-translation-table") + if translation_table: + cmd.append("-translation-table") - if input_charset: - cmd.extend(["-input-charset", input_charset]) + if input_charset: + cmd.extend(["-input-charset", input_charset]) - if exclude: - for i in force_list(exclude): - cmd.extend(["-x", i]) + if exclude: + for i in force_list(exclude): + cmd.extend(["-x", i]) - if boot_args: - cmd.extend(boot_args) + if boot_args: + cmd.extend(boot_args) - cmd.extend(["-o", iso]) + cmd.extend(["-o", iso]) - if graft_points: - cmd.append("-graft-points") - cmd.extend(["-path-list", graft_points]) + if graft_points: + cmd.append("-graft-points") + cmd.extend(["-path-list", graft_points]) + else: + # we're either using graft points or file lists, not both + cmd.extend(force_list(paths)) + + return cmd + + +def get_implantisomd5_cmd(iso_path, supported=False): + cmd = ["/usr/bin/implantisomd5"] + if supported: + cmd.append("--supported-iso") + cmd.append(iso_path) + return cmd + + +def get_checkisomd5_cmd(iso_path, just_print=False): + cmd = ["/usr/bin/checkisomd5"] + if just_print: + cmd.append("--md5sumonly") + cmd.append(iso_path) + return cmd + + +def get_implanted_md5(iso_path): + cmd = get_checkisomd5_cmd(iso_path, just_print=True) + retcode, output = run(cmd) + line = output.splitlines()[0] + return line.rsplit(":")[-1].strip() + + +def get_isohybrid_cmd(iso_path, arch): + # isohybrid is in syslinux which is x86 only + cmd = ["/usr/bin/isohybrid"] + # uefi is only supported on x86_64 + if arch == "x86_64": + cmd.append("--uefi") + cmd.append(iso_path) + return cmd + + +def get_manifest_cmd(iso_name): + return "isoinfo -R -f -i %s | grep -v '/TRANS.TBL$' | sort >> %s.manifest" % (pipes.quote(iso_name), pipes.quote(iso_name)) + + +def get_volume_id(path): + cmd = ["isoinfo", "-d", "-i", path] + retcode, output = run(cmd) + + for line in output.splitlines(): + line = line.strip() + if line.startswith("Volume id:"): + return line[11:].strip() + + raise RuntimeError("Could not read Volume ID") + + +def get_graft_points(paths, exclusive_paths=None, exclude=None): + # path priority in ascending order (1st = lowest prio) + # paths merge according to priority + # exclusive paths override whole dirs + + result = {} + exclude = exclude or [] + exclusive_paths = exclusive_paths or [] + + for i in paths: + if isinstance(i, dict): + tree = i else: - # we're either using graft points or file lists, not both - cmd.extend(force_list(paths)) + tree = _scan_tree(i) + result = _merge_trees(result, tree) - return cmd + for i in exclusive_paths: + tree = _scan_tree(i) + result = _merge_trees(result, tree, exclusive=True) - def get_implantisomd5_cmd(self, iso_path, supported=False): - cmd = ["/usr/bin/implantisomd5"] - if supported: - cmd.append("--supported-iso") - cmd.append(iso_path) - return cmd + # TODO: exclude + return result - def get_checkisomd5_cmd(self, iso_path, just_print=False): - cmd = ["/usr/bin/checkisomd5"] - if just_print: - cmd.append("--md5sumonly") - cmd.append(iso_path) - return cmd +def _paths_from_list(root, paths): + root = os.path.abspath(root).rstrip("/") + "/" + result = {} + for i in paths: + i = os.path.normpath(os.path.join(root, i)) + key = i[len(root):] + result[key] = i + return result - def get_implanted_md5(self, iso_path): - cmd = self.get_checkisomd5_cmd(iso_path, just_print=True) - retcode, output = run(cmd) - line = output.splitlines()[0] - result = line.rsplit(":")[-1].strip() - return result - def get_isohybrid_cmd(self, iso_path, arch): - # isohybrid is in syslinux which is x86 only - cmd = ["/usr/bin/isohybrid"] - # uefi is only supported on x86_64 - if arch == "x86_64": - cmd.append("--uefi") - cmd.append(iso_path) - return cmd +def _scan_tree(path): + path = os.path.abspath(path) + result = {} + for root, dirs, files in os.walk(path): + for f in files: + abspath = os.path.join(root, f) + relpath = relative_path(abspath, path.rstrip("/") + "/") + result[relpath] = abspath - def get_manifest_cmd(self, iso_name): - return "isoinfo -R -f -i %s | grep -v '/TRANS.TBL$' | sort >> %s.manifest" % (pipes.quote(iso_name), pipes.quote(iso_name)) + # include empty dirs + if root != path: + abspath = os.path.join(root, "") + relpath = relative_path(abspath, path.rstrip("/") + "/") + result[relpath] = abspath - def get_volume_id(self, path): - cmd = ["isoinfo", "-d", "-i", path] - retcode, output = run(cmd) + return result - for line in output.splitlines(): - line = line.strip() - if line.startswith("Volume id:"): - return line[11:].strip() - raise RuntimeError("Could not read Volume ID") +def _merge_trees(tree1, tree2, exclusive=False): + # tree2 has higher priority + result = tree2.copy() + all_dirs = set([os.path.dirname(i).rstrip("/") for i in result if os.path.dirname(i) != ""]) - def get_graft_points(self, paths, exclusive_paths=None, exclude=None): - # path priority in ascending order (1st = lowest prio) - # paths merge according to priority - # exclusive paths override whole dirs - - result = {} - exclude = exclude or [] - exclusive_paths = exclusive_paths or [] - - for i in paths: - if isinstance(i, dict): - tree = i - else: - tree = self._scan_tree(i) - result = self._merge_trees(result, tree) - - for i in exclusive_paths: - tree = self._scan_tree(i) - result = self._merge_trees(result, tree, exclusive=True) - - # TODO: exclude - return result - - def _paths_from_list(self, root, paths): - root = os.path.abspath(root).rstrip("/") + "/" - result = {} - for i in paths: - i = os.path.normpath(os.path.join(root, i)) - key = i[len(root):] - result[key] = i - return result - - def _scan_tree(self, path): - path = os.path.abspath(path) - result = {} - for root, dirs, files in os.walk(path): - for f in files: - abspath = os.path.join(root, f) - relpath = relative_path(abspath, path.rstrip("/") + "/") - result[relpath] = abspath - - # include empty dirs - if root != path: - abspath = os.path.join(root, "") - relpath = relative_path(abspath, path.rstrip("/") + "/") - result[relpath] = abspath - - return result - - def _merge_trees(self, tree1, tree2, exclusive=False): - # tree2 has higher priority - result = tree2.copy() - all_dirs = set([os.path.dirname(i).rstrip("/") for i in result if os.path.dirname(i) != ""]) - - for i in tree1: - dn = os.path.dirname(i) - if exclusive: - match = False - for a in all_dirs: - if dn == a or dn.startswith("%s/" % a): - match = True - break - if match: - continue - - if i in result: - continue - - result[i] = tree1[i] - return result - - def write_graft_points(self, file_name, h, exclude=None): - exclude = exclude or [] - result = {} - seen_dirs = set() - for i in sorted(h, reverse=True): - dn = os.path.dirname(i) - - if not i.endswith("/"): - result[i] = h[i] - seen_dirs.add(dn) - continue - - found = False - for j in seen_dirs: - if j.startswith(dn): - found = True + for i in tree1: + dn = os.path.dirname(i) + if exclusive: + match = False + for a in all_dirs: + if dn == a or dn.startswith("%s/" % a): + match = True break - if not found: - result[i] = h[i] + if match: + continue + + if i in result: + continue + + result[i] = tree1[i] + return result + + +def write_graft_points(file_name, h, exclude=None): + exclude = exclude or [] + result = {} + seen_dirs = set() + for i in sorted(h, reverse=True): + dn = os.path.dirname(i) + + if not i.endswith("/"): + result[i] = h[i] seen_dirs.add(dn) + continue - f = open(file_name, "w") - for i in sorted(result, cmp=cmp_graft_points): - # make sure all files required for boot come first, - # otherwise there may be problems with booting (large LBA address, etc.) - found = False - for excl in exclude: - if fnmatch(i, excl): - found = True - break - if found: - continue - f.write("%s=%s\n" % (i, h[i])) - f.close() + found = False + for j in seen_dirs: + if j.startswith(dn): + found = True + break + if not found: + result[i] = h[i] + seen_dirs.add(dn) + + f = open(file_name, "w") + for i in sorted(result, cmp=cmp_graft_points): + # make sure all files required for boot come first, + # otherwise there may be problems with booting (large LBA address, etc.) + found = False + for excl in exclude: + if fnmatch(i, excl): + found = True + break + if found: + continue + f.write("%s=%s\n" % (i, h[i])) + f.close() def _is_rpm(path): diff --git a/tests/test_buildinstall.py b/tests/test_buildinstall.py index 41044e7e..15491c56 100755 --- a/tests/test_buildinstall.py +++ b/tests/test_buildinstall.py @@ -636,11 +636,10 @@ class TestSymlinkIso(PungiTestCase): @mock.patch('pungi.phases.buildinstall.Image') @mock.patch('pungi.phases.buildinstall.get_mtime') @mock.patch('pungi.phases.buildinstall.get_file_size') - @mock.patch('pungi.phases.buildinstall.IsoWrapper') + @mock.patch('pungi.phases.buildinstall.iso') @mock.patch('pungi.phases.buildinstall.run') - def test_hardlink(self, run, IsoWrapperCls, get_file_size, get_mtime, ImageCls): + def test_hardlink(self, run, iso, get_file_size, get_mtime, ImageCls): self.compose.conf = {'buildinstall_symlink': False, 'disc_types': {}} - IsoWrapper = IsoWrapperCls.return_value get_file_size.return_value = 1024 get_mtime.return_value = 13579 @@ -655,14 +654,14 @@ class TestSymlinkIso(PungiTestCase): self.compose.get_image_name.mock_calls, [mock.call('x86_64', self.compose.variants['Server'], disc_type='boot', disc_num=None, suffix='.iso')]) - self.assertItemsEqual(IsoWrapper.get_implanted_md5.mock_calls, + self.assertItemsEqual(iso.get_implanted_md5.mock_calls, [mock.call(tgt)]) - self.assertItemsEqual(IsoWrapper.get_manifest_cmd.mock_calls, + self.assertItemsEqual(iso.get_manifest_cmd.mock_calls, [mock.call('image-name')]) - self.assertItemsEqual(IsoWrapper.get_volume_id.mock_calls, + self.assertItemsEqual(iso.get_volume_id.mock_calls, [mock.call(tgt)]) self.assertItemsEqual(run.mock_calls, - [mock.call(IsoWrapper.get_manifest_cmd.return_value, + [mock.call(iso.get_manifest_cmd.return_value, workdir=self.topdir + '/compose/Server/x86_64/iso')]) image = ImageCls.return_value @@ -675,7 +674,7 @@ class TestSymlinkIso(PungiTestCase): self.assertEqual(image.disc_number, 1) self.assertEqual(image.disc_count, 1) self.assertEqual(image.bootable, True) - self.assertEqual(image.implant_md5, IsoWrapper.get_implanted_md5.return_value) + self.assertEqual(image.implant_md5, iso.get_implanted_md5.return_value) self.assertEqual(image.can_fail, False) self.assertEqual(self.compose.im.add.mock_calls, [mock.call('Server', 'x86_64', image)]) @@ -683,14 +682,13 @@ class TestSymlinkIso(PungiTestCase): @mock.patch('pungi.phases.buildinstall.Image') @mock.patch('pungi.phases.buildinstall.get_mtime') @mock.patch('pungi.phases.buildinstall.get_file_size') - @mock.patch('pungi.phases.buildinstall.IsoWrapper') + @mock.patch('pungi.phases.buildinstall.iso') @mock.patch('pungi.phases.buildinstall.run') - def test_hardlink_with_custom_type(self, run, IsoWrapperCls, get_file_size, get_mtime, ImageCls): + def test_hardlink_with_custom_type(self, run, iso, get_file_size, get_mtime, ImageCls): self.compose.conf = { 'buildinstall_symlink': False, 'disc_types': {'boot': 'netinst'}, } - IsoWrapper = IsoWrapperCls.return_value get_file_size.return_value = 1024 get_mtime.return_value = 13579 @@ -705,14 +703,14 @@ class TestSymlinkIso(PungiTestCase): self.compose.get_image_name.mock_calls, [mock.call('x86_64', self.compose.variants['Server'], disc_type='netinst', disc_num=None, suffix='.iso')]) - self.assertItemsEqual(IsoWrapper.get_implanted_md5.mock_calls, + self.assertItemsEqual(iso.get_implanted_md5.mock_calls, [mock.call(tgt)]) - self.assertItemsEqual(IsoWrapper.get_manifest_cmd.mock_calls, + self.assertItemsEqual(iso.get_manifest_cmd.mock_calls, [mock.call('image-name')]) - self.assertItemsEqual(IsoWrapper.get_volume_id.mock_calls, + self.assertItemsEqual(iso.get_volume_id.mock_calls, [mock.call(tgt)]) self.assertItemsEqual(run.mock_calls, - [mock.call(IsoWrapper.get_manifest_cmd.return_value, + [mock.call(iso.get_manifest_cmd.return_value, workdir=self.topdir + '/compose/Server/x86_64/iso')]) image = ImageCls.return_value @@ -725,7 +723,7 @@ class TestSymlinkIso(PungiTestCase): self.assertEqual(image.disc_number, 1) self.assertEqual(image.disc_count, 1) self.assertEqual(image.bootable, True) - self.assertEqual(image.implant_md5, IsoWrapper.get_implanted_md5.return_value) + self.assertEqual(image.implant_md5, iso.get_implanted_md5.return_value) self.assertEqual(image.can_fail, True) self.assertEqual(self.compose.im.add.mock_calls, [mock.call('Server', 'x86_64', image)]) diff --git a/tests/test_createiso_phase.py b/tests/test_createiso_phase.py index a45a0983..ea1bdfa1 100755 --- a/tests/test_createiso_phase.py +++ b/tests/test_createiso_phase.py @@ -208,11 +208,11 @@ class CreateisoPhaseTest(helpers.PungiTestCase): class CreateisoThreadTest(helpers.PungiTestCase): - @mock.patch('pungi.phases.createiso.IsoWrapper') + @mock.patch('pungi.phases.createiso.iso') @mock.patch('pungi.phases.createiso.get_mtime') @mock.patch('pungi.phases.createiso.get_file_size') @mock.patch('pungi.phases.createiso.KojiWrapper') - def test_process_in_runroot(self, KojiWrapper, get_file_size, get_mtime, IsoWrapper): + def test_process_in_runroot(self, KojiWrapper, get_file_size, get_mtime, iso): compose = helpers.DummyCompose(self.topdir, { 'release_short': 'test', 'release_version': '1.0', @@ -256,9 +256,9 @@ class CreateisoThreadTest(helpers.PungiTestCase): run_runroot.call_args_list, [mock.call(get_runroot_cmd.return_value, log_file='%s/logs/x86_64/createiso-image-name.x86_64.log' % self.topdir)]) - self.assertEqual(IsoWrapper.return_value.get_implanted_md5.call_args_list, + self.assertEqual(iso.get_implanted_md5.call_args_list, [mock.call(cmd['iso_path'])]) - self.assertEqual(IsoWrapper.return_value.get_volume_id.call_args_list, + self.assertEqual(iso.get_volume_id.call_args_list, [mock.call(cmd['iso_path'])]) self.assertEqual(len(compose.im.add.call_args_list), 1) @@ -272,11 +272,11 @@ class CreateisoThreadTest(helpers.PungiTestCase): self.assertEqual(image.type, 'dvd') self.assertEqual(image.subvariant, 'Server') - @mock.patch('pungi.phases.createiso.IsoWrapper') + @mock.patch('pungi.phases.createiso.iso') @mock.patch('pungi.phases.createiso.get_mtime') @mock.patch('pungi.phases.createiso.get_file_size') @mock.patch('pungi.phases.createiso.KojiWrapper') - def test_process_source_iso(self, KojiWrapper, get_file_size, get_mtime, IsoWrapper): + def test_process_source_iso(self, KojiWrapper, get_file_size, get_mtime, iso): compose = helpers.DummyCompose(self.topdir, { 'release_short': 'test', 'release_version': '1.0', @@ -320,9 +320,9 @@ class CreateisoThreadTest(helpers.PungiTestCase): run_runroot.call_args_list, [mock.call(get_runroot_cmd.return_value, log_file='%s/logs/src/createiso-image-name.src.log' % self.topdir)]) - self.assertEqual(IsoWrapper.return_value.get_implanted_md5.call_args_list, + self.assertEqual(iso.get_implanted_md5.call_args_list, [mock.call(cmd['iso_path'])]) - self.assertEqual(IsoWrapper.return_value.get_volume_id.call_args_list, + self.assertEqual(iso.get_volume_id.call_args_list, [mock.call(cmd['iso_path'])]) self.assertEqual(len(compose.im.add.call_args_list), 2) @@ -336,11 +336,11 @@ class CreateisoThreadTest(helpers.PungiTestCase): self.assertEqual(image.type, 'dvd') self.assertEqual(image.subvariant, 'Server') - @mock.patch('pungi.phases.createiso.IsoWrapper') + @mock.patch('pungi.phases.createiso.iso') @mock.patch('pungi.phases.createiso.get_mtime') @mock.patch('pungi.phases.createiso.get_file_size') @mock.patch('pungi.phases.createiso.KojiWrapper') - def test_process_bootable(self, KojiWrapper, get_file_size, get_mtime, IsoWrapper): + def test_process_bootable(self, KojiWrapper, get_file_size, get_mtime, iso): compose = helpers.DummyCompose(self.topdir, { 'release_short': 'test', 'release_version': '1.0', @@ -386,9 +386,9 @@ class CreateisoThreadTest(helpers.PungiTestCase): run_runroot.call_args_list, [mock.call(get_runroot_cmd.return_value, log_file='%s/logs/x86_64/createiso-image-name.x86_64.log' % self.topdir)]) - self.assertEqual(IsoWrapper.return_value.get_implanted_md5.call_args_list, + self.assertEqual(iso.get_implanted_md5.call_args_list, [mock.call(cmd['iso_path'])]) - self.assertEqual(IsoWrapper.return_value.get_volume_id.call_args_list, + self.assertEqual(iso.get_volume_id.call_args_list, [mock.call(cmd['iso_path'])]) self.assertEqual(len(compose.im.add.call_args_list), 1) @@ -402,12 +402,12 @@ class CreateisoThreadTest(helpers.PungiTestCase): self.assertEqual(image.type, 'dvd') self.assertEqual(image.subvariant, 'Server') - @mock.patch('pungi.phases.createiso.IsoWrapper') + @mock.patch('pungi.phases.createiso.iso') @mock.patch('pungi.phases.createiso.get_mtime') @mock.patch('pungi.phases.createiso.get_file_size') @mock.patch('pungi.phases.createiso.KojiWrapper') def test_process_in_runroot_non_existing_tag(self, KojiWrapper, get_file_size, - get_mtime, IsoWrapper): + get_mtime, iso): compose = helpers.DummyCompose(self.topdir, { 'release_short': 'test', 'release_version': '1.0', @@ -434,11 +434,11 @@ class CreateisoThreadTest(helpers.PungiTestCase): self.assertEqual('Tag "f25-build" does not exist.', str(ctx.exception)) - @mock.patch('pungi.phases.createiso.IsoWrapper') + @mock.patch('pungi.phases.createiso.iso') @mock.patch('pungi.phases.createiso.get_mtime') @mock.patch('pungi.phases.createiso.get_file_size') @mock.patch('pungi.phases.createiso.KojiWrapper') - def test_process_in_runroot_crash(self, KojiWrapper, get_file_size, get_mtime, IsoWrapper): + def test_process_in_runroot_crash(self, KojiWrapper, get_file_size, get_mtime, iso): compose = helpers.DummyCompose(self.topdir, { 'release_short': 'test', 'release_version': '1.0', @@ -472,11 +472,11 @@ class CreateisoThreadTest(helpers.PungiTestCase): mock.call('BOOM') ]) - @mock.patch('pungi.phases.createiso.IsoWrapper') + @mock.patch('pungi.phases.createiso.iso') @mock.patch('pungi.phases.createiso.get_mtime') @mock.patch('pungi.phases.createiso.get_file_size') @mock.patch('pungi.phases.createiso.KojiWrapper') - def test_process_in_runroot_fail(self, KojiWrapper, get_file_size, get_mtime, IsoWrapper): + def test_process_in_runroot_fail(self, KojiWrapper, get_file_size, get_mtime, iso): compose = helpers.DummyCompose(self.topdir, { 'release_short': 'test', 'release_version': '1.0', @@ -515,12 +515,12 @@ class CreateisoThreadTest(helpers.PungiTestCase): % (self.topdir + '/logs/x86_64/createiso-image-name.x86_64.log')) ]) - @mock.patch('pungi.phases.createiso.IsoWrapper') + @mock.patch('pungi.phases.createiso.iso') @mock.patch('pungi.phases.createiso.get_mtime') @mock.patch('pungi.phases.createiso.get_file_size') @mock.patch('pungi.phases.createiso.run') @mock.patch('pungi.phases.createiso.KojiWrapper') - def test_process_locally(self, KojiWrapper, run, get_file_size, get_mtime, IsoWrapper): + def test_process_locally(self, KojiWrapper, run, get_file_size, get_mtime, iso): compose = helpers.DummyCompose(self.topdir, { 'release_short': 'test', 'release_version': '1.0', @@ -547,9 +547,9 @@ class CreateisoThreadTest(helpers.PungiTestCase): run.call_args_list, [mock.call(cmd['cmd'], show_cmd=True, logfile='%s/logs/x86_64/createiso-image-name.x86_64.log' % self.topdir)]) - self.assertEqual(IsoWrapper.return_value.get_implanted_md5.call_args_list, + self.assertEqual(iso.get_implanted_md5.call_args_list, [mock.call(cmd['iso_path'])]) - self.assertEqual(IsoWrapper.return_value.get_volume_id.call_args_list, + self.assertEqual(iso.get_volume_id.call_args_list, [mock.call(cmd['iso_path'])]) self.assertEqual(len(compose.im.add.call_args_list), 1) diff --git a/tests/test_ostree_installer_phase.py b/tests/test_ostree_installer_phase.py index ea4dd106..6cbc8539 100644 --- a/tests/test_ostree_installer_phase.py +++ b/tests/test_ostree_installer_phase.py @@ -55,7 +55,7 @@ class OstreeThreadTest(helpers.PungiTestCase): 'image_volid_formats': ['{release_short}-{variant}-{arch}'], }) - def assertImageAdded(self, compose, ImageCls, IsoWrapper): + def assertImageAdded(self, compose, ImageCls, iso): image = ImageCls.return_value self.assertEqual(image.path, 'Everything/x86_64/iso/image-name') self.assertEqual(image.mtime, 13579) @@ -66,7 +66,7 @@ class OstreeThreadTest(helpers.PungiTestCase): self.assertEqual(image.disc_number, 1) self.assertEqual(image.disc_count, 1) self.assertEqual(image.bootable, True) - self.assertEqual(image.implant_md5, IsoWrapper.return_value.get_implanted_md5.return_value) + self.assertEqual(image.implant_md5, iso.get_implanted_md5.return_value) self.assertEqual(compose.im.add.mock_calls, [mock.call('Everything', 'x86_64', image)]) @@ -111,10 +111,10 @@ class OstreeThreadTest(helpers.PungiTestCase): @mock.patch('productmd.images.Image') @mock.patch('pungi.util.get_mtime') @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.wrappers.iso.IsoWrapper') + @mock.patch('pungi.phases.ostree_installer.iso') @mock.patch('os.link') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_run(self, KojiWrapper, link, IsoWrapper, + def test_run(self, KojiWrapper, link, iso, get_file_size, get_mtime, ImageCls, run): self.compose.supported = False pool = mock.Mock() @@ -140,17 +140,17 @@ class OstreeThreadTest(helpers.PungiTestCase): 'file://%s/compose/Everything/x86_64/os' % self.topdir, cfg['release']) self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path) - self.assertImageAdded(self.compose, ImageCls, IsoWrapper) + self.assertImageAdded(self.compose, ImageCls, iso) self.assertAllCopied(run) @mock.patch('kobo.shortcuts.run') @mock.patch('productmd.images.Image') @mock.patch('pungi.util.get_mtime') @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.wrappers.iso.IsoWrapper') + @mock.patch('pungi.phases.ostree_installer.iso') @mock.patch('os.link') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_run_external_source(self, KojiWrapper, link, IsoWrapper, + def test_run_external_source(self, KojiWrapper, link, iso, get_file_size, get_mtime, ImageCls, run): pool = mock.Mock() cfg = { @@ -173,18 +173,18 @@ class OstreeThreadTest(helpers.PungiTestCase): self.assertRunrootCall(koji, 'http://example.com/repo/x86_64/', cfg['release'], isfinal=True) self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path) - self.assertImageAdded(self.compose, ImageCls, IsoWrapper) + self.assertImageAdded(self.compose, ImageCls, iso) self.assertAllCopied(run) @mock.patch('kobo.shortcuts.run') @mock.patch('productmd.images.Image') @mock.patch('pungi.util.get_mtime') @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.wrappers.iso.IsoWrapper') + @mock.patch('pungi.wrappers.iso') @mock.patch('os.link') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') def test_fail_with_relative_template_path_but_no_repo(self, KojiWrapper, link, - IsoWrapper, get_file_size, + iso, get_file_size, get_mtime, ImageCls, run): pool = mock.Mock() cfg = { @@ -213,10 +213,10 @@ class OstreeThreadTest(helpers.PungiTestCase): @mock.patch('productmd.images.Image') @mock.patch('pungi.util.get_mtime') @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.wrappers.iso.IsoWrapper') + @mock.patch('pungi.phases.ostree_installer.iso') @mock.patch('os.link') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_run_clone_templates(self, KojiWrapper, link, IsoWrapper, + def test_run_clone_templates(self, KojiWrapper, link, iso, get_file_size, get_mtime, ImageCls, run, get_dir_from_scm): pool = mock.Mock() @@ -254,17 +254,17 @@ class OstreeThreadTest(helpers.PungiTestCase): extra=['--add-template=%s/some_file.txt' % templ_dir, '--add-arch-template=%s/other_file.txt' % templ_dir]) self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path) - self.assertImageAdded(self.compose, ImageCls, IsoWrapper) + self.assertImageAdded(self.compose, ImageCls, iso) self.assertAllCopied(run) @mock.patch('kobo.shortcuts.run') @mock.patch('productmd.images.Image') @mock.patch('pungi.util.get_mtime') @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.wrappers.iso.IsoWrapper') + @mock.patch('pungi.phases.ostree_installer.iso') @mock.patch('os.link') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_run_with_implicit_release(self, KojiWrapper, link, IsoWrapper, + def test_run_with_implicit_release(self, KojiWrapper, link, iso, get_file_size, get_mtime, ImageCls, run): pool = mock.Mock() cfg = { @@ -312,17 +312,17 @@ class OstreeThreadTest(helpers.PungiTestCase): '--add-arch-template-var=ostree_ref=fedora-atomic/Rawhide/x86_64/docker-host'] ) self.assertIsoLinked(link, get_file_size, get_mtime, final_iso_path) - self.assertImageAdded(self.compose, ImageCls, IsoWrapper) + self.assertImageAdded(self.compose, ImageCls, iso) self.assertAllCopied(run) @mock.patch('kobo.shortcuts.run') @mock.patch('productmd.images.Image') @mock.patch('pungi.util.get_mtime') @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.wrappers.iso.IsoWrapper') + @mock.patch('pungi.phases.ostree_installer.iso') @mock.patch('os.link') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_fail_crash(self, KojiWrapper, link, IsoWrapper, get_file_size, + def test_fail_crash(self, KojiWrapper, link, iso, get_file_size, get_mtime, ImageCls, run): pool = mock.Mock() cfg = { @@ -345,10 +345,10 @@ class OstreeThreadTest(helpers.PungiTestCase): @mock.patch('productmd.images.Image') @mock.patch('pungi.util.get_mtime') @mock.patch('pungi.util.get_file_size') - @mock.patch('pungi.wrappers.iso.IsoWrapper') + @mock.patch('pungi.phases.ostree_installer.iso') @mock.patch('os.link') @mock.patch('pungi.wrappers.kojiwrapper.KojiWrapper') - def test_fail_runroot_fail(self, KojiWrapper, link, IsoWrapper, + def test_fail_runroot_fail(self, KojiWrapper, link, iso, get_file_size, get_mtime, ImageCls, run): pool = mock.Mock() cfg = {