From cba6470500e031462b2fbe6bf20a9f73a5f5a98c Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Thu, 9 Jul 2020 12:51:26 +0200 Subject: [PATCH] more --test test --- bin/zfs-autobackup | 2 +- run_tests | 2 +- test_externalfailures.py | 37 +++++++++++++++++++++++++++++++--- test_zfsautobackup.py | 43 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 5 deletions(-) diff --git a/bin/zfs-autobackup b/bin/zfs-autobackup index d8d1dcd..3167d6d 100755 --- a/bin/zfs-autobackup +++ b/bin/zfs-autobackup @@ -547,7 +547,7 @@ class ZfsDataset(): def __init__(self, zfs_node, name, force_exists=None): """name: full path of the zfs dataset - exists: specify if you already know a dataset exists or not. for performance reasons. (otherwise it will have to check with zfs list when needed) + exists: specify if you already know a dataset exists or not. for performance and testing reasons. (otherwise it will have to check with zfs list when needed) """ self.zfs_node=zfs_node self.name=name #full name diff --git a/run_tests b/run_tests index e3c4558..9ecfe5c 100755 --- a/run_tests +++ b/run_tests @@ -16,7 +16,7 @@ if ! [ -e /root/.ssh/id_rsa ]; then ssh -oStrictHostKeyChecking=no localhost true || exit 1 fi -coverage run --source bin.zfs_autobackup -m unittest discover -v +coverage run --source bin.zfs_autobackup -m unittest discover -vv EXIT=$? echo diff --git a/test_externalfailures.py b/test_externalfailures.py index 36daeaa..b90e741 100644 --- a/test_externalfailures.py +++ b/test_externalfailures.py @@ -36,10 +36,25 @@ class TestZfsNode(unittest2.TestCase): with patch('time.strftime', return_value="20101111000000"): self.generate_resume() + #--test should resume and succeed + with OutputIO() as buf: + with redirect_stdout(buf): + self.assertFalse(ZfsAutobackup("test test_target1 --verbose --test".split(" ")).run()) + + print(buf.getvalue()) + + #did we really resume? + if "0.6.5" in ZFS_USERSPACE: + #abort this late, for beter coverage + self.skipTest("Resume not supported in this ZFS userspace version") + else: + self.assertIn(": resuming", buf.getvalue()) + + #should resume and succeed with OutputIO() as buf: with redirect_stdout(buf): - self.assertFalse(ZfsAutobackup("test test_target1 --verbose --debug".split(" ")).run()) + self.assertFalse(ZfsAutobackup("test test_target1 --verbose".split(" ")).run()) print(buf.getvalue()) @@ -76,10 +91,24 @@ test_target1/test_source2/fs2/sub@test-20101111000000 with patch('time.strftime', return_value="20101111000001"): self.generate_resume() + #--test should resume and succeed + with OutputIO() as buf: + with redirect_stdout(buf): + self.assertFalse(ZfsAutobackup("test test_target1 --verbose --test".split(" ")).run()) + + print(buf.getvalue()) + + #did we really resume? + if "0.6.5" in ZFS_USERSPACE: + #abort this late, for beter coverage + self.skipTest("Resume not supported in this ZFS userspace version") + else: + self.assertIn(": resuming", buf.getvalue()) + #should resume and succeed with OutputIO() as buf: with redirect_stdout(buf): - self.assertFalse(ZfsAutobackup("test test_target1 --verbose --debug".split(" ")).run()) + self.assertFalse(ZfsAutobackup("test test_target1 --verbose".split(" ")).run()) print(buf.getvalue()) @@ -107,7 +136,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 # # generate an invalid resume token, and verify if its aborted automaticly - #FIXME: fails due to incorrectly created parent + # # FIXME: fails due to incorrectly created parent # def test_resumeabort(self): # if "0.6.5" in ZFS_USERSPACE: @@ -117,6 +146,8 @@ test_target1/test_source2/fs2/sub@test-20101111000000 # with patch('time.strftime', return_value="20101111000000"): # self.generate_resume() + # asdf + # #remove corresponding source snapshot # shelltest("zfs destroy test_source1/fs1@test-20101111000000") diff --git a/test_zfsautobackup.py b/test_zfsautobackup.py index a965791..8012f94 100644 --- a/test_zfsautobackup.py +++ b/test_zfsautobackup.py @@ -456,10 +456,18 @@ test_target1/test_source2/fs2/sub@test-20101111000000 canmount - - r=shelltest("touch /test_target1/test_source1/fs1/change.txt") r=shelltest("zfs snapshot test_target1/test_source1/fs1@incompatible1") + + with patch('time.strftime', return_value="20101111000002"): + #--test should fail, now incompatible + self.assertTrue(ZfsAutobackup("test test_target1 --verbose --allow-empty --test".split(" ")).run()) + with patch('time.strftime', return_value="20101111000002"): #should fail, now incompatible self.assertTrue(ZfsAutobackup("test test_target1 --verbose --allow-empty".split(" ")).run()) + with patch('time.strftime', return_value="20101111000003"): + #--test should succeed by destroying incompatibles + self.assertFalse(ZfsAutobackup("test test_target1 --verbose --allow-empty --destroy-incompatible --test".split(" ")).run()) with patch('time.strftime', return_value="20101111000003"): #should succeed by destroying incompatibles @@ -646,6 +654,7 @@ test_target1/test_source2/fs2/sub@test-20101111000000 def test_test(self): + #initial with patch('time.strftime', return_value="20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --test".split(" ")).run()) @@ -662,6 +671,40 @@ test_source2/fs3/sub test_target1 """) + #actual make initial backup + with patch('time.strftime', return_value="20101111000001"): + self.assertFalse(ZfsAutobackup("test test_target1 --verbose".split(" ")).run()) + + + #test incremental + with patch('time.strftime', return_value="20101111000000"): + self.assertFalse(ZfsAutobackup("test test_target1 --verbose --test".split(" ")).run()) + + r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) + self.assertMultiLineEqual(r,""" +test_source1 +test_source1/fs1 +test_source1/fs1@test-20101111000001 +test_source1/fs1/sub +test_source1/fs1/sub@test-20101111000001 +test_source2 +test_source2/fs2 +test_source2/fs2/sub +test_source2/fs2/sub@test-20101111000001 +test_source2/fs3 +test_source2/fs3/sub +test_target1 +test_target1/test_source1 +test_target1/test_source1/fs1 +test_target1/test_source1/fs1@test-20101111000001 +test_target1/test_source1/fs1/sub +test_target1/test_source1/fs1/sub@test-20101111000001 +test_target1/test_source2 +test_target1/test_source2/fs2 +test_target1/test_source2/fs2/sub +test_target1/test_source2/fs2/sub@test-20101111000001 +""") + ########################### # TODO: