From b81f5c4c0a2dec44833b1ef2db7beb0ef653fa86 Mon Sep 17 00:00:00 2001 From: bescoto Date: Mon, 31 May 2004 21:48:15 +0000 Subject: Added ownership test to roottest.py git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@548 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109 --- rdiff-backup/testing/commontest.py | 16 +++++++++-- rdiff-backup/testing/regressiontest.py | 7 ----- rdiff-backup/testing/roottest.py | 50 ++++++++++++++++++++++++++-------- rdiff-backup/testing/statisticstest.py | 2 +- 4 files changed, 52 insertions(+), 23 deletions(-) (limited to 'rdiff-backup') diff --git a/rdiff-backup/testing/commontest.py b/rdiff-backup/testing/commontest.py index de2b64e..636ce51 100644 --- a/rdiff-backup/testing/commontest.py +++ b/rdiff-backup/testing/commontest.py @@ -19,6 +19,13 @@ def Myrm(dirstring): if rp.isdir(): rp.chmod(0700) # otherwise may not be able to remove assert not os.system("rm -rf %s" % (dirstring,)) +def re_init_dir(rp): + """Delete directory if present, then recreate""" + if rp.lstat(): + Myrm(rp.path) + rp.setdata() + rp.mkdir() + def Make(): """Make sure the rdiff-backup script in the source dir is up-to-date""" os.chdir(SourceDir) @@ -298,7 +305,8 @@ def BackupRestoreSeries(source_local, dest_local, list_of_dirnames, restore_dirname = "testfiles/rest_out", compare_backups = 1, compare_eas = 0, - compare_acls = 0): + compare_acls = 0, + compare_ownership = 0): """Test backing up/restoring of a series of directories The dirnames correspond to a single directory at different times. @@ -325,7 +333,8 @@ def BackupRestoreSeries(source_local, dest_local, list_of_dirnames, if compare_backups: assert CompareRecursive(src_rp, dest_rp, compare_hardlinks, compare_eas = compare_eas, - compare_acls = compare_acls) + compare_acls = compare_acls, + compare_ownership = compare_ownership) time = 10000 for dirname in list_of_dirnames[:-1]: @@ -337,7 +346,8 @@ def BackupRestoreSeries(source_local, dest_local, list_of_dirnames, src_rp = rpath.RPath(Globals.local_connection, dirname) assert CompareRecursive(src_rp, restore_rp, compare_eas = compare_eas, - compare_acls = compare_acls) + compare_acls = compare_acls, + compare_ownership = compare_ownership) # Restore should default back to newest time older than it # with a backup then. diff --git a/rdiff-backup/testing/regressiontest.py b/rdiff-backup/testing/regressiontest.py index a0c4a3d..18ec1a3 100644 --- a/rdiff-backup/testing/regressiontest.py +++ b/rdiff-backup/testing/regressiontest.py @@ -17,13 +17,6 @@ log.Log.setverbosity(7) def get_local_rp(extension): return rpath.RPath(Globals.local_connection, "testfiles/" + extension) -def re_init_dir(rp): - """Delete directory if present, then recreate""" - if rp.lstat(): - Myrm(rp.path) - rp.setdata() - rp.mkdir() - class Local: """This is just a place to put increments relative to the local connection""" diff --git a/rdiff-backup/testing/roottest.py b/rdiff-backup/testing/roottest.py index 171321e..11da994 100644 --- a/rdiff-backup/testing/roottest.py +++ b/rdiff-backup/testing/roottest.py @@ -22,12 +22,42 @@ def Run(cmd): assert not os.system(cmd) class RootTest(unittest.TestCase): - dirlist1 = ["testfiles/root", "testfiles/various_file_types", "testfiles/increment4"] + dirlist1 = ["testfiles/root", "testfiles/various_file_types", + "testfiles/increment4"] dirlist2 = ["testfiles/increment4", "testfiles/root", "testfiles/increment1"] - def testLocal1(self): BackupRestoreSeries(1, 1, self.dirlist1) - def testLocal2(self): BackupRestoreSeries(1, 1, self.dirlist2) - def testRemote(self): BackupRestoreSeries(None, None, self.dirlist1) + def testLocal1(self): + BackupRestoreSeries(1, 1, self.dirlist1, compare_ownership = 1) + def testLocal2(self): + BackupRestoreSeries(1, 1, self.dirlist2, compare_ownership = 1) + def testRemote(self): + BackupRestoreSeries(None, None, self.dirlist1, compare_ownership = 1) + + def test_ownership(self): + """Test backing up and restoring directory with different uids + + This checks for a bug in 0.13.4 where uids and gids would not + be restored correctly. + + """ + dirrp = rpath.RPath(Globals.local_connection, "testfiles/root_owner") + def make_dir(): + re_init_dir(dirrp) + rp1 = dirrp.append('file1') + rp2 = dirrp.append('file2') + rp3 = dirrp.append('file3') + rp4 = dirrp.append('file4') + rp1.touch() + rp2.touch() + rp3.touch() + rp4.touch() + rp1.chown(2000, 2000) + rp2.chown(2001, 2001) + rp3.chown(2002, 2002) + rp4.chown(2003, 2003) + make_dir() + BackupRestoreSeries(1, 1, ['testfiles/root_owner', 'testfiles/empty'], + compare_ownership = 1) def test_ownership_mapping(self): """Test --user-mapping-file and --group-mapping-file options""" @@ -35,8 +65,7 @@ class RootTest(unittest.TestCase): """Write the directory testfiles/root_mapping""" rp = rpath.RPath(Globals.local_connection, "testfiles/root_mapping") - if rp.lstat(): Myrm(rp.path) - rp.mkdir() + re_init_dir(rp) rp1 = rp.append('1') rp1.touch() rp2 = rp.append('2') @@ -83,8 +112,7 @@ class HalfRoot(unittest.TestCase): """ rp1 = rpath.RPath(Globals.local_connection, "testfiles/root_half1") - if rp1.lstat(): Myrm(rp1.path) - rp1.mkdir() + re_init_dir(rp1) rp1_1 = rp1.append('foo') rp1_1.write_string('hello') rp1_1.chmod(0) @@ -105,8 +133,7 @@ class HalfRoot(unittest.TestCase): rp1_3.chmod(0) rp2 = rpath.RPath(Globals.local_connection, "testfiles/root_half2") - if rp2.lstat(): Myrm(rp2.path) - rp2.mkdir() + re_init_dir(rp2) rp2_1 = rp2.append('foo') rp2_1.write_string('goodbye') rp2_1.chmod(0) @@ -223,8 +250,7 @@ class NonRoot(unittest.TestCase): def make_root_dirs(self): """Make directory createable only by root""" rp = rpath.RPath(Globals.local_connection, "testfiles/root_out1") - if rp.lstat(): Myrm(rp.path) - rp.mkdir() + re_init_dir(rp) rp1 = rp.append("1") rp1.touch() rp2 = rp.append("2") diff --git a/rdiff-backup/testing/statisticstest.py b/rdiff-backup/testing/statisticstest.py index b198b61..686c4ca 100644 --- a/rdiff-backup/testing/statisticstest.py +++ b/rdiff-backup/testing/statisticstest.py @@ -184,7 +184,7 @@ class IncStatTest(unittest.TestCase): assert len(incs) == 2 s2 = statistics.StatsObj().read_stats_from_rp(incs[0]) assert s2.SourceFiles == 7 - assert 700000 <= s2.SourceFileSize < 750000 + assert 700000 <= s2.SourceFileSize < 750000, s2.SourceFileSize self.stats_check_initial(s2) root_stats = statistics.StatsObj().read_stats_from_rp(incs[1]) -- cgit v1.2.1