From b22113aad4753c88efd77e2d3beaab77b0844660 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Thu, 14 May 2020 18:17:00 +0200 Subject: [PATCH] cleanup tests --- basetest.py | 36 ++++++++++++++++++++++++++++++++ bin/zfs-autobackup | 6 +++--- run_tests | 2 +- test_executenode.py | 7 +------ test_thinner.py | 10 +-------- test_zfsnode.py | 51 ++++++++++++++++----------------------------- 6 files changed, 60 insertions(+), 52 deletions(-) create mode 100644 basetest.py diff --git a/basetest.py b/basetest.py new file mode 100644 index 0000000..4c86344 --- /dev/null +++ b/basetest.py @@ -0,0 +1,36 @@ +import subprocess +import random + +#default test stuff +import unittest +import subprocess +import time +from pprint import * +from bin.zfs_autobackup import * + + +def prepare_zpools(): + print("Preparing zfs filesystems...") + + #need ram blockdevice + # subprocess.call("rmmod brd", shell=True) + subprocess.check_call("modprobe brd rd_size=512000", shell=True) + + #remove old stuff + subprocess.call("zpool destroy test_source1", shell=True) + subprocess.call("zpool destroy test_source2", shell=True) + subprocess.call("zpool destroy test_target1", shell=True) + + #create pools + subprocess.check_call("zpool create test_source1 /dev/ram0", shell=True) + subprocess.check_call("zpool create test_source2 /dev/ram1", shell=True) + subprocess.check_call("zpool create test_target1 /dev/ram2", shell=True) + + #create test structure + subprocess.check_call("zfs create -p test_source1/fs1/sub", shell=True) + subprocess.check_call("zfs create -p test_source2/fs2/sub", shell=True) + subprocess.check_call("zfs create -p test_source2/fs3/sub", shell=True) + subprocess.check_call("zfs set autobackup:test=true test_source1/fs1", shell=True) + subprocess.check_call("zfs set autobackup:test=child test_source2/fs2", shell=True) + + print("Prepare done") diff --git a/bin/zfs-autobackup b/bin/zfs-autobackup index 9316630..9c106a6 100755 --- a/bin/zfs-autobackup +++ b/bin/zfs-autobackup @@ -1418,7 +1418,7 @@ class ZfsNode(ExecuteNode): class ZfsAutobackup: """main class""" - def __init__(self): + def __init__(self,argv): parser = argparse.ArgumentParser( description=HEADER, @@ -1465,7 +1465,7 @@ class ZfsAutobackup: parser.add_argument('--progress', action='store_true', help='show zfs progress output (to stderr). Enabled by default on ttys.') #note args is the only global variable we use, since its a global readonly setting anyway - args = parser.parse_args() + args = parser.parse_args(argv) self.args=args @@ -1624,5 +1624,5 @@ class ZfsAutobackup: if __name__ == "__main__": - zfs_autobackup=ZfsAutobackup() + zfs_autobackup=ZfsAutobackup(sys.argv) sys.exit(zfs_autobackup.run()) diff --git a/run_tests b/run_tests index 98939cd..71a77a5 100755 --- a/run_tests +++ b/run_tests @@ -1,3 +1,3 @@ #!/bin/bash -coverage run --source bin.zfs_autobackup -m unittest ; coverage report +coverage run --source bin.zfs_autobackup -m unittest -v $@; coverage report diff --git a/test_executenode.py b/test_executenode.py index ff205df..a0cd4ae 100644 --- a/test_executenode.py +++ b/test_executenode.py @@ -1,10 +1,5 @@ +from basetest import * -#default test stuff -import unittest -from bin.zfs_autobackup import * - -import subprocess -import time print("THIS TEST REQUIRES SSH TO LOCALHOST") diff --git a/test_thinner.py b/test_thinner.py index f12abf9..c9da816 100644 --- a/test_thinner.py +++ b/test_thinner.py @@ -1,13 +1,5 @@ +from basetest import * -#default test stuff -import unittest -from bin.zfs_autobackup import * - -#test specific -import random -import sys -import time -import pprint class Thing: def __init__(self, timestamp): diff --git a/test_zfsnode.py b/test_zfsnode.py index 5943fc1..9f1adee 100644 --- a/test_zfsnode.py +++ b/test_zfsnode.py @@ -1,43 +1,26 @@ +from basetest import * -#default test stuff -import unittest -from bin.zfs_autobackup import * - -import subprocess -import time -from pprint import pformat class TestZfsNode(unittest.TestCase): def setUp(self): - print("Preparing zfs filesystems...") - - #need ram blockdevice - # subprocess.call("rmmod brd", shell=True) - subprocess.check_call("modprobe brd rd_size=512000", shell=True) - - #remove old stuff - subprocess.call("zpool destroy test_source1", shell=True) - subprocess.call("zpool destroy test_source2", shell=True) - subprocess.call("zpool destroy test_target1", shell=True) - - #create pools - subprocess.check_call("zpool create test_source1 /dev/ram0", shell=True) - subprocess.check_call("zpool create test_source2 /dev/ram1", shell=True) - subprocess.check_call("zpool create test_target1 /dev/ram2", shell=True) - - #create test structure - subprocess.check_call("zfs create -p test_source1/fs1/sub", shell=True) - subprocess.check_call("zfs create -p test_source2/fs2/sub", shell=True) - subprocess.check_call("zfs create -p test_source2/fs3/sub", shell=True) - subprocess.check_call("zfs set autobackup:test=true test_source1/fs1", shell=True) - subprocess.check_call("zfs set autobackup:test=child test_source2/fs2", shell=True) - - print("Prepare done") - + prepare_zpools() return super().setUp() + def test_consistent_snapshot(self): + logger=Logger() + description="[Source]" + node=ZfsNode("test", logger, description=description) + + with self.subTest("### no changes, no snapshot"): + node.consistent_snapshot(node.selected_datasets, "snap1", 100000) + s=pformat(subprocess.check_call("zfs list -r -t all" , shell=True)) + print(s) + + + + def test_getselected(self): logger=Logger() @@ -51,7 +34,7 @@ class TestZfsNode(unittest.TestCase): (local): test_source1/fs1/sub, (local): test_source2/fs2/sub]""") - #caching, so expect same result + #caching, so expect same result after changing it subprocess.check_call("zfs set autobackup:test=true test_source2/fs3", shell=True) self.assertEqual (s, """[(local): test_source1/fs1, (local): test_source1/fs1/sub, @@ -59,5 +42,7 @@ class TestZfsNode(unittest.TestCase): + + if __name__ == '__main__': unittest.main() \ No newline at end of file