Exemplo n.º 1
0
def test_readdir_big_directory(endpoint, fl):
    children_num = 100000

    getattr_response = prepare_getattr('path', fuse_messages_pb2.DIR)

    repl = fuse_messages_pb2.FileChildren()
    for i in xrange(0, children_num):
        link = repl.child_links.add()
        link.uuid = "uuid{0}".format(i)
        link.name = "file{0}".format(i)

    response = messages_pb2.ServerMessage()
    response.fuse_response.file_children.CopyFrom(repl)
    response.fuse_response.status.code = common_messages_pb2.Status.ok

    empty_response = messages_pb2.ServerMessage()
    empty_response.fuse_response.file_children.CopyFrom(
        fuse_messages_pb2.FileChildren())
    empty_response.fuse_response.status.code = common_messages_pb2.Status.ok

    children = []
    with reply(endpoint, [getattr_response, response, empty_response]):
        assert 0 == fl.readdir('/random/path', children)

    assert len(children) == children_num + 2
Exemplo n.º 2
0
def do_release(endpoint, fl, uuid, fh):
    fsync_response = messages_pb2.ServerMessage()
    fsync_response.fuse_response.status.code = common_messages_pb2.Status.ok

    release_response = messages_pb2.ServerMessage()
    release_response.fuse_response.status.code = common_messages_pb2.Status.ok

    result = None
    with reply(endpoint, [fsync_response, release_response]) as queue:
        fl.release(uuid, fh)
        result = queue
    return result
Exemplo n.º 3
0
def test_readdir_should_read_dir(endpoint, fl, uuid, stat):
    file1 = common_messages_pb2.ChildLink()
    file1.uuid = "childUuid1"
    file1.name = "file1"

    file2 = common_messages_pb2.ChildLink()
    file2.uuid = "childUuid2"
    file2.name = "file2"

    repl = fuse_messages_pb2.FileChildren()
    repl.child_links.extend([file1, file2])

    response = messages_pb2.ServerMessage()
    response.fuse_response.file_children.CopyFrom(repl)
    response.fuse_response.status.code = common_messages_pb2.Status.ok

    children = []
    with reply(endpoint, response) as queue:
        children = fl.readdir(uuid)
        client_message = queue.get()

    assert sorted(children) == sorted([file1.name, file2.name, '..', '.'])

    assert client_message.HasField('fuse_request')
    assert client_message.fuse_request.HasField('file_request')

    file_request = client_message.fuse_request.file_request
    assert file_request.HasField('get_file_children')

    get_file_children = file_request.get_file_children
    assert get_file_children.offset == 0
    assert file_request.context_guid == uuid
Exemplo n.º 4
0
def prepare_location_update_event(blocks, stream_id, sequence_number):
    file_blocks = prepare_file_blocks(blocks)

    file_location = fuse_messages_pb2.FileLocation()
    file_location.uuid = 'uuid1'
    file_location.space_id = 'space1'
    file_location.storage_id = 'storage1'
    file_location.file_id = 'file1'
    file_location.provider_id = 'provider1'
    file_location.blocks.extend(file_blocks)

    update_event = event_messages_pb2.UpdateEvent()
    update_event.file_location.CopyFrom(file_location)

    event = event_messages_pb2.Event()
    event.counter = 1
    event.update_event.CopyFrom(update_event)

    events = event_messages_pb2.Events()
    events.events.extend([event])

    message_stream = stream_messages_pb2.MessageStream()
    message_stream.stream_id = stream_id
    message_stream.sequence_number = sequence_number

    server_msg = messages_pb2.ServerMessage()
    server_msg.message_stream.CopyFrom(message_stream)
    server_msg.events.CopyFrom(events)

    return server_msg
Exemplo n.º 5
0
def prepare_events(evt_list):
    evts = event_messages_pb2.Events()
    evts.events.extend(evt_list)

    msg = messages_pb2.ServerMessage()
    msg.events.CopyFrom(evts)

    return msg
Exemplo n.º 6
0
def prepare_location_response(uuid, blocks=[]):
    location = prepare_location(uuid, blocks)

    server_response = messages_pb2.ServerMessage()
    server_response.fuse_response.file_location.CopyFrom(location)
    server_response.fuse_response.status.code = common_messages_pb2.Status.ok

    return server_response
Exemplo n.º 7
0
def prepare_cancellation(sid):
    can = event_messages_pb2.SubscriptionCancellation()
    can.id = sid

    msg = messages_pb2.ServerMessage()
    msg.subscription_cancellation.CopyFrom(can)

    return msg
