commit f79570c7d08bdf0cef8690d4e87041908e0bcbac Author: Arturo Filastò art@fuffa.org Date: Sat Mar 9 02:06:26 2013 +0100
Attach errback to dl --- ooni/nettest.py | 6 +++--- ooni/reporter.py | 6 +++++- ooni/tasks.py | 1 - ooni/tests/test_reporter.py | 10 +++------- 4 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/ooni/nettest.py b/ooni/nettest.py index dc72ce8..4e73164 100644 --- a/ooni/nettest.py +++ b/ooni/nettest.py @@ -10,7 +10,7 @@ from ooni.utils import log, checkForRoot, NotRootError, geodata from ooni import config from ooni import otime
-from ooni import errors as e +from ooni import errors
from inspect import getmembers from StringIO import StringIO @@ -187,7 +187,7 @@ class NetTestLoader(object): log.msg("We will include some geo data in the report") try: client_geodata = geodata.IPToLocation(config.probe_ip) - except e.GeoIPDataFilesNotFound: + except errors.GeoIPDataFilesNotFound: log.err("Unable to find the geoip data files") client_geodata = {'city': None, 'countrycode': None, 'asn': None}
@@ -402,7 +402,7 @@ class NetTest(object): self.state.taskDone()
if len(self.report.reporters) == 0: - raise e.AllReportersFailed + raise errors.AllReportersFailed
return report_results
diff --git a/ooni/reporter.py b/ooni/reporter.py index a7bd933..596a001 100644 --- a/ooni/reporter.py +++ b/ooni/reporter.py @@ -398,6 +398,7 @@ class Report(object): log.debug("Reporters created: %s" % l) # Should we consume errors silently? dl = defer.DeferredList(l) + dl.addErrback(self.checkRemainingReporters) return dl
def failedOpeningReport(self, failure, reporter): @@ -410,7 +411,9 @@ class Report(object): log.err("Failed to open %s reporter, giving up..." % reporter) log.err("Reporter %s failed, removing from report..." % reporter) self.reporters.remove(reporter) - # Don't forward the exception unless there are no more reporters + return + + def checkRemainingReporters(self, failure): if len(self.reporters) == 0: log.err("Removed last reporter %s" % reporter) raise NoMoreReporters @@ -463,6 +466,7 @@ class Report(object): # to the deferredlist that checks to see if any reporters are left # and raise an exception if there are no remaining reporters dl = defer.DeferredList(l,fireOnOneErrback=True, consumeErrors=True) + dl.addErrback(self.checkRemainingReporters) return dl
def close(self, _): diff --git a/ooni/tasks.py b/ooni/tasks.py index c17a5c1..41cedc1 100644 --- a/ooni/tasks.py +++ b/ooni/tasks.py @@ -135,4 +135,3 @@ class ReportEntry(TaskWithTimeout):
def run(self): return self.reporter.writeReportEntry(self.measurement) - diff --git a/ooni/tests/test_reporter.py b/ooni/tests/test_reporter.py index d7ee907..ab2e8bf 100644 --- a/ooni/tests/test_reporter.py +++ b/ooni/tests/test_reporter.py @@ -4,7 +4,7 @@ from twisted.trial import unittest from ooni.reporter import Report, YAMLReporter, OONIBReporter, safe_dump from ooni.managers import ReportEntryManager, TaskManager from ooni.nettest import NetTest, NetTestState -from ooni.errors import ReportNotCreated, ReportAlreadyClosed +from ooni.errors import ReportNotCreated, ReportAlreadyClosed, NoMoreReporters
from ooni.tasks import TaskWithTimeout from ooni.tests.mocks import MockOReporter, MockTaskManager @@ -119,7 +119,7 @@ class TestReport(unittest.TestCase): d = report.write(MockMeasurement(MockNetTest())) def f(err): self.assertEquals(len(report.reporters),0) - d.addErrback(f) + d.addCallback(f) return d
class TestYAMLReporter(unittest.TestCase): @@ -138,7 +138,7 @@ class TestYAMLReporter(unittest.TestCase): def test_create_yaml_reporter(self): self.assertIsInstance(YAMLReporter(self.testDetails), YAMLReporter) - + def test_open_yaml_report_and_succeed(self): r = YAMLReporter(self.testDetails) r.createReport() @@ -150,10 +150,6 @@ class TestYAMLReporter(unittest.TestCase): r.created.addCallback(f) return r.created
- #def test_open_yaml_report_and_fail(self): - # #XXX: YAMLReporter does not handle failures of this type - # pass - def test_write_yaml_report_entry(self): r = YAMLReporter(self.testDetails) r.createReport()