예제 #1
0
def test_progress(tmpdir):
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.write(b"b" * 4096)
        f.seek(IMAGE_SIZE // 2)
        f.write(b"b" * 4096)
        f.truncate(IMAGE_SIZE)

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst, sparse=True)

    progress = []
    client.upload(src, url, pki.cert_file(config), secure=False,
                  progress=progress.append)

    assert progress == [
        # First write.
        4096,
        # First zero.
        IMAGE_SIZE // 2 - 4096,
        # Second write.
        4096,
        # Second zero
        IMAGE_SIZE // 2 - 4096,
    ]
예제 #2
0
def test_progress(tmpdir):
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.write(b"b" * 4096)
        f.seek(IMAGE_SIZE // 2)
        f.write(b"b" * 4096)
        f.truncate(IMAGE_SIZE)

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst, sparse=True)

    progress = []
    client.upload(src,
                  url,
                  pki.cert_file(config),
                  secure=False,
                  progress=progress.append)

    assert progress == [
        # First write.
        4096,
        # First zero.
        IMAGE_SIZE // 2 - 4096,
        # Second write.
        4096,
        # Second zero
        IMAGE_SIZE // 2 - 4096,
    ]
예제 #3
0
def https_connection():
    con = http_client.HTTPSConnection(config.images.host,
                                      config.images.port,
                                      pki.key_file(config),
                                      pki.cert_file(config))
    with closing(con):
        yield con
예제 #4
0
def test_upload_unix_socket(tmpdir, use_unix_socket):
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.write(b"b" * IMAGE_SIZE)

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst)

    client.upload(src, url, pki.cert_file(config), secure=False)

    check_content(src, dst)
예제 #5
0
def test_upload_unix_socket(tmpdir, use_unix_socket):
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.write(b"b" * IMAGE_SIZE)

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst)

    client.upload(src, url, pki.cert_file(config), secure=False)

    check_content(src, dst)
예제 #6
0
def test_upload_empty_sparse(tmpdir):
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.truncate(IMAGE_SIZE)

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst)

    client.upload(src, url, pki.cert_file(config), secure=False)

    check_content(src, dst)
    assert os.stat(dst).st_blocks == os.stat(src).st_blocks
예제 #7
0
def test_upload_empty_sparse(tmpdir):
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.truncate(IMAGE_SIZE)

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst)

    client.upload(src, url, pki.cert_file(config), secure=False)

    check_content(src, dst)
    assert os.stat(dst).st_blocks == os.stat(src).st_blocks
예제 #8
0
def test_upload_hole_at_middle_sparse(tmpdir):
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.truncate(IMAGE_SIZE)
        f.write(b"b" * (IMAGE_SIZE // 4))
        f.seek(IMAGE_SIZE // 2, os.SEEK_CUR)
        f.write(b"b" * (IMAGE_SIZE // 4))

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst)

    client.upload(src, url, pki.cert_file(config), secure=False)

    check_content(src, dst)
    assert os.stat(dst).st_blocks == os.stat(src).st_blocks
예제 #9
0
def test_upload_hole_at_middle_sparse(tmpdir):
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.truncate(IMAGE_SIZE)
        f.write(b"b" * (IMAGE_SIZE // 4))
        f.seek(IMAGE_SIZE // 2, os.SEEK_CUR)
        f.write(b"b" * (IMAGE_SIZE // 4))

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst)

    client.upload(src, url, pki.cert_file(config), secure=False)

    check_content(src, dst)
    assert os.stat(dst).st_blocks == os.stat(src).st_blocks
예제 #10
0
def test_split_big_zero(tmpdir):
    # Large zero ranges shhould be splitted to smaller chunks.
    size = client.MAX_ZERO_SIZE * 2 + client.MAX_ZERO_SIZE // 2
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.truncate(size)

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst, size=size, sparse=True)

    progress = []
    client.upload(src, url, pki.cert_file(config), secure=False,
                  progress=progress.append)

    assert progress == [
        client.MAX_ZERO_SIZE,
        client.MAX_ZERO_SIZE,
        client.MAX_ZERO_SIZE // 2,
    ]
예제 #11
0
def test_split_big_zero(tmpdir):
    # Large zero ranges shhould be splitted to smaller chunks.
    size = client.MAX_ZERO_SIZE * 2 + client.MAX_ZERO_SIZE // 2
    src = str(tmpdir.join("src"))
    with open(src, "wb") as f:
        f.truncate(size)

    dst = str(tmpdir.join("dst"))
    url = prepare_upload(dst, size=size, sparse=True)

    progress = []
    client.upload(src,
                  url,
                  pki.cert_file(config),
                  secure=False,
                  progress=progress.append)

    assert progress == [
        client.MAX_ZERO_SIZE,
        client.MAX_ZERO_SIZE,
        client.MAX_ZERO_SIZE // 2,
    ]
예제 #12
0
def connection():
    return http_client.HTTPSConnection(config.images.host, config.images.port,
                                       pki.key_file(config),
                                       pki.cert_file(config))
예제 #13
0
파일: http.py 프로젝트: oVirt/ovirt-imageio
def connection():
    return http_client.HTTPSConnection(
        config.images.host,
        config.images.port,
        pki.key_file(config),
        pki.cert_file(config))