Exemplo n.º 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,
    ]
Exemplo n.º 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,
    ]
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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,
    ]
Exemplo n.º 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,
    ]
Exemplo n.º 12
0
def connection():
    return http_client.HTTPSConnection(config.images.host, config.images.port,
                                       pki.key_file(config),
                                       pki.cert_file(config))
Exemplo n.º 13
0
def connection():
    return http_client.HTTPSConnection(
        config.images.host,
        config.images.port,
        pki.key_file(config),
        pki.cert_file(config))