forked from third-party-mirrors/zfs_autobackup
fixes. supports stdin
This commit is contained in:
parent
e7e1590919
commit
f530cf40f3
@ -60,6 +60,7 @@ dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798
|
|||||||
#breaks pipe when grep exists:
|
#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
|
#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'")
|
shelltest("python -m zfs_autobackup.ZfsCheck test_source1@test --debug | grep -m1 'Hashing tree'")
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
#should NOT be mounted anymore if cleanup went ok:
|
#should NOT be mounted anymore if cleanup went ok:
|
||||||
self.assertNotRegex(shelltest("mount"), "test_source1@test")
|
self.assertNotRegex(shelltest("mount"), "test_source1@test")
|
||||||
@ -73,6 +74,7 @@ dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798
|
|||||||
#breaks pipe when grep exists:
|
#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
|
#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/vol@test --debug | grep -m1 'Hashing dev'")
|
shelltest("python -m zfs_autobackup.ZfsCheck test_source1/vol@test --debug | grep -m1 'Hashing dev'")
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS)
|
r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS)
|
||||||
self.assertMultiLineEqual(r, """
|
self.assertMultiLineEqual(r, """
|
||||||
|
@ -34,8 +34,8 @@ 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.add_argument('--check', '-c', metavar="FILE", default=None,
|
group.add_argument('--check', '-c', metavar="FILE", default=None, const=True, nargs='?',
|
||||||
help="Read hashes from FILE and check them")
|
help="Read hashes from STDIN (or FILE) and check them")
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -138,12 +138,10 @@ class ZfsCheck(CliBase):
|
|||||||
|
|
||||||
snapshot = self.node.get_dataset(self.args.target)
|
snapshot = self.node.get_dataset(self.args.target)
|
||||||
if not snapshot.exists:
|
if not snapshot.exists:
|
||||||
snapshot.error("Snapshot not found")
|
raise Exception("Snapshot {} not found".format(snapshot))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if not snapshot.is_snapshot:
|
if not snapshot.is_snapshot:
|
||||||
snapshot.error("Dataset should be a snapshot")
|
raise Exception("Dataset {} should be a snapshot".format(snapshot))
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
dataset_type = snapshot.parent.properties['type']
|
dataset_type = snapshot.parent.properties['type']
|
||||||
|
|
||||||
@ -194,7 +192,12 @@ class ZfsCheck(CliBase):
|
|||||||
|
|
||||||
def input_parser(self, file_name):
|
def input_parser(self, file_name):
|
||||||
"""parse input lines and generate items to use in compare functions"""
|
"""parse input lines and generate items to use in compare functions"""
|
||||||
with open(file_name, 'r') as input_fh:
|
|
||||||
|
if self.args.check is True:
|
||||||
|
input_fh=sys.stdin
|
||||||
|
else:
|
||||||
|
input_fh=open(file_name, 'r')
|
||||||
|
|
||||||
for line in input_fh:
|
for line in input_fh:
|
||||||
i=line.rstrip().split("\t")
|
i=line.rstrip().split("\t")
|
||||||
#ignores lines without tabs
|
#ignores lines without tabs
|
||||||
@ -213,7 +216,7 @@ class ZfsCheck(CliBase):
|
|||||||
print("{}\t{}".format(*i))
|
print("{}\t{}".format(*i))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
sys.exit(0)
|
return 0
|
||||||
|
|
||||||
#run as compare
|
#run as compare
|
||||||
else:
|
else:
|
||||||
@ -228,7 +231,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))
|
||||||
|
|
||||||
sys.exit(min(255,errors))
|
return min(255,errors)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.error("Exception: " + str(e))
|
self.error("Exception: " + str(e))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user