mirror of
https://github.com/psy0rz/zfs_autobackup.git
synced 2025-05-28 01:09:13 +03:00
dont list bookmarks in existing tests
This commit is contained in:
parent
d79d6af548
commit
cf541c581c
@ -1,4 +1,3 @@
|
||||
|
||||
from basetest import *
|
||||
|
||||
|
||||
@ -6,125 +5,127 @@ class TestZfsNode(unittest2.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
prepare_zpools()
|
||||
self.longMessage=True
|
||||
self.longMessage = True
|
||||
|
||||
|
||||
|
||||
def test_destroymissing(self):
|
||||
|
||||
#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
|
||||
|
@ -301,7 +301,7 @@ test_target1/test_source2/fs2/sub encryptionroot -
|
||||
|
||||
# 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 - -
|
||||
|
@ -51,7 +51,7 @@ class TestExternalFailures(unittest2.TestCase):
|
||||
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
# 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 @@ test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000002
|
||||
# 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
|
||||
|
@ -25,7 +25,7 @@ class TestZfsNode(unittest2.TestCase):
|
||||
"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
|
||||
|
@ -16,7 +16,8 @@ class TestSendRecvPipes(unittest2.TestCase):
|
||||
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 @@ class TestSendRecvPipes(unittest2.TestCase):
|
||||
"--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 @@ test_target1/test_source2/fs2/sub@test-20101111000003
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000003
|
||||
["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
|
||||
|
@ -3,14 +3,14 @@ from zfs_autobackup.CmdPipe import CmdPipe
|
||||
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 @@ class TestZfsAutobackup(unittest2.TestCase):
|
||||
|
||||
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 @@ class TestZfsAutobackup(unittest2.TestCase):
|
||||
# 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 @@ test_source2/fs3/sub
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000001
|
||||
""")
|
||||
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000000 userrefs 0 -
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20111211000000
|
||||
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 @@ test_target1/test_source2/fs2/sub
|
||||
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 @@ test_target1/test_source2/fs2/sub
|
||||
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 @@ test_target1/test_source2
|
||||
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 @@ test_source2/fs3/sub
|
||||
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 @@ test_target1/test_source2/fs2/sub
|
||||
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 @@ test_target1/test_source2/fs2/sub userrefs - -
|
||||
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 @@ test_target1/fs2/sub@test-20101111000000
|
||||
""")
|
||||
|
||||
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/zero; echo $?")
|
||||
if r=="\n2\n":
|
||||
# on zfs utils 0.6.x -x isnt supported
|
||||
r = shelltest("zfs recv -x bla test >/dev/null </dev/zero; echo $?")
|
||||
if r == "\n2\n":
|
||||
self.skipTest("This zfs-userspace version doesnt support -x")
|
||||
|
||||
r=shelltest("zfs set refreservation=1M test_source1/fs1")
|
||||
r = shelltest("zfs set refreservation=1M test_source1/fs1")
|
||||
|
||||
with mocktime("20101111000000"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --clear-refreservation".split(" ")).run())
|
||||
self.assertFalse(
|
||||
ZfsAutobackup("test test_target1 --no-progress --verbose --clear-refreservation".split(" ")).run())
|
||||
|
||||
r=shelltest("zfs get -r refreservation test_source1 test_source2 test_target1")
|
||||
self.assertMultiLineEqual(r,"""
|
||||
r = shelltest("zfs get -r refreservation test_source1 test_source2 test_target1")
|
||||
self.assertMultiLineEqual(r, """
|
||||
NAME PROPERTY VALUE SOURCE
|
||||
test_source1 refreservation none default
|
||||
test_source1/fs1 refreservation 1M local
|
||||
@ -463,20 +463,19 @@ test_target1/test_source2/fs2/sub refreservation none
|
||||
test_target1/test_source2/fs2/sub@test-20101111000000 refreservation - -
|
||||
""")
|
||||
|
||||
def test_clearmount(self):
|
||||
|
||||
def test_clearmount(self):
|
||||
|
||||
#on zfs utils 0.6.x -o isnt supported
|
||||
r=shelltest("zfs recv -o bla=1 test >/dev/null </dev/zero; echo $?")
|
||||
if r=="\n2\n":
|
||||
# on zfs utils 0.6.x -o isnt supported
|
||||
r = shelltest("zfs recv -o bla=1 test >/dev/null </dev/zero; echo $?")
|
||||
if r == "\n2\n":
|
||||
self.skipTest("This zfs-userspace version doesnt support -o")
|
||||
|
||||
|
||||
with mocktime("20101111000000"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --clear-mountpoint --debug".split(" ")).run())
|
||||
self.assertFalse(
|
||||
ZfsAutobackup("test test_target1 --no-progress --verbose --clear-mountpoint --debug".split(" ")).run())
|
||||
|
||||
r=shelltest("zfs get -r canmount test_source1 test_source2 test_target1")
|
||||
self.assertMultiLineEqual(r,"""
|
||||
r = shelltest("zfs get -r canmount test_source1 test_source2 test_target1")
|
||||
self.assertMultiLineEqual(r, """
|
||||
NAME PROPERTY VALUE SOURCE
|
||||
test_source1 canmount on default
|
||||
test_source1/fs1 canmount on default
|
||||
@ -501,61 +500,63 @@ test_target1/test_source2/fs2/sub canmount noauto local
|
||||
test_target1/test_source2/fs2/sub@test-20101111000000 canmount - -
|
||||
""")
|
||||
|
||||
def test_rollback(self):
|
||||
|
||||
def test_rollback(self):
|
||||
|
||||
#initial backup
|
||||
# initial backup
|
||||
with mocktime("20101111000000"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run())
|
||||
|
||||
#make change
|
||||
r=shelltest("touch /test_target1/test_source1/fs1/change.txt")
|
||||
# make change
|
||||
r = shelltest("touch /test_target1/test_source1/fs1/change.txt")
|
||||
|
||||
with mocktime("20101111000001"):
|
||||
#should fail (busy)
|
||||
# should fail (busy)
|
||||
self.assertTrue(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run())
|
||||
|
||||
with mocktime("20101111000002"):
|
||||
#rollback, should succeed
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --rollback".split(" ")).run())
|
||||
# rollback, should succeed
|
||||
self.assertFalse(
|
||||
ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --rollback".split(" ")).run())
|
||||
|
||||
def test_destroyincompat(self):
|
||||
|
||||
def test_destroyincompat(self):
|
||||
|
||||
#initial backup
|
||||
# initial backup
|
||||
with mocktime("20101111000000"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run())
|
||||
|
||||
#add multiple compatible snapshot (written is still 0)
|
||||
r=shelltest("zfs snapshot test_target1/test_source1/fs1@compatible1")
|
||||
r=shelltest("zfs snapshot test_target1/test_source1/fs1@compatible2")
|
||||
# add multiple compatible snapshot (written is still 0)
|
||||
r = shelltest("zfs snapshot test_target1/test_source1/fs1@compatible1")
|
||||
r = shelltest("zfs snapshot test_target1/test_source1/fs1@compatible2")
|
||||
|
||||
with mocktime("20101111000001"):
|
||||
#should be ok, is compatible
|
||||
# should be ok, is compatible
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run())
|
||||
|
||||
#add incompatible snapshot by changing and snapshotting
|
||||
r=shelltest("touch /test_target1/test_source1/fs1/change.txt")
|
||||
r=shelltest("zfs snapshot test_target1/test_source1/fs1@incompatible1")
|
||||
|
||||
# add incompatible snapshot by changing and snapshotting
|
||||
r = shelltest("touch /test_target1/test_source1/fs1/change.txt")
|
||||
r = shelltest("zfs snapshot test_target1/test_source1/fs1@incompatible1")
|
||||
|
||||
with mocktime("20101111000002"):
|
||||
#--test should fail, now incompatible
|
||||
self.assertTrue(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --test".split(" ")).run())
|
||||
# --test should fail, now incompatible
|
||||
self.assertTrue(
|
||||
ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --test".split(" ")).run())
|
||||
|
||||
with mocktime("20101111000002"):
|
||||
#should fail, now incompatible
|
||||
# should fail, now incompatible
|
||||
self.assertTrue(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty".split(" ")).run())
|
||||
|
||||
with mocktime("20101111000003"):
|
||||
#--test should succeed by destroying incompatibles
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --destroy-incompatible --test --debug".split(" ")).run())
|
||||
# --test should succeed by destroying incompatibles
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test test_target1 --no-progress --verbose --allow-empty --destroy-incompatible --test --debug".split(
|
||||
" ")).run())
|
||||
|
||||
with mocktime("20101111000003"):
|
||||
#should succeed by destroying incompatibles
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --destroy-incompatible".split(" ")).run())
|
||||
# should succeed by destroying incompatibles
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test test_target1 --no-progress --verbose --allow-empty --destroy-incompatible".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
|
||||
@ -580,27 +581,27 @@ test_target1/test_source2/fs2/sub@test-20101111000002
|
||||
test_target1/test_source2/fs2/sub@test-20101111000003
|
||||
""")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def test_ssh(self):
|
||||
|
||||
#test all ssh directions
|
||||
# test all ssh directions
|
||||
|
||||
with mocktime("20101111000000"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --ssh-source localhost --exclude-received".split(" ")).run())
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test test_target1 --no-progress --verbose --allow-empty --ssh-source localhost --exclude-received".split(
|
||||
" ")).run())
|
||||
|
||||
with mocktime("20101111000001"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --ssh-target localhost --exclude-received".split(" ")).run())
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test test_target1 --no-progress --verbose --allow-empty --ssh-target localhost --exclude-received".split(
|
||||
" ")).run())
|
||||
|
||||
with mocktime("20101111000002"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --allow-empty --ssh-source localhost --ssh-target localhost".split(" ")).run())
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test test_target1 --no-progress --verbose --allow-empty --ssh-source localhost --ssh-target localhost".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
|
||||
@ -636,33 +637,34 @@ test_target1/test_source2/fs2/sub@test-20101111000001
|
||||
test_target1/test_source2/fs2/sub@test-20101111000002
|
||||
""")
|
||||
|
||||
def test_minchange(self):
|
||||
|
||||
def test_minchange(self):
|
||||
|
||||
#initial
|
||||
# initial
|
||||
with mocktime("20101111000000"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --min-change 100000".split(" ")).run())
|
||||
self.assertFalse(
|
||||
ZfsAutobackup("test test_target1 --no-progress --verbose --min-change 100000".split(" ")).run())
|
||||
|
||||
#make small change, use umount to reflect the changes immediately
|
||||
r=shelltest("zfs set compress=off test_source1")
|
||||
r=shelltest("touch /test_source1/fs1/change.txt")
|
||||
r=shelltest("zfs umount test_source1/fs1; zfs mount test_source1/fs1")
|
||||
# make small change, use umount to reflect the changes immediately
|
||||
r = shelltest("zfs set compress=off test_source1")
|
||||
r = shelltest("touch /test_source1/fs1/change.txt")
|
||||
r = shelltest("zfs umount test_source1/fs1; zfs mount test_source1/fs1")
|
||||
|
||||
|
||||
#too small change, takes no snapshots
|
||||
# too small change, takes no snapshots
|
||||
with mocktime("20101111000001"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --min-change 100000".split(" ")).run())
|
||||
self.assertFalse(
|
||||
ZfsAutobackup("test test_target1 --no-progress --verbose --min-change 100000".split(" ")).run())
|
||||
|
||||
#make big change
|
||||
r=shelltest("dd if=/dev/zero of=/test_source1/fs1/change.txt bs=200000 count=1")
|
||||
r=shelltest("zfs umount test_source1/fs1; zfs mount test_source1/fs1")
|
||||
# make big change
|
||||
r = shelltest("dd if=/dev/zero of=/test_source1/fs1/change.txt bs=200000 count=1")
|
||||
r = shelltest("zfs umount test_source1/fs1; zfs mount test_source1/fs1")
|
||||
|
||||
#bigger change, should take snapshot
|
||||
# bigger change, should take snapshot
|
||||
with mocktime("20101111000002"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --min-change 100000".split(" ")).run())
|
||||
self.assertFalse(
|
||||
ZfsAutobackup("test test_target1 --no-progress --verbose --min-change 100000".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
|
||||
@ -688,14 +690,14 @@ test_target1/test_source2/fs2/sub
|
||||
test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
""")
|
||||
|
||||
def test_test(self):
|
||||
def test_test(self):
|
||||
|
||||
#initial
|
||||
# initial
|
||||
with mocktime("20101111000000"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --test".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/sub
|
||||
@ -707,17 +709,17 @@ test_source2/fs3/sub
|
||||
test_target1
|
||||
""")
|
||||
|
||||
#actual make initial backup
|
||||
# actual make initial backup
|
||||
with mocktime("20101111000001"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose".split(" ")).run())
|
||||
|
||||
|
||||
#test incremental
|
||||
# test incremental
|
||||
with mocktime("20101111000002"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --allow-empty --verbose --test".split(" ")).run())
|
||||
self.assertFalse(
|
||||
ZfsAutobackup("test test_target1 --no-progress --allow-empty --verbose --test".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-20101111000001
|
||||
@ -741,7 +743,6 @@ test_target1/test_source2/fs2/sub
|
||||
test_target1/test_source2/fs2/sub@test-20101111000001
|
||||
""")
|
||||
|
||||
|
||||
def test_migrate(self):
|
||||
"""test migration from other snapshotting systems. zfs-autobackup should be able to continue from any common snapshot, not just its own."""
|
||||
|
||||
@ -752,8 +753,8 @@ test_target1/test_source2/fs2/sub@test-20101111000001
|
||||
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@migrate1
|
||||
@ -783,17 +784,20 @@ test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
"""test if keep-source=0 and keep-target=0 dont delete common snapshot and break backup"""
|
||||
|
||||
with mocktime("20101111000000"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --keep-source=0 --keep-target=0".split(" ")).run())
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test test_target1 --no-progress --verbose --keep-source=0 --keep-target=0".split(" ")).run())
|
||||
|
||||
#make snapshot, shouldnt delete 0
|
||||
# make snapshot, shouldnt delete 0
|
||||
with mocktime("20101111000001"):
|
||||
self.assertFalse(ZfsAutobackup("test --no-progress --verbose --keep-source=0 --keep-target=0 --allow-empty".split(" ")).run())
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test --no-progress --verbose --keep-source=0 --keep-target=0 --allow-empty".split(" ")).run())
|
||||
|
||||
#make snapshot 2, shouldnt delete 0 since it has holds, but will delete 1 since it has no holds
|
||||
# make snapshot 2, shouldnt delete 0 since it has holds, but will delete 1 since it has no holds
|
||||
with mocktime("20101111000002"):
|
||||
self.assertFalse(ZfsAutobackup("test --no-progress --verbose --keep-source=0 --keep-target=0 --allow-empty".split(" ")).run())
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test --no-progress --verbose --keep-source=0 --keep-target=0 --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
|
||||
@ -821,11 +825,13 @@ test_target1/test_source2/fs2/sub
|
||||
test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
""")
|
||||
|
||||
#make another backup but with no-holds. we should naturally endup with only number 3
|
||||
# make another backup but with no-holds. we should naturally endup with only number 3
|
||||
with mocktime("20101111000003"):
|
||||
self.assertFalse(ZfsAutobackup("test test_target1 --no-progress --verbose --keep-source=0 --keep-target=0 --no-holds --allow-empty --debug".split(" ")).run())
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test test_target1 --no-progress --verbose --keep-source=0 --keep-target=0 --no-holds --allow-empty --debug".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
|
||||
@ -850,12 +856,12 @@ test_target1/test_source2/fs2/sub
|
||||
test_target1/test_source2/fs2/sub@test-20101111000003
|
||||
""")
|
||||
|
||||
|
||||
# run with snapshot-only for 4, since we used no-holds, it will delete 3 on the source, breaking the backup
|
||||
with mocktime("20101111000004"):
|
||||
self.assertFalse(ZfsAutobackup("test --no-progress --verbose --keep-source=0 --keep-target=0 --allow-empty".split(" ")).run())
|
||||
self.assertFalse(ZfsAutobackup(
|
||||
"test --no-progress --verbose --keep-source=0 --keep-target=0 --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
|
||||
@ -880,26 +886,23 @@ test_target1/test_source2/fs2/sub
|
||||
test_target1/test_source2/fs2/sub@test-20101111000003
|
||||
""")
|
||||
|
||||
|
||||
def test_progress(self):
|
||||
|
||||
r=shelltest("dd if=/dev/urandom of=/test_source1/data.txt bs=5M count=1")
|
||||
r = shelltest("dd if=/dev/urandom of=/test_source1/data.txt bs=5M count=1")
|
||||
r = shelltest("zfs snapshot test_source1@test")
|
||||
|
||||
l=LogConsole(show_verbose=True, show_debug=True, color=False)
|
||||
n=ZfsNode(utc=False, snapshot_time_format="bla", hold_name="bla", logger=l)
|
||||
d=ZfsDataset(n,"test_source1@test")
|
||||
|
||||
sp=d.send_pipe([], prev_snapshot=None, resume_token=None, show_progress=True, raw=False, send_pipes=[], send_properties=True, write_embedded=True, zfs_compressed=True)
|
||||
|
||||
|
||||
l = LogConsole(show_verbose=True, show_debug=True, color=False)
|
||||
n = ZfsNode(utc=False, snapshot_time_format="bla", hold_name="bla", logger=l)
|
||||
d = ZfsDataset(n, "test_source1@test")
|
||||
|
||||
sp = d.send_pipe([], prev_snapshot=None, resume_token=None, show_progress=True, raw=False, send_pipes=[],
|
||||
send_properties=True, write_embedded=True, zfs_compressed=True)
|
||||
|
||||
with OutputIO() as buf:
|
||||
with redirect_stderr(buf):
|
||||
try:
|
||||
|
||||
p=n.run(["mbuffer", "-R1M", "-m4096", "-o" ,"/dev/null"], inp=sp)
|
||||
p = n.run(["mbuffer", "-R1M", "-m4096", "-o", "/dev/null"], inp=sp)
|
||||
# p=n.run(["dd", "of=/dev/null"], inp=sp)
|
||||
|
||||
except:
|
||||
@ -907,4 +910,4 @@ test_target1/test_source2/fs2/sub@test-20101111000003
|
||||
|
||||
print(list(buf.getvalue()))
|
||||
# correct message?
|
||||
self.assertRegex(buf.getvalue(),".*>>> .*minutes left.*")
|
||||
self.assertRegex(buf.getvalue(), ".*>>> .*minutes left.*")
|
||||
|
@ -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 @@ test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000001
|
||||
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 @@ test_target1/b/test_target1/a/test_source2@test-20101111000001
|
||||
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 @@ test_target1/b/test_target1/a/test_source2/fs2/sub@test-20101111000001
|
||||
|
||||
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 @@ test_target1/fs2/sub@test-20101111000000
|
||||
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 @@ test_target1/fs2/sub@test-20101111000000
|
||||
self.assertMultiLineEqual(r, """
|
||||
test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
""")
|
||||
|
||||
|
@ -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 @@ test_target1/test_source2/fs2/sub@test-20101111000001
|
||||
""")
|
||||
|
||||
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())
|
||||
# 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,"""
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000000
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000001
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000001
|
||||
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())
|
||||
"""
|
||||
[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,"""
|
||||
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 @@ test_target1/test_source1/fs1/sub@test2-20010201000000
|
||||
test_target1/test_source1/fs1/sub@other2
|
||||
test_target1/test_source1/fs1/sub@test2-20010203000000
|
||||
""")
|
||||
|
||||
|
||||
|
@ -57,7 +57,7 @@ class TestZfsAutobackup34(unittest2.TestCase):
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000002
|
||||
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 @@ test_source1/fs1/sub#test-20101111000001
|
||||
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 @@ test_source1/fs1/sub@test-20101111000002
|
||||
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 @@ test_target1/test_source2/fs2/sub@test-20101111000003
|
||||
|
||||
# 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
|
||||
|
@ -9,7 +9,6 @@ class TestZfsCheck(unittest2.TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
|
||||
def test_volume(self):
|
||||
|
||||
if exists("/.dockerenv"):
|
||||
@ -23,23 +22,26 @@ class TestZfsCheck(unittest2.TestCase):
|
||||
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 @@ class TestZfsCheck(unittest2.TestCase):
|
||||
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 @@ class TestZfsCheck(unittest2.TestCase):
|
||||
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 @@ dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798
|
||||
|
||||
# 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 @@ dir/testfile 0 2e863f1fcccd6642e4e28453eba10d2d3f74d798
|
||||
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 @@ whole_whole2_partial 0 309ffffba2e1977d12f3b7469971f30d28b94bdX
|
||||
|
||||
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 @@ whole_whole2_partial: Chunk 0 failed: 309ffffba2e1977d12f3b7469971f30d28b94bdX 3
|
||||
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 @@ whole_whole2_partial 0 309ffffba2e1977d12f3b7469971f30d28b94bd8
|
||||
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 @@ whole_whole2_partial 0 309ffffba2e1977d12f3b7469971f30d28b94bd8
|
||||
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 @@ test_source2/fs2/sub
|
||||
test_source2/fs3
|
||||
test_source2/fs3/sub
|
||||
test_target1
|
||||
""",r )
|
||||
|
||||
|
||||
|
||||
""", r)
|
||||
|
@ -12,13 +12,15 @@ class TestZfsNode(unittest2.TestCase):
|
||||
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 @@ test_target1
|
||||
""")
|
||||
|
||||
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 @@ test_target1
|
||||
""")
|
||||
|
||||
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 @@ test_target1
|
||||
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 @@ test_target1
|
||||
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 @@ test_target1
|
||||
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 @@ test_target1
|
||||
# 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 @@ test_target1
|
||||
|
||||
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 @@ test_target1
|
||||
(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 @@ test_target1
|
||||
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 @@ test_target1
|
||||
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)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user