Skip to content

Commit

Permalink
dont list bookmarks in existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
psy0rz committed Oct 8, 2024
1 parent d79d6af commit cf541c5
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 361 deletions.
87 changes: 44 additions & 43 deletions tests/test_destroymissing.py
Original file line number Diff line number Diff line change
@@ -1,130 +1,131 @@

from basetest import *


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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_encryption.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 - -
Expand Down
12 changes: 6 additions & 6 deletions tests/test_externalfailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions tests/test_sendrecvpipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand All @@ -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
Expand Down
Loading

0 comments on commit cf541c5

Please sign in to comment.