diff --git a/lorax.spec b/lorax.spec index 0d806007..18630a15 100644 --- a/lorax.spec +++ b/lorax.spec @@ -51,7 +51,7 @@ Requires: python3-mako Requires: python3-kickstart >= 3.19 Requires: python3-dnf >= 3.2.0 Requires: python3-librepo -Requires: python3-pycdlib +Requires: python3-pycdio %if 0%{?fedora} # Fedora specific deps diff --git a/src/pylorax/mount.py b/src/pylorax/mount.py index e51cafb9..a489bc76 100644 --- a/src/pylorax/mount.py +++ b/src/pylorax/mount.py @@ -21,8 +21,7 @@ import logging log = logging.getLogger("livemedia-creator") import os -import pycdlib -from pycdlib.pycdlibexception import PyCdlibException +import iso9660 from pylorax.imgutils import mount, umount @@ -92,13 +91,18 @@ class IsoMountpoint(object): def get_iso_label(self): """ - Get the iso's label using pycdlib + Get the iso's label using pycdio Sets self.label if one is found """ try: - iso = pycdlib.PyCdlib() - iso.open(self.iso_path) - self.label = iso.pvd.volume_identifier.decode("UTF-8").strip() - except PyCdlibException as e: + iso = iso9660.ISO9660.IFS(source=self.iso_path) + if not iso.is_open(): + raise RuntimeError("error opening file") + + self.label = iso.get_volume_id() + if self.label is None: + self.label = "" + raise RuntimeError("error reading volume id") + except RuntimeError as e: log.error("Problem reading label from %s: %s", self.iso_path, e) diff --git a/test-packages b/test-packages index 70570dda..61c75226 100644 --- a/test-packages +++ b/test-packages @@ -13,7 +13,7 @@ python3-magic python3-mako python3-pocketlint python3-psutil -python3-pycdlib +python3-pycdio python3-pylint python3-pytest python3-pytest-cov diff --git a/tests/pylorax/test_mount.py b/tests/pylorax/test_mount.py new file mode 100644 index 00000000..08f3e99c --- /dev/null +++ b/tests/pylorax/test_mount.py @@ -0,0 +1,38 @@ +import os +import subprocess +import tempfile +import unittest + +from pylorax.mount import IsoMountpoint +from pylorax.sysutils import joinpaths + + +def mktestiso(rootdir, volid): + # Make some fake files + for f in ("/images/pxeboot/vmlinuz", "/images/pxeboot/initrd.img", "/LiveOS/squashfs.img"): + p = joinpaths(rootdir, "sysroot", f) + os.makedirs(os.path.dirname(p), exist_ok=True) + with open(p, "w") as ff: + ff.write("I AM FAKE FILE %s" % f.upper()) + + # Make an iso of the files + make_iso = ["xorrisofs", "-o", joinpaths(rootdir, "test.iso"), + "-R", "-J", "-V", volid, + "-graft-points", "/=%s" % joinpaths(rootdir, "sysroot")] + subprocess.check_call(make_iso) + +@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers") +class IsoMountpointTest(unittest.TestCase): + def test_volid(self): + with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir: + mktestiso(work_dir, "Fedora-test-iso-x86_64") + self.assertTrue(os.path.exists(joinpaths(work_dir, "test.iso"))) + + iso = IsoMountpoint(joinpaths(work_dir, "test.iso")) + self.addCleanup(iso.umount) + self.assertEqual(iso.iso_path, joinpaths(work_dir, "test.iso")) + self.assertIsNotNone(iso.mount_dir) + self.assertTrue(iso.stage2) + self.assertTrue(iso.kernel.endswith("vmlinuz")) + self.assertTrue(iso.initrd.endswith("initrd.img")) + self.assertEqual(iso.label, "Fedora-test-iso-x86_64")