Exemple #1
0
    def doResize(self, *args, **kwargs):
        """ Resize this filesystem to new size @newsize.

            Arguments:

                None

            Keyword Arguments:

                intf -- InstallInterface instance

        """
        intf = kwargs.get("intf")

        if not self.exists:
            raise FSResizeError("filesystem does not exist", self.device)

        if not self.resizable:
            raise FSResizeError("filesystem not resizable", self.device)

        if self.targetSize == self.currentSize:
            return

        if not self.resizefsProg:
            return

        if not os.path.exists(self.device):
            raise FSResizeError("device does not exist", self.device)

        self.doCheck(intf=intf)

        w = None
        if intf:
            w = intf.progressWindow(_("Resizing"),
                                    _("Resizing filesystem on %s") %
                                    (self.device, ),
                                    100,
                                    pulse=True)

        try:
            rc = iutil.execWithPulseProgress(self.resizefsProg,
                                             self.resizeArgs,
                                             stdout="/dev/tty5",
                                             stderr="/dev/tty5",
                                             progress=w)
        except Exception as e:
            raise FSResizeError(e, self.device)
        finally:
            if w:
                w.pop()

        if rc:
            raise FSResizeError("resize failed: %s" % rc, self.device)

        self.doCheck(intf=intf)

        # XXX must be a smarter way to do this
        self._size = self.targetSize
        self.notifyKernel()
Exemple #2
0
    def doResize(self, *args, **kwargs):
        """ Resize this filesystem to new size @newsize.

            Arguments:

                None

            Keyword Arguments:

                intf -- InstallInterface instance

        """
        intf = kwargs.get("intf")

        if not self.exists:
            raise FSResizeError("filesystem does not exist", self.device)

        if not self.resizable:
            raise FSResizeError("filesystem not resizable", self.device)

        if self.targetSize == self.currentSize:
            return

        if not self.resizefsProg:
            return

        if not os.path.exists(self.device):
            raise FSResizeError("device does not exist", self.device)

        self.doCheck(intf=intf)

        w = None
        if intf:
            w = intf.progressWindow(_("Resizing"),
                                    _("Resizing filesystem on %s")
                                    % (self.device,),
                                    100, pulse = True)

        try:
            rc = iutil.execWithPulseProgress(self.resizefsProg,
                                             self.resizeArgs,
                                             stdout="/dev/tty5",
                                             stderr="/dev/tty5",
                                             progress=w)
        except Exception as e:
            raise FSResizeError(e, self.device)
        finally:
            if w:
                w.pop()

        if rc:
            raise FSResizeError("resize failed: %s" % rc, self.device)

        self.doCheck(intf=intf)

        # XXX must be a smarter way to do this
        self._size = self.targetSize
        self.notifyKernel()
Exemple #3
0
def mdadm(args, progress=None):
    rc = iutil.execWithPulseProgress("mdadm", args, stdout="/dev/tty5", stderr="/dev/tty5", progress=progress)
    if not rc:
        return

    try:
        msg = open("/tmp/program.log").readlines()[-1].strip()
    except Exception:
        msg = ""

    raise MDRaidError(msg)
Exemple #4
0
    def doCheck(self, intf=None):
        if not self.exists:
            raise FSError("filesystem has not been created")

        if not self.fsckProg:
            return

        if not os.path.exists(self.device):
            raise FSError("device does not exist")

        w = None
        if intf:
            w = intf.progressWindow(_("Checking"),
                                    _("Checking filesystem on %s") %
                                    (self.device),
                                    100,
                                    pulse=True)

        try:
            rc = iutil.execWithPulseProgress(self.fsckProg,
                                             self._getCheckArgs(),
                                             stdout="/dev/tty5",
                                             stderr="/dev/tty5",
                                             progress=w)
        except Exception as e:
            raise FSError("filesystem check failed: %s" % e)
        finally:
            if w:
                w.pop()

        if self._fsckFailed(rc):
            hdr = _("%(type)s filesystem check failure on %(device)s: ") % \
                    {"type": self.type, "device": self.device}

            msg = self._fsckErrorMessage(rc)

            if intf:
                help = _("Errors like this usually mean there is a problem "
                         "with the filesystem that will require user "
                         "interaction to repair.  Before restarting "
                         "installation, reboot to rescue mode or another "
                         "system that allows you to repair the filesystem "
                         "interactively.  Restart installation after you "
                         "have corrected the problems on the filesystem.")

                intf.messageWindow(_("Unrecoverable Error"),
                                   hdr + "\n\n" + msg + "\n\n" + help,
                                   custom_icon='error')
                sys.exit(0)
            else:
                raise FSError(hdr + msg)
