zfs-verify stuff

This commit is contained in:
Edwin Eefting 2022-01-18 20:54:19 +01:00
parent 6791bc4abd
commit 86d504722c
5 changed files with 85 additions and 1 deletions

View File

@ -62,6 +62,7 @@ def shelltest(cmd):
"""execute and print result as nice copypastable string for unit tests (adds extra newlines on top/bottom)"""
ret=(subprocess.check_output("SUDO_ASKPASS=./password.sh sudo -A "+cmd , shell=True).decode('utf-8'))
print("######### result of: {}".format(cmd))
print(ret)
print("#########")

View File

@ -32,6 +32,7 @@ class TestZfsEncryption(unittest2.TestCase):
def prepare_encrypted_dataset(self, key, path, unload_key=False):
# create encrypted source dataset
shelltest("rm /tmp/zfstest.key 2>/dev/null;true")
shelltest("echo {} > /tmp/zfstest.key".format(key))
shelltest("zfs create -o keylocation=file:///tmp/zfstest.key -o keyformat=passphrase -o encryption=on {}".format(path))

63
tests/test_verify.py Normal file
View File

@ -0,0 +1,63 @@
from zfs_autobackup.CmdPipe import CmdPipe
from basetest import *
import time
# test zfs-verify:
# - when there is no common snapshot at all
# - when encryption key not loaded
# - on datasets:
# - that are correct
# - that are different
# - that are not mounted
# - that are mounted
# - that are mounted on the "wrong" place
# - on zvols
# - that are correct
# - that are different
#
class TestZfsEncryption(unittest2.TestCase):
def setUp(self):
prepare_zpools()
shelltest("zfs create test_source1/fs1/ok_filesystem")
shelltest("cp *.py /test_source1/fs1/ok_filesystem")
shelltest("zfs create -V 1M test_source1/fs1/ok_zvol")
shelltest("dd if=/dev/urandom of=/dev/zvol/test_source1/fs1/ok_zvol count=1 bs=512k")
with patch('time.strftime', return_value="test-20101111000000"):
self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-progress".split(" ")).run())
# make sure we cant accidently compare current data
shelltest("rm /test_source1/fs1/ok_filesystem/*")
shelltest("dd if=/dev/zero of=/dev/zvol/test_source1/fs1/ok_zvol count=1 bs=512k")
def test_verify(self):
return
r = shelltest("zfs get -r -t filesystem encryptionroot test_target1")
self.assertMultiLineEqual(r,"""
NAME PROPERTY VALUE SOURCE
test_target1 encryptionroot - -
test_target1/encryptedtarget encryptionroot test_target1/encryptedtarget -
test_target1/encryptedtarget/test_source1 encryptionroot test_target1/encryptedtarget -
test_target1/encryptedtarget/test_source1/fs1 encryptionroot - -
test_target1/encryptedtarget/test_source1/fs1/encryptedsource encryptionroot test_target1/encryptedtarget/test_source1/fs1/encryptedsource -
test_target1/encryptedtarget/test_source1/fs1/encryptedsourcekeyless encryptionroot test_target1/encryptedtarget/test_source1/fs1/encryptedsourcekeyless -
test_target1/encryptedtarget/test_source1/fs1/sub encryptionroot - -
test_target1/encryptedtarget/test_source2 encryptionroot test_target1/encryptedtarget -
test_target1/encryptedtarget/test_source2/fs2 encryptionroot test_target1/encryptedtarget -
test_target1/encryptedtarget/test_source2/fs2/sub encryptionroot - -
test_target1/test_source1 encryptionroot - -
test_target1/test_source1/fs1 encryptionroot - -
test_target1/test_source1/fs1/encryptedsource encryptionroot test_target1/test_source1/fs1/encryptedsource -
test_target1/test_source1/fs1/encryptedsourcekeyless encryptionroot test_target1/test_source1/fs1/encryptedsourcekeyless -
test_target1/test_source1/fs1/sub encryptionroot - -
test_target1/test_source2 encryptionroot - -
test_target1/test_source2/fs2 encryptionroot - -
test_target1/test_source2/fs2/sub encryptionroot - -
""")

View File

@ -46,7 +46,8 @@ class ZfsAutoverify(ZfsAuto):
target_name = self.make_target_name(source_dataset)
target_dataset = ZfsDataset(target_node, target_name)
XXX
if source_dataset.properties['type']=="filesystem":
print("JOOO")
except Exception as e:
fail_count = fail_count + 1

View File

@ -1103,3 +1103,21 @@ class ZfsDataset:
resume_token = None
source_snapshot = self.find_next_snapshot(source_snapshot, also_other_snapshots)
def mount(self, mount_point):
cmd = [
"mount", "-t zfs", "-o zfsutil", self.name, mount_point
]
self.debug("Mounting to {}".format(mount_point))
self.zfs_node.run(cmd=cmd, valid_exitcodes=[0])
def unmount(self):
cmd = [
"umount", self.name
]
self.debug("Unmounting")
self.zfs_node.run(cmd=cmd, valid_exitcodes=[0])