mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-11 22:40:01 +03:00
test compare as well
This commit is contained in:
parent
0c6c75bf58
commit
f29cf13db3
@ -14,15 +14,24 @@ class TestZfsCheck(unittest2.TestCase):
|
||||
shelltest("zfs create -V200M test_source1/vol")
|
||||
shelltest("zfs snapshot test_source1/vol@test")
|
||||
|
||||
with OutputIO() as buf:
|
||||
with redirect_stdout(buf):
|
||||
self.assertFalse(ZfsCheck("test_source1/vol@test".split(" "),print_arguments=False).run())
|
||||
with self.subTest("Generate"):
|
||||
with OutputIO() as buf:
|
||||
with redirect_stdout(buf):
|
||||
self.assertFalse(ZfsCheck("test_source1/vol@test".split(" "),print_arguments=False).run())
|
||||
|
||||
print(buf.getvalue())
|
||||
self.assertEqual("""0 2c2ceccb5ec5574f791d45b63c940cff20550f9a
|
||||
print(buf.getvalue())
|
||||
self.assertEqual("""0 2c2ceccb5ec5574f791d45b63c940cff20550f9a
|
||||
1 2c2ceccb5ec5574f791d45b63c940cff20550f9a
|
||||
""", buf.getvalue())
|
||||
|
||||
#store on disk for next step
|
||||
with open("/tmp/testhashes", "w") as fh:
|
||||
fh.write(buf.getvalue())
|
||||
|
||||
with self.subTest("Compare"):
|
||||
self.assertFalse(ZfsCheck("test_source1/vol@test --check=/tmp/testhashes --verbose".split(" "),print_arguments=False).run())
|
||||
|
||||
|
||||
|
||||
def test_filesystem(self):
|
||||
prepare_zpools()
|
||||
@ -40,15 +49,23 @@ class TestZfsCheck(unittest2.TestCase):
|
||||
|
||||
shelltest("zfs snapshot test_source1@test")
|
||||
|
||||
with OutputIO() as buf:
|
||||
with redirect_stdout(buf):
|
||||
self.assertFalse(ZfsCheck("test_source1@test".split(" "), print_arguments=False).run())
|
||||
with self.subTest("Generate"):
|
||||
with OutputIO() as buf:
|
||||
with redirect_stdout(buf):
|
||||
self.assertFalse(ZfsCheck("test_source1@test".split(" "), print_arguments=False).run())
|
||||
|
||||
print(buf.getvalue())
|
||||
self.assertEqual("""testfile 0 3c0bf91170d873b8e327d3bafb6bc074580d11b7
|
||||
print(buf.getvalue())
|
||||
self.assertEqual("""testfile 0 3c0bf91170d873b8e327d3bafb6bc074580d11b7
|
||||
dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798
|
||||
""", buf.getvalue())
|
||||
|
||||
#store on disk for next step
|
||||
with open("/tmp/testhashes", "w") as fh:
|
||||
fh.write(buf.getvalue())
|
||||
|
||||
with self.subTest("Compare"):
|
||||
self.assertFalse(ZfsCheck("test_source1@test --check=/tmp/testhashes --verbose".split(" "),print_arguments=False).run())
|
||||
|
||||
|
||||
def test_brokenpipe_cleanup_filesystem(self):
|
||||
"""test if stuff is cleaned up correctly, in debugging mode , when a pipe breaks. """
|
||||
|
@ -34,8 +34,10 @@ class ZfsCheck(CliBase):
|
||||
group.add_argument('--count', metavar="COUNT", default=int((100 * (1024 ** 2)) / 4096),
|
||||
help="Hash chunks of COUNT blocks. Default %(default)s . (Chunk size is BYTES * COUNT) ", type=int) # 100MiB
|
||||
|
||||
group = parser.add_argument_group('Compare options')
|
||||
|
||||
group.add_argument('--check', '-c', metavar="FILE", default=None, const=True, nargs='?',
|
||||
help="Read hashes from STDIN (or FILE) and check them")
|
||||
help="Read hashes from STDIN (or FILE) and compare them")
|
||||
|
||||
return parser
|
||||
|
||||
@ -200,7 +202,8 @@ class ZfsCheck(CliBase):
|
||||
last_progress_time = time.time()
|
||||
progress_count = 0
|
||||
|
||||
for line in input_fh:
|
||||
line=input_fh.readline()
|
||||
while line:
|
||||
i=line.rstrip().split("\t")
|
||||
#ignores lines without tabs
|
||||
if (len(i)>1):
|
||||
@ -212,6 +215,8 @@ class ZfsCheck(CliBase):
|
||||
last_progress_time = time.time()
|
||||
self.progress("Checked {} hashes.".format(progress_count))
|
||||
|
||||
line=input_fh.readline()
|
||||
|
||||
def run(self):
|
||||
|
||||
try:
|
||||
@ -221,6 +226,9 @@ class ZfsCheck(CliBase):
|
||||
#run as generator
|
||||
if self.args.check==None:
|
||||
for i in self.generate(input_generator=None):
|
||||
|
||||
self.clear_progress()
|
||||
|
||||
if len(i)==3:
|
||||
print("{}\t{}\t{}".format(*i))
|
||||
else:
|
||||
@ -233,6 +241,7 @@ class ZfsCheck(CliBase):
|
||||
|
||||
sys.stdout.flush()
|
||||
|
||||
self.clear_progress()
|
||||
return 0
|
||||
|
||||
#run as compare
|
||||
@ -241,6 +250,7 @@ class ZfsCheck(CliBase):
|
||||
input_generator=self.input_parser(self.args.check)
|
||||
for i in self.generate(input_generator):
|
||||
errors=errors+1
|
||||
|
||||
if len(i)==4:
|
||||
(file_name, chunk_nr, compare_hexdigest, actual_hexdigest)=i
|
||||
self.log.error("{}\t{}\t{}\t{}".format(file_name, chunk_nr, compare_hexdigest, actual_hexdigest))
|
||||
@ -248,6 +258,7 @@ class ZfsCheck(CliBase):
|
||||
(chunk_nr, compare_hexdigest, actual_hexdigest) = i
|
||||
self.log.error("{}\t{}\t{}".format(chunk_nr, compare_hexdigest, actual_hexdigest))
|
||||
|
||||
self.clear_progress()
|
||||
return min(255,errors)
|
||||
|
||||
except Exception as e:
|
||||
|
Loading…
x
Reference in New Issue
Block a user