zfs-check broken pipe handling tests for volumes

This commit is contained in:
Edwin Eefting 2022-02-21 13:01:45 +01:00
parent 3e6a327647
commit a807ec320e
2 changed files with 35 additions and 29 deletions

View File

@ -107,21 +107,44 @@ dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798
""", buf.getvalue())
def test_brokenpipe_cleanup_filesystem(self):
"""test if stuff is cleaned up correctly, in debugging mode , when a pipe breaks. """
# def test_brokenpipe_cleanup_filesystem(self):
# """test if stuff is cleaned up correctly, in debugging mode , when a pipe breaks. """
#
# prepare_zpools()
# shelltest("cp tests/data/whole /test_source1/testfile")
# shelltest("zfs snapshot test_source1@test")
#
# #breaks pipe when grep exists:
# #important to use --debug, since that generates extra output which would be problematic if we didnt do correct SIGPIPE handling
# shelltest("python -m zfs_autobackup.ZfsCheck test_source1@test --debug | grep -m1 'Hashing tree'")
#
# #should NOT be mounted anymore if cleanup went ok:
# self.assertNotRegex(shelltest("mount"), "test_source1@test")
def test_brokenpipe_cleanup_volume(self):
prepare_zpools()
shelltest("cp tests/data/whole /test_source1/testfile")
shelltest("zfs snapshot test_source1@test")
shelltest("zfs create -V200M test_source1/vol")
shelltest("zfs snapshot test_source1/vol@test")
#breaks pipe when grep exists:
#important to use --debug, since that generates extra output which would be problematic if we didnt do correct SIGPIPE handling
shelltest("python -m zfs_autobackup.ZfsCheck test_source1@test --debug | grep -m1 Hashing")
#should NOT be mounted anymore if cleanup went ok:
self.assertNotRegex(shelltest("mount"), "test_source1@test")
shelltest("python -m zfs_autobackup.ZfsCheck test_source1/vol@test --debug | grep -m1 'Hashing dev'")
r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS)
self.assertMultiLineEqual(r, """
test_source1
test_source1/fs1
test_source1/fs1/sub
test_source1/vol
test_source1/vol@test
test_source2
test_source2/fs2
test_source2/fs2/sub
test_source2/fs3
test_source2/fs3/sub
test_target1
""")

View File

@ -31,6 +31,9 @@ class ZfsCheck(CliBase):
group.add_argument('--count', metavar="COUNT", default=int((100 * (1024 ** 2)) / 4096),
help="Generate a hash for every COUNT blocks. default %(default)s", type=int) # 100MiB
group.add_argument('--check', '-c', metavar="FILE", default=None,
help="Read hashes from FILE and check them")
return parser
def parse_args(self, argv):
@ -153,25 +156,5 @@ def cli():
if __name__ == "__main__":
# try:
# while True:
# # print("stderr", file=sys.stderr)
# print("loop")
# sys.stdout.flush()
#
# except BrokenPipeError:
# output_redir()
# print("pipe brookn", file=sys.stderr)
# sys.stderr.flush()
#
# devnull = os.open(os.devnull, os.O_WRONLY)
# os.dup2(devnull, sys.stdout.fileno())
#
# print("stout")
# sys.stdout.flush()
#
#
# print("hier kom ik nie", file=sys.stderr)
# open("yo" ,"w")
cli()