From 138c913e58f6a047da9388a44deee53bc6b3bff8 Mon Sep 17 00:00:00 2001 From: Edwin Eefting Date: Sun, 17 May 2020 16:59:46 +0200 Subject: [PATCH] close open filehandles. more tests --- basetest.py | 4 ++++ bin/zfs-autobackup | 5 ++++- run_tests | 8 +++++--- test_zfsautobackup.py | 11 +++++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 test_zfsautobackup.py diff --git a/basetest.py b/basetest.py index 779c9ee..c402cea 100644 --- a/basetest.py +++ b/basetest.py @@ -1,3 +1,5 @@ + + import subprocess import random @@ -9,6 +11,8 @@ from pprint import * from bin.zfs_autobackup import * + + def shelltest(cmd): """execute and print result as nice copypastable string for unit tests (adds extra newlines on top/bottom)""" ret=(subprocess.check_output(cmd , shell=True).decode('utf-8')) diff --git a/bin/zfs-autobackup b/bin/zfs-autobackup index 9c106a6..6c9f49f 100755 --- a/bin/zfs-autobackup +++ b/bin/zfs-autobackup @@ -435,12 +435,16 @@ class ExecuteNode(Logger): if p.poll()!=None and ((not isinstance(input, subprocess.Popen)) or input.poll()!=None) and eof_count==len(selectors): break + p.stderr.close() + p.stdout.close() if self.debug_output: self.debug("EXIT > {}".format(p.returncode)) #handle piped process error output and exit codes if isinstance(input, subprocess.Popen): + input.stderr.close() + input.stdout.close() if self.debug_output: self.debug("EXIT |> {}".format(input.returncode)) @@ -450,7 +454,6 @@ class ExecuteNode(Logger): if valid_exitcodes and p.returncode not in valid_exitcodes: raise(subprocess.CalledProcessError(p.returncode, encoded_cmd)) - if return_stderr: return ( output_lines, error_lines ) diff --git a/run_tests b/run_tests index aa00670..b5cbd9a 100755 --- a/run_tests +++ b/run_tests @@ -9,7 +9,7 @@ fi source $VIRTUAL_ENV/bin/activate || true # test needs ssh access to localhost for testing -if ! [ -t /root/.ssh/id_rsa ]; then +if ! [ -e /root/.ssh/id_rsa ]; then ssh-keygen -t rsa -f /root/.ssh/id_rsa -P '' || exit 1 cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys || exit 1 ssh -oStrictHostKeyChecking=no localhost true || exit 1 @@ -22,7 +22,9 @@ echo coverage report #this does automatic travis CI/https://coveralls.io/ intergration: -echo "Submitting to coveralls.io:" -coveralls +if which coveralls > /dev/null; then + echo "Submitting to coveralls.io:" + coveralls +fi exit $EXIT diff --git a/test_zfsautobackup.py b/test_zfsautobackup.py new file mode 100644 index 0000000..21e4aaa --- /dev/null +++ b/test_zfsautobackup.py @@ -0,0 +1,11 @@ +from basetest import * + + +class TestZfsAutobackup(unittest.TestCase): + + def setUp(self): + prepare_zpools() + return super().setUp() + + def test_defaults(self): + self.assertFalse(ZfsAutobackup("test test_target1".split(" ")).run())