[tor-commits] [ooni-probe/master] Add support for report_id inside of reports

art at torproject.org art at torproject.org
Fri Mar 27 15:24:02 UTC 2015


commit 5820bd45c0611cbd1c908df9ba4f2dfdc7e31f69
Author: Arturo Filastò <art at fuffa.org>
Date:   Wed Mar 25 11:38:05 2015 +0100

    Add support for report_id inside of reports
---
 data/ooniprobe.conf.sample |    2 ++
 ooni/nettest.py            |   49 +++++++++++++++++++++++++-------------------
 2 files changed, 30 insertions(+), 21 deletions(-)

diff --git a/data/ooniprobe.conf.sample b/data/ooniprobe.conf.sample
index 6c8f7f3..9f6d0f4 100644
--- a/data/ooniprobe.conf.sample
+++ b/data/ooniprobe.conf.sample
@@ -17,6 +17,8 @@ privacy:
     # Should we collect a full packet capture on the client?
     includepcap: false
 reports:
+    # Should we place a unique ID inside of every report
+    unique_id: true
     # This is a prefix for each packet capture file (.pcap) per test:
     pcap: null
     collector: null
diff --git a/ooni/nettest.py b/ooni/nettest.py
index 71cb94f..618066f 100644
--- a/ooni/nettest.py
+++ b/ooni/nettest.py
@@ -10,7 +10,7 @@ from twisted.python import usage, reflect
 
 from ooni import otime
 from ooni.tasks import Measurement
-from ooni.utils import log, sanitize_options
+from ooni.utils import log, sanitize_options, randomStr
 from ooni.utils.net import hasRawSocketPermission
 from ooni.settings import config
 
@@ -203,18 +203,20 @@ class NetTestLoader(object):
             input_file_hashes.append(input_file['hash'])
 
         options = sanitize_options(self.options)
-        test_details = {'start_time': otime.epochToUTC(time.time()),
-                        'probe_asn': config.probe_ip.geodata['asn'],
-                        'probe_cc': config.probe_ip.geodata['countrycode'],
-                        'probe_ip': config.probe_ip.geodata['ip'],
-                        'probe_city': config.probe_ip.geodata['city'],
-                        'test_name': self.testName,
-                        'test_version': self.testVersion,
-                        'software_name': 'ooniprobe',
-                        'software_version': software_version,
-                        'options': options,
-                        'input_hashes': input_file_hashes
-                        }
+        test_details = {
+            'start_time': otime.epochToUTC(time.time()),
+            'probe_asn': config.probe_ip.geodata['asn'],
+            'probe_cc': config.probe_ip.geodata['countrycode'],
+            'probe_ip': config.probe_ip.geodata['ip'],
+            'probe_city': config.probe_ip.geodata['city'],
+            'test_name': self.testName,
+            'test_version': self.testVersion,
+            'software_name': 'ooniprobe',
+            'software_version': software_version,
+            'options': options,
+            'input_hashes': input_file_hashes,
+            'report_id': self.reportID
+        }
         return test_details
 
     def _parseNetTestOptions(self, klass):
@@ -321,6 +323,10 @@ class NetTestLoader(object):
         self.testName = test_class_name_to_name(test_class.name)
         self.testCases = test_cases
         self.testClasses = set([])
+
+        if config.reports.unique_id is True:
+            self.reportID = randomStr(64)
+
         for test_class, test_method in self.testCases:
             self.testClasses.add(test_class)
 
@@ -341,7 +347,7 @@ class NetTestLoader(object):
 
             test_instance = klass()
             if test_instance.requiresRoot and not hasRawSocketPermission():
-                raise errors.InsufficientPrivileges
+                raise e.InsufficientPrivileges
             if test_instance.requiresTor:
                 self.requiresTor = True
             test_instance.requirements()
@@ -446,13 +452,14 @@ class NetTest(object):
         return ' '.join(tc.name for tc, _ in self.testCases)
 
     def doneNetTest(self, result):
-        if not self.summary:
-            return
-        print "Summary for %s" % self.testDetails['test_name']
-        print "------------" + "-"*len(self.testDetails['test_name'])
-        for test_class in self.testClasses:
-            test_instance = test_class()
-            test_instance.displaySummary(self.summary)
+        if self.summary:
+            print "Summary for %s" % self.testDetails['test_name']
+            print "------------" + "-"*len(self.testDetails['test_name'])
+            for test_class in self.testClasses:
+                test_instance = test_class()
+                test_instance.displaySummary(self.summary)
+        if self.testDetails["report_id"]:
+            print "Report ID: %s" % self.testDetails["report_id"]
 
     def doneReport(self, report_results):
         """





More information about the tor-commits mailing list