def test_ismount_non_existent(self):
     self.assertIs(posixpath.ismount(ABSTFN), False)
     try:
         os.mkdir(ABSTFN)
         self.assertIs(posixpath.ismount(ABSTFN), False)
     finally:
         safe_rmdir(ABSTFN)
 def test_ismount_non_existent(self):
     # Non-existent mountpoint.
     self.assertIs(posixpath.ismount(ABSTFN), False)
     try:
         os.mkdir(ABSTFN)
         self.assertIs(posixpath.ismount(ABSTFN), False)
     finally:
         safe_rmdir(ABSTFN)
Example #3
0
 def test_ismount_non_existent(self) -> None:
     # Non-existent mountpoint.
     self.assertIs(posixpath.ismount(ABSTFN), False)
     try:
         os.mkdir(ABSTFN)
         self.assertIs(posixpath.ismount(ABSTFN), False)
     finally:
         safe_rmdir(ABSTFN)
 def test_ismount_symlinks(self):
     # Symlinks are never mountpoints.
     try:
         os.symlink("/", ABSTFN)
         self.assertIs(posixpath.ismount(ABSTFN), False)
     finally:
         os.unlink(ABSTFN)
Example #5
0
def main(args=None):
    '''Umount S3QL file system
    
    This function writes to stdout/stderr and calls `system.exit()` instead
    of returning.
    '''

    if args is None:
        args = sys.argv[1:]

    options = parse_args(args)
    setup_logging(options)
    mountpoint = options.mountpoint
        
    # Check if it's a mount point
    if not posixpath.ismount(mountpoint):
        print('Not a mount point.', file=sys.stderr)
        sys.exit(1)

    # Check if it's an S3QL mountpoint
    ctrlfile = os.path.join(mountpoint, CTRL_NAME)
    if not (CTRL_NAME not in llfuse.listdir(mountpoint)
            and os.path.exists(ctrlfile)):
        print('Not an S3QL file system.', file=sys.stderr)
        sys.exit(1)

    if options.lazy:
        lazy_umount(mountpoint)
    else:
        blocking_umount(mountpoint)
Example #6
0
 def test_ismount_symlinks(self):
     # Symlinks are never mountpoints.
     try:
         os.symlink("/", ABSTFN)
         self.assertIs(posixpath.ismount(ABSTFN), False)
     finally:
         os.unlink(ABSTFN)
Example #7
0
def assert_s3ql_mountpoint(mountpoint):
    '''Raise QuietError if *mountpoint* is not an S3QL mountpoint

    Implicitly calls `assert_s3ql_fs` first. Returns name of the
    S3QL control file.
    '''

    ctrlfile = assert_s3ql_fs(mountpoint)
    if not posixpath.ismount(mountpoint):
        raise QuietError('%s is not a mount point' % mountpoint)

    return ctrlfile
Example #8
0
def assert_s3ql_mountpoint(mountpoint):
    '''Raise QuietError if *mountpoint* is not an S3QL mountpoint
    
    Implicitly calls `assert_s3ql_fs` first. Returns name of the 
    S3QL control file.
    '''

    ctrlfile = assert_s3ql_fs(mountpoint)
    if not posixpath.ismount(mountpoint):
        raise QuietError('%s is not a mount point' % mountpoint)

    return ctrlfile
    def test_ismount_different_device(self):
        save_lstat = os.lstat

        def fake_lstat(path):
            st_ino = 0
            st_dev = 0
            if path == ABSTFN:
                st_dev = 1
                st_ino = 1
            return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))

        try:
            os.lstat = fake_lstat
            self.assertIs(posixpath.ismount(ABSTFN), True)
        finally:
            os.lstat = save_lstat
 def test_ismount_different_device(self):
     # Simulate the path being on a different device from its parent by
     # mocking out st_dev.
     save_lstat = os.lstat
     def fake_lstat(path):
         st_ino = 0
         st_dev = 0
         if path == ABSTFN:
             st_dev = 1
             st_ino = 1
         return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
     try:
         os.lstat = fake_lstat
         self.assertIs(posixpath.ismount(ABSTFN), True)
     finally:
         os.lstat = save_lstat
