mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-04-11 22:40:01 +03:00
zfs-check fixes and tests
This commit is contained in:
parent
f397e7be59
commit
ed61f03b4b
@ -85,6 +85,16 @@ class TestZfsCheck(unittest2.TestCase):
|
||||
prepare_zpools()
|
||||
|
||||
shelltest("cp tests/data/whole /test_source1/testfile")
|
||||
shelltest("mkdir /test_source1/emptydir")
|
||||
shelltest("mkdir /test_source1/dir")
|
||||
shelltest("cp tests/data/whole2 /test_source1/dir/testfile")
|
||||
|
||||
#it should ignore these:
|
||||
shelltest("ln -s / /test_source1/symlink")
|
||||
shelltest("mknod /test_source1/c c 1 1")
|
||||
shelltest("mknod /test_source1/b b 1 1")
|
||||
shelltest("mkfifo /test_source1/f")
|
||||
|
||||
shelltest("zfs snapshot test_source1@test")
|
||||
|
||||
with OutputIO() as buf:
|
||||
@ -93,5 +103,11 @@ class TestZfsCheck(unittest2.TestCase):
|
||||
|
||||
print(buf.getvalue())
|
||||
self.assertEqual("""testfile 0 3c0bf91170d873b8e327d3bafb6bc074580d11b7
|
||||
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. """
|
||||
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
import time
|
||||
|
||||
import argparse
|
||||
from signal import signal, SIGPIPE
|
||||
from .util import output_redir
|
||||
|
||||
from .ZfsAuto import ZfsAuto
|
||||
|
||||
from . import compressors
|
||||
@ -489,6 +492,8 @@ class ZfsAutobackup(ZfsAuto):
|
||||
def cli():
|
||||
import sys
|
||||
|
||||
signal(SIGPIPE, output_redir)
|
||||
|
||||
sys.exit(ZfsAutobackup(sys.argv[1:], False).run())
|
||||
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
# from util import activate_volume_snapshot, create_mountpoints, cleanup_mountpoint
|
||||
from signal import signal, SIGPIPE
|
||||
from .util import output_redir
|
||||
|
||||
from .ZfsAuto import ZfsAuto
|
||||
from .ZfsNode import ZfsNode
|
||||
import sys
|
||||
@ -302,6 +305,8 @@ class ZfsAutoverify(ZfsAuto):
|
||||
def cli():
|
||||
import sys
|
||||
|
||||
signal(SIGPIPE, output_redir)
|
||||
|
||||
sys.exit(ZfsAutoverify(sys.argv[1:], False).run())
|
||||
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
from __future__ import print_function
|
||||
|
||||
from signal import signal, SIGPIPE
|
||||
|
||||
|
||||
from .ZfsNode import ZfsNode
|
||||
from .util import *
|
||||
from .CliBase import CliBase
|
||||
@ -62,8 +65,6 @@ class ZfsCheck(CliBase):
|
||||
print("{}\t{}\t{}".format(file, block, hash))
|
||||
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
||||
|
||||
# except BrokenPipeError:
|
||||
# output_redir()
|
||||
|
||||
finally:
|
||||
snapshot.unmount()
|
||||
@ -89,7 +90,7 @@ class ZfsCheck(CliBase):
|
||||
start_time = time.time()
|
||||
while time.time() - start_time < 10:
|
||||
for location in locations:
|
||||
if pathlib.Path(location).is_block_device():
|
||||
if os.path.exists(location):
|
||||
return location
|
||||
|
||||
# fake it in testmode
|
||||
@ -116,15 +117,12 @@ class ZfsCheck(CliBase):
|
||||
print("{}\t{}".format(block, hash))
|
||||
sys.stdout.flush() #important, to generate SIGPIPES on ssh disconnect
|
||||
|
||||
except BrokenPipeError:
|
||||
output_redir()
|
||||
|
||||
finally:
|
||||
self.deacitvate_volume_snapshot(snapshot)
|
||||
|
||||
def run(self):
|
||||
|
||||
|
||||
snapshot = self.node.get_dataset(self.args.snapshot)
|
||||
|
||||
if not snapshot.exists:
|
||||
@ -150,6 +148,8 @@ class ZfsCheck(CliBase):
|
||||
def cli():
|
||||
import sys
|
||||
|
||||
signal(SIGPIPE, output_redir)
|
||||
|
||||
sys.exit(ZfsCheck(sys.argv[1:], False).run())
|
||||
|
||||
|
||||
|
@ -64,7 +64,7 @@ def block_hash_tree(start_path, count=10000, bs=4096):
|
||||
try:
|
||||
for (dirpath, dirnames, filenames) in os.walk(".", onerror=walkerror):
|
||||
for f in filenames:
|
||||
file_path=os.path.join(dirpath, f)
|
||||
file_path=os.path.join(dirpath, f)[2:]
|
||||
|
||||
if (not os.path.islink(file_path)) and os.path.isfile(file_path):
|
||||
for (chunk_nr, hash) in block_hash(file_path, count, bs):
|
||||
|
Loading…
x
Reference in New Issue
Block a user