コード例 #1
0
ファイル: client_test.py プロジェクト: oVirt/ovirt-imageio
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
ファイル: client_test.py プロジェクト: oVirt/ovirt-imageio
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)
コード例 #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
ファイル: client_test.py プロジェクト: oVirt/ovirt-imageio
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
コード例 #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
ファイル: client_test.py プロジェクト: oVirt/ovirt-imageio
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
コード例 #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
ファイル: client_test.py プロジェクト: oVirt/ovirt-imageio
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,
    ]
コード例 #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
# At this stage, the SDK granted the permission to start transferring the disk, and the
# user should choose its preferred tool for doing it - regardless of the SDK.
# In this example, we will use Python's httplib.HTTPSConnection for transferring the data.
if args.direct:
    if transfer.transfer_url is not None:
        destination_url = transfer.transfer_url
    else:
        print(
            "Direct upload to host not supported (requires ovirt-engine 4.2 or above)."
        )
        sys.exit(1)
else:
    destination_url = transfer.proxy_url

image_size = os.path.getsize(args.filename)

with ui.ProgressBar(image_size) as pb:
    client.upload(args.filename,
                  destination_url,
                  args.cafile,
                  secure=args.secure,
                  progress=pb.update)

print("Finalizing transfer session...")
# Successful cleanup
transfer_service.finalize()
connection.close()

print("Upload completed successfully")
コード例 #12
0
ファイル: upload_disk.py プロジェクト: oVirt/ovirt-engine-sdk
print("Uploading image...")

# At this stage, the SDK granted the permission to start transferring the disk, and the
# user should choose its preferred tool for doing it - regardless of the SDK.
# In this example, we will use Python's httplib.HTTPSConnection for transferring the data.
if args.direct:
    if transfer.transfer_url is not None:
        destination_url = transfer.transfer_url
    else:
        print("Direct upload to host not supported (requires ovirt-engine 4.2 or above).")
        sys.exit(1)
else:
    destination_url = transfer.proxy_url

image_size = os.path.getsize(args.filename)

with ui.ProgressBar(image_size) as pb:
    client.upload(
        args.filename,
        destination_url,
        args.cafile,
        secure=args.secure,
        progress=pb.update)

print("Finalizing transfer session...")
# Successful cleanup
transfer_service.finalize()
connection.close()

print("Upload completed successfully")
コード例 #13
0
    time.sleep(1)
    transfer = transfer_service.get()

print("Uploading image...")

# At this stage, the SDK granted the permission to start transferring the disk, and the
# user should choose its preferred tool for doing it - regardless of the SDK.
# In this example, we will use Python's httplib.HTTPSConnection for transferring the data.
if direct_upload:
    if transfer.transfer_url is not None:
        destination_url = transfer.transfer_url
    else:
        print(
            "Direct upload to host not supported (requires ovirt-engine 4.2 or above)."
        )
        sys.exit(1)
else:
    destination_url = transfer.proxy_url

image_size = os.path.getsize(image_path)

with ui.ProgressBar(image_size) as pb:
    client.upload(image_path, destination_url, 'ca.pem', progress=pb.update)

print("Finalizing transfer session...")
# Successful cleanup
transfer_service.finalize()
connection.close()

print("Upload completed successfully")