diff --git a/tests/test_destroymissing.py b/tests/test_destroymissing.py index 89eb4ec..8e9edb2 100644 --- a/tests/test_destroymissing.py +++ b/tests/test_destroymissing.py @@ -1,4 +1,3 @@ - from basetest import * @@ -6,125 +5,127 @@ class TestZfsNode(unittest2.TestCase): def setUp(self): prepare_zpools() - self.longMessage=True - - - - def test_destroymissing(self): + self.longMessage = True - #initial backup - with mocktime("19101111000000"): #1000 years in past + def test_destroymissing(self): + # initial backup + with mocktime("19101111000000"): # 1000 years in past self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-holds".split(" ")).run()) - with mocktime("20101111000000"): #far in past - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-holds --allow-empty".split(" ")).run()) - + with mocktime("20101111000000"): # far in past + self.assertFalse( + ZfsAutobackup("test test_target1 --no-progress --verbose --no-holds --allow-empty".split(" ")).run()) with self.subTest("Should do nothing yet"): with OutputIO() as buf: with redirect_stdout(buf): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split( + " ")).run()) print(buf.getvalue()) self.assertNotIn(": Destroy missing", buf.getvalue()) - with self.subTest("missing dataset of us that still has children"): - - #just deselect it so it counts as 'missing' + # just deselect it so it counts as 'missing' shelltest("zfs set autobackup:test=child test_source1/fs1") with OutputIO() as buf: with redirect_stdout(buf), redirect_stderr(buf): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split( + " ")).run()) print(buf.getvalue()) - #should have done the snapshot cleanup for destoy missing: + # should have done the snapshot cleanup for destoy missing: self.assertIn("fs1@test-19101111000000: Destroying", buf.getvalue()) self.assertIn("fs1: Destroy missing: Still has children here.", buf.getvalue()) shelltest("zfs inherit autobackup:test test_source1/fs1") - with self.subTest("Normal destroyed leaf"): shelltest("zfs destroy -r test_source1/fs1/sub") - #wait for deadline of last snapshot + # wait for deadline of last snapshot with OutputIO() as buf: with redirect_stdout(buf): - #100y: lastest should not be old enough, while second to latest snapshot IS old enough: - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 100y".split(" ")).run()) + # 100y: lastest should not be old enough, while second to latest snapshot IS old enough: + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 100y".split( + " ")).run()) print(buf.getvalue()) self.assertIn(": Waiting for deadline", buf.getvalue()) - #past deadline, destroy + # past deadline, destroy with OutputIO() as buf: with redirect_stdout(buf): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 1y".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 1y".split( + " ")).run()) print(buf.getvalue()) self.assertIn("sub: Destroying", buf.getvalue()) - with self.subTest("Leaf with other snapshot still using it"): shelltest("zfs destroy -r test_source1/fs1") shelltest("zfs snapshot -r test_target1/test_source1/fs1@other1") - with OutputIO() as buf: with redirect_stdout(buf): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split( + " ")).run()) print(buf.getvalue()) - #cant finish because still in use: + # cant finish because still in use: self.assertIn("fs1: Destroy missing: Still in use", buf.getvalue()) shelltest("zfs destroy test_target1/test_source1/fs1@other1") - with self.subTest("In use by clone"): shelltest("zfs clone test_target1/test_source1/fs1@test-20101111000000 test_target1/clone1") with OutputIO() as buf: with redirect_stdout(buf), redirect_stderr(buf): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split( + " ")).run()) print(buf.getvalue()) - #now tries to destroy our own last snapshot (before the final destroy of the dataset) + # now tries to destroy our own last snapshot (before the final destroy of the dataset) self.assertIn("fs1@test-20101111000000: Destroying", buf.getvalue()) - #but cant finish because still in use: + # but cant finish because still in use: self.assertIn("fs1: Error during --destroy-missing", buf.getvalue()) shelltest("zfs destroy test_target1/clone1") - with self.subTest("Should leave test_source1 parent"): - with OutputIO() as buf: with redirect_stdout(buf), redirect_stderr(buf): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split( + " ")).run()) print(buf.getvalue()) - #should have done the snapshot cleanup for destoy missing: + # should have done the snapshot cleanup for destoy missing: self.assertIn("fs1: Destroying", buf.getvalue()) with OutputIO() as buf: with redirect_stdout(buf), redirect_stderr(buf): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --no-snapshot --destroy-missing 0s".split( + " ")).run()) print(buf.getvalue()) - #on second run it sees the dangling ex-parent but doesnt know what to do with it (since it has no own snapshot) + # on second run it sees the dangling ex-parent but doesnt know what to do with it (since it has no own snapshot) self.assertIn("test_source1: Destroy missing: has no snapshots made by us", buf.getvalue()) - - - - #end result - r=shelltest("zfs list -H -o name -r -t all test_target1") - self.assertMultiLineEqual(r,""" + # end result + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_target1") + self.assertMultiLineEqual(r, """ test_target1 test_target1/test_source1 test_target1/test_source2 diff --git a/tests/test_encryption.py b/tests/test_encryption.py index 3193f26..7b705bf 100644 --- a/tests/test_encryption.py +++ b/tests/test_encryption.py @@ -301,7 +301,7 @@ def test_resume_encrypt_with_no_key(self): # NOTE: On some versions this leaves 2 weird sub-datasets that should'nt be there (its probably a zfs bug?) # so we ignore this, and just make sure the backup resumes correctly after reloading the key. - # r = shelltest("zfs get -r -t all encryptionroot test_target1") + # r = shelltest("zfs get -r -t snapshot,filesystem encryptionroot test_target1") # self.assertEqual(r, """ # NAME PROPERTY VALUE SOURCE # test_target1 encryptionroot - - diff --git a/tests/test_externalfailures.py b/tests/test_externalfailures.py index c14bb97..a76292d 100644 --- a/tests/test_externalfailures.py +++ b/tests/test_externalfailures.py @@ -51,7 +51,7 @@ def test_initial_resume(self): self.assertIn(": resuming", buf.getvalue()) - r = shelltest("zfs list -H -o name -r -t all test_target1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_target1") self.assertMultiLineEqual(r, """ test_target1 test_target1/test_source1 @@ -94,7 +94,7 @@ def test_incremental_resume(self): # did we really resume? self.assertIn(": resuming", buf.getvalue()) - r = shelltest("zfs list -H -o name -r -t all test_target1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_target1") self.assertMultiLineEqual(r, """ test_target1 test_target1/test_source1 @@ -129,7 +129,7 @@ def test_initial_resumeabort(self): with mocktime("20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) - r = shelltest("zfs list -H -o name -r -t all test_target1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_target1") self.assertMultiLineEqual(r, """ test_target1 test_target1/test_source1 @@ -164,7 +164,7 @@ def test_incremental_resumeabort(self): with mocktime("20101111000002"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) - r = shelltest("zfs list -H -o name -r -t all test_target1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_target1") self.assertMultiLineEqual(r, """ test_target1 test_target1/test_source1 @@ -200,7 +200,7 @@ def test_abort_unwanted_resume(self): self.assertIn("Aborting resume", buf.getvalue()) - r = shelltest("zfs list -H -o name -r -t all test_target1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_target1") self.assertMultiLineEqual(r, """ test_target1 test_target1/test_source1 @@ -259,7 +259,7 @@ def test_ignoretransfererrors(self): # with mocktime("20101111000000"): # self.assertFalse(ZfsAutobackup("test test_target1 --verbose --allow-empty --no-progress".split(" ")).run()) # -# r = shelltest("zfs list -H -o name -r -t all test_target1") +# r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_target1") # # self.assertMultiLineEqual(r, """ # test_target1 diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 273636f..87213f7 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -25,7 +25,7 @@ def test_keepsource0target10queuedsend(self): "test test_target1 --no-progress --verbose --keep-source=0 --keep-target=10 --allow-empty".split( " ")).run()) - r = shelltest("zfs list -H -o name -r -t bookmark,filesystem " + TEST_POOLS) + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 diff --git a/tests/test_sendrecvpipes.py b/tests/test_sendrecvpipes.py index c552540..5c7b4f5 100644 --- a/tests/test_sendrecvpipes.py +++ b/tests/test_sendrecvpipes.py @@ -16,7 +16,8 @@ def test_send_basics(self): with self.subTest("local local pipe"): with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup( - ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", "--clear-mountpoint", + ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", + "--clear-mountpoint", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") @@ -44,7 +45,7 @@ def test_send_basics(self): "--ssh-source=localhost", "--ssh-target=localhost", "--send-pipe=dd bs=1M", "--recv-pipe=dd bs=2M"]).run()) - r = shelltest("zfs list -H -o name -r -t all test_target1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_target1") self.assertMultiLineEqual(r, """ test_target1 test_target1/test_source1 @@ -85,7 +86,8 @@ def test_buffer(self): with self.subTest("local local pipe"): with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup( - ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", "--clear-mountpoint", "--buffer=1M"]).run()) + ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", + "--clear-mountpoint", "--buffer=1M"]).run()) shelltest("zfs destroy -r test_target1/test_source1/fs1/sub") @@ -111,7 +113,7 @@ def test_buffer(self): ["test", "test_target1", "--allow-empty", "--exclude-received", "--no-holds", "--no-progress", "--ssh-source=localhost", "--ssh-target=localhost", "--buffer=1M"]).run()) - r = shelltest("zfs list -H -o name -r -t all test_target1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_target1") self.assertMultiLineEqual(r, """ test_target1 test_target1/test_source1 diff --git a/tests/test_zfsautobackup.py b/tests/test_zfsautobackup.py index 0a60477..c24b259 100644 --- a/tests/test_zfsautobackup.py +++ b/tests/test_zfsautobackup.py @@ -3,14 +3,14 @@ from basetest import * import time -from zfs_autobackup.LogConsole import LogConsole +from zfs_autobackup.LogConsole import LogConsole class TestZfsAutobackup(unittest2.TestCase): def setUp(self): prepare_zpools() - self.longMessage=True + self.longMessage = True def test_invalidpars(self): @@ -18,7 +18,9 @@ def test_invalidpars(self): with OutputIO() as buf: with redirect_stdout(buf): - self.assertEqual(ZfsAutobackup("test test_target1 --no-progress --resume --verbose --no-snapshot".split(" ")).run(), 0) + self.assertEqual( + ZfsAutobackup("test test_target1 --no-progress --resume --verbose --no-snapshot".split(" ")).run(), + 0) print(buf.getvalue()) self.assertIn("The --resume", buf.getvalue()) @@ -31,15 +33,14 @@ def test_invalidpars(self): # correct message? self.assertIn("Please create this dataset", buf.getvalue()) - - def test_snapshotmode(self): + def test_snapshotmode(self): """test snapshot tool mode""" with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test --no-progress --verbose".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@test-20101111000000 @@ -54,27 +55,26 @@ def test_snapshotmode(self): test_target1 """) - def test_defaults(self): - self.maxDiff=2000 + def test_defaults(self): + self.maxDiff = 2000 with self.subTest("no datasets selected"): with OutputIO() as buf: with redirect_stderr(buf): with mocktime("20101111000000"): - self.assertTrue(ZfsAutobackup("nonexisting test_target1 --verbose --debug --no-progress".split(" ")).run()) + self.assertTrue( + ZfsAutobackup("nonexisting test_target1 --verbose --debug --no-progress".split(" ")).run()) print(buf.getvalue()) - #correct message? + # correct message? self.assertIn("No source filesystems selected", buf.getvalue()) - with self.subTest("defaults with full verbose and debug"): - with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --debug --no-progress".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@test-20101111000000 @@ -102,9 +102,8 @@ def test_defaults(self): with mocktime("20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --allow-empty --no-progress".split(" ")).run()) - - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@test-20101111000000 @@ -135,9 +134,8 @@ def test_defaults(self): """) with self.subTest("verify holds"): - - r=shelltest("zfs get -r userrefs test_source1 test_source2 test_target1") - self.assertMultiLineEqual(r,""" + r = shelltest("zfs get -r userrefs test_source1 test_source2 test_target1") + self.assertMultiLineEqual(r, """ NAME PROPERTY VALUE SOURCE test_source1 userrefs - - test_source1/fs1 userrefs - - @@ -168,17 +166,20 @@ def test_defaults(self): test_target1/test_source2/fs2/sub@test-20101111000001 userrefs 1 - """) - #make sure time handling is correctly. try to make snapshots a year appart and verify that only snapshots mostly 1y old are kept - #So in this case we only want to see 2 snapshots of 2011, and none of the 2010's anymore. + # make sure time handling is correctly. try to make snapshots a year appart and verify that only snapshots mostly 1y old are kept + # So in this case we only want to see 2 snapshots of 2011, and none of the 2010's anymore. with self.subTest("test time checking"): with mocktime("20111211000000"): - self.assertFalse(ZfsAutobackup("test test_target1 --allow-empty --verbose --no-progress".split(" ")).run()) + self.assertFalse( + ZfsAutobackup("test test_target1 --allow-empty --verbose --no-progress".split(" ")).run()) with mocktime("20111211000001"): - self.assertFalse(ZfsAutobackup("test test_target1 --allow-empty --verbose --keep-source 1y1y --keep-target 1d1y --no-progress".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --allow-empty --verbose --keep-source 1y1y --keep-target 1d1y --no-progress".split( + " ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@test-20111211000000 @@ -208,16 +209,16 @@ def test_defaults(self): test_target1/test_source2/fs2/sub@test-20111211000001 """) - def test_ignore_othersnaphots(self): + def test_ignore_othersnaphots(self): - r=shelltest("zfs snapshot test_source1/fs1@othersimple") - r=shelltest("zfs snapshot test_source1/fs1@otherdate-20001111000000") + r = shelltest("zfs snapshot test_source1/fs1@othersimple") + r = shelltest("zfs snapshot test_source1/fs1@otherdate-20001111000000") with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@othersimple @@ -243,16 +244,17 @@ def test_ignore_othersnaphots(self): test_target1/test_source2/fs2/sub@test-20101111000000 """) - def test_othersnaphots(self): + def test_othersnaphots(self): - r=shelltest("zfs snapshot test_source1/fs1@othersimple") - r=shelltest("zfs snapshot test_source1/fs1@otherdate-20001111000000") + r = shelltest("zfs snapshot test_source1/fs1@othersimple") + r = shelltest("zfs snapshot test_source1/fs1@otherdate-20001111000000") with mocktime("20101111000000"): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --other-snapshots".split(" ")).run()) + self.assertFalse( + ZfsAutobackup("test test_target1 --no-progress --verbose --other-snapshots".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@othersimple @@ -280,16 +282,15 @@ def test_othersnaphots(self): test_target1/test_source2/fs2/sub@test-20101111000000 """) - - def test_nosnapshot(self): + def test_nosnapshot(self): with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-snapshot --no-progress".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - #(only parents are created ) - #TODO: it probably shouldn't create these - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + # (only parents are created ) + # TODO: it probably shouldn't create these + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1/sub @@ -304,14 +305,13 @@ def test_nosnapshot(self): test_target1/test_source2/fs2 """) - - def test_nosend(self): + def test_nosend(self): with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-send --no-progress".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@test-20101111000000 @@ -326,15 +326,15 @@ def test_nosend(self): test_target1 """) - - def test_ignorereplicated(self): - r=shelltest("zfs snapshot test_source1/fs1@otherreplication") + def test_ignorereplicated(self): + r = shelltest("zfs snapshot test_source1/fs1@otherreplication") with mocktime("20101111000000"): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --ignore-replicated".split(" ")).run()) + self.assertFalse( + ZfsAutobackup("test test_target1 --no-progress --verbose --ignore-replicated".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@otherreplication @@ -357,13 +357,13 @@ def test_ignorereplicated(self): test_target1/test_source2/fs2/sub@test-20101111000000 """) - def test_noholds(self): + def test_noholds(self): with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --no-holds --no-progress".split(" ")).run()) - r=shelltest("zfs get -r userrefs test_source1 test_source2 test_target1") - self.assertMultiLineEqual(r,""" + r = shelltest("zfs get -r userrefs test_source1 test_source2 test_target1") + self.assertMultiLineEqual(r, """ NAME PROPERTY VALUE SOURCE test_source1 userrefs - - test_source1/fs1 userrefs - - @@ -388,14 +388,13 @@ def test_noholds(self): test_target1/test_source2/fs2/sub@test-20101111000000 userrefs 0 - """) - - def test_strippath(self): + def test_strippath(self): with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --verbose --strip-path=1 --no-progress".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@test-20101111000000 @@ -418,27 +417,28 @@ def test_strippath(self): """) def test_strippath_collision(self): - with self.assertRaisesRegexp(Exception,"collision"): + with self.assertRaisesRegexp(Exception, "collision"): ZfsAutobackup("test test_target1 --verbose --strip-path=2 --no-progress --debug".split(" ")).run() def test_strippath_toomuch(self): - with self.assertRaisesRegexp(Exception,"too much"): + with self.assertRaisesRegexp(Exception, "too much"): ZfsAutobackup("test test_target1 --verbose --strip-path=3 --no-progress --debug".split(" ")).run() - def test_clearrefres(self): + def test_clearrefres(self): - #on zfs utils 0.6.x -x isnt supported - r=shelltest("zfs recv -x bla test >/dev/null /dev/null /dev/null /dev/null >> .*minutes left.*") + self.assertRegex(buf.getvalue(), ".*>>> .*minutes left.*") diff --git a/tests/test_zfsautobackup31.py b/tests/test_zfsautobackup31.py index e8650a7..f6dd7b0 100644 --- a/tests/test_zfsautobackup31.py +++ b/tests/test_zfsautobackup31.py @@ -1,23 +1,25 @@ from basetest import * import time + class TestZfsAutobackup31(unittest2.TestCase): """various new 3.1 features""" def setUp(self): prepare_zpools() - self.longMessage=True + self.longMessage = True def test_no_thinning(self): - with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) with mocktime("20101111000001"): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --keep-target=0 --keep-source=0 --no-thinning".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --allow-empty --keep-target=0 --keep-source=0 --no-thinning".split( + " ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@test-20101111000000 @@ -47,7 +49,6 @@ def test_no_thinning(self): test_target1/test_source2/fs2/sub@test-20101111000001 """) - def test_re_replication(self): """test re-replication of something thats already a backup (new in v3.1-beta5)""" @@ -55,16 +56,18 @@ def test_re_replication(self): shelltest("zfs create test_target1/b") with mocktime("20101111000000"): - self.assertFalse(ZfsAutobackup("test test_target1/a --no-progress --verbose --debug --allow-empty".split(" ")).run()) + self.assertFalse( + ZfsAutobackup("test test_target1/a --no-progress --verbose --debug --allow-empty".split(" ")).run()) - #NOTE: since v3.4 this changed. autobackup: properties are filtered. So its up to the admin to reset this property on the other side: + # NOTE: since v3.4 this changed. autobackup: properties are filtered. So its up to the admin to reset this property on the other side: shelltest("zfs set autobackup:test=true test_target1/a") with mocktime("20101111000001"): - self.assertFalse(ZfsAutobackup("test test_target1/b --no-progress --verbose --allow-empty".split(" ")).run()) + self.assertFalse( + ZfsAutobackup("test test_target1/b --no-progress --verbose --allow-empty".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t snapshot test_target1") - #NOTE: it wont backup test_target1/a/test_source2/fs2/sub to test_target1/b since it doesnt have the zfs_autobackup property anymore. + r = shelltest("zfs list -H -o name -r -t snapshot test_target1") + # NOTE: it wont backup test_target1/a/test_source2/fs2/sub to test_target1/b since it doesnt have the zfs_autobackup property anymore. self.assertMultiLineEqual(""" test_target1/a@test-20101111000001 test_target1/a/test_source1@test-20101111000001 @@ -92,10 +95,9 @@ def test_re_replication(self): test_target1/b/test_target1/a/test_source2/fs2@test-20101111000001 test_target1/b/test_target1/a/test_source2/fs2/sub@test-20101111000000 test_target1/b/test_target1/a/test_source2/fs2/sub@test-20101111000001 -""",r) +""", r) def test_zfs_compressed(self): - with mocktime("20101111000000"): self.assertFalse( ZfsAutobackup("test test_target1 --no-progress --verbose --debug --zfs-compressed".split(" ")).run()) @@ -107,19 +109,18 @@ def test_force(self): with mocktime("20101111000000"): self.assertFalse( - ZfsAutobackup("test test_target1 --no-progress --verbose --debug --force --strip-path=1".split(" ")).run()) + ZfsAutobackup( + "test test_target1 --no-progress --verbose --debug --force --strip-path=1".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t snapshot test_target1") - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot test_target1") + self.assertMultiLineEqual(r, """ test_target1@test-20101111000000 test_target1/fs1@test-20101111000000 test_target1/fs1/sub@test-20101111000000 test_target1/fs2/sub@test-20101111000000 """) - def test_exclude_unchanged(self): - shelltest("zfs snapshot -r test_source1@somesnapshot") with mocktime("20101111000000"): @@ -127,7 +128,7 @@ def test_exclude_unchanged(self): ZfsAutobackup( "test test_target1 --verbose --allow-empty --exclude-unchanged=1".split(" ")).run()) - #everything should be excluded, but should not return an error (see #190) + # everything should be excluded, but should not return an error (see #190) with mocktime("20101111000001"): self.assertFalse( ZfsAutobackup( @@ -137,4 +138,3 @@ def test_exclude_unchanged(self): self.assertMultiLineEqual(r, """ test_target1/test_source2/fs2/sub@test-20101111000000 """) - diff --git a/tests/test_zfsautobackup32.py b/tests/test_zfsautobackup32.py index 068d322..cdb2bbe 100644 --- a/tests/test_zfsautobackup32.py +++ b/tests/test_zfsautobackup32.py @@ -1,29 +1,30 @@ from basetest import * + class TestZfsAutobackup32(unittest2.TestCase): """various new 3.2 features""" def setUp(self): prepare_zpools() - self.longMessage=True + self.longMessage = True def test_invalid_common_snapshot(self): - with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) - #create 2 snapshots with the same name, which are invalid as common snapshot + # create 2 snapshots with the same name, which are invalid as common snapshot shelltest("zfs snapshot test_source1/fs1@invalid") shelltest("zfs snapshot test_target1/test_source1/fs1@invalid") with mocktime("20101111000001"): - #try the old way (without guid checking), and fail: - self.assertEqual(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --no-guid-check".split(" ")).run(),1) - #new way should be ok: + # try the old way (without guid checking), and fail: + self.assertEqual(ZfsAutobackup( + "test test_target1 --no-progress --verbose --allow-empty --no-guid-check".split(" ")).run(), 1) + # new way should be ok: self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot".split(" ")).run()) - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@test-20101111000000 @@ -56,23 +57,25 @@ def test_invalid_common_snapshot(self): """) def test_invalid_common_snapshot_with_data(self): - with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) - #create 2 snapshots with the same name, which are invalid as common snapshot + # create 2 snapshots with the same name, which are invalid as common snapshot shelltest("zfs snapshot test_source1/fs1@invalid") shelltest("touch /test_target1/test_source1/fs1/shouldnotbeHere") shelltest("zfs snapshot test_target1/test_source1/fs1@invalid") with mocktime("20101111000001"): - #try the old way and fail: - self.assertEqual(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --destroy-incompatible --no-guid-check".split(" ")).run(),1) - #new way should be ok - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --no-snapshot --destroy-incompatible".split(" ")).run()) - - r=shelltest("zfs list -H -o name -r -t all "+TEST_POOLS) - self.assertMultiLineEqual(r,""" + # try the old way and fail: + self.assertEqual(ZfsAutobackup( + "test test_target1 --no-progress --verbose --allow-empty --destroy-incompatible --no-guid-check".split( + " ")).run(), 1) + # new way should be ok + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --no-snapshot --destroy-incompatible".split(" ")).run()) + + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) + self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 test_source1/fs1@test-20101111000000 @@ -103,8 +106,7 @@ def test_invalid_common_snapshot_with_data(self): test_target1/test_source2/fs2/sub@test-20101111000001 """) - - #check consistent mounting behaviour, see issue #112 + # check consistent mounting behaviour, see issue #112 def test_mount_consitency_mounted(self): """only filesystems that have canmount=on with a mountpoint should be mounted. """ @@ -113,35 +115,32 @@ def test_mount_consitency_mounted(self): with mocktime("20101111000000"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) - r=shelltest("zfs mount |grep -o /test_target1.*") - self.assertMultiLineEqual(r,""" + r = shelltest("zfs mount |grep -o /test_target1.*") + self.assertMultiLineEqual(r, """ /test_target1 /test_target1/test_source1/fs1 /test_target1/test_source1/fs1/sub /test_target1/test_source2/fs2/sub """) - def test_mount_consitency_unmounted(self): """only test_target1 should be mounted in this test""" shelltest("zfs create -V 10M test_source1/fs1/subvol") with mocktime("20101111000000"): - self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --clear-mountpoint".split(" ")).run()) + self.assertFalse(ZfsAutobackup( + "test test_target1 --no-progress --verbose --allow-empty --clear-mountpoint".split(" ")).run()) - r=shelltest("zfs mount |grep -o /test_target1.*") - self.assertMultiLineEqual(r,""" + r = shelltest("zfs mount |grep -o /test_target1.*") + self.assertMultiLineEqual(r, """ /test_target1 """) - - - def test_transfer_thinning(self): # test pre/post/during transfer thinning and efficient transfer (no transerring of stuff that gets deleted on target) - #less output + # less output shelltest("zfs set autobackup:test2=true test_source1/fs1/sub") # nobody wants this one, will be destroyed before transferring (over a year ago) @@ -167,24 +166,24 @@ def test_transfer_thinning(self): with redirect_stdout(buf): # now do thinning and transfer all at once with mocktime("20010203000000"): - self.assertFalse(ZfsAutobackup("--keep-source=1d10d --keep-target=1m10m --allow-empty --verbose --clear-mountpoint --other-snapshots test2 test_target1".split(" ")).run()) - + self.assertFalse(ZfsAutobackup( + "--keep-source=1d10d --keep-target=1m10m --allow-empty --verbose --clear-mountpoint --other-snapshots test2 test_target1".split( + " ")).run()) print(buf.getvalue()) self.assertIn( -""" - [Source] test_source1/fs1/sub@test2-20000101000000: Destroying - [Source] test_source1/fs1/sub@test2-20010101000000: -> test_target1/test_source1/fs1/sub (new) - [Source] test_source1/fs1/sub@other1: -> test_target1/test_source1/fs1/sub - [Source] test_source1/fs1/sub@test2-20010101000000: Destroying - [Source] test_source1/fs1/sub@test2-20010201000000: -> test_target1/test_source1/fs1/sub - [Source] test_source1/fs1/sub@other2: -> test_target1/test_source1/fs1/sub - [Source] test_source1/fs1/sub@test2-20010203000000: -> test_target1/test_source1/fs1/sub -""", buf.getvalue()) - - - r=shelltest("zfs list -H -o name -r -t snapshot test_source1 test_target1") - self.assertMultiLineEqual(r,""" + """ + [Source] test_source1/fs1/sub@test2-20000101000000: Destroying + [Source] test_source1/fs1/sub@test2-20010101000000: -> test_target1/test_source1/fs1/sub (new) + [Source] test_source1/fs1/sub@other1: -> test_target1/test_source1/fs1/sub + [Source] test_source1/fs1/sub@test2-20010101000000: Destroying + [Source] test_source1/fs1/sub@test2-20010201000000: -> test_target1/test_source1/fs1/sub + [Source] test_source1/fs1/sub@other2: -> test_target1/test_source1/fs1/sub + [Source] test_source1/fs1/sub@test2-20010203000000: -> test_target1/test_source1/fs1/sub + """, buf.getvalue()) + + r = shelltest("zfs list -H -o name -r -t snapshot test_source1 test_target1") + self.assertMultiLineEqual(r, """ test_source1/fs1/sub@other1 test_source1/fs1/sub@test2-20010201000000 test_source1/fs1/sub@other2 @@ -196,5 +195,3 @@ def test_transfer_thinning(self): test_target1/test_source1/fs1/sub@other2 test_target1/test_source1/fs1/sub@test2-20010203000000 """) - - diff --git a/tests/test_zfsautobackup34.py b/tests/test_zfsautobackup34.py index ea7943b..68bc4a1 100644 --- a/tests/test_zfsautobackup34.py +++ b/tests/test_zfsautobackup34.py @@ -57,7 +57,7 @@ def test_select_bookmark_or_snapshot(self): with mocktime("20101111000002"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) - r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 @@ -102,7 +102,7 @@ def test_disable_bookmarks(self): with mocktime("20101111000001"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) - r = shelltest("zfs list -H -o name -r -t all test_source1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_source1") self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 @@ -118,7 +118,7 @@ def test_disable_bookmarks(self): self.assertFalse(ZfsAutobackup( "test test_target1 --no-progress --verbose --allow-empty --no-bookmarks".split(" ")).run()) - r = shelltest("zfs list -H -o name -r -t all test_source1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_source1") self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 @@ -133,7 +133,7 @@ def test_disable_bookmarks(self): with mocktime("20101111000003"): self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run()) - r = shelltest("zfs list -H -o name -r -t all test_source1") + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem test_source1") self.assertMultiLineEqual(r, """ test_source1 test_source1/fs1 @@ -207,7 +207,7 @@ def test_double_send_bookmark(self): # result: # for target a the bookmarks should be at 20101111000002, for target b the bookmarks should be at 20101111000003 - r = shelltest("zfs list -H -r -t all -o name " + TEST_POOLS) + r = shelltest("zfs list -H -r -t snapshot,filesystem -o name " + TEST_POOLS) self.assertRegexpMatches(r, """ test_source1 diff --git a/tests/test_zfscheck.py b/tests/test_zfscheck.py index cb239f3..38e5eb7 100644 --- a/tests/test_zfscheck.py +++ b/tests/test_zfscheck.py @@ -9,7 +9,6 @@ class TestZfsCheck(unittest2.TestCase): def setUp(self): pass - def test_volume(self): if exists("/.dockerenv"): @@ -23,23 +22,26 @@ def test_volume(self): with self.subTest("Generate"): with OutputIO() as buf: with redirect_stdout(buf): - self.assertFalse(ZfsCheck("test_source1/vol@test".split(" "),print_arguments=False).run()) + self.assertFalse(ZfsCheck("test_source1/vol@test".split(" "), print_arguments=False).run()) print(buf.getvalue()) self.assertEqual("""0 2c2ceccb5ec5574f791d45b63c940cff20550f9a 1 2c2ceccb5ec5574f791d45b63c940cff20550f9a """, buf.getvalue()) - #store on disk for next step, add one error. + # store on disk for next step, add one error. with open("/tmp/testhashes", "w") as fh: - fh.write(buf.getvalue()+"1\t2c2ceccb5ec5574f791d45b63c940cff20550f9X") + fh.write(buf.getvalue() + "1\t2c2ceccb5ec5574f791d45b63c940cff20550f9X") with self.subTest("Compare"): with OutputIO() as buf: with redirect_stdout(buf): - self.assertEqual(1, ZfsCheck("test_source1/vol@test --check=/tmp/testhashes".split(" "),print_arguments=False).run()) + self.assertEqual(1, ZfsCheck("test_source1/vol@test --check=/tmp/testhashes".split(" "), + print_arguments=False).run()) print(buf.getvalue()) - self.assertEqual("Chunk 1 failed: 2c2ceccb5ec5574f791d45b63c940cff20550f9X 2c2ceccb5ec5574f791d45b63c940cff20550f9a\n", buf.getvalue()) + self.assertEqual( + "Chunk 1 failed: 2c2ceccb5ec5574f791d45b63c940cff20550f9X 2c2ceccb5ec5574f791d45b63c940cff20550f9a\n", + buf.getvalue()) def test_filesystem(self): prepare_zpools() @@ -49,7 +51,7 @@ def test_filesystem(self): shelltest("mkdir /test_source1/dir") shelltest("cp tests/data/whole2 /test_source1/dir/testfile") - #it should ignore these: + # 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") @@ -67,17 +69,20 @@ def test_filesystem(self): dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798 """, buf.getvalue()) - #store on disk for next step, add error + # store on disk for next step, add error with open("/tmp/testhashes", "w") as fh: - fh.write(buf.getvalue()+"dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d79X") + fh.write(buf.getvalue() + "dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d79X") with self.subTest("Compare"): with OutputIO() as buf: with redirect_stdout(buf): - self.assertEqual(1, ZfsCheck("test_source1@test --check=/tmp/testhashes".split(" "),print_arguments=False).run()) + self.assertEqual(1, ZfsCheck("test_source1@test --check=/tmp/testhashes".split(" "), + print_arguments=False).run()) print(buf.getvalue()) - self.assertEqual("dir/testfile: Chunk 0 failed: 2e863f1fcccd6642e4e28453eba10d2d3f74d79X 2e863f1fcccd6642e4e28453eba10d2d3f74d798\n", buf.getvalue()) + self.assertEqual( + "dir/testfile: Chunk 0 failed: 2e863f1fcccd6642e4e28453eba10d2d3f74d79X 2e863f1fcccd6642e4e28453eba10d2d3f74d798\n", + buf.getvalue()) def test_file(self): @@ -92,14 +97,17 @@ def test_file(self): # store on disk for next step, add error with open("/tmp/testhashes", "w") as fh: - fh.write(buf.getvalue()+"0 3c0bf91170d873b8e327d3bafb6bc074580d11bX") + fh.write(buf.getvalue() + "0 3c0bf91170d873b8e327d3bafb6bc074580d11bX") with self.subTest("Compare"): with OutputIO() as buf: with redirect_stdout(buf): - self.assertEqual(1,ZfsCheck("tests/data/whole --check=/tmp/testhashes".split(" "), print_arguments=False).run()) + self.assertEqual(1, ZfsCheck("tests/data/whole --check=/tmp/testhashes".split(" "), + print_arguments=False).run()) print(buf.getvalue()) - self.assertEqual("Chunk 0 failed: 3c0bf91170d873b8e327d3bafb6bc074580d11bX 3c0bf91170d873b8e327d3bafb6bc074580d11b7\n", buf.getvalue()) + self.assertEqual( + "Chunk 0 failed: 3c0bf91170d873b8e327d3bafb6bc074580d11bX 3c0bf91170d873b8e327d3bafb6bc074580d11b7\n", + buf.getvalue()) def test_tree(self): shelltest("rm -rf /tmp/testtree; mkdir /tmp/testtree") @@ -115,13 +123,12 @@ def test_tree(self): with redirect_stdout(buf): self.assertFalse(ZfsCheck("/tmp/testtree --skip=1".split(" "), print_arguments=False).run()) - #since order varies, just check count (there is one empty line for some reason, only when testing like this) + # since order varies, just check count (there is one empty line for some reason, only when testing like this) print(buf.getvalue().split("\n")) - self.assertEqual(len(buf.getvalue().split("\n")),4) + self.assertEqual(len(buf.getvalue().split("\n")), 4) ###################################### with self.subTest("Compare, all incorrect, skip 1"): - # store on disk for next step, add error with open("/tmp/testhashes", "w") as fh: fh.write(""" @@ -134,13 +141,14 @@ def test_tree(self): with OutputIO() as buf: with redirect_stdout(buf): - self.assertEqual(ZfsCheck("/tmp/testtree --check=/tmp/testhashes --skip=1".split(" "), print_arguments=False).run(), 3) + self.assertEqual(ZfsCheck("/tmp/testtree --check=/tmp/testhashes --skip=1".split(" "), + print_arguments=False).run(), 3) print(buf.getvalue()) self.assertMultiLineEqual("""partial: Chunk 0 failed: 642027d63bb0afd7e0ba197f2c66ad03e3d70deX 642027d63bb0afd7e0ba197f2c66ad03e3d70de1 whole2: Chunk 0 failed: 2e863f1fcccd6642e4e28453eba10d2d3f74d79X 2e863f1fcccd6642e4e28453eba10d2d3f74d798 whole_whole2_partial: Chunk 0 failed: 309ffffba2e1977d12f3b7469971f30d28b94bdX 309ffffba2e1977d12f3b7469971f30d28b94bd8 -""",buf.getvalue()) +""", buf.getvalue()) #################################### with self.subTest("Generate"): @@ -148,10 +156,10 @@ def test_tree(self): with redirect_stdout(buf): self.assertFalse(ZfsCheck("/tmp/testtree".split(" "), print_arguments=False).run()) - #file order on disk can vary, so sort it.. - sorted=buf.getvalue().split("\n") + # file order on disk can vary, so sort it.. + sorted = buf.getvalue().split("\n") sorted.sort() - sorted="\n".join(sorted)+"\n" + sorted = "\n".join(sorted) + "\n" print(sorted) self.assertEqual(""" @@ -184,11 +192,11 @@ def test_brokenpipe_cleanup_filesystem(self): shelltest("cp tests/data/whole /test_source1/testfile") shelltest("zfs snapshot test_source1@test") - #breaks pipe when head exists - #important to use --debug, since that generates extra output which would be problematic if we didnt do correct SIGPIPE handling + # breaks pipe when head 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 | head -n1") - #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") def test_brokenpipe_cleanup_volume(self): @@ -199,12 +207,12 @@ def test_brokenpipe_cleanup_volume(self): 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 + # 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/vol@test --debug| grep -m1 'Hashing file'") # time.sleep(1) - r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) self.assertMultiLineEqual(""" test_source1 test_source1/fs1 @@ -217,7 +225,4 @@ def test_brokenpipe_cleanup_volume(self): test_source2/fs3 test_source2/fs3/sub test_target1 -""",r ) - - - +""", r) diff --git a/tests/test_zfsnode.py b/tests/test_zfsnode.py index 813abd4..dbfc03e 100644 --- a/tests/test_zfsnode.py +++ b/tests/test_zfsnode.py @@ -12,13 +12,15 @@ def setUp(self): def test_consistent_snapshot(self): logger = LogStub() description = "[Source]" - node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) + node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", + logger=logger, description=description) with self.subTest("first snapshot"): - (selected_datasets, excluded_datasets)=node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, - exclude_unchanged=0) + (selected_datasets, excluded_datasets) = node.selected_datasets(property_name="autobackup:test", + exclude_paths=[], exclude_received=False, + exclude_unchanged=0) node.consistent_snapshot(selected_datasets, "test-20101111000001", 100000) - r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) self.assertEqual(r, """ test_source1 test_source1/fs1 @@ -35,10 +37,11 @@ def test_consistent_snapshot(self): """) with self.subTest("second snapshot, no changes, no snapshot"): - (selected_datasets, excluded_datasets)=node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, - exclude_unchanged=0) + (selected_datasets, excluded_datasets) = node.selected_datasets(property_name="autobackup:test", + exclude_paths=[], exclude_received=False, + exclude_unchanged=0) node.consistent_snapshot(selected_datasets, "test-20101111000002", 1) - r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) self.assertEqual(r, """ test_source1 test_source1/fs1 @@ -55,9 +58,11 @@ def test_consistent_snapshot(self): """) with self.subTest("second snapshot, no changes, empty snapshot"): - (selected_datasets, excluded_datasets) =node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=0) + (selected_datasets, excluded_datasets) = node.selected_datasets(property_name="autobackup:test", + exclude_paths=[], exclude_received=False, + exclude_unchanged=0) node.consistent_snapshot(selected_datasets, "test-20101111000002", 0) - r = shelltest("zfs list -H -o name -r -t all " + TEST_POOLS) + r = shelltest("zfs list -H -o name -r -t snapshot,filesystem " + TEST_POOLS) self.assertEqual(r, """ test_source1 test_source1/fs1 @@ -79,12 +84,16 @@ def test_consistent_snapshot(self): def test_consistent_snapshot_prepostcmds(self): logger = LogStub() description = "[Source]" - node = ZfsNode(utc=False, snapshot_time_format="test", hold_name="test", logger=logger, description=description, debug_output=True) + node = ZfsNode(utc=False, snapshot_time_format="test", hold_name="test", logger=logger, description=description, + debug_output=True) with self.subTest("Test if all cmds are executed correctly (no failures)"): with OutputIO() as buf: with redirect_stdout(buf): - (selected_datasets, excluded_datasets) =node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=0) + (selected_datasets, excluded_datasets) = node.selected_datasets(property_name="autobackup:test", + exclude_paths=[], + exclude_received=False, + exclude_unchanged=0) node.consistent_snapshot(selected_datasets, "test-1", 0, pre_snapshot_cmds=["echo pre1", "echo pre2"], @@ -96,12 +105,15 @@ def test_consistent_snapshot_prepostcmds(self): self.assertIn("STDOUT > post1", buf.getvalue()) self.assertIn("STDOUT > post2", buf.getvalue()) - - with self.subTest("Failure in the middle, only pre1 and both post1 and post2 should be executed, no snapshot should be attempted"): + with self.subTest( + "Failure in the middle, only pre1 and both post1 and post2 should be executed, no snapshot should be attempted"): with OutputIO() as buf: with redirect_stdout(buf): with self.assertRaises(ExecuteError): - (selected_datasets, excluded_datasets) =node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=0) + (selected_datasets, excluded_datasets) = node.selected_datasets(property_name="autobackup:test", + exclude_paths=[], + exclude_received=False, + exclude_unchanged=0) node.consistent_snapshot(selected_datasets, "test-1", 0, pre_snapshot_cmds=["echo pre1", "false", "echo pre2"], @@ -118,8 +130,11 @@ def test_consistent_snapshot_prepostcmds(self): with OutputIO() as buf: with redirect_stdout(buf): with self.assertRaises(ExecuteError): - #same snapshot name as before so it fails - (selected_datasets, excluded_datasets) =node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, exclude_unchanged=0) + # same snapshot name as before so it fails + (selected_datasets, excluded_datasets) = node.selected_datasets(property_name="autobackup:test", + exclude_paths=[], + exclude_received=False, + exclude_unchanged=0) node.consistent_snapshot(selected_datasets, "test-1", 0, pre_snapshot_cmds=["echo pre1", "echo pre2"], @@ -136,20 +151,20 @@ def test_timestamps(self): # Assert that timestamps keep relative order both for utc and for localtime logger = LogStub() description = "[Source]" - node_local = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) - node_utc = ZfsNode(utc=True, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) + node_local = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", + logger=logger, description=description) + node_utc = ZfsNode(utc=True, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", + logger=logger, description=description) for node in [node_local, node_utc]: with self.subTest("timestamp ordering " + ("utc" if node == node_utc else "localtime")): - dataset_a = ZfsDataset(node,"test_source1@test-20101111000001") - dataset_b = ZfsDataset(node,"test_source1@test-20101111000002") - dataset_c = ZfsDataset(node,"test_source1@test-20240101020202") + dataset_a = ZfsDataset(node, "test_source1@test-20101111000001") + dataset_b = ZfsDataset(node, "test_source1@test-20101111000002") + dataset_c = ZfsDataset(node, "test_source1@test-20240101020202") self.assertGreater(dataset_b.timestamp, dataset_a.timestamp) self.assertGreater(dataset_c.timestamp, dataset_b.timestamp) - def test_getselected(self): - # should be excluded by property shelltest("zfs create test_source1/fs1/subexcluded") shelltest("zfs set autobackup:test=false test_source1/fs1/subexcluded") @@ -165,9 +180,11 @@ def test_getselected(self): logger = LogStub() description = "[Source]" - node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) - (selected_datasets, excluded_datasets)=node.selected_datasets(property_name="autobackup:test", exclude_paths=[], exclude_received=False, - exclude_unchanged=1) + node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", + logger=logger, description=description) + (selected_datasets, excluded_datasets) = node.selected_datasets(property_name="autobackup:test", + exclude_paths=[], exclude_received=False, + exclude_unchanged=1) s = pformat(selected_datasets) print(s) @@ -177,11 +194,11 @@ def test_getselected(self): (local): test_source1/fs1/sub, (local): test_source2/fs2/sub]""") - def test_validcommand(self): logger = LogStub() description = "[Source]" - node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) + node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", + logger=logger, description=description) with self.subTest("test invalid option"): self.assertFalse(node.valid_command(["zfs", "send", "--invalid-option", "nonexisting"])) @@ -191,7 +208,8 @@ def test_validcommand(self): def test_supportedsendoptions(self): logger = LogStub() description = "[Source]" - node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description) + node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", + logger=logger, description=description) # -D propably always supported self.assertGreater(len(node.supported_send_options), 0) @@ -199,7 +217,8 @@ def test_supportedrecvoptions(self): logger = LogStub() description = "[Source]" # NOTE: this could hang via ssh if we dont close filehandles properly. (which was a previous bug) - node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", logger=logger, description=description, ssh_to='localhost') + node = ZfsNode(utc=False, snapshot_time_format="test-%Y%m%d%H%M%S", hold_name="zfs_autobackup:test", + logger=logger, description=description, ssh_to='localhost') self.assertIsInstance(node.supported_recv_options, list)