Exemple #5
0
def lvm(args, progress=None):
    rc = iutil.execWithPulseProgress("lvm", args,
                                     stdout = "/dev/tty5",
                                     stderr = "/dev/tty5",
                                     progress=progress)
    if not rc:
        return

    try:
        msg = open("/tmp/program.log").readlines()[-1].strip()
    except Exception:
        msg = ""

    raise LVMError(msg)
Exemple #6
0
    def doCheck(self, intf=None):
        if not self.exists:
            raise FSError("filesystem has not been created")

        if not self.fsckProg:
            return

        if not os.path.exists(self.device):
            raise FSError("device does not exist")

        w = None
        if intf:
            w = intf.progressWindow(_("Checking"),
                                    _("Checking filesystem on %s")
                                    % (self.device),
                                    100, pulse = True)

        try:
            rc = iutil.execWithPulseProgress(self.fsckProg,
                                             self._getCheckArgs(),
                                             stdout="/dev/tty5",
                                             stderr="/dev/tty5",
                                             progress = w)
        except Exception as e:
            raise FSError("filesystem check failed: %s" % e)
        finally:
            if w:
                w.pop()

        if self._fsckFailed(rc):
            hdr = _("%(type)s filesystem check failure on %(device)s: ") % \
                    {"type": self.type, "device": self.device}

            msg = self._fsckErrorMessage(rc)

            if intf:
                help = _("Errors like this usually mean there is a problem "
                         "with the filesystem that will require user "
                         "interaction to repair.  Before restarting "
                         "installation, reboot to rescue mode or another "
                         "system that allows you to repair the filesystem "
                         "interactively.  Restart installation after you "
                         "have corrected the problems on the filesystem.")

                intf.messageWindow(_("Unrecoverable Error"),
                                   hdr + "\n\n" + msg + "\n\n" + help,
                                   custom_icon='error')
                sys.exit(0)
            else:
                raise FSError(hdr + msg)
Exemple #7
0
def mkswap(device, label='', progress=None):
    # We use -f to force since mkswap tends to refuse creation on lvs with
    # a message about erasing bootbits sectors on whole disks. Bah.
    argv = ["-f"]
    if label:
        argv.extend(["-L", label])
    argv.append(device)

    rc = iutil.execWithPulseProgress("mkswap", argv,
                                     stderr = "/dev/tty5",
                                     stdout = "/dev/tty5",
                                     progress=progress)

    if rc:
        raise SwapError("mkswap failed for '%s'" % device)
Exemple #8
0
def mkswap(device, label='', progress=None):
    # We use -f to force since mkswap tends to refuse creation on lvs with
    # a message about erasing bootbits sectors on whole disks. Bah.
    argv = ["-f"]
    if label:
        argv.extend(["-L", label])
    argv.append(device)

    rc = iutil.execWithPulseProgress("mkswap",
                                     argv,
                                     stderr="/dev/tty5",
                                     stdout="/dev/tty5",
                                     progress=progress)

    if rc:
        raise SwapError("mkswap failed for '%s'" % device)
Exemple #9
0
def lvm(args, progress=None):
    rc = iutil.execWithPulseProgress("lvm", args,
                                     stdout = "/dev/tty5",
                                     stderr = "/dev/tty5",
                                     progress=progress)
    if not rc:
        return

    try:
        # grab the last line of program.log and strip off the timestamp
        msg = open("/tmp/program.log").readlines()[-1]
        msg = msg.split("program: ", 1)[1].strip()
    except Exception:
        msg = ""

    raise LVMError(msg)
