mount: Switch to using pycdio instead of pycdlib
Also add a root only test for IsoMountpoint.
(cherry picked from commit c4aba2e47f
)
This commit is contained in:
parent
88f948f2eb
commit
225adff76c
@ -51,7 +51,7 @@ Requires: python3-mako
|
|||||||
Requires: python3-kickstart >= 3.19
|
Requires: python3-kickstart >= 3.19
|
||||||
Requires: python3-dnf >= 3.2.0
|
Requires: python3-dnf >= 3.2.0
|
||||||
Requires: python3-librepo
|
Requires: python3-librepo
|
||||||
Requires: python3-pycdlib
|
Requires: python3-pycdio
|
||||||
|
|
||||||
%if 0%{?fedora}
|
%if 0%{?fedora}
|
||||||
# Fedora specific deps
|
# Fedora specific deps
|
||||||
|
@ -21,8 +21,7 @@ import logging
|
|||||||
log = logging.getLogger("livemedia-creator")
|
log = logging.getLogger("livemedia-creator")
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pycdlib
|
import iso9660
|
||||||
from pycdlib.pycdlibexception import PyCdlibException
|
|
||||||
|
|
||||||
from pylorax.imgutils import mount, umount
|
from pylorax.imgutils import mount, umount
|
||||||
|
|
||||||
@ -92,13 +91,18 @@ class IsoMountpoint(object):
|
|||||||
|
|
||||||
def get_iso_label(self):
|
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
|
Sets self.label if one is found
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
iso = pycdlib.PyCdlib()
|
iso = iso9660.ISO9660.IFS(source=self.iso_path)
|
||||||
iso.open(self.iso_path)
|
if not iso.is_open():
|
||||||
self.label = iso.pvd.volume_identifier.decode("UTF-8").strip()
|
raise RuntimeError("error opening file")
|
||||||
except PyCdlibException as e:
|
|
||||||
|
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)
|
log.error("Problem reading label from %s: %s", self.iso_path, e)
|
||||||
|
@ -13,7 +13,7 @@ python3-magic
|
|||||||
python3-mako
|
python3-mako
|
||||||
python3-pocketlint
|
python3-pocketlint
|
||||||
python3-psutil
|
python3-psutil
|
||||||
python3-pycdlib
|
python3-pycdio
|
||||||
python3-pylint
|
python3-pylint
|
||||||
python3-pytest
|
python3-pytest
|
||||||
python3-pytest-cov
|
python3-pytest-cov
|
||||||
|
38
tests/pylorax/test_mount.py
Normal file
38
tests/pylorax/test_mount.py
Normal 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")
|
Loading…
Reference in New Issue
Block a user