check_cmd cleaned up

This commit is contained in:
bigtedde 2023-07-13 11:27:18 -04:00
parent fdb21af6e6
commit f502941137
1 changed files with 27 additions and 7 deletions

View File

@ -71,7 +71,8 @@ def test_date_matching(archivers, request):
create_src_archive(archiver, "archive1", ts=earliest_ts)
create_src_archive(archiver, "archive2", ts=ts_in_between)
create_src_archive(archiver, "archive3")
output = cmd(archiver, f"--repo={repo_location}", "check", "-v", "--archives-only", "--oldest=23e", exit_code=2)
cmd(archiver, f"--repo={repo_location}", "check", "-v", "--archives-only", "--oldest=23e", exit_code=2)
output = cmd(archiver, f"--repo={repo_location}", "check", "-v", "--archives-only", "--oldest=1m", exit_code=0)
assert "archive1" in output
assert "archive2" in output
@ -115,12 +116,15 @@ def test_missing_file_chunk(archivers, request):
else:
pytest.fail("should not happen") # convert 'fail'
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)
output = cmd(archiver, f"--repo={repo_location}", "check", "--repair", exit_code=0)
assert "New missing file chunk detected" in output
cmd(archiver, f"--repo={repo_location}", "check", exit_code=0)
output = cmd(archiver, f"--repo={repo_location}", "list", "archive1", "--format={health}#{path}{NL}", exit_code=0)
assert "broken#" in output
# check that the file in the old archives has now a different chunk list without the killed chunk
for archive_name in ("archive1", "archive2"):
archive, repository = open_archive(repo_path, archive_name)
@ -132,9 +136,11 @@ def test_missing_file_chunk(archivers, request):
break
else:
pytest.fail("should not happen") # convert 'fail'
# do a fresh backup (that will include the killed chunk)
with patch.object(ChunkBuffer, "BUFFER_SIZE", 10):
create_src_archive(archiver, "archive3")
# check should be able to heal the file now:
output = cmd(archiver, f"--repo={repo_location}", "check", "-v", "--repair", exit_code=0)
assert "Healed previously missing file chunk" in output
@ -150,6 +156,7 @@ def test_missing_file_chunk(archivers, request):
break
else:
pytest.fail("should not happen")
# list is also all-healthy again
output = cmd(archiver, f"--repo={repo_location}", "list", "archive1", "--format={health}#{path}{NL}", exit_code=0)
assert "broken#" not in output
@ -164,6 +171,7 @@ def test_missing_archive_item_chunk(archivers, request):
with repository:
repository.delete(archive.metadata.items[0])
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)
cmd(archiver, f"--repo={repo_location}", "check", "--repair", exit_code=0)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=0)
@ -178,6 +186,7 @@ def test_missing_archive_metadata(archivers, request):
with repository:
repository.delete(archive.id)
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)
cmd(archiver, f"--repo={repo_location}", "check", "--repair", exit_code=0)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=0)
@ -192,6 +201,7 @@ def test_missing_manifest(archivers, request):
with repository:
repository.delete(Manifest.MANIFEST_ID)
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)
output = cmd(archiver, f"--repo={repo_location}", "check", "-v", "--repair", exit_code=0)
assert "archive1" in output
@ -210,6 +220,7 @@ def test_corrupted_manifest(archivers, request):
corrupted_manifest = manifest + b"corrupted!"
repository.put(Manifest.MANIFEST_ID, corrupted_manifest)
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)
output = cmd(archiver, f"--repo={repo_location}", "check", "-v", "--repair", exit_code=0)
assert "archive1" in output
@ -231,6 +242,7 @@ def test_manifest_rebuild_corrupted_chunk(archivers, request):
corrupted_chunk = chunk + b"corrupted!"
repository.put(archive.id, corrupted_chunk)
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)
output = cmd(archiver, f"--repo={repo_location}", "check", "-v", "--repair", exit_code=0)
assert "archive2" in output
@ -262,6 +274,7 @@ def test_manifest_rebuild_duplicate_archive(archivers, request):
archive_id = repo_objs.id_hash(archive)
repository.put(archive_id, repo_objs.format(archive_id, {}, archive))
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)
cmd(archiver, f"--repo={repo_location}", "check", "--repair", exit_code=0)
output = cmd(archiver, f"--repo={repo_location}", "rlist")
@ -272,14 +285,16 @@ def test_manifest_rebuild_duplicate_archive(archivers, request):
def test_extra_chunks(archivers, request):
archiver = request.getfixturevalue(archivers)
check_cmd_setUp(archiver)
if archiver.prefix == "ssh://__testsuite__":
if archiver.prefix:
pytest.skip("only works locally")
repo_location = archiver.repository_location
check_cmd_setUp(archiver)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=0)
with Repository(archiver.repository_location, exclusive=True) as repository:
with Repository(repo_location, exclusive=True) as repository:
repository.put(b"01234567890123456789012345678901", b"xxxx")
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)
cmd(archiver, f"--repo={repo_location}", "check", "--repair", exit_code=0)
@ -290,12 +305,13 @@ def test_extra_chunks(archivers, request):
@pytest.mark.parametrize("init_args", [["--encryption=repokey-aes-ocb"], ["--encryption", "none"]])
def test_verify_data(archivers, request, init_args):
archiver = request.getfixturevalue(archivers)
check_cmd_setUp(archiver)
repo_location, repo_path = archiver.repository_location, archiver.repository_path
check_cmd_setUp(archiver)
shutil.rmtree(repo_path)
cmd(archiver, f"--repo={repo_location}", "rcreate", *init_args)
create_src_archive(archiver, "archive1")
archive, repository = open_archive(repo_path, "archive1")
with repository:
for item in archive.iter_items():
if item.path.endswith(src_file):
@ -305,9 +321,11 @@ def test_verify_data(archivers, request, init_args):
repository.put(chunk.id, data)
break
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=0)
output = cmd(archiver, f"--repo={repo_location}", "check", "--verify-data", exit_code=1)
assert bin_to_hex(chunk.id) + ", integrity error" in output
# repair (heal is tested in another test)
output = cmd(archiver, f"--repo={repo_location}", "check", "--repair", "--verify-data", exit_code=0)
assert bin_to_hex(chunk.id) + ", integrity error" in output
@ -316,12 +334,14 @@ def test_verify_data(archivers, request, init_args):
def test_empty_repository(archivers, request):
archiver = request.getfixturevalue(archivers)
if archiver.prefix == "ssh://__testsuite__":
if archiver.prefix:
pytest.skip("only works locally")
check_cmd_setUp(archiver)
repo_location = archiver.repository_location
check_cmd_setUp(archiver)
with Repository(repo_location, exclusive=True) as repository:
for id_ in repository.list():
repository.delete(id_)
repository.commit(compact=False)
cmd(archiver, f"--repo={repo_location}", "check", exit_code=1)