예제 #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
 def test_log_watchdog(self):
     testfile = join(const.TEMP_DIR, "testfile")
     testline = "test line"
     fu.write_to_file(testfile, "line1\n" + testline + "\nline3")
     self.should_raise("Watchdog did not raised expected exception.",
                       gu.log_watchdog, "not test line", testfile, 1, 1)
     self.should_not_raise("Watchdog raised unexpected exception.",
                           gu.log_watchdog, testline, testfile, 5, 1)
예제 #3
0
 def test_log_watchdog(self):
     testfile = join(const.TEMP_DIR, "testfile")
     testline = "test line"
     fu.write_to_file(testfile, "line1\n" + testline + "\nline3")
     self.should_raise("Watchdog did not raised expected exception.",
                       gu.log_watchdog, "not test line", testfile, 1, 1)
     self.should_not_raise("Watchdog raised unexpected exception.",
                           gu.log_watchdog, testline, testfile, 5, 1)