Skip to content

Commit

Permalink
Merge PR186: add server --relay-database-path and --stats-json-path
Browse files Browse the repository at this point in the history
  • Loading branch information
warner committed Jun 26, 2017
2 parents 13ff246 + 44a4473 commit 9413eda
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
25 changes: 23 additions & 2 deletions src/wormhole/server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
"""
Expand All @@ -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)

Expand Down Expand Up @@ -102,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
"""
Expand All @@ -116,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)

Expand Down
4 changes: 2 additions & 2 deletions src/wormhole/server/cmd_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def makeService(self, so):
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,
)

Expand Down
1 change: 1 addition & 0 deletions src/wormhole/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, rendezvous_web_port, transit_port,
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 = {
Expand Down
27 changes: 18 additions & 9 deletions src/wormhole/test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,18 @@ def mock_print(file):
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
relay_database_path = "relay.sqlite"
stats_json_path = "stats.json"


class Server(unittest.TestCase):

def setUp(self):
Expand All @@ -1183,15 +1195,6 @@ def test_server_disallow_list(self, fake_twistd):
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)
Expand All @@ -1211,3 +1214,9 @@ def test_restart_no_args(self, fake_start_reserver):
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)

0 comments on commit 9413eda

Please sign in to comment.