Exemple #10
0
def mdadm(args, progress=None):
    rc = iutil.execWithPulseProgress("mdadm",
                                     args,
                                     stdout="/dev/tty5",
                                     stderr="/dev/tty5",
                                     progress=progress)
    if not rc:
        return

    try:
        # grab the last line of program.log and strip off the timestamp
        msg = open("/tmp/program.log").readlines()[-1]
        msg = msg.split("program: ", 1)[1].strip()
    except Exception:
        msg = ""

    raise MDRaidError(msg)
    def startup(self, intf, exclusiveDisks, zeroMbr):
        """ Look for any unformatted DASDs in the system and offer the user
            the option for format them with dasdfmt or exit the installer.
        """
        if self.started:
            return

        self.started = True
        out = "/dev/tty5"
        err = "/dev/tty5"

        if not iutil.isS390():
            return

        # Trigger udev data about the dasd devices on the system
        udev_trigger(action="change", name="dasd*")

        log.info("Checking for unformatted DASD devices:")

        for device in os.listdir("/sys/block"):
            if not device.startswith("dasd"):
                continue

            statusfile = "/sys/block/%s/device/status" % (device, )
            if not os.path.isfile(statusfile):
                continue

            f = open(statusfile, "r")
            status = f.read().strip()
            f.close()

            if status in ["unformatted"] and device not in exclusiveDisks:
                bypath = deviceNameToDiskByPath(device)
                if not bypath:
                    bypath = "/dev/" + device

                log.info("    %s (%s) status is %s, needs dasdfmt" % (
                    device,
                    bypath,
                    status,
                ))
                self._dasdlist.append((device, bypath))

        if not len(self._dasdlist):
            log.info("    no unformatted DASD devices found")
            return

        askUser = True

        if zeroMbr:
            askUser = False
        elif not intf and not zeroMbr:
            log.info("    non-interactive kickstart install without zerombr "
                     "command, unable to run dasdfmt, exiting installer")
            sys.exit(0)

        c = len(self._dasdlist)

        if intf and askUser:
            devs = ''
            for dasd, bypath in self._dasdlist:
                devs += "%s\n" % (bypath, )

            rc = intf.questionInitializeDASD(c, devs)
            if rc == 1:
                log.info("    not running dasdfmt, continuing installation")
                return

        # gather total cylinder count
        argv = ["-t", "-v"] + self.commonArgv
        for dasd, bypath in self._dasdlist:
            buf = iutil.execWithCapture(self.dasdfmt,
                                        argv + ["/dev/" + dasd],
                                        stderr=err)
            for line in buf.splitlines():
                if line.startswith("Drive Geometry: "):
                    # line will look like this:
                    # Drive Geometry: 3339 Cylinders * 15 Heads =  50085 Tracks
                    cyls = long(filter(lambda s: s, line.split(' '))[2])
                    self.totalCylinders += cyls
                    break

        # format DASDs
        argv = ["-P"] + self.commonArgv
        update = self._updateProgressWindow

        title = P_("Formatting DASD Device", "Formatting DASD Devices", c)
        msg = P_("Preparing %d DASD device for use with Linux..." % c,
                 "Preparing %d DASD devices for use with Linux..." % c, c)

        if intf:
            if self.totalCylinders:
                pw = intf.progressWindow(title, msg, 1.0)
            else:
                pw = intf.progressWindow(title, msg, 100, pulse=True)

        for dasd, bypath in self._dasdlist:
            log.info("Running dasdfmt on %s" % (bypath, ))
            arglist = argv + ["/dev/" + dasd]

            try:
                if intf and self.totalCylinders:
                    rc = iutil.execWithCallback(self.dasdfmt,
                                                arglist,
                                                stdout=out,
                                                stderr=err,
                                                callback=update,
                                                callback_data=pw,
                                                echo=False)
                elif intf:
                    rc = iutil.execWithPulseProgress(self.dasdfmt,
                                                     arglist,
                                                     stdout=out,
                                                     stderr=err,
                                                     progress=pw)
                else:
                    rc = iutil.execWithRedirect(self.dasdfmt,
                                                arglist,
                                                stdout=out,
                                                stderr=err)
            except Exception as e:
                raise DasdFormatError(e, bypath)

            if rc:
                raise DasdFormatError("dasdfmt failed: %s" % rc, bypath)

        if intf:
            pw.pop()