Example #11
0
 def test_ismount_symlinks(self):
     # Symlinks are never mountpoints.
     try:
         os.symlink("/", ABSTFN)
         self.assertIs(posixpath.ismount(ABSTFN), False)
     finally:
         os.unlink(ABSTFN)
         if sys.platform == 'OpenVMS':
             # OpenVMS has a bug - after deleting symlink to "/" we cannot use the symlink name for some time
             while True:
                 try:
                     os.mkdir(ABSTFN)
                     os.rmdir(ABSTFN)
                     break
                 except:
                     pass
Example #12
0
 def test_ismount_different_device(self):
     # Simulate the path being on a different device from its parent by
     # mocking out st_dev.
     save_lstat = os.lstat
     def fake_lstat(path):
         st_ino = 0
         st_dev = 0
         if path == ABSTFN:
             st_dev = 1
             st_ino = 1
         return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
     try:
         os.lstat = fake_lstat
         self.assertIs(posixpath.ismount(ABSTFN), True)
     finally:
         os.lstat = save_lstat
Example #13
0
 def test_ismount_different_device(self) -> None:
     # Simulate the path being on a different device from its parent by
     # mocking out st_dev.
     save_lstat = os.lstat
     def fake_lstat(path):
         st_ino = 0
         st_dev = 0
         if path == ABSTFN:
             st_dev = 1
             st_ino = 1
         return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
     try:
         setattr(os, 'lstat', fake_lstat) # mypy: can't modify os directly
         self.assertIs(posixpath.ismount(ABSTFN), True)
     finally:
         setattr(os, 'lstat', save_lstat)
Example #14
0
 def test_ismount_different_device(self):
     raise NotImplementedError() # cannot modify os.lstat currently
     # Simulate the path being on a different device from its parent by
     # mocking out st_dev.
     save_lstat = os.lstat
     def fake_lstat(path):
         st_ino = 0
         st_dev = 0
         if path == ABSTFN:
             st_dev = 1
             st_ino = 1
         return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
     try:
         #os.lstat = fake_lstat
         self.assertIs(posixpath.ismount(ABSTFN), True)
     finally:
         pass
Example #15
0
def main(args=None):
    '''Print file system statistics to sys.stdout'''

    if args is None:
        args = sys.argv[1:]

    options = parse_args(args)
    setup_logging(options)
    mountpoint = options.mountpoint

    # Check if it's a mount point
    if not posixpath.ismount(mountpoint):
        raise QuietError('%s is not a mount point' % mountpoint)

    # Check if it's an S3QL mountpoint
    ctrlfile = os.path.join(mountpoint, CTRL_NAME)
    if not (CTRL_NAME not in llfuse.listdir(mountpoint)
            and os.path.exists(ctrlfile)):
        raise QuietError('%s is not a mount point' % mountpoint)

    if os.stat(ctrlfile).st_uid != os.geteuid() and os.geteuid() != 0:
        raise QuietError('Only root and the mounting user may run s3qlstat.')

    # Use a decent sized buffer, otherwise the statistics have to be
    # calculated thee(!) times because we need to invoce getxattr
    # three times.
    buf = llfuse.getxattr(ctrlfile, b's3qlstat', size_guess=256)

    (entries, blocks, inodes, fs_size, dedup_size,
     compr_size, db_size) = struct.unpack('QQQQQQQ', buf)
    p_dedup = dedup_size * 100 / fs_size if fs_size else 0
    p_compr_1 = compr_size * 100 / fs_size if fs_size else 0
    p_compr_2 = compr_size * 100 / dedup_size if dedup_size else 0
    mb = 1024 ** 2
    print ('Directory entries:    %d' % entries,
           'Inodes:               %d' % inodes,
           'Data blocks:          %d' % blocks,
           'Total data size:      %.2f MiB' % (fs_size / mb),
           'After de-duplication: %.2f MiB (%.2f%% of total)'
             % (dedup_size / mb, p_dedup),
           'After compression:    %.2f MiB (%.2f%% of total, %.2f%% of de-duplicated)'
             % (compr_size / mb, p_compr_1, p_compr_2),
           'Database size:        %.2f MiB (uncompressed)' % (db_size / mb),
           '(some values do not take into account not-yet-uploaded dirty blocks in cache)',
           sep='\n')
