mount: Switch to using pycdio instead of pycdlib

Also add a root only test for IsoMountpoint.
This commit is contained in:
Brian C. Lane 2021-10-28 16:08:37 -07:00
parent 87f9f77e24
commit c4aba2e47f
4 changed files with 51 additions and 9 deletions

View File

@ -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

View File

@ -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)

View File

@ -13,7 +13,7 @@ python3-magic
python3-mako
python3-pocketlint
python3-psutil
python3-pycdlib
python3-pycdio
python3-pylint
python3-pytest
python3-pytest-cov

View File

@ -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")