- self.failUnlessReallyEqual(rc, 0)
- self.failUnlessReallyEqual(out, "foo")
- d.addCallback(_check3)
- d.addCallback(lambda res: self.do_cli("ls", "tahoe:backups/Archives"))
- def _check4((rc, out, err)):
- self.failUnlessReallyEqual(err, "")
- self.failUnlessReallyEqual(rc, 0)
- self.old_archives = out.split()
- self.failUnlessReallyEqual(len(self.old_archives), 1)
- d.addCallback(_check4)
-
-
- d.addCallback(self.stall, 1.1)
- d.addCallback(lambda res: do_backup())
- def _check4a((rc, out, err)):
- # second backup should reuse everything, if the backupdb is
- # available
- self.failUnlessReallyEqual(err, "")
- self.failUnlessReallyEqual(rc, 0)
- if have_bdb:
- fu, fr, fs, dc, dr, ds = self.count_output(out)
- # foo.txt, bar.txt, blah.txt
- self.failUnlessReallyEqual(fu, 0)
- self.failUnlessReallyEqual(fr, 3)
- self.failUnlessReallyEqual(fs, 0)
- # empty, home, home/parent, home/parent/subdir
- self.failUnlessReallyEqual(dc, 0)
- self.failUnlessReallyEqual(dr, 4)
- self.failUnlessReallyEqual(ds, 0)
- d.addCallback(_check4a)
-
- if have_bdb:
- # sneak into the backupdb, crank back the "last checked"
- # timestamp to force a check on all files
- def _reset_last_checked(res):
- dbfile = os.path.join(self.get_clientdir(),
- "private", "backupdb.sqlite")
- self.failUnless(os.path.exists(dbfile), dbfile)
- bdb = backupdb.get_backupdb(dbfile)
- bdb.cursor.execute("UPDATE last_upload SET last_checked=0")
- bdb.cursor.execute("UPDATE directories SET last_checked=0")
- bdb.connection.commit()
-
- d.addCallback(_reset_last_checked)
-
- d.addCallback(self.stall, 1.1)
- d.addCallback(lambda res: do_backup(verbose=True))
- def _check4b((rc, out, err)):
- # we should check all files, and re-use all of them. None of
- # the directories should have been changed, so we should
- # re-use all of them too.
- self.failUnlessReallyEqual(err, "")
- self.failUnlessReallyEqual(rc, 0)
- fu, fr, fs, dc, dr, ds = self.count_output(out)
- fchecked, dchecked = self.count_output2(out)
- self.failUnlessReallyEqual(fchecked, 3)
- self.failUnlessReallyEqual(fu, 0)
- self.failUnlessReallyEqual(fr, 3)
- self.failUnlessReallyEqual(fs, 0)
- self.failUnlessReallyEqual(dchecked, 4)
- self.failUnlessReallyEqual(dc, 0)
- self.failUnlessReallyEqual(dr, 4)
- self.failUnlessReallyEqual(ds, 0)
- d.addCallback(_check4b)
-
- d.addCallback(lambda res: self.do_cli("ls", "tahoe:backups/Archives"))
- def _check5((rc, out, err)):
- self.failUnlessReallyEqual(err, "")
- self.failUnlessReallyEqual(rc, 0)
- self.new_archives = out.split()
- expected_new = 2
- if have_bdb:
- expected_new += 1
- self.failUnlessReallyEqual(len(self.new_archives), expected_new, out)
- # the original backup should still be the oldest (i.e. sorts
- # alphabetically towards the beginning)
- self.failUnlessReallyEqual(sorted(self.new_archives)[0],
- self.old_archives[0])
- d.addCallback(_check5)
-
- d.addCallback(self.stall, 1.1)
- def _modify(res):
- self.writeto("parent/subdir/foo.txt", "FOOF!")
- # and turn a file into a directory
- os.unlink(os.path.join(source, "parent/blah.txt"))
- os.mkdir(os.path.join(source, "parent/blah.txt"))
- self.writeto("parent/blah.txt/surprise file", "surprise")
- self.writeto("parent/blah.txt/surprisedir/subfile", "surprise")
- # turn a directory into a file
- os.rmdir(os.path.join(source, "empty"))
- self.writeto("empty", "imagine nothing being here")
- return do_backup()
- d.addCallback(_modify)
- def _check5a((rc, out, err)):
- # second backup should reuse bar.txt (if backupdb is available),
- # and upload the rest. None of the directories can be reused.
- self.failUnlessReallyEqual(err, "")
- self.failUnlessReallyEqual(rc, 0)
- if have_bdb:
- fu, fr, fs, dc, dr, ds = self.count_output(out)
- # new foo.txt, surprise file, subfile, empty
- self.failUnlessReallyEqual(fu, 4)
- # old bar.txt
- self.failUnlessReallyEqual(fr, 1)
- self.failUnlessReallyEqual(fs, 0)
- # home, parent, subdir, blah.txt, surprisedir
- self.failUnlessReallyEqual(dc, 5)
- self.failUnlessReallyEqual(dr, 0)
- self.failUnlessReallyEqual(ds, 0)
- d.addCallback(_check5a)
- d.addCallback(lambda res: self.do_cli("ls", "tahoe:backups/Archives"))
- def _check6((rc, out, err)):
- self.failUnlessReallyEqual(err, "")
- self.failUnlessReallyEqual(rc, 0)
- self.new_archives = out.split()
- expected_new = 3
- if have_bdb:
- expected_new += 1
- self.failUnlessReallyEqual(len(self.new_archives), expected_new)
- self.failUnlessReallyEqual(sorted(self.new_archives)[0],
- self.old_archives[0])
- d.addCallback(_check6)
- d.addCallback(lambda res: self.do_cli("get", "tahoe:backups/Latest/parent/subdir/foo.txt"))
- def _check7((rc, out, err)):
- self.failUnlessReallyEqual(err, "")
- self.failUnlessReallyEqual(rc, 0)
- self.failUnlessReallyEqual(out, "FOOF!")
- # the old snapshot should not be modified
- return self.do_cli("get", "tahoe:backups/Archives/%s/parent/subdir/foo.txt" % self.old_archives[0])
- d.addCallback(_check7)
- def _check8((rc, out, err)):
- self.failUnlessReallyEqual(err, "")
- self.failUnlessReallyEqual(rc, 0)
- self.failUnlessReallyEqual(out, "foo")
- d.addCallback(_check8)
-
- return d
-
- # on our old dapper buildslave, this test takes a long time (usually
- # 130s), so we have to bump up the default 120s timeout. The create-alias
- # and initial backup alone take 60s, probably because of the handful of
- # dirnodes being created (RSA key generation). The backup between check4
- # and check4a takes 6s, as does the backup before check4b.
- test_backup.timeout = 3000
-
- def _check_filtering(self, filtered, all, included, excluded):
- filtered = set(filtered)
- all = set(all)
- included = set(included)
- excluded = set(excluded)
- self.failUnlessReallyEqual(filtered, included)
- self.failUnlessReallyEqual(all.difference(filtered), excluded)
-
- def test_exclude_options(self):
- root_listdir = (u'lib.a', u'_darcs', u'subdir', u'nice_doc.lyx')
- subdir_listdir = (u'another_doc.lyx', u'run_snake_run.py', u'CVS', u'.svn', u'_darcs')
- basedir = "cli/Backup/exclude_options"
- fileutil.make_dirs(basedir)
- nodeurl_path = os.path.join(basedir, 'node.url')
- fileutil.write(nodeurl_path, 'http://example.net:2357/')
-
- # test simple exclude
- backup_options = cli.BackupOptions()
- backup_options.parseOptions(['--exclude', '*lyx', '--node-directory',
- basedir, 'from', 'to'])
- filtered = list(backup_options.filter_listdir(root_listdir))
- self._check_filtering(filtered, root_listdir, (u'lib.a', u'_darcs', u'subdir'),
- (u'nice_doc.lyx',))
- # multiple exclude
- backup_options = cli.BackupOptions()
- backup_options.parseOptions(['--exclude', '*lyx', '--exclude', 'lib.?', '--node-directory',
- basedir, 'from', 'to'])
- filtered = list(backup_options.filter_listdir(root_listdir))
- self._check_filtering(filtered, root_listdir, (u'_darcs', u'subdir'),
- (u'nice_doc.lyx', u'lib.a'))
- # vcs metadata exclusion
- backup_options = cli.BackupOptions()
- backup_options.parseOptions(['--exclude-vcs', '--node-directory',
- basedir, 'from', 'to'])
- filtered = list(backup_options.filter_listdir(subdir_listdir))
- self._check_filtering(filtered, subdir_listdir, (u'another_doc.lyx', u'run_snake_run.py',),
- (u'CVS', u'.svn', u'_darcs'))
- # read exclude patterns from file
- exclusion_string = "_darcs\n*py\n.svn"
- excl_filepath = os.path.join(basedir, 'exclusion')
- fileutil.write(excl_filepath, exclusion_string)
- backup_options = cli.BackupOptions()
- backup_options.parseOptions(['--exclude-from', excl_filepath, '--node-directory',
- basedir, 'from', 'to'])
- filtered = list(backup_options.filter_listdir(subdir_listdir))
- self._check_filtering(filtered, subdir_listdir, (u'another_doc.lyx', u'CVS'),
- (u'.svn', u'_darcs', u'run_snake_run.py'))
- # test BackupConfigurationError
- self.failUnlessRaises(cli.BackupConfigurationError,
- backup_options.parseOptions,
- ['--exclude-from', excl_filepath + '.no', '--node-directory',
- basedir, 'from', 'to'])
-
- # test that an iterator works too
- backup_options = cli.BackupOptions()
- backup_options.parseOptions(['--exclude', '*lyx', '--node-directory',
- basedir, 'from', 'to'])
- filtered = list(backup_options.filter_listdir(iter(root_listdir)))
- self._check_filtering(filtered, root_listdir, (u'lib.a', u'_darcs', u'subdir'),
- (u'nice_doc.lyx',))
-
- def test_exclude_options_unicode(self):
- nice_doc = u"nice_d\u00F8c.lyx"
- try:
- doc_pattern_arg = u"*d\u00F8c*".encode(get_argv_encoding())
- except UnicodeEncodeError:
- raise unittest.SkipTest("A non-ASCII command argument could not be encoded on this platform.")
-
- root_listdir = (u'lib.a', u'_darcs', u'subdir', nice_doc)
- basedir = "cli/Backup/exclude_options_unicode"
- fileutil.make_dirs(basedir)
- nodeurl_path = os.path.join(basedir, 'node.url')
- fileutil.write(nodeurl_path, 'http://example.net:2357/')
-
- # test simple exclude
- backup_options = cli.BackupOptions()
- backup_options.parseOptions(['--exclude', doc_pattern_arg, '--node-directory',
- basedir, 'from', 'to'])
- filtered = list(backup_options.filter_listdir(root_listdir))
- self._check_filtering(filtered, root_listdir, (u'lib.a', u'_darcs', u'subdir'),
- (nice_doc,))
- # multiple exclude
- backup_options = cli.BackupOptions()
- backup_options.parseOptions(['--exclude', doc_pattern_arg, '--exclude', 'lib.?', '--node-directory',
- basedir, 'from', 'to'])
- filtered = list(backup_options.filter_listdir(root_listdir))
- self._check_filtering(filtered, root_listdir, (u'_darcs', u'subdir'),
- (nice_doc, u'lib.a'))
- # read exclude patterns from file
- exclusion_string = doc_pattern_arg + "\nlib.?"
- excl_filepath = os.path.join(basedir, 'exclusion')
- fileutil.write(excl_filepath, exclusion_string)
- backup_options = cli.BackupOptions()
- backup_options.parseOptions(['--exclude-from', excl_filepath, '--node-directory',
- basedir, 'from', 'to'])
- filtered = list(backup_options.filter_listdir(root_listdir))
- self._check_filtering(filtered, root_listdir, (u'_darcs', u'subdir'),
- (nice_doc, u'lib.a'))
-
- # test that an iterator works too
- backup_options = cli.BackupOptions()
- backup_options.parseOptions(['--exclude', doc_pattern_arg, '--node-directory',
- basedir, 'from', 'to'])
- filtered = list(backup_options.filter_listdir(iter(root_listdir)))
- self._check_filtering(filtered, root_listdir, (u'lib.a', u'_darcs', u'subdir'),
- (nice_doc,))
-
- def test_ignore_symlinks(self):
- if not hasattr(os, 'symlink'):
- raise unittest.SkipTest("Symlinks are not supported by Python on this platform.")
-
- self.basedir = os.path.dirname(self.mktemp())
- self.set_up_grid()
-
- source = os.path.join(self.basedir, "home")
- self.writeto("foo.txt", "foo")
- os.symlink(os.path.join(source, "foo.txt"), os.path.join(source, "foo2.txt"))
-
- d = self.do_cli("create-alias", "tahoe")
- d.addCallback(lambda res: self.do_cli("backup", "--verbose", source, "tahoe:test"))
-
- def _check((rc, out, err)):
- self.failUnlessReallyEqual(rc, 2)
- foo2 = os.path.join(source, "foo2.txt")
- self.failUnlessReallyEqual(err, "WARNING: cannot backup symlink '%s'\n" % foo2)
-
- fu, fr, fs, dc, dr, ds = self.count_output(out)
- # foo.txt
- self.failUnlessReallyEqual(fu, 1)
- self.failUnlessReallyEqual(fr, 0)
- # foo2.txt
- self.failUnlessReallyEqual(fs, 1)
- # home
- self.failUnlessReallyEqual(dc, 1)
- self.failUnlessReallyEqual(dr, 0)
- self.failUnlessReallyEqual(ds, 0)
-