diff --git a/dataserv_client/api.py b/dataserv_client/api.py index 2244bc5..86557a5 100644 --- a/dataserv_client/api.py +++ b/dataserv_client/api.py @@ -273,7 +273,8 @@ def audit(self, delay=common.DEFAULT_AUDIT_DELAY, limit=None): def farm(self, workers=1, cleanup=False, rebuild=False, repair=False, set_height_interval=common.DEFAULT_SET_HEIGHT_INTERVAL, - delay=common.DEFAULT_DELAY, limit=None): + delay=common.DEFAULT_DELAY, limit=None, + speedtesturl=common.DEFAULT_SPEEDTEST_URL): """ Fully automatic client for users wishing a simple turnkey solution. This will run all functions automatically with the most sane defaults and as little user interface as possible. @@ -296,6 +297,8 @@ def farm(self, workers=1, cleanup=False, rebuild=False, repair=False, rebuild = deserialize.flag(rebuild) repair = deserialize.flag(repair) + speedtesturl = deserialize.url(speedtesturl) + # farmer never gives up self._init_messenger() self.messenger.retry_limit = 99999999999999999999999999999999999999 @@ -305,14 +308,14 @@ def farm(self, workers=1, cleanup=False, rebuild=False, repair=False, except exceptions.AddressAlreadyRegistered: pass # already registered ... - self.set_bandwidth() + self.set_bandwidth(speedtesturl) self.build(workers=workers, cleanup=cleanup, rebuild=rebuild, repair=repair, set_height_interval=set_height_interval) self.poll(delay=delay, limit=limit) return True - def set_bandwidth(self): - results = speedtest() + def set_bandwidth(self, speedtesturl): + results = speedtest(speedtesturl=speedtesturl) self.messenger.set_bandwidth(results["upload"], results["download"]) diff --git a/dataserv_client/bandwidth_test.py b/dataserv_client/bandwidth_test.py index 0f1a633..18e5592 100644 --- a/dataserv_client/bandwidth_test.py +++ b/dataserv_client/bandwidth_test.py @@ -350,7 +350,7 @@ def getAttributesByTagName(dom, tagName): return dict(list(elem.attributes.items())) -def getConfig(url='://www.speedtest.net/speedtest-config.php', configxml=None): +def getConfig(url, configxml=None): """Download the speedtest.net configuration and return only the data we are interested in """ @@ -530,7 +530,7 @@ def version(): raise SystemExit(__version__) -def speedtest(): +def speedtest(speedtesturl): """Run the full speedtest.net test""" global shutdown_event, source, scheme @@ -544,7 +544,7 @@ def speedtest(): build_user_agent() try: - config = getConfig() + config = getConfig(url=speedtesturl) except URLError: print_('Cannot retrieve speedtest configuration') sys.exit(1) diff --git a/dataserv_client/cli.py b/dataserv_client/cli.py index 129f895..7374afb 100644 --- a/dataserv_client/cli.py +++ b/dataserv_client/cli.py @@ -189,6 +189,11 @@ def _add_farm(command_parser): "--limit", default=None, help="Limit poll time in seconds." ) + farm_parser.add_argument( + "--speedtesturl", default=common.DEFAULT_SPEEDTEST_URL, + help="URL of the speedtest (default: {0}).".format(common.DEFAULT_SPEEDTEST_URL) + ) + def _parse_args(args): class ArgumentParser(argparse.ArgumentParser): diff --git a/dataserv_client/common.py b/dataserv_client/common.py index aad677c..1cc535e 100644 --- a/dataserv_client/common.py +++ b/dataserv_client/common.py @@ -6,6 +6,7 @@ DEFAULT_URL = "http://status.driveshare.org" +DEFAULT_SPEEDTEST_URL = "http://www.speedtest.net/speedtest-config.php" # read default delay from os environ if available diff --git a/tests/test_bandwidth_test.py b/tests/test_bandwidth_test.py index a7ee710..0120a69 100644 --- a/tests/test_bandwidth_test.py +++ b/tests/test_bandwidth_test.py @@ -1,4 +1,5 @@ import dataserv_client.bandwidth_test as bt +from dataserv_client import common import unittest import socket import time @@ -116,10 +117,10 @@ def test_get_config(self): """ - self.assertTrue(type(bt.getConfig(configxml=configxml)) is dict) + self.assertTrue(type(bt.getConfig(url=common.DEFAULT_SPEEDTEST_URL, configxml=configxml)) is dict) def test_closest_servers(self): - configxml = bt.getConfig() + configxml = bt.getConfig(url=common.DEFAULT_SPEEDTEST_URL) servers = bt.closestServers(configxml["client"]) self.assertTrue(len(servers)) self.assertTrue(type(bt.getBestServer(servers)) is dict) diff --git a/tests/test_client.py b/tests/test_client.py index b308433..baec1f9 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -489,7 +489,8 @@ def test_farm(self): "--repair", "--set_height_interval=3", "--delay=0", - "--limit=0" + "--limit=0", + "--speedtesturl=" + common.DEFAULT_SPEEDTEST_URL ] # no pings needed for check args self.assertTrue(cli.main(args))