Beispiel #1
0
def test_zero_repr():
    op = directio.Zero("/path", 100)
    rep = repr(op)
    assert "Zero" in rep
    assert "path='/path'" in rep
    assert "offset=0" in rep
    assert "size=100" in rep
    assert "done=0" in rep
    assert "active" in rep
Beispiel #2
0
def test_zero(tmpdir, offset, size, sparse):
    dst = tmpdir.join("src")
    data = "x" * directio.BUFFERSIZE * 2
    dst.write(data)
    op = directio.Zero(str(dst), size, offset=offset, sparse=sparse)
    op.run()
    with io.open(str(dst), "rb") as f:
        assert f.read(offset) == data[:offset]
        assert f.read(size) == b"\0" * size
        assert f.read() == data[offset + size:]
Beispiel #3
0
def test_zero_flush(tmpdir, monkeypatch, flush, calls):
    # This would be much cleaner when we add backend object implementing flush.
    fsync = os.fsync
    fsync_calls = [0]

    def counted_fsync(fd):
        fsync_calls[0] += 1
        fsync(fd)

    monkeypatch.setattr("os.fsync", counted_fsync)
    dst = tmpdir.join("src")
    data = "x" * directio.BUFFERSIZE * 2
    dst.write(data)
    size = len(data)
    op = directio.Zero(str(dst), size, flush=flush)
    op.run()
    with io.open(str(dst), "rb") as f:
        assert f.read() == b"\0" * size
    assert fsync_calls[0] == calls
Beispiel #4
0
    def _zero(self, ticket_id, msg):
        size = validate.integer(msg, "size", minval=0)
        offset = validate.integer(msg, "offset", minval=0, default=0)
        flush = validate.boolean(msg, "flush", default=False)

        ticket = tickets.authorize(ticket_id, "write", offset, size)

        self.log.info(
            "Zeroing %d bytes at offset %d flush %s to %s for ticket %s", size,
            offset, flush, ticket.url.path, ticket_id)
        op = directio.Zero(ticket.url.path,
                           size,
                           offset=offset,
                           flush=flush,
                           buffersize=self.config.daemon.buffer_size,
                           clock=self.clock)
        try:
            ticket.run(op)
        except errors.PartialContent as e:
            raise HTTPBadRequest(str(e))
        return web.response()
Beispiel #5
0
def test_zero_repr_active():
    op = directio.Zero("/path", 100)
    op.close()
    assert "active" not in repr(op)
Beispiel #6
0
def test_zero_close_twice(tmpfile):
    op = directio.Zero(str(tmpfile), 100)
    op.run()
    op.close()  # should do nothing
    assert not op.active
Beispiel #7
0
def test_zero_close_on_error():
    op = directio.Zero("/no/such/file", 100)
    with pytest.raises(OSError):
        op.run()
    assert not op.active
Beispiel #8
0
def test_zero_close_on_success(tmpfile):
    op = directio.Zero(str(tmpfile), 100)
    op.run()
    assert not op.active
Beispiel #9
0
def test_zero_busy():
    op = directio.Zero("/no/such/file", 100)
    assert op.active