from allmydata.scripts.common import DEFAULT_ALIAS, get_aliases
from allmydata.scripts import cli, debug, runner, backupdb
-from allmydata.test.common import SystemTestMixin
from allmydata.test.common_util import StallMixin
+from allmydata.test.no_network import GridTestMixin
from twisted.internet import threads # CLI tests use deferToThread
from twisted.python import usage
class CLITestMixin:
def do_cli(self, verb, *args, **kwargs):
nodeargs = [
- "--node-directory", self.getdir("client0"),
+ "--node-directory", self.get_clientdir(),
]
argv = [verb] + nodeargs + list(args)
stdin = kwargs.get("stdin", "")
d.addCallback(_done)
return d
-class CreateAlias(SystemTestMixin, CLITestMixin, unittest.TestCase):
+class CreateAlias(GridTestMixin, CLITestMixin, unittest.TestCase):
def _test_webopen(self, args, expected_url):
woo = cli.WebopenOptions()
- all_args = ["--node-directory", self.getdir("client0")] + list(args)
+ all_args = ["--node-directory", self.get_clientdir()] + list(args)
woo.parseOptions(all_args)
urls = []
rc = cli.webopen(woo, urls.append)
def test_create(self):
self.basedir = os.path.dirname(self.mktemp())
- d = self.set_up_nodes()
- d.addCallback(lambda res: self.do_cli("create-alias", "tahoe"))
+ self.set_up_grid()
+
+ d = self.do_cli("create-alias", "tahoe")
def _done((rc,stdout,stderr)):
self.failUnless("Alias 'tahoe' created" in stdout)
self.failIf(stderr)
- aliases = get_aliases(self.getdir("client0"))
+ aliases = get_aliases(self.get_clientdir())
self.failUnless("tahoe" in aliases)
self.failUnless(aliases["tahoe"].startswith("URI:DIR2:"))
d.addCallback(_done)
d.addCallback(lambda res: self.do_cli("create-alias", "two"))
def _stash_urls(res):
- aliases = get_aliases(self.getdir("client0"))
- node_url_file = os.path.join(self.getdir("client0"), "node.url")
+ aliases = get_aliases(self.get_clientdir())
+ node_url_file = os.path.join(self.get_clientdir(), "node.url")
nodeurl = open(node_url_file, "r").read().strip()
uribase = nodeurl + "uri/"
self.tahoe_url = uribase + urllib.quote(aliases["tahoe"])
def _check_create_duplicate((rc,stdout,stderr)):
self.failIfEqual(rc, 0)
self.failUnless("Alias 'two' already exists!" in stderr)
- aliases = get_aliases(self.getdir("client0"))
+ aliases = get_aliases(self.get_clientdir())
self.failUnlessEqual(aliases["two"], self.two_uri)
d.addCallback(_check_create_duplicate)
def _check_add_duplicate((rc,stdout,stderr)):
self.failIfEqual(rc, 0)
self.failUnless("Alias 'two' already exists!" in stderr)
- aliases = get_aliases(self.getdir("client0"))
+ aliases = get_aliases(self.get_clientdir())
self.failUnlessEqual(aliases["two"], self.two_uri)
d.addCallback(_check_add_duplicate)
return d
-class Put(SystemTestMixin, CLITestMixin, unittest.TestCase):
+class Put(GridTestMixin, CLITestMixin, unittest.TestCase):
def test_unlinked_immutable_stdin(self):
# tahoe get `echo DATA | tahoe put`
self.basedir = self.mktemp()
DATA = "data" * 100
- d = self.set_up_nodes()
- d.addCallback(lambda res: self.do_cli("put", stdin=DATA))
+ self.set_up_grid()
+ d = self.do_cli("put", stdin=DATA)
def _uploaded(res):
(rc, stdout, stderr) = res
self.failUnless("waiting for file data on stdin.." in stderr)
self.basedir = os.path.dirname(self.mktemp())
# this will be "allmydata.test.test_cli/Put/test_put_from_file/RANDOM"
# and the RANDOM directory will exist. Raw mktemp returns a filename.
+ self.set_up_grid()
rel_fn = os.path.join(self.basedir, "DATAFILE")
abs_fn = os.path.abspath(rel_fn)
f = open(rel_fn, "w")
f.write("short file")
f.close()
- d = self.set_up_nodes()
- d.addCallback(lambda res: self.do_cli("put", rel_fn))
+ d = self.do_cli("put", rel_fn)
def _uploaded((rc,stdout,stderr)):
readcap = stdout
self.failUnless(readcap.startswith("URI:LIT:"))
# tahoe put file.txt DIRCAP:./uploaded.txt
# tahoe put file.txt DIRCAP:./subdir/uploaded.txt
self.basedir = os.path.dirname(self.mktemp())
+ self.set_up_grid()
rel_fn = os.path.join(self.basedir, "DATAFILE")
abs_fn = os.path.abspath(rel_fn)
f.write(DATA)
f.close()
- d = self.set_up_nodes()
- d.addCallback(lambda res: self.do_cli("create-alias", "tahoe"))
+ d = self.do_cli("create-alias", "tahoe")
d.addCallback(lambda res:
self.do_cli("put", rel_fn, "uploaded.txt"))
self.failUnlessEqual(stdout, DATA))
def _get_dircap(res):
- self.dircap = get_aliases(self.getdir("client0"))["tahoe"]
+ self.dircap = get_aliases(self.get_clientdir())["tahoe"]
d.addCallback(_get_dircap)
d.addCallback(lambda res:
# tahoe get FILECAP, compare against DATA2
# tahoe put file.txt FILECAP
self.basedir = os.path.dirname(self.mktemp())
+ self.set_up_grid()
+
DATA = "data" * 100
DATA2 = "two" * 100
rel_fn = os.path.join(self.basedir, "DATAFILE")
f.write(DATA3)
f.close()
- d = self.set_up_nodes()
-
- d.addCallback(lambda res: self.do_cli("put", "--mutable", stdin=DATA))
+ d = self.do_cli("put", "--mutable", stdin=DATA)
def _created(res):
(rc, stdout, stderr) = res
self.failUnless("waiting for file data on stdin.." in stderr)
# tahoe get uploaded.txt, compare against DATA2
self.basedir = os.path.dirname(self.mktemp())
+ self.set_up_grid()
+
DATA1 = "data" * 100
fn1 = os.path.join(self.basedir, "DATA1")
f = open(fn1, "w")
f.write(DATA2)
f.close()
- d = self.set_up_nodes()
- d.addCallback(lambda res: self.do_cli("create-alias", "tahoe"))
+ d = self.do_cli("create-alias", "tahoe")
d.addCallback(lambda res:
self.do_cli("put", "--mutable", fn1, "tahoe:uploaded.txt"))
d.addCallback(lambda res:
d.addCallback(lambda (rc,out,err): self.failUnlessEqual(out, DATA2))
return d
-class Cp(SystemTestMixin, CLITestMixin, unittest.TestCase):
+class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
+
def test_not_enough_args(self):
o = cli.CpOptions()
self.failUnlessRaises(usage.UsageError,
def test_unicode_filename(self):
self.basedir = os.path.dirname(self.mktemp())
+ self.set_up_grid()
fn1 = os.path.join(self.basedir, "Ă„rtonwall")
DATA1 = "unicode file content"
# Bug #534
# Assure that uploading a file whose name contains unicode character doesn't
# prevent further uploads in the same directory
- d = self.set_up_nodes()
- d.addCallback(lambda res: self.do_cli("create-alias", "tahoe"))
+ d = self.do_cli("create-alias", "tahoe")
d.addCallback(lambda res: self.do_cli("cp", fn1, "tahoe:"))
d.addCallback(lambda res: self.do_cli("cp", fn2, "tahoe:"))
raise unittest.SkipTest("There is no symlink on this platform.")
# cp -r on a directory containing a dangling symlink shouldn't assert
self.basedir = os.path.dirname(self.mktemp())
+ self.set_up_grid()
dn = os.path.join(self.basedir, "dir")
os.mkdir(dn)
fn = os.path.join(dn, "Fakebandica")
ln = os.path.join(dn, "link")
os.symlink(fn, ln)
- d = self.set_up_nodes()
- d.addCallback(lambda res: self.do_cli("create-alias", "tahoe"))
+ d = self.do_cli("create-alias", "tahoe")
d.addCallback(lambda res: self.do_cli("cp", "--recursive",
dn, "tahoe:"))
return d
-class Backup(SystemTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
+class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
+
def writeto(self, path, data):
d = os.path.dirname(os.path.join(self.basedir, "home", path))
fileutil.make_dirs(d)
def test_backup(self):
self.basedir = os.path.dirname(self.mktemp())
+ self.set_up_grid()
# is the backupdb available? If so, we test that a second backup does
# not create new directories.
cmd.append("tahoe:backups")
return self.do_cli(*cmd)
- d = self.set_up_nodes()
- d.addCallback(lambda res: self.do_cli("create-alias", "tahoe"))
+ d = self.do_cli("create-alias", "tahoe")
if not have_bdb:
d.addCallback(lambda res: self.do_cli("backup", source, "tahoe:backups"))
# 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.basedir,
- "client0", "private", "backupdb.sqlite")
+ 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")