Exemple #12
0
    def doResize(self, *args, **kwargs):
        """ Resize this filesystem to new size @newsize.

            Arguments:

                None

            Keyword Arguments:

                intf -- InstallInterface instance

        """
        intf = kwargs.get("intf")

        if not self.exists:
            raise FSResizeError("filesystem does not exist", self.device)

        if not self.resizable:
            raise FSResizeError("filesystem not resizable", self.device)

        if self.targetSize == self.currentSize:
            return

        if not self.resizefsProg:
            return

        if not os.path.exists(self.device):
            raise FSResizeError("device does not exist", self.device)

        self.doCheck(intf=intf)

        # The first minimum size can be incorrect if the fs was not
        # properly unmounted. After doCheck the minimum size will be correct
        # so run the check one last time and bump up the size if it was too
        # small.
        self._minInstanceSize = None
        if self.targetSize < self.minSize:
            self.targetSize = self.minSize
            log.info("Minimum size changed, setting targetSize on %s to %s" \
                     % (self.device, self.targetSize))

        w = None
        if intf:
            w = intf.progressWindow(_("Resizing"),
                                    _("Resizing filesystem on %s") %
                                    (self.device, ),
                                    100,
                                    pulse=True)

        try:
            rc = iutil.execWithPulseProgress(self.resizefsProg,
                                             self.resizeArgs,
                                             stdout="/dev/tty5",
                                             stderr="/dev/tty5",
                                             progress=w)
        except Exception as e:
            raise FSResizeError(e, self.device)
        finally:
            if w:
                w.pop()

        if rc:
            raise FSResizeError("resize failed: %s" % rc, self.device)

        self.doCheck(intf=intf)

        # XXX must be a smarter way to do this
        self._size = self.targetSize
        self.notifyKernel()
Exemple #13
0
    def doFormat(self, *args, **kwargs):
        """ Create the filesystem.

            Arguments:

                None

            Keyword Arguments:

                intf -- InstallInterface instance
                options -- list of options to pass to mkfs

        """
        log_method_call(self,
                        type=self.mountType,
                        device=self.device,
                        mountpoint=self.mountpoint)

        intf = kwargs.get("intf")
        options = kwargs.get("options")

        if self.exists:
            raise FormatCreateError("filesystem already exists", self.device)

        if not self.formattable:
            return

        if not self.mkfsProg:
            return

        if self.exists:
            return

        if not os.path.exists(self.device):
            raise FormatCreateError("device does not exist", self.device)

        argv = self._getFormatOptions(options=options)

        w = None
        if intf:
            w = intf.progressWindow(_("Formatting"),
                                    _("Creating %s filesystem on %s") %
                                    (self.type, self.device),
                                    100,
                                    pulse=True)

        try:
            rc = iutil.execWithPulseProgress(self.mkfsProg,
                                             argv,
                                             stdout="/dev/tty5",
                                             stderr="/dev/tty5",
                                             progress=w)
        except Exception as e:
            raise FormatCreateError(e, self.device)
        finally:
            if w:
                w.pop()

        if rc:
            raise FormatCreateError("format failed: %s" % rc, self.device)

        self.exists = True
        self.notifyKernel()

        if self.label:
            self.writeLabel(self.label)
Exemple #14
0
    def doFormat(self, *args, **kwargs):
        """ Create the filesystem.

            Arguments:

                None

            Keyword Arguments:

                intf -- InstallInterface instance
                options -- list of options to pass to mkfs

        """
        log_method_call(self, type=self.mountType, device=self.device,
                        mountpoint=self.mountpoint)

        intf = kwargs.get("intf")
        options = kwargs.get("options")

        if self.exists:
            raise FormatCreateError("filesystem already exists", self.device)

        if not self.formattable:
            return

        if not self.mkfsProg:
            return

        if self.exists:
            return

        if not os.path.exists(self.device):
            raise FormatCreateError("device does not exist", self.device)

        argv = self._getFormatOptions(options=options)

        w = None
        if intf:
            w = intf.progressWindow(_("Formatting"),
                                    _("Creating %s filesystem on %s")
                                    % (self.type, self.device),
                                    100, pulse = True)

        try:
            rc = iutil.execWithPulseProgress(self.mkfsProg,
                                             argv,
                                             stdout="/dev/tty5",
                                             stderr="/dev/tty5",
                                             progress=w)
        except Exception as e:
            raise FormatCreateError(e, self.device)
        finally:
            if w:
                w.pop()

        if rc:
            raise FormatCreateError("format failed: %s" % rc, self.device)

        self.exists = True
        self.notifyKernel()

        if self.label:
            self.writeLabel(self.label)
