Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions dataserv_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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"])
6 changes: 3 additions & 3 deletions dataserv_client/bandwidth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions dataserv_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions dataserv_client/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/test_bandwidth_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import dataserv_client.bandwidth_test as bt
from dataserv_client import common
import unittest
import socket
import time
Expand Down Expand Up @@ -116,10 +117,10 @@ def test_get_config(self):
<upload testlength="10" ratio="5" initialtest="0" mintestsize="32K" threads="2" maxchunksize="512K" maxchunkcount="50" threadsperurl="4" />
</settings>
"""
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)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down