252
251
nodedir1 = "cli/test_catalog_shares/node1"
253
252
sharedir = os.path.join(nodedir1, "storage", "shares", "mq", "mqfblse6m5a6dh45isu2cg7oji")
254
253
fileutil.make_dirs(sharedir)
255
f = open(os.path.join(sharedir, "8"), "wb")
256
open("cli/test_catalog_shares/node1/storage/shares/mq/not-a-dir", "wb").close()
254
fileutil.write("cli/test_catalog_shares/node1/storage/shares/mq/not-a-dir", "")
257
255
# write a bogus share that looks a little bit like CHK
258
f.write("\x00\x00\x00\x01" + "\xff" * 200) # this triggers an assert
256
fileutil.write(os.path.join(sharedir, "8"),
257
"\x00\x00\x00\x01" + "\xff" * 200) # this triggers an assert
261
259
nodedir2 = "cli/test_catalog_shares/node2"
262
260
fileutil.make_dirs(nodedir2)
263
open("cli/test_catalog_shares/node1/storage/shares/not-a-dir", "wb").close()
261
fileutil.write("cli/test_catalog_shares/node1/storage/shares/not-a-dir", "")
265
263
# now make sure that the 'catalog-shares' commands survives the error
266
264
out, err = self._catalog_shares(nodedir1, nodedir2)
298
296
self.failUnlessEqual(ga1("c:file"), ("CA", "file"))
299
297
self.failUnlessEqual(ga1("c:dir/file"), ("CA", "dir/file"))
300
298
self.failUnlessEqual(ga1("URI:stuff"), ("URI:stuff", ""))
299
self.failUnlessEqual(ga1("URI:stuff/file"), ("URI:stuff", "file"))
301
300
self.failUnlessEqual(ga1("URI:stuff:./file"), ("URI:stuff", "file"))
302
self.failUnlessEqual(ga1("URI:stuff:./dir/file"),
303
("URI:stuff", "dir/file"))
301
self.failUnlessEqual(ga1("URI:stuff/dir/file"), ("URI:stuff", "dir/file"))
302
self.failUnlessEqual(ga1("URI:stuff:./dir/file"), ("URI:stuff", "dir/file"))
304
303
self.failUnlessRaises(common.UnknownAliasError, ga1, "missing:")
305
304
self.failUnlessRaises(common.UnknownAliasError, ga1, "missing:dir")
306
305
self.failUnlessRaises(common.UnknownAliasError, ga1, "missing:dir/file")
369
370
self.failUnlessRaises(common.UnknownAliasError, ga3, "missing:")
370
371
self.failUnlessRaises(common.UnknownAliasError, ga3, "missing:dir")
371
372
self.failUnlessRaises(common.UnknownAliasError, ga3, "missing:dir/file")
373
# calling get_alias with a path that doesn't include an alias and
374
# default set to something that isn't in the aliases argument should
375
# raise an UnknownAliasError.
377
return get_alias(aliases, path, "badddefault:")
378
self.failUnlessRaises(common.UnknownAliasError, ga4, "afile")
379
self.failUnlessRaises(common.UnknownAliasError, ga4, "a/dir/path/")
382
old = common.pretend_platform_uses_lettercolon
384
common.pretend_platform_uses_lettercolon = True
385
retval = get_alias(aliases, path, "baddefault:")
387
common.pretend_platform_uses_lettercolon = old
389
self.failUnlessRaises(common.UnknownAliasError, ga5, "C:\\Windows")
374
392
class Help(unittest.TestCase):
588
class Ln(GridTestMixin, CLITestMixin, unittest.TestCase):
589
def _create_test_file(self):
590
data = "puppies" * 1000
591
path = os.path.join(self.basedir, "datafile")
597
def test_ln_without_alias(self):
598
# if invoked without an alias when the 'tahoe' alias doesn't
599
# exist, 'tahoe ln' should output a useful error message and not
601
self.basedir = "cli/Ln/ln_without_alias"
603
d = self.do_cli("ln", "from", "to")
604
def _check((rc, out, err)):
605
self.failUnlessEqual(rc, 1)
606
self.failUnlessIn("error:", err)
607
d.addCallback(_check)
608
# Make sure that validation extends to the "to" parameter
609
d.addCallback(lambda ign: self.do_cli("create-alias", "havasu"))
610
d.addCallback(lambda ign: self._create_test_file())
611
d.addCallback(lambda ign: self.do_cli("put", self.datafile,
613
d.addCallback(lambda ign: self.do_cli("ln", "havasu:from", "to"))
614
d.addCallback(_check)
617
def test_ln_with_nonexistent_alias(self):
618
# If invoked with aliases that don't exist, 'tahoe ln' should
619
# output a useful error message and not a stack trace.
620
self.basedir = "cli/Ln/ln_with_nonexistent_alias"
622
d = self.do_cli("ln", "havasu:from", "havasu:to")
623
def _check((rc, out, err)):
624
self.failUnlessEqual(rc, 1)
625
self.failUnlessIn("error:", err)
626
d.addCallback(_check)
627
# Make sure that validation occurs on the to parameter if the
628
# from parameter passes.
629
d.addCallback(lambda ign: self.do_cli("create-alias", "havasu"))
630
d.addCallback(lambda ign: self._create_test_file())
631
d.addCallback(lambda ign: self.do_cli("put", self.datafile,
633
d.addCallback(lambda ign: self.do_cli("ln", "havasu:from", "huron:to"))
634
d.addCallback(_check)
577
638
class Put(GridTestMixin, CLITestMixin, unittest.TestCase):
579
640
def test_unlinked_immutable_stdin(self):
853
923
self.failUnlessEqual("-r-- %d -" % len(small), out.strip())
854
924
d.addCallback(lambda ign: self.do_cli("ls", "-l", self.goodcap))
855
925
d.addCallback(_check5)
926
unknown_immcap = "imm.URI:unknown"
927
def _create_unknown(ign):
929
kids = {u"unknownchild-imm": (nm.create_from_cap(unknown_immcap), {})}
930
return self.rootnode.create_subdirectory(u"unknown", initial_children=kids,
932
d.addCallback(_create_unknown)
933
def _check6((rc, out, err)):
934
# listing a directory referencing an unknown object should print
935
# an extra message to stderr
936
self.failUnlessEqual(rc, 0)
937
self.failUnlessIn("?r-- ? - unknownchild-imm\n", out)
938
self.failUnlessIn("included unknown objects", err)
939
d.addCallback(lambda ign: self.do_cli("ls", "-l", "unknown"))
940
d.addCallback(_check6)
941
def _check7((rc, out, err)):
942
# listing an unknown cap directly should print an extra message
943
# to stderr (currently this only works if the URI starts with 'URI:'
944
# after any 'ro.' or 'imm.' prefix, otherwise it will be confused
946
self.failUnlessEqual(rc, 0)
947
self.failUnlessIn("?r-- ? -\n", out)
948
self.failUnlessIn("included unknown objects", err)
949
d.addCallback(lambda ign: self.do_cli("ls", "-l", unknown_immcap))
950
d.addCallback(_check7)
953
def test_list_without_alias(self):
954
# doing just 'tahoe ls' without specifying an alias or first
955
# doing 'tahoe create-alias tahoe' should fail gracefully.
956
self.basedir = "cli/List/list_without_alias"
958
d = self.do_cli("ls")
959
def _check((rc, out, err)):
960
self.failUnlessEqual(rc, 1)
961
self.failUnlessIn("error:", err)
962
d.addCallback(_check)
965
def test_list_with_nonexistent_alias(self):
966
# doing 'tahoe ls' while specifying an alias that doesn't already
967
# exist should fail with an informative error message
968
self.basedir = "cli/List/list_with_nonexistent_alias"
970
d = self.do_cli("ls", "nonexistent:")
971
def _check((rc, out, err)):
972
self.failUnlessEqual(rc, 1)
973
self.failUnlessIn("error:", err)
974
self.failUnlessIn("nonexistent", err)
975
d.addCallback(_check)
858
979
class Mv(GridTestMixin, CLITestMixin, unittest.TestCase):
859
980
def test_mv_behavior(self):
950
1071
"mv moved the wrong thing"))
1074
def test_mv_without_alias(self):
1075
# doing 'tahoe mv' without explicitly specifying an alias or
1076
# creating the default 'tahoe' alias should fail with a useful
1078
self.basedir = "cli/Mv/mv_without_alias"
1080
d = self.do_cli("mv", "afile", "anotherfile")
1081
def _check((rc, out, err)):
1082
self.failUnlessEqual(rc, 1)
1083
self.failUnlessIn("error:", err)
1084
d.addCallback(_check)
1085
# check to see that the validation extends to the
1086
# target argument by making an alias that will work with the first
1088
d.addCallback(lambda ign: self.do_cli("create-alias", "havasu"))
1089
def _create_a_test_file(ign):
1090
self.test_file_path = os.path.join(self.basedir, "afile")
1091
f = open(self.test_file_path, "wb")
1092
f.write("puppies" * 100)
1094
d.addCallback(_create_a_test_file)
1095
d.addCallback(lambda ign: self.do_cli("put", self.test_file_path,
1097
d.addCallback(lambda ign: self.do_cli("mv", "havasu:afile",
1099
d.addCallback(_check)
1102
def test_mv_with_nonexistent_alias(self):
1103
# doing 'tahoe mv' with an alias that doesn't exist should fail
1104
# with an informative error message.
1105
self.basedir = "cli/Mv/mv_with_nonexistent_alias"
1107
d = self.do_cli("mv", "fake:afile", "fake:anotherfile")
1108
def _check((rc, out, err)):
1109
self.failUnlessEqual(rc, 1)
1110
self.failUnlessIn("error:", err)
1111
self.failUnlessIn("fake", err)
1112
d.addCallback(_check)
1113
# check to see that the validation extends to the
1114
# target argument by making an alias that will work with the first
1116
d.addCallback(lambda ign: self.do_cli("create-alias", "havasu"))
1117
def _create_a_test_file(ign):
1118
self.test_file_path = os.path.join(self.basedir, "afile")
1119
f = open(self.test_file_path, "wb")
1120
f.write("puppies" * 100)
1122
d.addCallback(_create_a_test_file)
1123
d.addCallback(lambda ign: self.do_cli("put", self.test_file_path,
1125
d.addCallback(lambda ign: self.do_cli("mv", "havasu:afile",
1126
"fake:anotherfile"))
1127
d.addCallback(_check)
953
1131
class Cp(GridTestMixin, CLITestMixin, unittest.TestCase):
955
1133
def test_not_enough_args(self):
1007
1185
self.set_up_grid()
1008
1186
outdir = os.path.join(self.basedir, "outdir")
1009
1187
os.mkdir(outdir)
1010
self.do_cli("create-alias", "tahoe")
1011
1188
fn1 = os.path.join(self.basedir, "Metallica")
1012
1189
fn2 = os.path.join(outdir, "Not Metallica")
1013
1190
fn3 = os.path.join(outdir, "test2")
1014
1191
DATA1 = "puppies" * 10000
1015
open(fn1, "wb").write(DATA1)
1016
d = self.do_cli("put", fn1)
1192
fileutil.write(fn1, DATA1)
1194
d = self.do_cli("create-alias", "tahoe")
1195
d.addCallback(lambda ign: self.do_cli("put", fn1))
1017
1196
def _put_file((rc, out, err)):
1018
1197
self.failUnlessEqual(rc, 0)
1019
1198
# keep track of the filecap
1020
1199
self.filecap = out.strip()
1021
1200
d.addCallback(_put_file)
1022
1202
# Let's try copying this to the disk using the filecap
1023
1203
# cp FILECAP filename
1024
d.addCallback(lambda res: self.do_cli("cp", self.filecap, fn2))
1204
d.addCallback(lambda ign: self.do_cli("cp", self.filecap, fn2))
1025
1205
def _copy_file((rc, out, err)):
1026
1206
self.failUnlessEqual(rc, 0)
1027
results = open(fn2, "r").read()
1207
results = fileutil.read(fn2)
1028
1208
self.failUnlessEqual(results, DATA1)
1209
d.addCallback(_copy_file)
1029
1211
# Test with ./ (see #761)
1030
1212
# cp FILECAP localdir
1031
d.addCallback(lambda res: self.do_cli("cp", self.filecap, outdir))
1213
d.addCallback(lambda ign: self.do_cli("cp", self.filecap, outdir))
1032
1214
def _resp((rc, out, err)):
1033
1215
self.failUnlessEqual(rc, 1)
1034
1216
self.failUnlessIn("error: you must specify a destination filename",
1036
1218
d.addCallback(_resp)
1037
1220
# Create a directory, linked at tahoe:test
1038
d.addCallback(lambda res: self.do_cli("mkdir", "tahoe:test"))
1221
d.addCallback(lambda ign: self.do_cli("mkdir", "tahoe:test"))
1039
1222
def _get_dir((rc, out, err)):
1040
1223
self.failUnlessEqual(rc, 0)
1041
1224
self.dircap = out.strip()
1042
1225
d.addCallback(_get_dir)
1043
1227
# Upload a file to the directory
1044
d.addCallback(lambda res:
1045
self.do_cli("put", fn1, "tahoe:test/test_file"))
1228
d.addCallback(lambda ign:
1229
self.do_cli("put", fn1, "tahoe:test/test_file"))
1046
1230
d.addCallback(lambda (rc, out, err): self.failUnlessEqual(rc, 0))
1047
1232
# cp DIRCAP/filename localdir
1048
d.addCallback(lambda res:
1233
d.addCallback(lambda ign:
1049
1234
self.do_cli("cp", self.dircap + "/test_file", outdir))
1050
1235
def _get_resp((rc, out, err)):
1051
1236
self.failUnlessEqual(rc, 0)
1052
results = open(os.path.join(outdir, "test_file"), "r").read()
1237
results = fileutil.read(os.path.join(outdir, "test_file"))
1053
1238
self.failUnlessEqual(results, DATA1)
1054
1239
d.addCallback(_get_resp)
1055
1241
# cp -r DIRCAP/filename filename2
1056
d.addCallback(lambda res:
1242
d.addCallback(lambda ign:
1057
1243
self.do_cli("cp", self.dircap + "/test_file", fn3))
1058
1244
def _get_resp2((rc, out, err)):
1059
1245
self.failUnlessEqual(rc, 0)
1060
results = open(fn3, "r").read()
1246
results = fileutil.read(fn3)
1061
1247
self.failUnlessEqual(results, DATA1)
1062
1248
d.addCallback(_get_resp2)
1251
def test_cp_with_nonexistent_alias(self):
1252
# when invoked with an alias or aliases that don't exist, 'tahoe cp'
1253
# should output a sensible error message rather than a stack trace.
1254
self.basedir = "cli/Cp/cp_with_nonexistent_alias"
1256
d = self.do_cli("cp", "fake:file1", "fake:file2")
1257
def _check((rc, out, err)):
1258
self.failUnlessEqual(rc, 1)
1259
self.failUnlessIn("error:", err)
1260
d.addCallback(_check)
1261
# 'tahoe cp' actually processes the target argument first, so we
1262
# need to check to make sure that validation extends to the
1264
d.addCallback(lambda ign: self.do_cli("create-alias", "tahoe"))
1265
d.addCallback(lambda ign: self.do_cli("cp", "fake:file1",
1267
d.addCallback(_check)
1065
1271
class Backup(GridTestMixin, CLITestMixin, StallMixin, unittest.TestCase):
1067
1273
def writeto(self, path, data):
1068
d = os.path.dirname(os.path.join(self.basedir, "home", path))
1069
fileutil.make_dirs(d)
1070
f = open(os.path.join(self.basedir, "home", path), "w")
1274
full_path = os.path.join(self.basedir, "home", path)
1275
fileutil.make_dirs(os.path.dirname(full_path))
1276
fileutil.write(full_path, data)
1074
1278
def count_output(self, out):
1075
1279
mo = re.search(r"(\d)+ files uploaded \((\d+) reused\), "
1468
1668
d.addErrback(_cleanup)
1671
def test_backup_without_alias(self):
1672
# 'tahoe backup' should output a sensible error message when invoked
1673
# without an alias instead of a stack trace.
1674
self.basedir = os.path.dirname(self.mktemp())
1676
source = os.path.join(self.basedir, "file1")
1677
d = self.do_cli('backup', source, source)
1678
def _check((rc, out, err)):
1679
self.failUnlessEqual(rc, 1)
1680
self.failUnlessIn("error:", err)
1681
d.addCallback(_check)
1684
def test_backup_with_nonexistent_alias(self):
1685
# 'tahoe backup' should output a sensible error message when invoked
1686
# with a nonexistent alias.
1687
self.basedir = os.path.dirname(self.mktemp())
1689
source = os.path.join(self.basedir, "file1")
1690
d = self.do_cli("backup", source, "nonexistent:" + source)
1691
def _check((rc, out, err)):
1692
self.failUnlessEqual(rc, 1)
1693
self.failUnlessIn("error:", err)
1694
self.failUnlessIn("nonexistent", err)
1695
d.addCallback(_check)
1472
1699
class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
1992
def test_check_without_alias(self):
1993
# 'tahoe check' should output a sensible error message if it needs to
1994
# find the default alias and can't
1995
self.basedir = "cli/Check/check_without_alias"
1997
d = self.do_cli("check")
1998
def _check((rc, out, err)):
1999
self.failUnlessEqual(rc, 1)
2000
self.failUnlessIn("error:", err)
2001
d.addCallback(_check)
2002
d.addCallback(lambda ign: self.do_cli("deep-check"))
2003
d.addCallback(_check)
2006
def test_check_with_nonexistent_alias(self):
2007
# 'tahoe check' should output a sensible error message if it needs to
2008
# find an alias and can't.
2009
self.basedir = "cli/Check/check_with_nonexistent_alias"
2011
d = self.do_cli("check", "nonexistent:")
2012
def _check((rc, out, err)):
2013
self.failUnlessEqual(rc, 1)
2014
self.failUnlessIn("error:", err)
2015
self.failUnlessIn("nonexistent", err)
2016
d.addCallback(_check)
1765
2020
class Errors(GridTestMixin, CLITestMixin, unittest.TestCase):
1766
2021
def test_get(self):
1767
2022
self.basedir = "cli/Errors/get"
2054
class Get(GridTestMixin, CLITestMixin, unittest.TestCase):
2055
def test_get_without_alias(self):
2056
# 'tahoe get' should output a useful error message when invoked
2057
# without an explicit alias and when the default 'tahoe' alias
2058
# hasn't been created yet.
2059
self.basedir = "cli/Get/get_without_alias"
2061
d = self.do_cli('get', 'file')
2062
def _check((rc, out, err)):
2063
self.failUnlessEqual(rc, 1)
2064
self.failUnlessIn("error:", err)
2065
d.addCallback(_check)
2068
def test_get_with_nonexistent_alias(self):
2069
# 'tahoe get' should output a useful error message when invoked with
2070
# an explicit alias that doesn't exist.
2071
self.basedir = "cli/Get/get_with_nonexistent_alias"
2073
d = self.do_cli("get", "nonexistent:file")
2074
def _check((rc, out, err)):
2075
self.failUnlessEqual(rc, 1)
2076
self.failUnlessIn("error:", err)
2077
self.failUnlessIn("nonexistent", err)
2078
d.addCallback(_check)
2082
class Manifest(GridTestMixin, CLITestMixin, unittest.TestCase):
2083
def test_manifest_without_alias(self):
2084
# 'tahoe manifest' should output a useful error message when invoked
2085
# without an explicit alias when the default 'tahoe' alias is
2087
self.basedir = "cli/Manifest/manifest_without_alias"
2089
d = self.do_cli("manifest")
2090
def _check((rc, out, err)):
2091
self.failUnlessEqual(rc, 1)
2092
self.failUnlessIn("error:", err)
2093
d.addCallback(_check)
2096
def test_manifest_with_nonexistent_alias(self):
2097
# 'tahoe manifest' should output a useful error message when invoked
2098
# with an explicit alias that doesn't exist.
2099
self.basedir = "cli/Manifest/manifest_with_nonexistent_alias"
2101
d = self.do_cli("manifest", "nonexistent:")
2102
def _check((rc, out, err)):
2103
self.failUnlessEqual(rc, 1)
2104
self.failUnlessIn("error:", err)
2105
self.failUnlessIn("nonexistent", err)
2106
d.addCallback(_check)
2110
class Mkdir(GridTestMixin, CLITestMixin, unittest.TestCase):
2111
def test_mkdir_with_nonexistent_alias(self):
2112
# when invoked with an alias that doesn't exist, 'tahoe mkdir'
2113
# should output a sensible error message rather than a stack
2115
self.basedir = "cli/Mkdir/mkdir_with_nonexistent_alias"
2117
d = self.do_cli("mkdir", "havasu:")
2118
def _check((rc, out, err)):
2119
self.failUnlessEqual(rc, 1)
2120
self.failUnlessIn("error:", err)
2121
d.addCallback(_check)
2125
class Rm(GridTestMixin, CLITestMixin, unittest.TestCase):
2126
def test_rm_without_alias(self):
2127
# 'tahoe rm' should behave sensibly when invoked without an explicit
2128
# alias before the default 'tahoe' alias has been created.
2129
self.basedir = "cli/Rm/rm_without_alias"
2131
d = self.do_cli("rm", "afile")
2132
def _check((rc, out, err)):
2133
self.failUnlessIn("error:", err)
2134
self.failUnlessEqual(rc, 1)
2135
d.addCallback(_check)
2138
def test_rm_with_nonexistent_alias(self):
2139
# 'tahoe rm' should behave sensibly when invoked with an explicit
2140
# alias that doesn't exist.
2141
self.basedir = "cli/Rm/rm_with_nonexistent_alias"
2143
d = self.do_cli("rm", "nonexistent:afile")
2144
def _check((rc, out, err)):
2145
self.failUnlessEqual(rc, 1)
2146
self.failUnlessIn("error:", err)
2147
self.failUnlessIn("nonexistent", err)
2148
d.addCallback(_check)
1798
2152
class Stats(GridTestMixin, CLITestMixin, unittest.TestCase):
1799
2153
def test_empty_directory(self):
1800
2154
self.basedir = "cli/Stats/empty_directory"
1822
2176
d.addCallback(_check_stats)
2180
def test_stats_without_alias(self):
2181
# when invoked with no explicit alias and before the default 'tahoe'
2182
# alias is created, 'tahoe stats' should output an informative error
2183
# message, not a stack trace.
2184
self.basedir = "cli/Stats/stats_without_alias"
2186
d = self.do_cli("stats")
2187
def _check((rc, out, err)):
2188
self.failUnlessEqual(rc, 1)
2189
self.failUnlessIn("error:", err)
2190
d.addCallback(_check)
2193
def test_stats_with_nonexistent_alias(self):
2194
# when invoked with an explicit alias that doesn't exist,
2195
# 'tahoe stats' should output a useful error message.
2196
self.basedir = "cli/Stats/stats_with_nonexistent_alias"
2198
d = self.do_cli("stats", "havasu:")
2199
def _check((rc, out, err)):
2200
self.failUnlessEqual(rc, 1)
2201
self.failUnlessIn("error:", err)
2202
d.addCallback(_check)
2206
class Webopen(GridTestMixin, CLITestMixin, unittest.TestCase):
2207
def test_webopen_with_nonexistent_alias(self):
2208
# when invoked with an alias that doesn't exist, 'tahoe webopen'
2209
# should output an informative error message instead of a stack
2211
self.basedir = "cli/Webopen/webopen_with_nonexistent_alias"
2213
d = self.do_cli("webopen", "fake:")
2214
def _check((rc, out, err)):
2215
self.failUnlessEqual(rc, 1)
2216
self.failUnlessIn("error:", err)
2217
d.addCallback(_check)