mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-13 22:47:12 +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 create -V200M test_source1/vol")
|
||||||
shelltest("zfs snapshot test_source1/vol@test")
|
shelltest("zfs snapshot test_source1/vol@test")
|
||||||
|
|
||||||
with OutputIO() as buf:
|
with self.subTest("Generate"):
|
||||||
with redirect_stdout(buf):
|
with OutputIO() as buf:
|
||||||
self.assertFalse(ZfsCheck("test_source1/vol@test".split(" "),print_arguments=False).run())
|
with redirect_stdout(buf):
|
||||||
|
self.assertFalse(ZfsCheck("test_source1/vol@test".split(" "),print_arguments=False).run())
|
||||||
|
|
||||||
print(buf.getvalue())
|
print(buf.getvalue())
|
||||||
self.assertEqual("""0 2c2ceccb5ec5574f791d45b63c940cff20550f9a
|
self.assertEqual("""0 2c2ceccb5ec5574f791d45b63c940cff20550f9a
|
||||||
1 2c2ceccb5ec5574f791d45b63c940cff20550f9a
|
1 2c2ceccb5ec5574f791d45b63c940cff20550f9a
|
||||||
""", buf.getvalue())
|
""", 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):
|
def test_filesystem(self):
|
||||||
prepare_zpools()
|
prepare_zpools()
|
||||||
@ -40,15 +49,23 @@ class TestZfsCheck(unittest2.TestCase):
|
|||||||
|
|
||||||
shelltest("zfs snapshot test_source1@test")
|
shelltest("zfs snapshot test_source1@test")
|
||||||
|
|
||||||
with OutputIO() as buf:
|
with self.subTest("Generate"):
|
||||||
with redirect_stdout(buf):
|
with OutputIO() as buf:
|
||||||
self.assertFalse(ZfsCheck("test_source1@test".split(" "), print_arguments=False).run())
|
with redirect_stdout(buf):
|
||||||
|
self.assertFalse(ZfsCheck("test_source1@test".split(" "), print_arguments=False).run())
|
||||||
|
|
||||||
print(buf.getvalue())
|
print(buf.getvalue())
|
||||||
self.assertEqual("""testfile 0 3c0bf91170d873b8e327d3bafb6bc074580d11b7
|
self.assertEqual("""testfile 0 3c0bf91170d873b8e327d3bafb6bc074580d11b7
|
||||||
dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798
|
dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798
|
||||||
""", buf.getvalue())
|
""", 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):
|
def test_brokenpipe_cleanup_filesystem(self):
|
||||||
"""test if stuff is cleaned up correctly, in debugging mode , when a pipe breaks. """
|
"""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),
|
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
|
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='?',
|
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
|
return parser
|
||||||
|
|
||||||
@ -200,7 +202,8 @@ class ZfsCheck(CliBase):
|
|||||||
last_progress_time = time.time()
|
last_progress_time = time.time()
|
||||||
progress_count = 0
|
progress_count = 0
|
||||||
|
|
||||||
for line in input_fh:
|
line=input_fh.readline()
|
||||||
|
while line:
|
||||||
i=line.rstrip().split("\t")
|
i=line.rstrip().split("\t")
|
||||||
#ignores lines without tabs
|
#ignores lines without tabs
|
||||||
if (len(i)>1):
|
if (len(i)>1):
|
||||||
@ -212,6 +215,8 @@ class ZfsCheck(CliBase):
|
|||||||
last_progress_time = time.time()
|
last_progress_time = time.time()
|
||||||
self.progress("Checked {} hashes.".format(progress_count))
|
self.progress("Checked {} hashes.".format(progress_count))
|
||||||
|
|
||||||
|
line=input_fh.readline()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -221,6 +226,9 @@ class ZfsCheck(CliBase):
|
|||||||
#run as generator
|
#run as generator
|
||||||
if self.args.check==None:
|
if self.args.check==None:
|
||||||
for i in self.generate(input_generator=None):
|
for i in self.generate(input_generator=None):
|
||||||
|
|
||||||
|
self.clear_progress()
|
||||||
|
|
||||||
if len(i)==3:
|
if len(i)==3:
|
||||||
print("{}\t{}\t{}".format(*i))
|
print("{}\t{}\t{}".format(*i))
|
||||||
else:
|
else:
|
||||||
@ -233,6 +241,7 @@ class ZfsCheck(CliBase):
|
|||||||
|
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
self.clear_progress()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
#run as compare
|
#run as compare
|
||||||
@ -241,6 +250,7 @@ class ZfsCheck(CliBase):
|
|||||||
input_generator=self.input_parser(self.args.check)
|
input_generator=self.input_parser(self.args.check)
|
||||||
for i in self.generate(input_generator):
|
for i in self.generate(input_generator):
|
||||||
errors=errors+1
|
errors=errors+1
|
||||||
|
|
||||||
if len(i)==4:
|
if len(i)==4:
|
||||||
(file_name, chunk_nr, compare_hexdigest, actual_hexdigest)=i
|
(file_name, chunk_nr, compare_hexdigest, actual_hexdigest)=i
|
||||||
self.log.error("{}\t{}\t{}\t{}".format(file_name, chunk_nr, compare_hexdigest, actual_hexdigest))
|
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
|
(chunk_nr, compare_hexdigest, actual_hexdigest) = i
|
||||||
self.log.error("{}\t{}\t{}".format(chunk_nr, compare_hexdigest, actual_hexdigest))
|
self.log.error("{}\t{}\t{}".format(chunk_nr, compare_hexdigest, actual_hexdigest))
|
||||||
|
|
||||||
|
self.clear_progress()
|
||||||
return min(255,errors)
|
return min(255,errors)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user