Example #1
0
    def __clearDisks(self, hasMultipath):
        """
        Clears all disks of the system. This cleaning will erase ALL DATA of the
        disks. There is no step back.

        @rtype: None
        @return: Nothing
        """
        try:

            # bug 109358: try to stop all raid partitions. it should be done first
            # in a scenario where there is a LVM on top of a SW RAID. However, in
            # a opposite way (RAID on top of LVM) it will fail. So we just let pass
            # any exception from sw raid.
            try:
                raid.stop()

            except:
                pass

            # delete LVM entities before partitioning
            self.__logger.info('Deleting LVM entities...')
            self.__logger.debug('PV Delete List: %s' % str(self.__pvDeleteList))
            self.__logger.debug('VG Delete List: %s' % str(self.__vgDeleteList))
            self.__logger.debug('LV Delete List: %s' % str(self.__lvDeleteList))

            lvm.delLvmEntities(self.__pvDeleteList,
                               self.__vgDeleteList,
                               self.__lvDeleteList)

            # stop LVM volume groups to avoid problems with disks partitioning
            self.__logger.info('Stopping LVM...')
            lvm.stop()

            # Bug 109358: if SW RAID is on top a LVM we can stop it safetly now
            # because LVM was just stopped above. If any problem happens from now
            # on we need to let the exception raises above.
            raid.stop()

        except PKVMError as e:
            raise

        except Exception as e:
            self.__logger.critical("Unexpected error")
            self.__logger.critical("EXCEPTION:" + str(type(e)))
            self.__logger.critical(str(e))
            self.__logger.critical("Stacktrace:" + str(traceback.format_exc()))
            raise PKVMError("PARTITIONER", "ERROR", "ERROR")

        # perform custom setup for multipath devices
        self.__logger.info('Performing custom multipath configuration...')
        self.__logger.debug('Has multipath = %s' % str(hasMultipath))
        tolerantMode = multipath.setup(hasMultipath,
                                       bool(len(self.__lvmCommands)),
                                       bool(len(self.__raidCommands)),
                                       self.__tolerantMode)

        # wait for udev to handle all events
        run(CMD_UDEV_SETTLE)
Example #2
0
    def resetRootDevice(self):
        """
        Formats root device (according LVM default scheme) and adjusts all
        pointers to allow reinstall the system correctly.

        Important: this method is directly related to LVM default partitioning
        scheme. It assumes that root device is under /dev/mapper/vg_root-lv_root
        path. If this default scheme changes on future, this method must be
        revisited to assure its functionality.

        @rtype: bool
        @return: True if everything is ok, False otherwise
        """
        # restart LVM volume groups to assure its functionality
        self.__logger.info('Restarting LVM...')
        lvm.stop()
        lvm.start(self.__tolerantMode)
        
        # wait for udev to handle all events
        if run(CMD_UDEV_SETTLE) != 0:
            raise RuntimeError('Error: udevadm settle failure')

        # Do not trust content from / partition.  User can screw up
        # with its / partition and try a reinstall to fix it.  Thus
        # our code cannot trust on reading content from old and dirty
        # / partition.  We can just infere /boot partition by
        # appending 2 to the detected disk.
        installed_disk = self.getPreviousInstalledDisk()
        boot_partition = self.genBootPartitionName(installed_disk)
        self.__bootDevice = boot_partition

        # check multipath
        self.__hasMultipath = self.__diskParameters[installed_disk.split('/')[-1]]['mpath']

        # as consequence, configure prep device path
        self.__prepDevice = self.__bootDevice[:-1] + "1"

        # update root, log, data and swap paths
        self.__rootDevice = '/dev/mapper/%s-%s' % (VGROOT, LVROOT)
        self.__logDevice  = '/dev/mapper/%s-%s' % (VGLOG, LVLOG)
        self.__dataDevice = '/dev/mapper/%s-%s' % (VGDATA, LVDATA)
        self.__swapDevice = '/dev/mapper/%s-%s' % (VGSWAP, LVSWAP)

        self.__logger.debug("resetRootDevice(): __prepDevice = %s" % self.__prepDevice)
        self.__logger.debug("resetRootDevice(): __bootDevice = %s" % self.__bootDevice)
        self.__logger.debug("resetRootDevice(): __rootDevice = %s" % self.__rootDevice)
        self.__logger.debug("resetRootDevice(): __logDevice = %s" % self.__logDevice)
        self.__logger.debug("resetRootDevice(): __dataDevice = %s" % self.__dataDevice)
        self.__logger.debug("resetRootDevice(): __swapDevice = %s" % self.__swapDevice)

        # format boot, root and swap devices
        formatPartition(self.__bootDevice)
        formatPartition(self.__rootDevice)
        formatSwapPartition(self.__swapDevice)

        return True
Example #3
0
    def __createLVMEntities(self, hasMultipath):
        """
        Calls methods to create LVM entities on system. This method creates all
        required physical volumns, volumn groups and logical volumns to install
        the system.

        @rtype: None
        @return: Nothing
        """
        # can't create PVs: abort
        self.__logger.info('Creating physical volumns...')
        self.__logger.debug('LVM PV Create List:\n%s' % str(self.__pvCreateList))
        if not lvm.createPVs(self.__pvCreateList, hasMultipath):
            raise PKVMError("PARTITIONER", "LVM", "CREATE_LVM")

        # can't create VGs: abort
        self.__logger.info('Creating volumn groups...')
        self.__logger.debug('LVM VG Create List:\n%s' % str(self.__vgCreateList))
        if not lvm.createVGs(self.__vgCreateList, hasMultipath):
            raise PKVMError("PARTITIONER", "LVM", "CREATE_LVM")

        # can't create LVs: abort
        self.__logger.info('Creating logical volumns...')
        self.__logger.debug('LVM LV Create List:\n%s' % str(self.__lvCreateList))
        if not lvm.createLVs(self.__lvCreateList):
            raise PKVMError("PARTITIONER", "LVM", "CREATE_LVM")

        # can't resize LVM entities: abort
        self.__logger.info('Resizing LVMs entities...')
        self.__logger.debug('LVM Reuse List:\n%s' % str(self.__lvUseList))
        if not lvm.resizeLVs(self.__lvUseList):
            raise PKVMError("PARTITIONER", "LVM", "CREATE_LVM")

        # can't adjust PVs: abort
        self.__logger.info('Adjusting physical volumns...')
        self.__logger.debug('LVM Adjust PVs List:\n%s' % str(self.__vgUseList))
        if not lvm.adjustPVs(self.__vgUseList, hasMultipath):
            raise PKVMError("PARTITIONER", "LVM", "CREATE_LVM")

        # restart LVM volume groups to avoid any problems later
        self.__logger.info('Restarting LVM...')
        lvm.stop()
        lvm.start(self.__tolerantMode)