Exemple #15
0
    def startup(self, intf, exclusiveDisks, zeroMbr):
        """ Look for any unformatted DASDs in the system and offer the user
            the option for format them with dasdfmt or exit the installer.
        """
        if self.started:
            return

        self.started = True
        out = "/dev/tty5"
        err = "/dev/tty5"

        if not iutil.isS390():
            return

        # Trigger udev data about the dasd devices on the system
        udev_trigger(action="change", name="dasd*")

        log.info("Checking for unformatted DASD devices:")

        for device in os.listdir("/sys/block"):
            if not device.startswith("dasd"):
                continue

            statusfile = "/sys/block/%s/device/status" % (device,)
            if not os.path.isfile(statusfile):
                continue

            f = open(statusfile, "r")
            status = f.read().strip()
            f.close()

            if status in ["unformatted"] and device not in exclusiveDisks:
                bypath = deviceNameToDiskByPath(device)
                if not bypath:
                    bypath = "/dev/" + device

                log.info("    %s (%s) status is %s, needs dasdfmt" % (device,
                                                                      bypath,
                                                                      status,))
                self._dasdlist.append((device, bypath))

        if not len(self._dasdlist):
            log.info("    no unformatted DASD devices found")
            return

        askUser = True

        if zeroMbr:
            askUser = False
        elif not intf and not zeroMbr:
            log.info("    non-interactive kickstart install without zerombr "
                     "command, unable to run dasdfmt, exiting installer")
            sys.exit(0)

        c = len(self._dasdlist)

        if intf and askUser:
            devs = ''
            for dasd, bypath in self._dasdlist:
                devs += "%s\n" % (bypath,)

            rc = intf.questionInitializeDASD(c, devs)
            if rc == 1:
                log.info("    not running dasdfmt, continuing installation")
                return

        # gather total cylinder count
        argv = ["-t", "-v"] + self.commonArgv
        for dasd, bypath in self._dasdlist:
            buf = iutil.execWithCapture(self.dasdfmt, argv + ["/dev/" + dasd],
                                        stderr=err)
            for line in buf.splitlines():
                if line.startswith("Drive Geometry: "):
                    # line will look like this:
                    # Drive Geometry: 3339 Cylinders * 15 Heads =  50085 Tracks
                    cyls = long(filter(lambda s: s, line.split(' '))[2])
                    self.totalCylinders += cyls
                    break

        # format DASDs
        argv = ["-P"] + self.commonArgv
        update = self._updateProgressWindow

        title = P_("Formatting DASD Device", "Formatting DASD Devices", c)
        msg = P_("Preparing %d DASD device for use with Linux..." % c,
                 "Preparing %d DASD devices for use with Linux..." % c, c)

        if intf:
            if self.totalCylinders:
                pw = intf.progressWindow(title, msg, 1.0)
            else:
                pw = intf.progressWindow(title, msg, 100, pulse=True)

        for dasd, bypath in self._dasdlist:
            log.info("Running dasdfmt on %s" % (bypath,))
            arglist = argv + ["/dev/" + dasd]

            try:
                if intf and self.totalCylinders:
                    rc = iutil.execWithCallback(self.dasdfmt, arglist,
                                                stdout=out, stderr=err,
                                                callback=update,
                                                callback_data=pw,
                                                echo=False)
                elif intf:
                    rc = iutil.execWithPulseProgress(self.dasdfmt, arglist,
                                                     stdout=out, stderr=err,
                                                     progress=pw)
                else:
                    rc = iutil.execWithRedirect(self.dasdfmt, arglist,
                                                stdout=out, stderr=err)
            except Exception as e:
                raise DasdFormatError(e, bypath)

            if rc:
                raise DasdFormatError("dasdfmt failed: %s" % rc, bypath)

        if intf:
            pw.pop()
