def reset_install_device(self): """Unmount the previous base repo and reset the install_device.""" # cdrom: install_device.teardown (INSTALL_TREE) # hd: umount INSTALL_TREE, install_device.teardown (ISO_DIR) # nfs: umount INSTALL_TREE # nfsiso: umount INSTALL_TREE, umount ISO_DIR if os.path.ismount(INSTALL_TREE): if self.install_device and \ payload_utils.get_mount_device_path(INSTALL_TREE) == self.install_device.path: payload_utils.teardown_device(self.install_device) else: payload_utils.unmount(INSTALL_TREE, raise_exc=True) if os.path.ismount(ISO_DIR): if self.install_device and \ payload_utils.get_mount_device_path(ISO_DIR) == self.install_device.path: payload_utils.teardown_device(self.install_device) # The below code will fail when nfsiso is the stage2 source # But if we don't do this we may not be able to switch from # one nfsiso repo to another nfsiso repo. We need to have a # way to detect the stage2 state and work around it. # Commenting out the below is a hack for F18. FIXME # else: # # NFS # blivet.util.umount(ISO_DIR) self.install_device = None
def _setup_device(device, mountpoint): """Prepare an install CD/DVD for use as a package source.""" log.info("setting up device %s and mounting on %s", device.name, mountpoint) # Is there a symlink involved? If so, let's get the actual path. # This is to catch /run/install/isodir vs. /mnt/install/isodir, for # instance. real_mountpoint = os.path.realpath(mountpoint) mount_device_path = payload_utils.get_mount_device_path( real_mountpoint) if mount_device_path: log.warning("%s is already mounted on %s", mount_device_path, mountpoint) if mount_device_path == device.path: return else: payload_utils.unmount(real_mountpoint) try: payload_utils.setup_device(device) payload_utils.mount_device(device, mountpoint) except StorageError as e: log.error("mount failed: %s", e) payload_utils.teardown_device(device) raise PayloadSetupError(str(e))
def _setup_install_tree(self, device, install_tree_path, device_mount_dir): self._setup_device(device, mountpoint=device_mount_dir) path = os.path.normpath("%s/%s" % (device_mount_dir, install_tree_path)) if not verify_valid_installtree(path): payload_utils.teardown_device(device) raise PayloadSetupError("failed to find valid installation tree")
def _unmount_source_directory(self, mount_point): if os.path.ismount(mount_point): device_path = payload_utils.get_mount_device_path(mount_point) device = payload_utils.resolve_device(self.storage, device_path) if device: payload_utils.teardown_device(device) else: payload_utils.unmount(mount_point, raise_exc=True)
def _find_and_mount_iso(self, device, device_mount_dir, iso_path, iso_mount_dir): """Find and mount installation source from ISO on device. Return changed path to the iso to save looking for iso in the future call. """ self._setup_device(device, mountpoint=device_mount_dir) # check for ISO images in the newly mounted dir path = device_mount_dir if iso_path: path = os.path.normpath("%s/%s" % (path, iso_path)) # XXX it would be nice to streamline this when we're just setting # things back up after storage activation instead of having to # pretend we don't already know which ISO image we're going to # use image = find_first_iso_image(path) if not image: payload_utils.teardown_device(device) raise PayloadSetupError("failed to find valid iso image") if path.endswith(".iso"): path = os.path.dirname(path) # this could already be set up the first time through if not os.path.ismount(iso_mount_dir): # mount the ISO on a loop image = os.path.normpath("%s/%s" % (path, image)) payload_utils.mount(image, iso_mount_dir, fstype='iso9660', options="ro") if not iso_path.endswith(".iso"): result_path = os.path.normpath("%s/%s" % (iso_path, os.path.basename(image))) while result_path.startswith("/"): # ridiculous result_path = result_path[1:] return result_path return iso_path