def test_invalid_values(self): di = DiscInfo() di.timestamp = "foo" di.description = "Fedora 21" di.arch = "x86_64" di.disc_numbers = ["ALL"] self.assertRaises(TypeError, di.dumps)
def test_parse_no_disc_numbers(self): lines = [ "1386856788.124593", "Fedora 20", "x86_64", ] di = DiscInfo() di.loads("\n".join(lines)) self.assertEqual(di.timestamp, 1386856788.124593) self.assertEqual(di.description, "Fedora 20") self.assertEqual(di.arch, "x86_64") self.assertEqual(di.disc_numbers, ["ALL"])
def test_parse_no_disc_numbers(self): lines = [ "1386856788.124593", "Fedora 20", "x86_64", ] di = DiscInfo() di.loads("\n".join(lines)) self.assertEqual(di.timestamp, 1386856788.124593) self.assertEqual(di.description, "Fedora 20") self.assertEqual(di.arch, "x86_64") self.assertEqual(di.disc_numbers, ["ALL"])
def test_all(self): di = DiscInfo() di.now() di.description = "Fedora 20" di.arch = "x86_64" di.disc_numbers = ["ALL"] di.dump(self.path) self._test_identity(di)
def _test_identity(self, di): first = os.path.join(self.tmp_dir, "first") second = os.path.join(self.tmp_dir, "second") # write original file di.dump(first) # read file and write it back di = DiscInfo() di.load(first) di.dump(second) # check if first and second files are identical self.assertSameFiles(first, second)
def test_all(self): di = DiscInfo() di.now() di.description = "Fedora 20" di.arch = "x86_64" di.disc_numbers = ["ALL"] di.dump(self.path) self._test_identity(di)
def test_disc_numbers(self): di = DiscInfo() di.timestamp = 1386856788.124593 di.description = "Fedora 20" di.arch = "x86_64" di.disc_numbers = [1, "2", 3] di.dump(self.path) self._test_identity(di)
def test_disc_numbers(self): di = DiscInfo() di.timestamp = 1386856788.124593 di.description = "Fedora 20" di.arch = "x86_64" di.disc_numbers = [1, "2", 3] di.dump(self.path) self._test_identity(di)
def test_invalid_values(self): di = DiscInfo() di.timestamp = "foo" di.description = "Fedora 21" di.arch = "x86_64" di.disc_numbers = ["ALL"] self.assertRaises(TypeError, di.dumps)
def _test_identity(self, di): first = os.path.join(self.tmp_dir, "first") second = os.path.join(self.tmp_dir, "second") # write original file di.dump(first) # read file and write it back di = DiscInfo() di.load(first) di.dump(second) # check if first and second files are identical self.assertSameFiles(first, second)
def findFirstIsoImage(path): """ Find the first iso image in path This also supports specifying a specific .iso image Returns the basename of the image """ try: os.stat(path) except OSError: return None arch = _arch mount_path = "/mnt/install/cdimage" discinfo_path = os.path.join(mount_path, ".discinfo") if os.path.isfile(path) and path.endswith(".iso"): files = [os.path.basename(path)] path = os.path.dirname(path) else: files = os.listdir(path) for fn in files: what = os.path.join(path, fn) log.debug("Checking %s", what) if not isys.isIsoImage(what): continue log.debug("mounting %s on %s", what, mount_path) try: blivet.util.mount(what, mount_path, fstype="iso9660", options="ro") except OSError: continue if not os.access(discinfo_path, os.R_OK): blivet.util.umount(mount_path) continue log.debug("Reading .discinfo") disc_info = DiscInfo() try: disc_info.load(discinfo_path) disc_arch = disc_info.arch except Exception as ex: # pylint: disable=broad-except log.warning(".discinfo file can't be loaded: %s", ex) continue log.debug("discArch = %s", disc_arch) if disc_arch != arch: log.warning("findFirstIsoImage: architectures mismatch: %s, %s", disc_arch, arch) blivet.util.umount(mount_path) continue # If there's no repodata, there's no point in trying to # install from it. if not _check_repodata(mount_path): log.warning("%s doesn't have a valid repodata, skipping", what) blivet.util.umount(mount_path) continue # warn user if images appears to be wrong size if os.stat(what)[stat.ST_SIZE] % 2048: log.warning("%s appears to be corrupted", what) exn = InvalidImageSizeError("size is not a multiple of 2048 bytes", what) if errorHandler.cb(exn) == ERROR_RAISE: raise exn log.info("Found disc at %s", fn) blivet.util.umount(mount_path) return fn return None
def findFirstIsoImage(path): """ Find the first iso image in path This also supports specifying a specific .iso image Returns the basename of the image """ try: os.stat(path) except OSError: return None arch = _arch mount_path = "/mnt/install/cdimage" discinfo_path = os.path.join(mount_path, ".discinfo") if os.path.isfile(path) and path.endswith(".iso"): files = [os.path.basename(path)] path = os.path.dirname(path) else: files = os.listdir(path) for fn in files: what = os.path.join(path, fn) log.debug("Checking %s", what) if not isys.isIsoImage(what): continue log.debug("mounting %s on %s", what, mount_path) try: blivet.util.mount(what, mount_path, fstype="iso9660", options="ro") except OSError: continue if not os.access(discinfo_path, os.R_OK): blivet.util.umount(mount_path) continue log.debug("Reading .discinfo") disc_info = DiscInfo() try: disc_info.load(discinfo_path) disc_arch = disc_info.arch except Exception as ex: # pylint: disable=broad-except log.warning(".discinfo file can't be loaded: %s", ex) continue log.debug("discArch = %s", disc_arch) if disc_arch != arch: log.warning("findFirstIsoImage: architectures mismatch: %s, %s", disc_arch, arch) blivet.util.umount(mount_path) continue # If there's no repodata, there's no point in trying to # install from it. if not _check_repodata(mount_path): log.warning("%s doesn't have repodata, skipping", what) blivet.util.umount(mount_path) continue # warn user if images appears to be wrong size if os.stat(what)[stat.ST_SIZE] % 2048: log.warning("%s appears to be corrupted", what) exn = InvalidImageSizeError("size is not a multiple of 2048 bytes", what) if errorHandler.cb(exn) == ERROR_RAISE: raise exn log.info("Found disc at %s", fn) blivet.util.umount(mount_path) return fn return None
def test_read_discinfo(self): for i in os.listdir(self.discinfo_path): path = os.path.join(self.discinfo_path, i) di = DiscInfo() di.load(path)
def test_empty(self): di = DiscInfo() self.assertRaises(ValueError, di.dump, self.path)
def test_read_discinfo(self): for i in os.listdir(self.discinfo_path): path = os.path.join(self.discinfo_path, i) di = DiscInfo() di.load(path)
def find_first_iso_image(path, mount_path="/mnt/install/cdimage"): """Find the first iso image in path. :param str path: path to the directory with iso image(s); this also supports pointing to a specific .iso image :param str mount_path: path for mounting the ISO when checking it is valid FIXME once payloads are modularized: - this should move somewhere else - mount_path should lose the legacy default :return: basename of the image - file name without path :rtype: str or None """ try: os.stat(path) except OSError: return None arch = _arch discinfo_path = os.path.join(mount_path, ".discinfo") if os.path.isfile(path) and path.endswith(".iso"): files = [os.path.basename(path)] path = os.path.dirname(path) else: files = os.listdir(path) for fn in files: what = os.path.join(path, fn) log.debug("Checking %s", what) if not isys.isIsoImage(what): continue log.debug("Mounting %s on %s", what, mount_path) try: blivet.util.mount(what, mount_path, fstype="iso9660", options="ro") except OSError: continue if not os.access(discinfo_path, os.R_OK): blivet.util.umount(mount_path) continue log.debug("Reading .discinfo") disc_info = DiscInfo() # TODO replace next 2 blocks with: # pyanaconda.modules.payloads.source.utils.is_valid_install_disk try: disc_info.load(discinfo_path) disc_arch = disc_info.arch except Exception as ex: # pylint: disable=broad-except log.warning(".discinfo file can't be loaded: %s", ex) continue log.debug("discArch = %s", disc_arch) if disc_arch != arch: log.warning("Architectures mismatch in find_first_iso_image: %s != %s", disc_arch, arch) blivet.util.umount(mount_path) continue # If there's no repodata, there's no point in trying to # install from it. if not _check_repodata(mount_path): log.warning("%s doesn't have a valid repodata, skipping", what) blivet.util.umount(mount_path) continue # warn user if images appears to be wrong size if os.stat(what)[stat.ST_SIZE] % 2048: log.warning("%s appears to be corrupted", what) exn = InvalidImageSizeError("size is not a multiple of 2048 bytes", what) if errorHandler.cb(exn) == ERROR_RAISE: raise exn log.info("Found disc at %s", fn) blivet.util.umount(mount_path) return fn return None