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