[tor-commits] [ooni-probe/master] Handle more failure types
art at torproject.org
art at torproject.org
Tue Aug 27 09:21:51 UTC 2013
commit 27065e664834a536ecba39798ea98fb2f1a39342
Author: Arturo Filastò <art at fuffa.org>
Date: Thu Aug 22 15:20:16 2013 +0200
Handle more failure types
* Make sure tests will still work properly even if Tor is not running.
(cherry picked from commit 783fc4673a674bec54b958d23f3356bcc0c27286)
---
ooni/errors.py | 17 +++++++++++++----
ooni/templates/httpt.py | 7 +++++--
2 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/ooni/errors.py b/ooni/errors.py
index 58d894a..200491e 100644
--- a/ooni/errors.py
+++ b/ooni/errors.py
@@ -2,7 +2,7 @@ from twisted.internet.defer import TimeoutError as DeferTimeoutError
from twisted.web._newclient import ResponseNeverReceived
from twisted.internet.error import ConnectionRefusedError, TCPTimedOutError
-from twisted.internet.error import DNSLookupError
+from twisted.internet.error import DNSLookupError, ConnectError, ConnectionLost
from twisted.internet.error import TimeoutError as GenericTimeoutError
from txsocksx.errors import SOCKSError
@@ -26,7 +26,8 @@ def handleAllFailures(failure):
SOCKSError, MethodsNotAcceptedError, AddressNotSupported,
ConnectionError, NetworkUnreachable, ConnectionLostEarly,
ConnectionNotAllowed, NoAcceptableMethods, ServerFailure,
- HostUnreachable, ConnectionRefused, TTLExpired, CommandNotSupported)
+ HostUnreachable, ConnectionRefused, TTLExpired, CommandNotSupported,
+ ConnectError, ConnectionLost)
return failureToString(failure)
@@ -47,9 +48,17 @@ def failureToString(failure):
string = None
if isinstance(failure.value, ConnectionRefusedError):
- log.err("Connection refused. The backend may be down")
+ log.err("Connection refused.")
string = 'connection_refused_error'
+ elif isinstance(failure.value, ConnectionLost):
+ log.err("Connection lost.")
+ string = 'connection_lost_error'
+
+ elif isinstance(failure.value, ConnectError):
+ log.err("Connect error.")
+ string = 'connect_error'
+
elif isinstance(failure.value, gaierror):
log.err("Address family for hostname not supported")
string = 'address_family_not_supported_error'
@@ -110,7 +119,7 @@ def failureToString(failure):
string = 'socks_error'
else:
- log.err("Unknown failure type: %s" % type(failure))
+ log.err("Unknown failure type: %s" % type(failure.value))
string = 'unknown_failure %s' % str(failure.value)
return string
diff --git a/ooni/templates/httpt.py b/ooni/templates/httpt.py
index 0bca5df..472cc77 100644
--- a/ooni/templates/httpt.py
+++ b/ooni/templates/httpt.py
@@ -286,6 +286,9 @@ class HTTPTest(NetTestCase):
request['url'] = url
request['headers'] = headers
request['body'] = body
+ request['tor'] = False
+ if use_tor:
+ request['tor'] = True
if self.randomizeUA:
log.debug("Randomizing user agent")
@@ -304,9 +307,9 @@ class HTTPTest(NetTestCase):
headers = TrueHeaders(request['headers'])
def errback(failure, request):
- failure_string = handleAllFailures(failure)
log.err("Error performing %s" % request)
- HTTPTest.addToReport(self, request, failure_string=failure_string)
+ failure_string = handleAllFailures(failure)
+ self.addToReport(request, failure_string=failure_string)
return failure
d = agent.request(request['method'], request['url'], headers,
More information about the tor-commits
mailing list