From 777d722b0d4d1baa891621fe86af743bbec3909b Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Mon, 26 Jun 2017 15:41:47 -0400 Subject: [PATCH 1/3] Let me use FakeConfig in another test method --- src/wormhole/test/test_cli.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/wormhole/test/test_cli.py b/src/wormhole/test/test_cli.py index 90fdbe4..45dfab7 100644 --- a/src/wormhole/test/test_cli.py +++ b/src/wormhole/test/test_cli.py @@ -1172,6 +1172,14 @@ class Dispatch(unittest.TestCase): self.assertEqual(cfg.stderr.getvalue(), expected) +class FakeConfig(object): + no_daemon = True + blur_usage = True + advertise_version = u"fake.version.1" + transit = str('tcp:4321') + rendezvous = str('tcp:1234') + signal_error = True + allow_list = False class Server(unittest.TestCase): def setUp(self): @@ -1183,15 +1191,6 @@ class Server(unittest.TestCase): self.assertEqual(0, result.exit_code) def test_server_plugin(self): - class FakeConfig(object): - no_daemon = True - blur_usage = True - advertise_version = u"fake.version.1" - transit = str('tcp:4321') - rendezvous = str('tcp:1234') - signal_error = True - allow_list = False - cfg = FakeConfig() plugin = MyPlugin(cfg) relay = plugin.makeService(None) From 6b20cb760af69a9811657e7b247999eac9a8cec5 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Mon, 26 Jun 2017 15:42:19 -0400 Subject: [PATCH 2/3] Take cli args for db and stats paths --- src/wormhole/server/cli.py | 17 ++++++++++++++++- src/wormhole/server/cmd_server.py | 4 ++-- src/wormhole/server/server.py | 1 + src/wormhole/test/test_cli.py | 10 ++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/wormhole/server/cli.py b/src/wormhole/server/cli.py index b86984f..e3384f0 100644 --- a/src/wormhole/server/cli.py +++ b/src/wormhole/server/cli.py @@ -22,6 +22,15 @@ def server(ctx): # this is the setuptools entrypoint for bin/wormhole-server ctx.obj = Config() +_relay_database_path = click.option( + "--relay-database-path", default="relay.sqlite", metavar="PATH", + help="location for the relay server state database", +) +_stats_json_path = click.option( + "--stats-json-path", default="stats.json", metavar="PATH", + help="location to write the relay stats file", +) + @server.command() @click.option( "--rendezvous", default="tcp:4000", metavar="tcp:PORT", @@ -52,9 +61,13 @@ def server(ctx): # this is the setuptools entrypoint for bin/wormhole-server "--disallow-list", is_flag=True, help="never send list of allocated nameplates", ) +@_relay_database_path +@_stats_json_path @click.pass_obj def start(cfg, signal_error, no_daemon, blur_usage, advertise_version, - transit, rendezvous, disallow_list): + transit, rendezvous, disallow_list, relay_database_path, + stats_json_path, +): """ Start a relay server """ @@ -66,6 +79,8 @@ def start(cfg, signal_error, no_daemon, blur_usage, advertise_version, cfg.rendezvous = str(rendezvous) cfg.signal_error = signal_error cfg.allow_list = not disallow_list + cfg.relay_database_path = relay_database_path + cfg.stats_json_path = stats_json_path start_server(cfg) diff --git a/src/wormhole/server/cmd_server.py b/src/wormhole/server/cmd_server.py index 7aff110..1cabea3 100644 --- a/src/wormhole/server/cmd_server.py +++ b/src/wormhole/server/cmd_server.py @@ -17,10 +17,10 @@ class MyPlugin(object): self.args.rendezvous, self.args.transit, self.args.advertise_version, - "relay.sqlite", + self.args.relay_database_path, self.args.blur_usage, signal_error=self.args.signal_error, - stats_file="stats.json", + stats_file=self.args.stats_json_path, allow_list=self.args.allow_list, ) diff --git a/src/wormhole/server/server.py b/src/wormhole/server/server.py index 39cab57..da94f21 100644 --- a/src/wormhole/server/server.py +++ b/src/wormhole/server/server.py @@ -38,6 +38,7 @@ class RelayServer(service.MultiService): service.MultiService.__init__(self) self._blur_usage = blur_usage self._allow_list = allow_list + self._db_url = db_url db = get_db(db_url) welcome = { diff --git a/src/wormhole/test/test_cli.py b/src/wormhole/test/test_cli.py index 45dfab7..7466ce7 100644 --- a/src/wormhole/test/test_cli.py +++ b/src/wormhole/test/test_cli.py @@ -1180,6 +1180,10 @@ class FakeConfig(object): rendezvous = str('tcp:1234') signal_error = True allow_list = False + relay_database_path = "relay.sqlite" + stats_json_path = "stats.json" + + class Server(unittest.TestCase): def setUp(self): @@ -1210,3 +1214,9 @@ class Server(unittest.TestCase): cfg = fake_start_reserver.mock_calls[0][1][0] MyPlugin(cfg).makeService(None) + def test_state_locations(self): + cfg = FakeConfig() + plugin = MyPlugin(cfg) + relay = plugin.makeService(None) + self.assertEqual('relay.sqlite', relay._db_url) + self.assertEqual('stats.json', relay._stats_file) From 44a44738ecbd4e3d22be327854dfbfb925f45826 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 26 Jun 2017 21:26:06 +0100 Subject: [PATCH 3/3] take new args for 'restart' too, fixes test failure --- src/wormhole/server/cli.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wormhole/server/cli.py b/src/wormhole/server/cli.py index e3384f0..c644588 100644 --- a/src/wormhole/server/cli.py +++ b/src/wormhole/server/cli.py @@ -117,9 +117,13 @@ def start(cfg, signal_error, no_daemon, blur_usage, advertise_version, "--disallow-list", is_flag=True, help="never send list of allocated nameplates", ) +@_relay_database_path +@_stats_json_path @click.pass_obj def restart(cfg, signal_error, no_daemon, blur_usage, advertise_version, - transit, rendezvous, disallow_list): + transit, rendezvous, disallow_list, relay_database_path, + stats_json_path, + ): """ Re-start a relay server """ @@ -131,6 +135,8 @@ def restart(cfg, signal_error, no_daemon, blur_usage, advertise_version, cfg.rendezvous = str(rendezvous) cfg.signal_error = signal_error cfg.allow_list = not disallow_list + cfg.relay_database_path = relay_database_path + cfg.stats_json_path = stats_json_path restart_server(cfg)