コード例 #1
0
    def getDisks(self,detailed=None):
        """
        Get list of all available disks on machine
        """
        blks = lsblk.lsblk()
        devices = self._loaddisks(blks)
        # loading hrds
        for disk in devices:
            for partition in disk.partitions:
                if partition.fstype == 'swap' or\
                        not disks.isValidFS(partition.fstype):
                    continue

                if partition.mountpoint and partition.fstype != 'btrfs':
                    # partition is already mounted, no need to remount it
                    hrd = self._loadhrd(partition.mountpoint)
                elif partition.fstype:
                    with mount.Mount(partition.name,
                                     options='ro') as mnt:
                        hrd = self._loadhrd(mnt.path)

                partition.hrd = hrd
        if detailed:
           return blks
        else:
            return devices
コード例 #2
0
    def setUp(self):
        super(TestTakeSnapshotSSH, self).setUp()
        self.include = TemporaryDirectory()
        generic.create_test_files(self.include.name)

        #mount
        self.cfg.setCurrentHashId(mount.Mount(cfg=self.cfg).mount())
コード例 #3
0
ファイル: test_restore.py プロジェクト: kortschak/backintime
    def setUp(self):
        super(TestRestoreSSH, self).setUp()
        self.include = TemporaryDirectory()
        generic.create_test_files(os.path.join(self.remoteSIDBackupPath, self.include.name[1:]))

        #mount
        self.cfg.setCurrentHashId(mount.Mount(cfg = self.cfg).mount())
コード例 #4
0
ファイル: backintime.py プロジェクト: utajum/backintime
def _umount(cfg):
    """
    Unmount external filesystems.

    cfg:    config.Config instance
    """
    try:
        mount.Mount(cfg=cfg).umount(cfg.current_hash_id)
    except MountException as ex:
        logger.error(str(ex))
コード例 #5
0
ファイル: blockSD.py プロジェクト: zofuthan/vdsm
    def mountMaster(self):
        """
        Mount the master metadata file system. Should be called only by SPM.
        """
        lvm.activateLVs(self.sdUUID, MASTERLV)
        masterDir = os.path.join(self.domaindir, sd.MASTER_FS_DIR)
        fileUtils.createdir(masterDir)

        masterfsdev = lvm.lvPath(self.sdUUID, MASTERLV)
        cmd = [constants.EXT_FSCK, "-p", masterfsdev]
        (rc, out, err) = misc.execCmd(cmd,
                                      sudo=True,
                                      deathSignal=signal.SIGKILL)
        # fsck exit codes
        # 0    - No errors
        # 1    - File system errors corrected
        # 2    - File system errors corrected, system should
        #        be rebooted
        # 4    - File system errors left uncorrected
        # 8    - Operational error
        # 16   - Usage or syntax error
        # 32   - E2fsck canceled by user request
        # 128  - Shared library error
        if rc == 1 or rc == 2:
            # rc is a number
            self.log.info("fsck corrected fs errors (%s)", rc)
        if rc >= 4:
            raise se.BlockStorageDomainMasterFSCKError(masterfsdev, rc)

        # TODO: Remove when upgrade is only from a version which creates ext3
        # Try to add a journal - due to unfortunate circumstances we exposed
        # to the public the code that created ext2 file system instead of ext3.
        # In order to make up for it we are trying to add journal here, just
        # to be sure (and we have fixed the file system creation).
        # If there is a journal already tune2fs will do nothing, indicating
        # this condition only with exit code. However, we do not really care.
        cmd = [constants.EXT_TUNE2FS, "-j", masterfsdev]
        misc.execCmd(cmd, sudo=True, deathSignal=signal.SIGKILL)

        masterMount = mount.Mount(masterfsdev, masterDir)

        try:
            masterMount.mount(vfstype=mount.VFS_EXT3)
        except mount.MountError as ex:
            rc, out = ex
            raise se.BlockStorageDomainMasterMountError(masterfsdev, rc, out)

        cmd = [
            constants.EXT_CHOWN,
            "%s:%s" % (constants.METADATA_USER, constants.METADATA_GROUP),
            masterDir
        ]
        (rc, out, err) = misc.execCmd(cmd, sudo=True)
        if rc != 0:
            self.log.error("failed to chown %s", masterDir)
コード例 #6
0
ファイル: backintime.py プロジェクト: yduf/backintime
def _umount(cfg):
    """
    Unmount external filesystems.

    Args:
        cfg (config.Config):    config that should be used
    """
    try:
        mount.Mount(cfg=cfg).umount(cfg.current_hash_id)
    except MountException as ex:
        logger.error(str(ex))
