def log_watchdog(line, logfile, timeout, delay=1, callback=None):
    set_timeout(timeout, callback)
    while not exists(logfile):
        sleep(delay)
    while line not in fu.read_file(logfile):
        sleep(delay)
    cancel_timeout()
Exemple #2
0
def log_watchdog(line, logfile, timeout, delay=1, callback=None):
    set_timeout(timeout, callback)
    while not exists(logfile):
        sleep(delay)
    while line not in fu.read_file(logfile):
        sleep(delay)
    cancel_timeout()
Exemple #3
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 #4
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))