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

[tor-commits] [ooni-probe/master] Use the process template in the netalyzr test



commit 51c9b63c9cbf4499f43ec497e883afbfee8388c8
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date:   Wed Apr 27 12:07:02 2016 +0200

    Use the process template in the netalyzr test
    
    * Clean up text of psiphon test
---
 ooni/nettests/third_party/netalyzr.py | 77 +++++++++++++++++++----------------
 ooni/nettests/third_party/psiphon.py  |  2 +-
 2 files changed, 43 insertions(+), 36 deletions(-)

diff --git a/ooni/nettests/third_party/netalyzr.py b/ooni/nettests/third_party/netalyzr.py
index 3154af7..ee5c477 100644
--- a/ooni/nettests/third_party/netalyzr.py
+++ b/ooni/nettests/third_party/netalyzr.py
@@ -6,55 +6,62 @@
 #           Arturo "hellais" Filastò <art@xxxxxxxxx>
 # :licence: see LICENSE
 
-from ooni import nettest
-from ooni.utils import log
 import time
 import os
+import distutils.spawn
+
+from twisted.python import usage
 from twisted.internet import reactor, threads
 
-class NetalyzrWrapperTest(nettest.NetTestCase):
-    name = "NetalyzrWrapper"
-    requiresRoot = False
-    requiresTor = False
+from ooni.templates import process
+from ooni.utils import log
 
-    def setUp(self):
-        cwd = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
+class JavaNotInstalled(Exception):
+    pass
 
-        # XXX set the output directory to something more uniform
-        outputdir = os.path.join(cwd, '..', '..')
+class CouldNotFindNetalyzrCli(Exception):
+    pass
 
-        program_path = os.path.join(cwd, 'NetalyzrCLI.jar')
-        program = "java -jar %s -d" % program_path
+class UsageOptions(usage.Options):
+    optParameters = [
+        ['clipath', 'p', None, 'Specify the path to NetalyzrCLI.jar (can be '
+                               'downloaded from '
+                               'http://netalyzr.icsi.berkeley.edu/NetalyzrCLI.jar)']
+    ]
 
-        test_token = time.asctime(time.gmtime()).replace(" ", "_").strip()
+class NetalyzrWrapperTest(process.ProcessTest):
+    name = "NetalyzrWrapper"
+    description = "A wrapper around the Netalyzr java command line client"
+    author = "Jacob Appelbaum <jacob@xxxxxxxxxxxxx>"
+
+    requiredOptions = ['clipath']
 
-        self.output_file = os.path.join(outputdir,
-                "NetalyzrCLI_" + test_token + ".out")
-        self.output_file.strip()
-        self.run_me = program + " 2>&1 >> " + self.output_file
+    usageOptions = UsageOptions
+    requiresRoot = False
+    requiresTor = False
 
-    def blocking_call(self):
-        try:
-            result = threads.blockingCallFromThread(reactor, os.system, self.run_me) 
-        except:
-            log.debug("Netalyzr had an error, please see the log file: %s" % self.output_file)
-        finally:
-            self.clean_up()
+    timeout = 300
+
+    def requirements(self):
+        if not distutils.spawn.find_executable("java"):
+            raise JavaNotInstalled("Java is not installed.")
+
+    def setUp(self):
+        if not os.path.exists(self.localOptions['clipath']):
+            raise CouldNotFindNetalyzrCli("Could not find NetalyzrCLI.jar at {}".format(self.localOptions['clipath']))
 
-    def clean_up(self):
-        self.report['netalyzr_report'] = self.output_file
-        log.debug("finished running NetalzrWrapper")
-        log.debug("Please check %s for Netalyzr output" % self.output_file)
+        self.command = [
+            distutils.spawn.find_executable("java"),
+            "-jar",
+            "{}".format(self.localOptions['clipath']),
+            "-d"
+        ]
 
     def test_run_netalyzr(self):
         """
         This test simply wraps netalyzr and runs it from command line
         """
         log.msg("Running NetalyzrWrapper (this will take some time, be patient)")
-        log.debug("with command '%s'" % self.run_me)
-        # XXX we probably want to use a processprotocol here to obtain the
-        # stdout from Netalyzr. This would allows us to visualize progress
-        # (currently there is no progress because the stdout of os.system is
-        # trapped by twisted) and to include the link to the netalyzr report
-        # directly in the OONI report, perhaps even downloading it.
-        reactor.callInThread(self.blocking_call)
+        log.debug("with command '%s'" % self.command)
+        self.d = self.run(self.command, env=os.environ, usePTY=1)
+        return self.d
diff --git a/ooni/nettests/third_party/psiphon.py b/ooni/nettests/third_party/psiphon.py
index d4eb18f..9e50832 100644
--- a/ooni/nettests/third_party/psiphon.py
+++ b/ooni/nettests/third_party/psiphon.py
@@ -31,7 +31,7 @@ class PsiphonTest(httpt.HTTPTest,  process.ProcessTest):
     """
 
     name = "Psiphon Test"
-    description = ("Bootstraps Psiphon and"
+    description = ("Bootstraps Psiphon and "
                    "does a HTTP GET for the specified URL")
     author = "juga"
     version = "0.1.0"



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