コード例 #7
0
ファイル: backintime.py プロジェクト: utajum/backintime
def _mount(cfg):
    """
    Mount external filesystems.

    cfg:    config.Config instance
    """
    try:
        hash_id = mount.Mount(cfg=cfg).mount()
    except MountException as ex:
        logger.error(str(ex))
        sys.exit(RETURN_ERR)
    else:
        cfg.set_current_hash_id(hash_id)
コード例 #8
0
    def umount(self):
        """
        Unmount partition
        """
        if self.invalid:
            raise PartitionError('Partition is invalid')

        if self.hrd is None:
            raise PartitionError('No HRD attached to disk')

        path = self.hrd.get('mountpath')
        mnt = mount.Mount(self.name, path)
        mnt.umount()
        self.refresh()
コード例 #9
0
ファイル: backintime.py プロジェクト: yduf/backintime
def _mount(cfg):
    """
    Mount external filesystems.

    Args:
        cfg (config.Config):    config that should be used
    """
    try:
        hash_id = mount.Mount(cfg=cfg).mount()
    except MountException as ex:
        logger.error(str(ex))
        sys.exit(RETURN_ERR)
    else:
        cfg.setCurrentHashId(hash_id)
コード例 #10
0
    def test_can_mount_ssh_rw(self):
        mnt = mount.Mount(cfg = self.cfg, tmp_mount = True)
        mnt.preMountCheck(mode = 'ssh', first_run = True, **self.mount_kwargs)

        try:
            hash_id = mnt.mount(mode = 'ssh', check = False, **self.mount_kwargs)
            full_path = os.path.join(self.sharePath,".local","share","backintime","mnt",hash_id,"mountpoint","testfile")

            # warning - don't use os.access for checking writability
            # https://github.com/bit-team/backintime/issues/490#issuecomment-156265196
            with open(full_path, 'wt') as f:
                f.write('foo')
        finally:
            mnt.umount(hash_id = hash_id)
コード例 #11
0
 def _dumpHRD(self):
     with mount.Mount(self.name) as mnt:
         filepath = j.tools.path.get(mnt.path).joinpath('.disk.hrd')
         filepath.write_text(str(self.hrd))
         filepath.chmod(400)
コード例 #12
0
 def remount(self):
     mount.Mount(cfg=self.cfg).umount(self.cfg.current_hash_id)
     hash_id = mount.Mount(cfg=self.cfg).mount()
コード例 #13
0
    def tearDown(self):
        #unmount
        mount.Mount(cfg=self.cfg).umount(self.cfg.current_hash_id)
        super(TestRestoreSSH, self).tearDown()

        self.include.cleanup()
コード例 #14
0
ファイル: storageServer.py プロジェクト: kripper/vdsm
 def __init__(self, spec, vfsType=None, options=""):
     self._vfsType = vfsType
     self._remotePath = spec
     self._options = options
     self._mount = mount.Mount(spec, self._getLocalPath())
コード例 #15
0
def checkConfig(cfg, crontab = True):
    import mount
    from exceptions import MountException
    def announceTest():
        print()
        print(frame(test))

    def failed():
        print(test + ': ' + bcolors.FAIL + 'failed' + bcolors.ENDC)

    def okay():
        print(test + ': ' + bcolors.OKGREEN + 'done' + bcolors.ENDC)

    def errorHandler(msg):
        print(bcolors.WARNING + 'WARNING: ' + bcolors.ENDC + msg)

    cfg.set_error_handler(errorHandler)
    mode = cfg.get_snapshots_mode()

    if cfg.SNAPSHOT_MODES[mode][0] is not None:
        #pre_mount_check
        test = 'Run mount tests'
        announceTest()
        mnt = mount.Mount(cfg = cfg, tmp_mount = True)
        try:
            mnt.pre_mount_check(mode = mode, first_run = True)
        except MountException as ex:
            failed()
            print(str(ex))
            return False
        okay()

        #okay, lets try to mount
        test = 'Mount'
        announceTest()
        try:
            hash_id = mnt.mount(mode = mode, check = False)
        except MountException as ex:
            failed()
            print(str(ex))
            return False
        okay()

    test = 'Check/prepair snapshot path'
    announceTest()
    snapshots_path = cfg.get_snapshots_path(mode = mode, tmp_mount = True)

    if not cfg.set_snapshots_path( snapshots_path, mode = mode ):
        failed()
        return False
    okay()

    #umount
    if not cfg.SNAPSHOT_MODES[mode][0] is None:
        test = 'Unmount'
        announceTest()
        try:
            mnt.umount(hash_id = hash_id)
        except MountException as ex:
            failed()
            print(str(ex))
            return False
        okay()

    test = 'Check config'
    announceTest()
    if not cfg.check_config():
        failed()
        return False
    okay()

    if crontab:
        test = 'Install crontab'
        announceTest()
        if not cfg.setup_cron():
            failed()
            return False
        okay()

    return True