Beispiel #1
0
def test_from_add_to_done_lpview(tmpdir):
    file = tmpdir.join('a')
    file.write('abc')
    fpath = str(file)
    key = 'key'

    remote_md5 = ops.compute_md5_for_file_asbase64(str(file))

    a = None
    lpview = modelsul.LocalPathView(
        fd_start=0,
        fd_end=3,
        mode=None,
        next=None,
        slice_num=None,
        total_slices=1,
    )
    try:
        a = ops.LocalFileMd5Offload(num_workers=1)
        result = a.pop_done_queue()
        assert result is None

        a.add_localfile_for_md5_check(key, fpath, fpath, remote_md5,
                                      azmodels.StorageModes.Block, lpview)
        i = 33
        checked = False
        while i > 0:
            result = a.pop_done_queue()
            if result is None:
                time.sleep(0.3)
                i -= 1
                continue
            assert len(result) == 5
            assert result[0] == key
            assert result[1] == str(file)
            assert result[2] == 3
            assert result[3] == remote_md5
            assert result[4]
            checked = True
            break
        assert checked
    finally:
        if a:
            a.finalize_processes()
def test_localpath(tmpdir):
    tmpdir.join('a').write('zz')
    pp = pathlib.Path(str(tmpdir))
    rp = pathlib.Path('a')
    file = pp / rp
    stat = file.stat()

    lp = upload.LocalPath(pp, rp, use_stdin=True, view=None)
    assert lp.absolute_path == file
    assert lp.size == 0
    assert lp.total_size == 0
    assert lp.lmt == 0
    assert lp.mode.replace('o', '') == '00'
    assert lp.uid == 0
    assert lp.gid == 0

    lp = upload.LocalPath(pp, rp, use_stdin=False, view=None)
    assert lp.absolute_path == file
    assert lp.size == stat.st_size
    assert lp.total_size == stat.st_size
    assert lp.lmt == stat.st_mtime
    assert lp.mode.replace('o', '') == str(oct(stat.st_mode)).replace('o', '')
    assert lp.uid == stat.st_uid
    assert lp.gid == stat.st_gid

    lpview = upload.LocalPathView(
        fd_start=1,
        fd_end=2,
        slice_num=1,
        mode=upload.VectoredIoDistributionMode.Stripe,
        total_slices=2,
        next=None,
    )
    lp = upload.LocalPath(pp, rp, use_stdin=False, view=lpview)
    assert lp.absolute_path == file
    assert lp.size == 1
    assert lp.total_size == stat.st_size
    assert lp.lmt == stat.st_mtime
    assert lp.mode.replace('o', '') == str(oct(stat.st_mode)).replace('o', '')
    assert lp.uid == stat.st_uid
    assert lp.gid == stat.st_gid