Merge PR376

This adds "tahoe create-client" (and create-node) arguments which set the
default encoding parameters of the newly-created node (modifying the initial
tahoe.cfg contents). Easier than creating the node and then immediately
editing tahoe.cfg.

Closes ticket:2848
This commit is contained in:
Brian Warner 2016-12-13 22:34:32 -08:00
commit a7479f1fe1
3 changed files with 45 additions and 3 deletions

View File

@ -152,12 +152,23 @@ class CreateClientOptions(_CreateBaseOptions):
"Specify which TCP port to run the HTTP interface on. Use 'none' to disable."),
("basedir", "C", None, "Specify which Tahoe base directory should be used. This has the same effect as the global --node-directory option. [default: %s]"
% quote_local_unicode_path(_default_nodedir)),
("shares-needed", None, 3, "Needed shares required for uploaded files."),
("shares-happy", None, 7, "How many servers new files must be placed on."),
("shares-total", None, 10, "Total shares required for uploaded files."),
]
# This is overridden in order to ensure we get a "Wrong number of
# arguments." error when more than one argument is given.
def parseArgs(self, basedir=None):
BasedirOptions.parseArgs(self, basedir)
for name in ["shares-needed", "shares-happy", "shares-total"]:
try:
int(self[name])
except ValueError:
raise UsageError(
"--{} must be an integer".format(name)
)
class CreateNodeOptions(CreateClientOptions):
optFlags = [
@ -277,6 +288,8 @@ def write_node_config(c, config):
def write_client_config(c, config):
# note, config can be a plain dict, it seems -- see
# test_configutil.py in test_create_client_config
c.write("[client]\n")
c.write("# Which services should this client connect to?\n")
introducer = config.get("introducer", None) or ""
@ -288,9 +301,9 @@ def write_client_config(c, config):
c.write("# This can be changed at any time: the encoding is saved in\n")
c.write("# each filecap, and we can download old files with any encoding\n")
c.write("# settings\n")
c.write("#shares.needed = 3\n")
c.write("#shares.happy = 7\n")
c.write("#shares.total = 10\n")
c.write("shares.needed = {}\n".format(config['shares-needed']))
c.write("shares.happy = {}\n".format(config['shares-happy']))
c.write("shares.total = {}\n".format(config['shares-total']))
c.write("\n")
boolstr = {True:"true", False:"false"}

View File

@ -43,6 +43,32 @@ class Config(unittest.TestCase):
self.assertEqual(cfg.get("node", "tub.location"), "disabled")
self.assertFalse(cfg.has_section("connections"))
@defer.inlineCallbacks
def test_non_default_storage_args(self):
basedir = self.mktemp()
rc, out, err = yield run_cli(
"create-client",
'--shares-total', '19',
'--shares-needed', '2',
'--shares-happy', '11',
basedir,
)
cfg = read_config(basedir)
self.assertEqual(2, cfg.getint("client", "shares.needed"))
self.assertEqual(11, cfg.getint("client", "shares.happy"))
self.assertEqual(19, cfg.getint("client", "shares.total"))
@defer.inlineCallbacks
def test_illegal_shares_total(self):
basedir = self.mktemp()
rc, out, err = yield run_cli(
"create-client",
'--shares-total', 'funballs',
basedir,
)
self.assertNotEqual(0, rc)
self.assertTrue('--shares-total must be an integer' in err + out)
@defer.inlineCallbacks
def test_client_hide_ip_no_i2p_txtorcon(self):
# hmm, I must be doing something weird, these don't work as

View File

@ -88,6 +88,9 @@ class ConfigUtilTests(GridTestMixin, unittest.TestCase):
"webport": "tcp:3456",
"hide-ip": False,
"listen": "none",
"shares-needed": "1",
"shares-happy": "1",
"shares-total": "1",
}
create_node.write_node_config(f, opts)
create_node.write_client_config(f, opts)