diff options
Diffstat (limited to 'rdiff-backup/testing')
-rw-r--r-- | rdiff-backup/testing/commontest.py | 23 | ||||
-rw-r--r-- | rdiff-backup/testing/finaltest.py | 11 | ||||
-rw-r--r-- | rdiff-backup/testing/hardlinktest.py | 24 | ||||
-rw-r--r-- | rdiff-backup/testing/regressiontest.py | 16 | ||||
-rw-r--r-- | rdiff-backup/testing/robusttest.py | 36 | ||||
-rw-r--r-- | rdiff-backup/testing/roottest.py | 66 |
6 files changed, 91 insertions, 85 deletions
diff --git a/rdiff-backup/testing/commontest.py b/rdiff-backup/testing/commontest.py index c527e83..8bd0f53 100644 --- a/rdiff-backup/testing/commontest.py +++ b/rdiff-backup/testing/commontest.py @@ -112,14 +112,7 @@ def InternalMirror(source_local, dest_local, src_dir, dest_dir): src_root = rpath.RPath(Globals.local_connection, src_dir) dest_root = rpath.RPath(Globals.local_connection, dest_dir) dest_rbdir = dest_root.append("rdiff-backup-data") - dest_incdir = dest_rbdir.append("increments") - # We need to create these directories or else failure because - # --force option not given. - if not dest_root.lstat(): dest_root.mkdir() - if not dest_rbdir.lstat(): dest_rbdir.mkdir() - if not dest_incdir.lstat(): dest_incdir.mkdir() - InternalBackup(source_local, dest_local, src_dir, dest_dir) dest_root.setdata() Myrm(dest_rbdir.path) @@ -173,7 +166,7 @@ def _reset_connections(src_rp, dest_rp): def CompareRecursive(src_rp, dest_rp, compare_hardlinks = 1, equality_func = None, exclude_rbdir = 1, - ignore_tmp_files = None): + ignore_tmp_files = None, compare_ownership = 0): """Compare src_rp and dest_rp, which can be directories This only compares file attributes, not the actual data. This @@ -218,7 +211,9 @@ def CompareRecursive(src_rp, dest_rp, compare_hardlinks = 1, dsiter1, dsiter2 = src_select.set_iter(), dest_select.set_iter() def hardlink_equal(src_rorp, dest_rorp): - if not src_rorp.equal_verbose(dest_rorp): return None + if not src_rorp.equal_verbose(dest_rorp, + compare_ownership = compare_ownership): + return None if Hardlink.rorp_eq(src_rorp, dest_rorp): return 1 Log("%s: %s" % (src_rorp.index, Hardlink.get_indicies(src_rorp, 1)), 3) Log("%s: %s" % (dest_rorp.index, @@ -240,7 +235,9 @@ def CompareRecursive(src_rp, dest_rp, compare_hardlinks = 1, if dest_rorp.index[-1].endswith('.missing'): return 1 if compare_hardlinks: if Hardlink.rorp_eq(src_rorp, dest_rorp): return 1 - elif src_rorp.equal_verbose(dest_rorp): return 1 + elif src_rorp.equal_verbose(dest_rorp, + compare_ownership = compare_ownership): + return 1 Log("%s: %s" % (src_rorp.index, Hardlink.get_indicies(src_rorp, 1)), 3) Log("%s: %s" % (dest_rorp.index, Hardlink.get_indicies(dest_rorp, None)), 3) @@ -256,7 +253,8 @@ def CompareRecursive(src_rp, dest_rp, compare_hardlinks = 1, else: result = lazy.Iter.equal(dsiter1, dsiter2, 1, rbdir_equal) elif not exclude_rbdir: result = lazy.Iter.equal(dsiter1, dsiter2, 1, rbdir_equal) - else: result = lazy.Iter.equal(dsiter1, dsiter2, 1) + else: result = lazy.Iter.equal(dsiter1, dsiter2, 1, + lambda x, y: x.equal_verbose(y, compare_ownership = compare_ownership)) for i in dsiter1: pass # make sure all files processed anyway for i in dsiter2: pass @@ -321,6 +319,8 @@ def MirrorTest(source_local, dest_local, list_of_dirnames, """Mirror each of list_of_dirnames, and compare after each""" Globals.set('preserve_hardlinks', compare_hardlinks) dest_rp = rpath.RPath(Globals.local_connection, dest_dirname) + old_force_val = Main.force + Main.force = 1 Myrm(dest_dirname) for dirname in list_of_dirnames: @@ -331,3 +331,4 @@ def MirrorTest(source_local, dest_local, list_of_dirnames, InternalMirror(source_local, dest_local, dirname, dest_dirname) _reset_connections(src_rp, dest_rp) assert CompareRecursive(src_rp, dest_rp, compare_hardlinks) + Main.force = old_force_val diff --git a/rdiff-backup/testing/finaltest.py b/rdiff-backup/testing/finaltest.py index 44a8a2a..7945eb5 100644 --- a/rdiff-backup/testing/finaltest.py +++ b/rdiff-backup/testing/finaltest.py @@ -42,8 +42,9 @@ class PathSetter(unittest.TestCase): self.reset_schema() def reset_schema(self): - self.rb_schema = SourceDir + \ - "/../rdiff-backup -v5 --remote-schema './chdir-wrapper2 %s' " + self.rb_schema = (SourceDir + + "/../rdiff-backup -v3 --no-compare-inode " + "--remote-schema './chdir-wrapper2 %s' ") def refresh(self, *rp_list): """Reread data for the given rps""" @@ -215,6 +216,12 @@ class Final(PathSetter): self.set_connections(None, None, "test2/tmp/", "../../") self.exec_rb(None, '../../../../../../proc', 'testfiles/procoutput') + def testProcRemote2(self): + """Test mirroring proc, this time when proc is remote, dest local""" + Myrm("testfiles/procoutput") + self.set_connections("test1/", "../", None, None) + self.exec_rb(None, '../../../../../../proc', 'testfiles/procoutput') + def testWindowsMode(self): """Test backup with the --windows-mode option""" old_schema = self.rb_schema diff --git a/rdiff-backup/testing/hardlinktest.py b/rdiff-backup/testing/hardlinktest.py index a675e8a..22dc31d 100644 --- a/rdiff-backup/testing/hardlinktest.py +++ b/rdiff-backup/testing/hardlinktest.py @@ -2,7 +2,7 @@ import os, unittest, time from commontest import * from rdiff_backup import Globals, Hardlink, selection, rpath -Log.setverbosity(7) +Log.setverbosity(3) class HardlinkTest(unittest.TestCase): """Test cases for Hard links""" @@ -142,10 +142,27 @@ class HardlinkTest(unittest.TestCase): hl2_4.hardlink(hl2_1.path) rpath.copy_attribs(hlout1_sub, hlout2_sub) + # Now try backing up twice, making sure hard links are preserved InternalBackup(1, 1, hlout1.path, output.path) + out_subdir = output.append("subdir") + assert out_subdir.append("hardlink1").getinode() == \ + out_subdir.append("hardlink2").getinode() + assert out_subdir.append("hardlink3").getinode() == \ + out_subdir.append("hardlink4").getinode() + assert out_subdir.append("hardlink1").getinode() != \ + out_subdir.append("hardlink3").getinode() + time.sleep(1) InternalBackup(1, 1, hlout2.path, output.path) - + out_subdir.setdata() + assert out_subdir.append("hardlink1").getinode() == \ + out_subdir.append("hardlink4").getinode() + assert out_subdir.append("hardlink2").getinode() == \ + out_subdir.append("hardlink3").getinode() + assert out_subdir.append("hardlink1").getinode() != \ + out_subdir.append("hardlink2").getinode() + + # Now try restoring, still checking hard links. out2 = rpath.RPath(Globals.local_connection, "testfiles/out2") hlout1 = out2.append("hardlink1") hlout2 = out2.append("hardlink2") @@ -165,7 +182,8 @@ class HardlinkTest(unittest.TestCase): int(time.time())) out2.setdata() for rp in [hlout1, hlout2, hlout3, hlout4]: rp.setdata() - assert hlout1.getinode() == hlout4.getinode() + assert hlout1.getinode() == hlout4.getinode(), \ + "%s %s" % (hlout1.path, hlout4.path) assert hlout2.getinode() == hlout3.getinode() assert hlout1.getinode() != hlout2.getinode() diff --git a/rdiff-backup/testing/regressiontest.py b/rdiff-backup/testing/regressiontest.py index 5c55986..e0eeeaf 100644 --- a/rdiff-backup/testing/regressiontest.py +++ b/rdiff-backup/testing/regressiontest.py @@ -245,21 +245,15 @@ class MirrorTest(PathSetter): def testPermSkipLocal(self): """Test to see if rdiff-backup will skip unreadable files""" self.setPathnames(None, None, None, None) - Globals.change_source_perms = None Time.setcurtime() self.Mirror(self.one_unreadable, self.one_unreadable_out) - Globals.change_source_perms = 1 - self.Mirror(self.one_unreadable, self.one_unreadable_out) # Could add test, but for now just make sure it doesn't exit def testPermSkipRemote(self): """Test skip of unreadable files remote""" self.setPathnames('test1', '../', 'test2/tmp', '../../') - Globals.change_source_perms = None Time.setcurtime() self.Mirror(self.one_unreadable, self.one_unreadable_out) - Globals.change_source_perms = 1 - self.Mirror(self.one_unreadable, self.one_unreadable_out) # Could add test, but for now just make sure it doesn't exit def refresh(self, *rps): @@ -294,8 +288,6 @@ class MirrorTest(PathSetter): def deleteoutput(self): assert not os.system("rm -rf testfiles/output*") self.rbdir = self.rpout.append('rdiff-backup-data') - self.rpout.mkdir() - self.rbdir.mkdir() self.reset_rps() def reset_rps(self): @@ -309,8 +301,9 @@ class MirrorTest(PathSetter): rp.setdata() def runtest(self): + self.deleteoutput() Time.setcurtime() - assert self.rbdir.lstat() + assert not self.rbdir.lstat() self.Mirror(self.inc1rp, self.rpout) assert CompareRecursive(Local.inc1rp, Local.rpout) @@ -328,6 +321,7 @@ class MirrorTest(PathSetter): self.Mirror(self.inc1rp, self.rpout) #rpath.RPath.copy_attribs(self.inc1rp, self.rpout) assert CompareRecursive(Local.inc1rp, Local.rpout) + Myrm(Local.rpout.append("rdiff-backup-data").path) self.Mirror(self.inc2rp, self.rpout) assert CompareRecursive(Local.inc2rp, Local.rpout) @@ -335,11 +329,13 @@ class MirrorTest(PathSetter): def Mirror(self, rpin, rpout): """Like backup.Mirror, but setup first, cleanup later""" Main.force = 1 + assert not rpout.append("rdiff-backup-data").lstat() Main.misc_setup([rpin, rpout]) Main.backup_set_select(rpin) Main.backup_init_dirs(rpin, rpout) backup.Mirror(rpin, rpout) - Log.close_logfile() + log.ErrorLog.close() + log.Log.close_logfile() Hardlink.clear_dictionaries() if __name__ == "__main__": unittest.main() diff --git a/rdiff-backup/testing/robusttest.py b/rdiff-backup/testing/robusttest.py index 6b9e356..17b4ac2 100644 --- a/rdiff-backup/testing/robusttest.py +++ b/rdiff-backup/testing/robusttest.py @@ -4,42 +4,6 @@ from commontest import * from rdiff_backup import rpath, robust, TempFile, Globals -class TempFileTest(unittest.TestCase): - """Test creation and management of tempfiles in TempFile module""" - rp_base = rpath.RPath(Globals.local_connection, - "./testfiles/robust/testfile_base") - def testBasic(self): - """Make a temp file, write to it, and then delete it - - Also test tempfile accounting and file name prefixing. - - """ - assert not TempFile._tempfiles - tf = TempFile.new(self.rp_base) - assert TempFile._tempfiles == [tf] - assert tf.dirsplit()[0] == "testfiles/robust", tf.dirsplit()[0] - assert not tf.lstat() - fp = tf.open("w") - fp.write("hello") - assert not fp.close() - fp = tf.open("r") - assert fp.read() == "hello" - assert not fp.close() - tf.delete() - assert not TempFile._tempfiles - - def testRename(self): - """Test renaming of tempfile""" - tf = TempFile.new(self.rp_base) - assert TempFile._tempfiles - tf.touch() - destination = rpath.RPath(Globals.local_connection, - "./testfiles/robust/testfile_dest") - tf.rename(destination) - assert not TempFile._tempfiles - assert destination.lstat() - destination.delete() - class RobustTest(unittest.TestCase): """Test robust module""" def test_check_common_error(self): diff --git a/rdiff-backup/testing/roottest.py b/rdiff-backup/testing/roottest.py index 81292b2..6193893 100644 --- a/rdiff-backup/testing/roottest.py +++ b/rdiff-backup/testing/roottest.py @@ -10,7 +10,7 @@ that are meant to be run as root. Globals.set('change_source_perms', None) Globals.counter = 0 -log.Log.setverbosity(4) +log.Log.setverbosity(6) def Run(cmd): print "Running: ", cmd @@ -33,9 +33,9 @@ class NonRoot(unittest.TestCase): """ user = 'ben' - def make_root_dir(self): + def make_root_dirs(self): """Make directory createable only by root""" - rp = rpath.RPath(Globals.local_connection, "testfiles/root_out") + rp = rpath.RPath(Globals.local_connection, "testfiles/root_out1") if rp.lstat(): Myrm(rp.path) rp.mkdir() rp1 = rp.append("1") @@ -48,39 +48,59 @@ class NonRoot(unittest.TestCase): rp3.chown(2, 2) rp4 = rp.append("dev") rp4.makedev('c', 4, 28) - return rp + + sp = rpath.RPath(Globals.local_connection, "testfiles/root_out2") + if sp.lstat(): Myrm(sp.path) + Run("cp -a %s %s" % (rp.path, sp.path)) + rp2 = sp.append("2") + rp2.chown(2, 2) + rp3 = sp.append("3") + rp3.chown(1, 1) + assert not CompareRecursive(rp, sp, compare_ownership = 1) + + return rp, sp + + def backup(self, input_rp, output_rp, time): + backup_cmd = ("rdiff-backup --no-compare-inode " + "--current-time %s %s %s" % + (time, input_rp.path, output_rp.path)) + Run("su %s -c '%s'" % (self.user, backup_cmd)) + + def restore(self, dest_rp, restore_rp, time = None): + assert restore_rp.path == "testfiles/rest_out" + Myrm(restore_rp.path) + if time is None: time = "now" + restore_cmd = "rdiff-backup -r %s %s %s" % (time, dest_rp.path, + restore_rp.path,) + Run(restore_cmd) def test_non_root(self): """Main non-root -> root test""" Myrm("testfiles/output") - input_rp = self.make_root_dir() + input_rp1, input_rp2 = self.make_root_dirs() Globals.change_ownership = 1 output_rp = rpath.RPath(Globals.local_connection, "testfiles/output") restore_rp = rpath.RPath(Globals.local_connection, "testfiles/rest_out") empty_rp = rpath.RPath(Globals.local_connection, "testfiles/empty") - backup_cmd = "rdiff-backup %s %s" % (input_rp.path, output_rp.path) - Run("su %s -c '%s'" % (self.user, backup_cmd)) + self.backup(input_rp1, output_rp, 1000000) + self.restore(output_rp, restore_rp) + assert CompareRecursive(input_rp1, restore_rp, compare_ownership = 1) - Myrm("testfiles/rest_out") - restore_cmd = "rdiff-backup -r now %s %s" % (output_rp.path, - restore_rp.path,) - Run(restore_cmd) - assert CompareRecursive(input_rp, restore_rp) + self.backup(input_rp2, output_rp, 2000000) + self.restore(output_rp, restore_rp) + assert CompareRecursive(input_rp2, restore_rp, compare_ownership = 1) - backup_cmd = "rdiff-backup %s %s" % (empty_rp.path, output_rp.path) - Run("su %s -c '%s'" % (self.user, backup_cmd)) + self.backup(empty_rp, output_rp, 3000000) + self.restore(output_rp, restore_rp) + assert CompareRecursive(empty_rp, restore_rp, compare_ownership = 1) + + self.restore(output_rp, restore_rp, 1000000) + assert CompareRecursive(input_rp1, restore_rp, compare_ownership = 1) - Myrm("testfiles/rest_out") - Run(restore_cmd) - assert CompareRecursive(empty_rp, restore_rp) + self.restore(output_rp, restore_rp, 2000000) + assert CompareRecursive(input_rp2, restore_rp, compare_ownership = 1) - Myrm("testfiles/rest_out") - restore_cmd = "rdiff-backup -r 1 %s %s" % (output_rp.path, - restore_rp.path,) - Run(restore_cmd) - assert CompareRecursive(input_rp, restore_rp) - if __name__ == "__main__": unittest.main() |