Example #16
0
    def test_ismount_different_device(self) -> None:
        # Simulate the path being on a different device from its parent by
        # mocking out st_dev.
        save_lstat = os.lstat

        def fake_lstat(path):
            st_ino = 0
            st_dev = 0
            if path == ABSTFN:
                st_dev = 1
                st_ino = 1
            return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))

        try:
            setattr(os, 'lstat', fake_lstat)  # mypy: can't modify os directly
            self.assertIs(posixpath.ismount(ABSTFN), True)
        finally:
            os.lstat = save_lstat
    def test_ismount_directory_not_readable(self):
        save_lstat = os.lstat

        def fake_lstat(path):
            st_ino = 0
            st_dev = 0
            if path.startswith(ABSTFN) and path != ABSTFN:
                raise OSError('Fake [Errno 13] Permission denied')
            if path == ABSTFN:
                st_dev = 1
                st_ino = 1
            return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))

        try:
            os.lstat = fake_lstat
            self.assertIs(posixpath.ismount(ABSTFN), True)
        finally:
            os.lstat = save_lstat
Example #18
0
    def test_ismount_non_existent(self):
        # Non-existent mountpoint.
        self.assertIs(posixpath.ismount(ABSTFN), False)
        try:
            os.mkdir(ABSTFN)
            self.assertIs(posixpath.ismount(ABSTFN), False)
        finally:
            safe_rmdir(ABSTFN)

        self.assertIs(posixpath.ismount('/\udfff'), False)
        self.assertIs(posixpath.ismount(b'/\xff'), False)
        self.assertIs(posixpath.ismount('/\x00'), False)
        self.assertIs(posixpath.ismount(b'/\x00'), False)
Example #19
0
def check_mount(mountpoint):
    '''Check that "mountpoint" is a mountpoint and a valid s3ql fs'''
    
    try:
        os.stat(mountpoint)
    except OSError as exc:
        if exc.errno is errno.ENOTCONN:
            raise FSCrashedError(mountpoint)
        raise
        
    if not posixpath.ismount(mountpoint):
        raise NotMountPointError(mountpoint)

    ctrlfile = os.path.join(mountpoint, CTRL_NAME)
    if not (
        CTRL_NAME not in llfuse.listdir(mountpoint) and
        os.path.exists(ctrlfile)
    ):
        raise NotS3qlFsError(mountpoint)
Example #20
0
 def test_ismount_directory_not_readable(self):
     # issue #2466: Simulate ismount run on a directory that is not
     # readable, which used to return False.
     save_lstat = os.lstat
     def fake_lstat(path):
         st_ino = 0
         st_dev = 0
         if path.startswith(ABSTFN) and path != ABSTFN:
             # ismount tries to read something inside the ABSTFN directory;
             # simulate this being forbidden (no read permission).
             raise OSError("Fake [Errno 13] Permission denied")
         if path == ABSTFN:
             st_dev = 1
             st_ino = 1
         return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
     try:
         os.lstat = fake_lstat
         self.assertIs(posixpath.ismount(ABSTFN), True)
     finally:
         os.lstat = save_lstat
Example #21
0
 def test_ismount_directory_not_readable(self):
     # issue #2466: Simulate ismount run on a directory that is not
     # readable, which used to return False.
     save_lstat = os.lstat
     def fake_lstat(path):
         st_ino = 0
         st_dev = 0
         if path.startswith(ABSTFN) and path != ABSTFN:
             # ismount tries to read something inside the ABSTFN directory;
             # simulate this being forbidden (no read permission).
             raise OSError("Fake [Errno 13] Permission denied")
         if path == ABSTFN:
             st_dev = 1
             st_ino = 1
         return posix.stat_result((0, st_ino, st_dev, 0, 0, 0, 0, 0, 0, 0))
     try:
         os.lstat = fake_lstat
         self.assertIs(posixpath.ismount(ABSTFN), True)
     finally:
         os.lstat = save_lstat