Exemplo n.º 8
0
def test_release_should_not_send_release_message_if_handle_id_is_not_set(
        endpoint, fl):
    do_open(endpoint, fl, size=0)
    release_response = messages_pb2.ServerMessage()
    release_response.fuse_response.status.code = common_messages_pb2.Status.ok

    with reply(endpoint, []) as queue:
        assert 0 == fl.release('/random/path')
        assert queue.empty()
Exemplo n.º 9
0
def prepare_open_response(handle_id='handle_id'):
    repl = fuse_messages_pb2.FileOpened()
    repl.handle_id = handle_id

    server_response = messages_pb2.ServerMessage()
    server_response.fuse_response.file_opened.CopyFrom(repl)
    server_response.fuse_response.status.code = common_messages_pb2.Status.ok

    return server_response
Exemplo n.º 10
0
def prepare_rename_response(new_uuid):
    repl = fuse_messages_pb2.FileRenamed()
    repl.new_uuid = new_uuid

    server_response = messages_pb2.ServerMessage()
    server_response.fuse_response.file_renamed.CopyFrom(repl)
    server_response.fuse_response.status.code = common_messages_pb2.Status.ok

    return server_response
Exemplo n.º 11
0
def prepare_helper_response():
    repl = fuse_messages_pb2.HelperParams()
    repl.helper_name = 'null'

    server_response = messages_pb2.ServerMessage()
    server_response.fuse_response.helper_params.CopyFrom(repl)
    server_response.fuse_response.status.code = common_messages_pb2.Status.ok

    return server_response
Exemplo n.º 12
0
def test_readdir_should_pass_readdir_errors(endpoint, fl, uuid, stat):
    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.eperm

    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, response):
            fl.readdir(uuid)

    assert 'Operation not permitted' in str(excinfo.value)
Exemplo n.º 13
0
def test_getxattr_should_return_enoattr_for_invalid_xattr(endpoint, fl, uuid):
    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.enodata

    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, response):
            fl.getxattr(uuid, "org.onedata.dontexist")

    assert 'No data available' in str(excinfo.value)
Exemplo n.º 14
0
def test_rename_should_pass_getattr_errors(endpoint, fl):
    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.rename('/random/path', 'dawaw')

    assert 'No such file or directory' in str(excinfo.value)
Exemplo n.º 15
0
def test_truncate_should_pass_getattr_errors(endpoint, fl):
    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.eperm

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

    assert 'Operation not permitted' in str(excinfo.value)
Exemplo n.º 16
0
def test_chmod_should_pass_chmod_errors(endpoint, fl, uuid):
    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.chmod(uuid, 0312)

    assert 'No such file or directory' in str(excinfo.value)
Exemplo n.º 17
0
def test_rename_should_pass_rename_errors(endpoint, fl, uuid):
    getattr_response = prepare_attr_response(uuid, fuse_messages_pb2.DIR)
    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.eperm

    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, [getattr_response, response]):
            fl.rename('parentUuid', 'name', 'newParentUuid', 'newName')

    assert 'Operation not permitted' in str(excinfo.value)
Exemplo n.º 18
0
def test_open_should_pass_location_errors(endpoint, fl):
    getattr_response = prepare_getattr('path', fuse_messages_pb2.REG)
    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.eperm

    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, [getattr_response, response]):
            fl.open('/random/path', 0)

    assert 'Operation not permitted' in str(excinfo.value)
Exemplo n.º 19
0
def test_truncate_should_pass_truncate_errors(endpoint, fl, uuid):
    getattr_response = prepare_attr_response(uuid, fuse_messages_pb2.REG)
    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.eperm

    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, [getattr_response, response]):
            fl.truncate(uuid, 3)

    assert 'Operation not permitted' in str(excinfo.value)
Exemplo n.º 20
0
def prepare_listxattr_response(uuid):
    repl = fuse_messages_pb2.XattrList()

    repl.names.extend(["xattr1", "xattr2", "xattr3", "xattr4"])

    server_response = messages_pb2.ServerMessage()
    server_response.fuse_response.xattr_list.CopyFrom(repl)
    server_response.fuse_response.status.code = common_messages_pb2.Status.ok

    return server_response
Exemplo n.º 21
0
def test_mknod_should_pass_location_errors(endpoint, fl, parentUuid,
                                           parentStat):
    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.eperm

    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, response):
            fl.mknod(parentUuid, 'childName', 0123)

    assert 'Operation not permitted' in str(excinfo.value)
Exemplo n.º 22
0
def prepare_getxattr_response(uuid, name, value):
    repl = fuse_messages_pb2.Xattr()

    repl.name = name
    repl.value = value

    server_response = messages_pb2.ServerMessage()
    server_response.fuse_response.xattr.CopyFrom(repl)
    server_response.fuse_response.status.code = common_messages_pb2.Status.ok

    return server_response
