[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Maintain backward compatibility



commit b86eaff915439fea01c15049b2b7252a39dc1afa
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date:   Sat Jan 30 12:36:49 2016 +0100

    Maintain backward compatibility
---
 ooni/nettest.py     |  2 +-
 ooni/oonibclient.py |  3 ---
 ooni/reporter.py    | 42 +++++++++++++++++++++++++++---------------
 3 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/ooni/nettest.py b/ooni/nettest.py
index 5207b8a..e347d55 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -330,7 +330,7 @@ class NetTestLoader(object):
         self.testClasses = set([])
         self.testHelpers = {}
 
-        if config.reports.unique_id is True:
+        if config.reports.unique_id is True and not self.reportID:
             self.reportID = randomStr(64)
 
         for test_class, test_method in self.testCases:
diff --git a/ooni/oonibclient.py b/ooni/oonibclient.py
index 126eeb7..388bb68 100644
--- a/ooni/oonibclient.py
+++ b/ooni/oonibclient.py
@@ -81,7 +81,6 @@ class OONIBClient(object):
                 except ValueError:
                     raise e.get_error(None)
                 if 'error' in response:
-                    print "Got this backend error message %s" % response
                     log.err("Got this backend error message %s" % response)
                     raise e.get_error(response['error'])
                 return response
@@ -171,7 +170,6 @@ class OONIBClient(object):
             @d.addErrback
             def err(err):
                 log.err("Failed to get descriptor for deck %s" % deck_hash)
-                print err
                 log.exception(err)
 
             return d
@@ -193,7 +191,6 @@ class OONIBClient(object):
             @d.addErrback
             def err(err):
                 log.err("Failed to download the deck %s" % deck_hash)
-                print err
                 log.exception(err)
 
             return d
diff --git a/ooni/reporter.py b/ooni/reporter.py
index 3ea1b10..b725540 100644
--- a/ooni/reporter.py
+++ b/ooni/reporter.py
@@ -15,7 +15,6 @@ from twisted.python.util import untilConcludes
 from twisted.internet import defer, reactor
 from twisted.web.client import Agent
 from twisted.internet.error import ConnectionRefusedError
-from twisted.python.failure import Failure
 from twisted.internet.endpoints import TCP4ClientEndpoint
 
 from txsocksx.http import SOCKS5Agent
@@ -190,14 +189,17 @@ class YAMLReporter(OReporter):
 
     def writeReportEntry(self, entry):
         log.debug("Writing report with YAML reporter")
-        self._write('---\n')
+        content = '---\n'
         if isinstance(entry, Measurement):
-            self._write(safe_dump(entry.testInstance.report))
-        elif isinstance(entry, Failure):
-            self._write(entry.value)
+            report_entry = entry.testInstance.report
         elif isinstance(entry, dict):
-            self._write(safe_dump(entry))
-        self._write('...\n')
+            report_entry = entry
+        else:
+            raise Exception("Failed to serialise entry")
+        content += safe_dump(report_entry)
+        content += '...\n'
+        report_entry.update(self.testDetails)
+        self._write(content)
 
     def createReport(self):
         """
@@ -261,20 +263,28 @@ class OONIBReporter(OReporter):
     def serializeEntry(self, entry, serialisation_format="yaml"):
         if serialisation_format == "json":
             if isinstance(entry, Measurement):
-                report_entry = entry.testInstance.report
-            elif isinstance(entry, Failure):
-                report_entry = {'failure': entry.value}
+                report_entry = {
+                    'input': entry.testInstance.report.pop('input', None),
+                    'test_keys': entry.testInstance.report
+                }
             elif isinstance(entry, dict):
-                report_entry = entry
+                report_entry = {
+                    'input': entry.pop('input', None),
+                    'test_keys': entry
+                }
+            else:
+                raise Exception("Failed to serialise entry")
+            report_entry.update(self.testDetails)
             return report_entry
         else:
             content = '---\n'
             if isinstance(entry, Measurement):
                 report_entry = entry.testInstance.report
-            elif isinstance(entry, Failure):
-                report_entry = {'failure': entry.value}
             elif isinstance(entry, dict):
                 report_entry = entry
+            else:
+                raise Exception("Failed to serialise entry")
+            report_entry.update(self.testDetails)
             content += safe_dump(report_entry)
             content += '...\n'
             return content
@@ -290,8 +300,10 @@ class OONIBReporter(OReporter):
         else:
             serialisation_format = 'yaml'
 
-        request = {'format': serialisation_format,
-                   'content': self.serializeEntry(entry, serialisation_format)}
+        request = {
+            'format': serialisation_format,
+            'content': self.serializeEntry(entry, serialisation_format)
+        }
 
         log.debug("Updating report with id %s (%s)" % (self.reportID, url))
         request_json = json.dumps(request)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits