Exemple #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)
Exemple #2
0
    def __createRAIDArrays(self):
        """
        Calls required methods to create RAID arrays on system.

        @rtype: None
        @return: Nothing
        """
        # start RAID arrays to work on them again
        raid.start()

        # create RAID arrays
        raid.createArrays(self.__raidCommands)

        # wait for RAID arrays to become clean
        raid.wait(self.__raidCommands)

        # stop RAID arrays to avoid any problems later
        raid.stop()
Exemple #3
0
def _reReadPartitionTable(disk, hasMultipath = False):
    """
    Asks the kernel to re-read the partition table before trying
    to format it

    @type  disk: basestring
    @param disk: disk device name

    @type  hasMultipath: bool
    @param hasMultipath: info about multipath on machine

    @rtype: bool
    @return: True if partition table sync successfull. False otherwise
    """
    # give some opportunities to sync the partition table before
    # returning false
    for i in range(1, MAX_SYNC_ATTEMPTS):

        # log the number of attempts
        llecho('Re-reading partition table for %s (try %d)' % (disk, i))

        # wait 1 second
        time.sleep(1)

        # FIXME: during the attempt to read the partitions, raid should
        # be inactive or it will block devices belonging to its array
        # and will make the next command to fail. It is not clear why
        # raid becomes active here since is has been stopped in
        # manage_parts. It demands further investigation.
        if hasMultipath:
            raid.stop()

        # partition table re-read successfully: return success
        if run(CMD_HDPARM_Z % disk) == 0:
            return True

    return False