예제 #1
0
def test_getattrs_should_cache_attrs(endpoint, fl):
    fuse_response = prepare_getattr('path', fuse_messages_pb2.REG)

    stat = fslogic.Stat()
    with reply(endpoint, fuse_response):
        assert 0 == fl.getattr('/random/path', stat)

    new_stat = fslogic.Stat()
    assert fl.getattr('/random/path', new_stat) == 0
    assert stat == new_stat
    assert 3 == endpoint.all_messages_count()
예제 #2
0
def test_write_should_change_file_size(endpoint, fl):
    do_open(endpoint, fl, blocks=[(0, 5)], size=5)
    assert 20 == fl.write('/random/path', 10, 20)

    stat = fslogic.Stat()
    fl.getattr('/random/path', stat)
    assert 30 == stat.size
예제 #3
0
def test_getattrs_should_get_attrs(endpoint, fl):
    response = prepare_getattr('path', fuse_messages_pb2.REG)

    stat = fslogic.Stat()
    with reply(endpoint, response) as queue:
        assert 0 == fl.getattr('/random/path', stat)
        client_message = queue.get()

    assert client_message.HasField('fuse_request')

    fuse_request = client_message.fuse_request
    assert fuse_request.HasField('get_file_attr')

    get_file_attr = fuse_request.get_file_attr
    assert get_file_attr.entry_type == fuse_messages_pb2.PATH
    assert get_file_attr.entry == '/random/path'

    repl = response.fuse_response.file_attr
    assert stat.atime == repl.atime
    assert stat.mtime == repl.mtime
    assert stat.ctime == repl.ctime
    assert stat.gid == repl.gid
    assert stat.uid == repl.uid
    assert stat.mode == repl.mode | fslogic.regularMode()
    assert stat.size == repl.size
예제 #4
0
def test_getattrs_should_pass_errors(endpoint, fl):
    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.enoent

    stat = fslogic.Stat()
    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, response):
            fl.getattr('/random/path', stat)

    assert 'No such file or directory' in str(excinfo.value)
예제 #5
0
def test_chmod_should_change_cached_mode(appmock_client, endpoint, fl):
    getattr_response = prepare_getattr('path', fuse_messages_pb2.REG)

    stat = fslogic.Stat()
    with reply(endpoint, getattr_response):
        fl.getattr('/random/path', stat)

    assert stat.mode == getattr_response.fuse_response.file_attr.mode | \
                        fslogic.regularMode()
    assert 3 == endpoint.all_messages_count()
    appmock_client.reset_tcp_history()

    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.ok
    with reply(endpoint, response):
        fl.chmod('/random/path', 0356)

    stat = fslogic.Stat()
    fl.getattr('/random/path', stat)

    assert stat.mode == 0356 | fslogic.regularMode()
예제 #6
0
def test_utime_should_change_cached_times(appmock_client, endpoint, fl):
    getattr_response = prepare_getattr('path', fuse_messages_pb2.REG)

    stat = fslogic.Stat()
    with reply(endpoint, getattr_response):
        fl.getattr('/random/path', stat)

    assert stat.atime == getattr_response.fuse_response.file_attr.atime
    assert stat.mtime == getattr_response.fuse_response.file_attr.mtime
    assert 3 == endpoint.all_messages_count()
    appmock_client.reset_tcp_history()

    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.ok
    with reply(endpoint, response):
        fl.utime('/random/path')

    stat = fslogic.Stat()
    fl.getattr('/random/path', stat)

    assert stat.atime != getattr_response.fuse_response.file_attr.atime
    assert stat.mtime != getattr_response.fuse_response.file_attr.mtime
예제 #7
0
def test_rename_should_change_caches(appmock_client, endpoint, fl):
    getattr_response = prepare_getattr('path', fuse_messages_pb2.DIR)
    rename_response = prepare_rename()

    with reply(endpoint, [getattr_response, rename_response]):
        fl.rename('/random/path', '/random/path2')

    stat = fslogic.Stat()
    fl.getattr('/random/path2', stat)

    assert stat.size == getattr_response.fuse_response.file_attr.size
    1 == endpoint.all_messages_count()
    appmock_client.reset_tcp_history()

    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.enoent

    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, response):
            fl.getattr('/random/path', stat)

    assert 'No such file or directory' in str(excinfo.value)