Exemplo n.º 1
0
 def test_do_write(self):
     fd, tmpfile = mkstemp()
     try:
         cnt = fs.do_write(fd, "test")
         assert cnt == len("test")
     finally:
         os.close(fd)
         os.remove(tmpfile)
Exemplo n.º 2
0
 def test_do_write_err(self):
     fd, tmpfile = mkstemp()
     try:
         fd1 = os.open(tmpfile, os.O_RDONLY)
         try:
             fs.do_write(fd1, "test")
         except GlusterFileSystemOSError:
             pass
         else:
             self.fail("GlusterFileSystemOSError expected")
         finally:
             os.close(fd1)
     except GlusterFileSystemOSError as ose:
         self.fail("Open failed with %s" % ose.strerror)
     finally:
         os.close(fd)
         os.remove(tmpfile)
Exemplo n.º 3
0
 def test_do_write_err(self):
     fd, tmpfile = mkstemp()
     try:
         fd1 = os.open(tmpfile, os.O_RDONLY)
         try:
             fs.do_write(fd1, "test")
         except GlusterFileSystemOSError:
             pass
         else:
             self.fail("GlusterFileSystemOSError expected")
         finally:
             os.close(fd1)
     except GlusterFileSystemOSError as ose:
         self.fail("Open failed with %s" % ose.strerror)
     finally:
         os.close(fd)
         os.remove(tmpfile)
Exemplo n.º 4
0
 def test_do_write(self):
     fd, tmpfile = mkstemp()
     try:
         cnt = fs.do_write(fd, "test")
         assert cnt == len("test")
     finally:
         os.close(fd)
         os.remove(tmpfile)
Exemplo n.º 5
0
 def _write_entire_chunk(self, chunk):
     bytes_per_sync = self._disk_file._mgr.bytes_per_sync
     while chunk:
         written = do_write(self._fd, chunk)
         chunk = chunk[written:]
         self._upload_size += written
         # For large files sync every 512MB (by default) written
         diff = self._upload_size - self._last_sync
         if diff >= bytes_per_sync:
             do_fdatasync(self._fd)
             do_fadvise64(self._fd, self._last_sync, diff)
             self._last_sync = self._upload_size
Exemplo n.º 6
0
 def _write_entire_chunk(self, chunk):
     bytes_per_sync = self._disk_file._mgr.bytes_per_sync
     while chunk:
         written = do_write(self._fd, chunk)
         chunk = chunk[written:]
         self._upload_size += written
         # For large files sync every 512MB (by default) written
         diff = self._upload_size - self._last_sync
         if diff >= bytes_per_sync:
             do_fdatasync(self._fd)
             do_fadvise64(self._fd, self._last_sync, diff)
             self._last_sync = self._upload_size
Exemplo n.º 7
0
    def test_do_write_DiskFileNoSpace(self):
        def mock_os_write_enospc(fd, msg):
            raise OSError(errno.ENOSPC, os.strerror(errno.ENOSPC))

        def mock_os_write_edquot(fd, msg):
            raise OSError(errno.EDQUOT, os.strerror(errno.EDQUOT))

        with patch('os.write', mock_os_write_enospc):
            try:
                fs.do_write(9, "blah")
            except DiskFileNoSpace:
                pass
            else:
                self.fail("Expected DiskFileNoSpace exception")

        with patch('os.write', mock_os_write_edquot):
            try:
                fs.do_write(9, "blah")
            except DiskFileNoSpace:
                pass
            else:
                self.fail("Expected DiskFileNoSpace exception")
Exemplo n.º 8
0
    def test_do_write_DiskFileNoSpace(self):

        def mock_os_write_enospc(fd, msg):
            raise OSError(errno.ENOSPC, os.strerror(errno.ENOSPC))

        def mock_os_write_edquot(fd, msg):
            raise OSError(errno.EDQUOT, os.strerror(errno.EDQUOT))

        with patch('os.write', mock_os_write_enospc):
            try:
                fs.do_write(9, "blah")
            except DiskFileNoSpace:
                pass
            else:
                self.fail("Expected DiskFileNoSpace exception")

        with patch('os.write', mock_os_write_edquot):
            try:
                fs.do_write(9, "blah")
            except DiskFileNoSpace:
                pass
            else:
                self.fail("Expected DiskFileNoSpace exception")