Exemplo n.º 23
0
def test_read_should_pass_errors(file_handle, file_id, endpoint, helper,
                                 parameters):
    server_message = messages_pb2.ServerMessage()
    server_message.proxyio_response.status.code = \
        common_messages_pb2.Status.eperm

    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, server_message):
            helper.read(file_handle, random_int(), random_int())

    assert 'Operation not permitted' in str(excinfo.value)
Exemplo n.º 24
0
def test_write_should_pass_write_errors(file_id, endpoint, helper, parameters):
    server_message = messages_pb2.ServerMessage()
    server_message.proxyio_response.status.code = \
        common_messages_pb2.Status.eacces

    file_handle = helper.open(file_id, parameters)

    with pytest.raises(RuntimeError) as excinfo:
        with reply(endpoint, server_message):
            helper.write(file_handle, random_str(), random_int())

    assert 'Permission denied' in str(excinfo.value)
Exemplo n.º 25
0
def test_release_should_clear_handle_id_if_set(endpoint, fl):
    do_open(endpoint, fl, size=0, handle_id='handle_id')
    release_response = messages_pb2.ServerMessage()
    release_response.fuse_response.status.code = common_messages_pb2.Status.ok

    with reply(endpoint, [release_response]):
        assert 0 == fl.release('/random/path')

    assert fl.open('/random/path', 0) >= 0
    with reply(endpoint, []) as queue:
        assert 0 == fl.release('/random/path')
        assert queue.empty()
Exemplo n.º 26
0
def prepare_checksum(data):
    md = hashlib.new('MD4')
    md.update(data)
    hash = md.digest()

    repl = fuse_messages_pb2.Checksum()
    repl.value = hash

    server_response = messages_pb2.ServerMessage()
    server_response.fuse_response.checksum.CopyFrom(repl)
    server_response.fuse_response.status.code = common_messages_pb2.Status.ok

    return server_response
Exemplo n.º 27
0
def test_release_should_send_release_message_if_handle_id_is_set(endpoint, fl):
    do_open(endpoint, fl, size=0, handle_id='handle_id')
    release_response = messages_pb2.ServerMessage()
    release_response.fuse_response.status.code = common_messages_pb2.Status.ok

    with reply(endpoint, [release_response]) as queue:
        assert 0 == fl.release('/random/path')
        client_message = queue.get()

    assert client_message.HasField('fuse_request')

    fuse_request = client_message.fuse_request
    assert fuse_request.HasField('release')
Exemplo n.º 28
0
def prepare_sync_response(uuid, data, blocks):
    md = hashlib.new('MD4')
    md.update(data)

    repl = fuse_messages_pb2.SyncResponse()
    repl.checksum = md.digest()
    repl.file_location.CopyFrom(prepare_location(uuid, blocks))

    server_response = messages_pb2.ServerMessage()
    server_response.fuse_response.sync_response.CopyFrom(repl)
    server_response.fuse_response.status.code = common_messages_pb2.Status.ok

    return server_response
Exemplo n.º 29
0
def test_readdir_big_directory(endpoint, fl, uuid, stat):
    children_num = 100000

    repl = fuse_messages_pb2.FileChildren()
    for i in xrange(0, children_num):
        link = repl.child_links.add()
        link.uuid = "uuid{0}".format(i)
        link.name = "file{0}".format(i)

    response = messages_pb2.ServerMessage()
    response.fuse_response.file_children.CopyFrom(repl)
    response.fuse_response.status.code = common_messages_pb2.Status.ok

    empty_response = messages_pb2.ServerMessage()
    empty_response.fuse_response.file_children.CopyFrom(
        fuse_messages_pb2.FileChildren())
    empty_response.fuse_response.status.code = common_messages_pb2.Status.ok

    with reply(endpoint, [response, empty_response]):
        children = fl.readdir(uuid)

    assert len(children) == children_num + 2
Exemplo n.º 30
0
def test_removexattr_should_remove_xattr(endpoint, fl, uuid):
    xattr_name = "org.onedata.acl"
    response = messages_pb2.ServerMessage()
    response.fuse_response.status.code = common_messages_pb2.Status.ok

    with reply(endpoint, response) as queue:
        fl.removexattr(uuid, xattr_name)
        client_message = queue.get()

    assert client_message.HasField('fuse_request')
    assert client_message.fuse_request.HasField('file_request')
    file_request = client_message.fuse_request.file_request
    assert file_request.context_guid == uuid

    remove_xattr_request = file_request.remove_xattr
    assert remove_xattr_request.HasField('name')
    assert remove_xattr_request.name == xattr_name