Example #22
0
 def test_ismount(self):
     self.assertIs(posixpath.ismount("/"), True)
Example #23
0
 def test_ismount(self):
     self.assertIs(posixpath.ismount("/"), True)
     self.assertIs(posixpath.ismount(b"/"), True)
 def test_ismount_symlinks(self):
     try:
         os.symlink('/', ABSTFN)
         self.assertIs(posixpath.ismount(ABSTFN), False)
     finally:
         os.unlink(ABSTFN)
Example #25
0
 def test_ismount(self):
     self.assertIs(posixpath.ismount("/"), True)
     with warnings.catch_warnings():
         self.assertIs(posixpath.ismount(b"/"), True)
 def test_ismount(self):
     self.assertIs(posixpath.ismount("/"), True)
     with warnings.catch_warnings():
         warnings.simplefilter("ignore", DeprecationWarning)
         self.assertIs(posixpath.ismount(b"/"), True)
Example #27
0
 def __len__(self):
     if self["protocol"] == "local" and os.path.isdir(self["path"]):
         return True
     return os.path.isdir(self.local_path) and ismount(
         self.local_path) and len(os.listdir(self.local_path)) != 0
Example #28
0
    def test_ismount(self):
        self.assertIs(posixpath.ismount("/"), True)

        self.assertRaises(TypeError, posixpath.ismount)
    def test_ismount(self):
        self.assertIs(posixpath.ismount("/"), True)

        self.assertRaises(TypeError, posixpath.ismount)
Example #30
0
 def test_ismount(self) -> None:
     self.assertIs(posixpath.ismount("/"), True)
     self.assertIs(posixpath.ismount(b"/"), True)
Example #31
0
    def test_ismount(self):
        if os.name in ('mac', ):
            return
        self.assertIs(posixpath.ismount("/"), True)

        self.assertRaises(TypeError, posixpath.ismount)
Example #32
0
 def test_ismount(self):
     self.assertIs(posixpath.ismount("/"), True)
     with warnings.catch_warnings():
         warnings.simplefilter("ignore", DeprecationWarning)
         self.assertIs(posixpath.ismount(b"/"), True)
Example #33
0
 def __len__(self):
     return ismount(self.local_path) and len(os.listdir(self.local_path)) != 0
Example #34
0
base_dir = os.path.dirname(os.path.realpath(__file__))
sites = []
sites_dir = os.path.join(base_dir, "sites")
for f in os.listdir(sites_dir):
    if not os.path.isdir(os.path.join(sites_dir, f)):
        continue
    sites.append(f)

for site in sites:
    stripname = site.replace("-", "")
    db = DB(host="localhost",
            user=stripname,
            password="******",
            database="nebula_{}".format(stripname))
    db.query("SELECT id, settings FROM storages")
    for id_storage, settings in db.fetchall():
        mountpoint = "/mnt/{}_{:02d}".format(site, id_storage)
        if not os.path.isdir(mountpoint):
            print("Creating mountpoint {}".format(mountpoint))
            os.makedirs(mountpoint)

        if not posixpath.ismount(mountpoint):
            print("Mounting {} storage {}".format(site, id_storage))
            credentials = "user={},pass={}".format(settings["login"],
                                                   settings["password"])

            cmd = "mount.cifs {} {} -o '{}'".format(settings["path"],
                                                    mountpoint, credentials)
            os.system(cmd)
Example #35
0
 def __len__(self):
     return ismount(
         self.local_path) and len(os.listdir(self.local_path)) != 0
Example #36
0
 def update_event(self, inp=-1):
     self.set_output_val(0, posixpath.ismount(self.input(0)))