def test_done(self, *baton): ''' Invoked when the test is done ''' # # Stop streaming test events to interested parties # via the log streaming API. # Do not stop processing immediately and give HTTP # code time to stream logs to the client in case # connections fails immediately. # This must not be done when we're processing the # somewhat internal 'rendezvous' or 'mlab-ns' tests. # if self.queue[0][0] != 'rendezvous' and self.queue[0][0] != 'mlab-ns': POLLER.sched(2, STREAMING_LOG.stop_streaming) # Paranoid if baton[0] != 'testdone': raise RuntimeError('runner_core: invoked for the wrong event') # Notify the caller that the test is done deferred, ctx = self.queue.popleft()[1:] deferred.callback(ctx) # # Allow for more tests # If callback() adds one more test, that would # be run by the run_queue() invocation below. # self.running = False # Eventually run next queued test self.run_queue()
def _api_exit(self, stream, request, query): POLLER.sched(0, POLLER.break_loop) response = Message() stringio = StringIO.StringIO("See you, space cowboy\n") response.compose(code="200", reason="Ok", body=stringio, mimetype="text/plain", keepalive=False) stream.send_response(request, response)
def main(args): CONFIG.register_descriptions({ "http.client.class": "Specify alternate ClientHTTP-like class", "http.client.method": "Specify alternate HTTP method", "http.client.stats": "Enable printing download stats on stdout", "http.client.stdout": "Enable writing response to stdout", "http.client.uri": "Specify URI to download from/upload to", }) common.main("http.client", "Simple Neubot HTTP client", args) conf = CONFIG.copy() if conf["http.client.stats"]: POLLER.sched(0.5, MEASURER.start) make_client = TestClient if conf["http.client.class"]: make_client = utils.import_class(conf["http.client.class"]) if not conf["http.client.uri"]: sys.stdout.write("Please, specify URI via -D http.client.uri=URI\n") sys.exit(0) client = make_client(POLLER) client.configure(conf, MEASURER) client.connect_uri(conf["http.client.uri"]) POLLER.loop() sys.exit(0)
def connection_made(self): self.buffer = "A" * self.conf["net.stream.chunk"] duration = self.conf["net.stream.duration"] if duration >= 0: POLLER.sched(duration, self._do_close) if self.kind == "discard": self.start_recv() elif self.kind == "chargen": self.start_send(self.buffer) elif self.kind == "echo": self.start_recv() else: self.close()
def connection_made(self): self.buffer = "A" * self.conf.get("net.stream.chunk", 32768) MEASURER.register_stream(self) duration = self.conf.get("net.stream.duration", 10) if duration >= 0: POLLER.sched(duration, self._do_close) if self.kind == "discard": self.start_recv() elif self.kind == "chargen": self.start_send(self.buffer) elif self.kind == "echo": self.start_recv() else: self.close()
def _periodic(self, *args, **kwargs): POLLER.sched(INTERVAL, self._periodic) self._tofire, q = [], self._tofire for event in q: # # WARNING! Please resist the temptation of merging # the [] and the del into a single pop() because that # will not work: this is a defaultdict and so here # event might not be in _subscribers. # queue = self._subscribers[event] del self._subscribers[event] logging.debug("* periodic: %s", event) self._fireq(event, queue)
def test_done(self, *baton): ''' Invoked when the test is done ''' # # Stop streaming test events to interested parties # via the log streaming API. # Do not stop processing immediately and give HTTP # code time to stream logs to the client in case # connections fails immediately. # This must not be done when we're processing the # somewhat internal 'rendezvous' test. # if self.queue[0][0] != 'rendezvous': POLLER.sched(2, LOG.stop_streaming) # Paranoid if baton[0] != 'testdone': raise RuntimeError('Invoked for the wrong event') # Notify the caller that the test is done callback, ctx = self.queue.popleft()[1:] try: if ctx: callback(ctx) else: callback() except (KeyboardInterrupt, SystemExit): raise except: exc = asyncore.compact_traceback() error = str(exc) LOG.error('runner_core: catched exception: %s' % error) # # Allow for more tests # If callback() adds one more test, that would # be run by the run_queue() invocation below. # self.running = False # Eventually run next queued test self.run_queue()
def _do_update_queue(self): pos = 1 for session in self.queue: if pos <= 3 and not session.active: session.active = True session.queuepos = pos pos = pos + 1 if not self.task: self.task = POLLER.sched(60, self._sample_queue_length)
def _schedule(self): # # Typically the user does not specify the interval # and we use a random value around 1500 seconds. # The random value is extracted just once and from # that point on we keep using it. # interval = CONFIG["agent.interval"] if not interval: if not self._interval: self._interval = 1380 + random.randrange(0, 240) interval = self._interval LOG.info("* Next rendezvous in %d seconds" % interval) fn = lambda *args, **kwargs: self.connect_uri() self._task = POLLER.sched(interval, fn) STATE.update("idle", publish=False) STATE.update("next_rendezvous", self._task.timestamp)
def _schedule(self): ''' Schedule next rendezvous ''' # # Typically the user does not specify the interval # and we use a random value around 1500 seconds. # The random value is extracted just once and from # that point on we keep using it. # Suggested by Elias S.G. Carotti some time ago. # interval = CONFIG["agent.interval"] if not interval: if not self._interval: self._interval = 1380 + random.randrange(0, 240) interval = self._interval logging.info("* Next rendezvous in %d seconds", interval) task = POLLER.sched(interval, self.run) STATE.update("idle", publish=False) STATE.update("next_rendezvous", task.timestamp)
def __init__(self): self._timestamps = collections.defaultdict(int) self._subscribers = collections.defaultdict(list) self._tofire = [] POLLER.sched(INTERVAL, self._periodic)
def use_database(self): POLLER.sched(INTERVAL, self._maintain_database) self._use_database = True
def _maintain_database(self, *args, **kwargs): POLLER.sched(INTERVAL, self._maintain_database) if (self._use_database and not NOTIFIER.is_subscribed("testdone")): self._writeback()
def _speedtest_check_timeout(self, *args, **kwargs): POLLER.sched(3, self._speedtest_check_timeout) if TRACKER.session_prune(): NOTIFIER.publish(RENEGOTIATE)
def __init__(self, poller): ServerHTTP.__init__(self, poller) self.begin_test = 0 POLLER.sched(3, self._speedtest_check_timeout) self.test_server = ServerTest(poller)
def _sample_queue_length(self, *args, **kwargs): LOG.info("SessionTracker: queue length: %d\n" % len(self.queue)) self.task = POLLER.sched(60, self._sample_queue_length)