Esempio n. 1
0
    def test_do_stat_eio_ten(self):
        def mock_os_stat_eio(path):
            raise OSError(errno.EIO, os.strerror(errno.EIO))

        try:
            with patch('os.stat', mock_os_stat_eio):
                fs.do_stat('/tmp')
        except FileConnectorFileSystemOSError:
            pass
        else:
            self.fail("FileConnectorFileSystemOSError expected")
Esempio n. 2
0
    def test_do_stat_err(self):
        def mock_os_stat_eacces(path):
            raise OSError(errno.EACCES, os.strerror(errno.EACCES))

        try:
            with patch('os.stat', mock_os_stat_eacces):
                fs.do_stat('/tmp')
        except FileConnectorFileSystemOSError:
            pass
        else:
            self.fail("FileConnectorFileSystemOSError expected")
Esempio n. 3
0
    def test_do_stat_eio_twice(self):
        count = [0]
        _os_stat = os.stat

        def mock_os_stat_eio(path):
            count[0] += 1
            if count[0] <= 2:
                raise OSError(errno.EIO, os.strerror(errno.EIO))
            return _os_stat(path)

        with patch('os.stat', mock_os_stat_eio):
            fs.do_stat('/tmp') is not None
Esempio n. 4
0
    def get_object_metadata(self, obj_path_or_fd, stats=None,
                            calculate_etag=True):
        """
        Return metadata of object.
        """
        if not stats:
            if isinstance(obj_path_or_fd, int):
                # We are given a file descriptor, so this is an invocation from
                # the DiskFile.open() method.
                stats = do_fstat(obj_path_or_fd)
            else:
                # We are given a path to the object when the
                # DiskDir.list_objects_iter method invokes us.
                stats = do_stat(obj_path_or_fd)

        if not stats:
            metadata = {}
        else:
            is_dir = stat.S_ISDIR(stats.st_mode)
            if calculate_etag:
                etag = md5().hexdigest() if is_dir else _get_etag(
                    obj_path_or_fd)
            else:
                etag = FC_ETAG
            metadata = {
                X_TYPE: OBJECT,
                X_TIMESTAMP: normalize_timestamp(stats.st_ctime),
                X_CONTENT_TYPE: DIR_TYPE if is_dir else FILE_TYPE,
                X_OBJECT_TYPE: DIR_NON_OBJECT if is_dir else FILE,
                X_CONTENT_LENGTH: 0 if is_dir else stats.st_size,
                X_ETAG: etag}
        return metadata
Esempio n. 5
0
    def test_do_stat(self):
        tmpdir = mkdtemp()
        try:
            fd, tmpfile = mkstemp(dir=tmpdir)
            buf1 = os.stat(tmpfile)
            buf2 = fs.do_stat(tmpfile)

            assert buf1 == buf2
        finally:
            os.close(fd)
            os.remove(tmpfile)
            os.rmdir(tmpdir)
Esempio n. 6
0
 def test_do_stat_enoent(self):
     res = fs.do_stat(os.path.join('/tmp', str(random.random())))
     assert res is None