Exemple #16
0
    def format_dasds(self, intf, askUser, dasdlist):
        """ Iterate through a given list of DASDs and run dasdfmt on them. """
        out = "/dev/tty5"
        err = "/dev/tty5"

        c = len(dasdlist)

        if intf and askUser:
            devs = ''
            for dasd, bypath in dasdlist:
                devs += "%s\n" % (bypath, )

            rc = intf.questionInitializeDASD(c, devs)
            if rc == 1:
                log.info("    not running dasdfmt, continuing installation")
                return

        # gather total cylinder count
        argv = ["-t", "-v"] + self.commonArgv
        for dasd, bypath in dasdlist:
            buf = iutil.execWithCapture(self.dasdfmt,
                                        argv + ["/dev/" + dasd],
                                        stderr=err)
            for line in buf.splitlines():
                if line.startswith("Drive Geometry: "):
                    # line will look like this:
                    # Drive Geometry: 3339 Cylinders * 15 Heads =  50085 Tracks
                    cyls = long(filter(lambda s: s, line.split(' '))[2])
                    self.totalCylinders += cyls
                    break

        # format DASDs
        argv = ["-P"] + self.commonArgv
        update = self._updateProgressWindow

        title = P_("Formatting DASD Device", "Formatting DASD Devices", c)
        msg = P_("Preparing %d DASD device for use with Linux..." % c,
                 "Preparing %d DASD devices for use with Linux..." % c, c)

        if intf:
            if self.totalCylinders:
                pw = intf.progressWindow(title, msg, 1.0)
            else:
                pw = intf.progressWindow(title, msg, 100, pulse=True)

        for dasd, bypath in dasdlist:
            log.info("Running dasdfmt on %s" % (bypath, ))
            arglist = argv + ["/dev/" + dasd]

            try:
                if intf and self.totalCylinders:
                    rc = iutil.execWithCallback(self.dasdfmt,
                                                arglist,
                                                stdout=out,
                                                stderr=err,
                                                callback=update,
                                                callback_data=pw,
                                                echo=False)
                elif intf:
                    rc = iutil.execWithPulseProgress(self.dasdfmt,
                                                     arglist,
                                                     stdout=out,
                                                     stderr=err,
                                                     progress=pw)
                else:
                    rc = iutil.execWithRedirect(self.dasdfmt,
                                                arglist,
                                                stdout=out,
                                                stderr=err)
            except Exception as e:
                raise DasdFormatError(e, bypath)

            if rc:
                raise DasdFormatError("dasdfmt failed: %s" % rc, bypath)

        if intf:
            pw.pop()
Exemple #17
0
    def doResize(self, *args, **kwargs):
        """ Resize this filesystem to new size @newsize.

            Arguments:

                None

            Keyword Arguments:

                intf -- InstallInterface instance

        """
        intf = kwargs.get("intf")

        if not self.exists:
            raise FSResizeError("filesystem does not exist", self.device)

        if not self.resizable:
            raise FSResizeError("filesystem not resizable", self.device)

        if self.targetSize == self.currentSize:
            return

        if not self.resizefsProg:
            return

        if not os.path.exists(self.device):
            raise FSResizeError("device does not exist", self.device)

        self.doCheck(intf=intf)

        # The first minimum size can be incorrect if the fs was not
        # properly unmounted. After doCheck the minimum size will be correct
        # so run the check one last time and bump up the size if it was too
        # small.
        self._minInstanceSize = None
        if self.targetSize < self.minSize:
            self.targetSize = self.minSize
            log.info("Minimum size changed, setting targetSize on %s to %s" \
                     % (self.device, self.targetSize))

        w = None
        if intf:
            w = intf.progressWindow(_("Resizing"),
                                    _("Resizing filesystem on %s")
                                    % (self.device,),
                                    100, pulse = True)

        try:
            rc = iutil.execWithPulseProgress(self.resizefsProg,
                                             self.resizeArgs,
                                             stdout="/dev/tty5",
                                             stderr="/dev/tty5",
                                             progress=w)
        except Exception as e:
            raise FSResizeError(e, self.device)
        finally:
            if w:
                w.pop()

        if rc:
            raise FSResizeError("resize failed: %s" % rc, self.device)

        self.doCheck(intf=intf)

        # XXX must be a smarter way to do this
        self._size = self.targetSize
        self.notifyKernel()