def import_via_link(self, path, csum): """Adds a file to a blobstore via a hard link.""" blob = self.csum_to_path(csum) duplicate = blob.exists() if not duplicate: ensure_link(blob, path) ensure_readonly(blob) return duplicate
def test_farmfs_blob_corruption(vol, capsys): a = Path('a', vol) with a.open('w') as a_fd: a_fd.write('a') a_csum = str(a.checksum()) r = farmfs_ui(['freeze'], vol) captured = capsys.readouterr() assert r == 0 a_blob = a.readlink() a_blob.unlink() with a_blob.open('w') as a_fd: a_fd.write('b') ensure_readonly(a_blob) r = farmfs_ui(['fsck', '--checksums'], vol) captured = capsys.readouterr() assert captured.out == 'CORRUPTION checksum mismatch in blob ' + a_csum + '\n' assert captured.err == "" assert r == 2
def test_farmfs_blob_corruption(tmp_path, capsys): root = Path(str(tmp_path)) r1 = farmfs_ui(['mkfs'], root) captured = capsys.readouterr() assert r1 == 0 a = Path('a', root) with a.open('w') as a_fd: a_fd.write('a') a_csum = str(a.checksum()) r2 = farmfs_ui(['freeze'], root) captured = capsys.readouterr() assert r2 == 0 a_blob = a.readlink() a_blob.unlink() with a_blob.open('w') as a_fd: a_fd.write('b') ensure_readonly(a_blob) r3 = farmfs_ui(['fsck', '--checksums'], root) captured = capsys.readouterr() assert captured.out == 'CORRUPTION checksum mismatch in blob ' + a_csum + '\n' assert captured.err == "" assert r3 == 2
def test_s3_upload(tmp_path, capsys): tmp = Path(str(tmp_path)) vol = tmp.join("vol") a = Path('a', vol) # Make the Farm r = farmfs_ui(['mkfs'], vol) captured = capsys.readouterr() assert r == 0 # Make a with a.open('w') as fd: fd.write('a') a_csum = str(a.checksum()) r = farmfs_ui(['freeze'], vol) captured = capsys.readouterr() assert r == 0 # upload to s3 bucket = 's3libtestbucket' prefix = str(uuid.uuid1()) # Assert s3 bucket/prefix is empty r = dbg_ui(['s3', 'list', bucket, prefix], vol) captured = capsys.readouterr() assert r == 0 assert captured.out == "" assert captured.err == "" # Upload the contents. r = dbg_ui(['s3', 'upload', '--quiet', bucket, prefix], vol) captured = capsys.readouterr() assert r == 0 assert captured.out == \ 'Fetching remote blobs\n' + \ 'Remote Blobs: 0\n' + \ 'Fetching local blobs\n' + \ 'Local Blobs: 1\n' + \ 'Uploading 1 blobs to s3\n' + \ 'Successfully uploaded\n' assert captured.err == "" # Upload again r = dbg_ui(['s3', 'upload', '--quiet', bucket, prefix], vol) captured = capsys.readouterr() assert r == 0 assert captured.out == \ 'Fetching remote blobs\n' + \ 'Remote Blobs: 1\n' + \ 'Fetching local blobs\n' + \ 'Local Blobs: 1\n' + \ 'Uploading 0 blobs to s3\n' + \ 'Successfully uploaded\n' assert captured.err == "" # verify checksums r = dbg_ui(['s3', 'check', bucket, prefix], vol) captured = capsys.readouterr() assert r == 0 assert captured.out == "All S3 blobs etags match\n" assert captured.err == "" # verify corrupt checksum a_blob = a.readlink() a_blob.unlink() with a_blob.open('w') as fd: fd.write('b') b_csum = str(a.checksum()) ensure_readonly(a_blob) prefix2 = str(uuid.uuid1()) r = dbg_ui(['s3', 'upload', '--quiet', bucket, prefix2], vol) captured = capsys.readouterr() assert r == 0 r = dbg_ui(['s3', 'check', bucket, prefix2], vol) captured = capsys.readouterr() assert r == 2 assert captured.out == a_csum + " " + b_csum + "\n" assert captured.err == ""
def link_to_blob(self, path, csum): """Forces path into a symlink to csum""" new_link = self.csum_to_path(csum) ensure_symlink(path, new_link) ensure_readonly(path)