Exemple #1
0
 def start_tor(self,
               datadir,
               args,
               stdout_loglevel=DEFAULT_TOR_LOGLEVEL,
               quiet=DEFAULT_TOR_LOG_QUIET):
     tor_proc_name = basename(datadir)
     pid_file = join(datadir, "pid")
     pid = fu.read_file(pid_file)
     if fu.is_pid_running(pid):
         log.debug(
             "TEST: {} process is already running.".format(tor_proc_name))
         return int(pid)
     logfile = join(datadir, DEBUG_FNAME)
     fu.removedir(datadir)
     log.debug("TEST: Starting Tor {}".format(tor_proc_name))
     log_args = [
         "--DataDirectory", datadir, "--Log",
         "debug file {}".format(logfile), "--Log",
         "{} stdout".format(stdout_loglevel)
     ]
     if quiet:
         log_args += ["--quiet"]
     cmd = ["tor"] + args + log_args
     log.debug("COMMAND: {}".format(" ".join(cmd)))
     process = Popen(cmd)
     try:
         self.tor_log_watchdog(logfile)
     except gu.TimeExceededError:
         log.error("Attempt to run tor process has timedout!")
         self.tearDown()
         return
     fu.write_to_file(join(datadir, "pid"), str(process.pid))
     log.debug("TEST: Finished loading {}".format(tor_proc_name))
     return process.pid
Exemple #2
0
 def tearDownClass(cls):
     super(UnmanagedTorTest, cls).tearDownClass()
     try:
         for datadir in DATA_DIRS.itervalues():
             pidfile = join(datadir, "pid")
             if exists(pidfile):
                 pid = int(fu.read_file(pidfile))
                 fu.terminate_process(pid)
                 log.debug("TEST: killed Tor {}.".format(basename(datadir)))
                 fu.removedir(datadir)
     except Exception as exc:
         log.exception("Exception raised tearing down class {}: {}".format(
             cls.__name__, exc))
Exemple #3
0
def clean_test_setting():
    """Clean folders and processes."""
    processes = ["tor", "obfsproxy"]
    log.info("Cleaning test setting...")
    for proc in psutil.process_iter():
        if proc.name() in processes:
            proc.kill()
            log.info(proc.name() + " killed!")
    for dirpath in DATA_DIRS.itervalues():
        log.debug("Will remove old log directory: " + dirpath)
        fu.removedir(dirpath)
    obfs_log_prefix = "obfsproxy_tester_"
    for end in ["client", "server"]:
        dirpath = join(const.TEMP_DIR, obfs_log_prefix + end + ".log")
        log.debug("Will remove old obfsproxy log file: " + dirpath)
        fu.removefile(dirpath)