示例#1
0
    def prepare(self):
        """Prepare for this test
        - does test.doPrepare()
        - sends prepare messages to target probes
        - waits for all targets to reply with ready
        """
        # prepare everyone
        self.test.doPrepare()
        for target in self.test.getTargets():
            ProbeStorage.connectToProbe(target)
            # prepare for the test width given id
            Client.send(
                Prepare(target, self.test.getId(), self.test.getName(),
                        self.test.getOptions(), Identification.PROBE_ID))

        # wait for everyone to be ready
        self.isReadyForTest.wait(self.test.prepareTimeout)
        if not self.isReadyForTest.is_set():
            # TODO: send abort ?
            self.testError = TestError(
                "Prepare action timed out, probes did not reply in time")
        self.isReadyForTest.clear()
        if self.testError:
            raise self.testError

        testLogger.info("Prepare over, executing test")
示例#2
0
 def manageAdd(cls, action):
     """Add a probe to the DHT
     :param action: Add action containing the probe to add
     """
     assert isinstance(action, a.Add)
     cls.logger.debug("Managing Add task")
     #add the probe to the local DHT
     ProbeStorage.addProbe(ProbeStorage.newProbe(action.getIdSonde(), action.getIpSonde()))
     if action.hello is not None:
         # tell the new probe about all other probe
         Client.send(action.hello)
     cls.logger.info("Added probe %s, id %s to known probes", action.getIpSonde(), action.getIdSonde())
示例#3
0
 def manageUpdateProbes(cls, action):
     """Update your list of probes with this set of probes
     :param action: UpdateProbes action instance
     """
     assert isinstance(action, a.UpdateProbes)
     cls.logger.info("Joined overlay size %s", len(action.getProbeList()))
     if action.echo is not None:
         Client.send(Hello(action.echo, list(ProbeStorage.getAllOtherProbes()), Identification.PROBE_ID))
         cls.logger.info("Sent echo to %s", action.echo)
     for probe in action.getProbeList():
         # don't re-add ourselves to the local DHT
         if probe.getId() != Identification.PROBE_ID:
             ProbeStorage.addProbe(ProbeStorage.newProbe(probe.getId(), probe.getIp()))
示例#4
0
 def manageAdd(cls, action):
     """Add a probe to the DHT
     :param action: Add action containing the probe to add
     """
     assert isinstance(action, a.Add)
     cls.logger.debug("Managing Add task")
     #add the probe to the local DHT
     ProbeStorage.addProbe(
         ProbeStorage.newProbe(action.getIdSonde(), action.getIpSonde()))
     if action.hello is not None:
         # tell the new probe about all other probe
         Client.send(action.hello)
     cls.logger.info("Added probe %s, id %s to known probes",
                     action.getIpSonde(), action.getIdSonde())
示例#5
0
 def abort(self):
     """Abort a currently running test
     Does different actions depending of the current status of the test"""
     if not self.overed:
         self.test.doOver()
     self.testError = TestAborted("A probe send an abort signal")
     for target in self.test.getTargets():
         # this test is aborted!
         Client.send(Abort(target, self.test.getId()))
     # releasing all flags
     self.isReadyForTest.set()
     self.areReportsCollected.set()
     testLogger.ddebug("Abort message broadcast")
     self.isReadyForTest.set()
     testLogger.info("Test cancelled")
示例#6
0
 def abort(self):
     """Abort a currently running test
     Does different actions depending of the current status of the test"""
     if not self.overed:
         self.test.doOver()
     self.testError = TestAborted("A probe send an abort signal")
     for target in self.test.getTargets():
         # this test is aborted!
         Client.send(Abort(target, self.test.getId()))
     # releasing all flags
     self.isReadyForTest.set()
     self.areReportsCollected.set()
     testLogger.ddebug("Abort message broadcast")
     self.isReadyForTest.set()
     testLogger.info("Test cancelled")
示例#7
0
 def manageUpdateProbes(cls, action):
     """Update your list of probes with this set of probes
     :param action: UpdateProbes action instance
     """
     assert isinstance(action, a.UpdateProbes)
     cls.logger.info("Joined overlay size %s", len(action.getProbeList()))
     if action.echo is not None:
         Client.send(
             Hello(action.echo, list(ProbeStorage.getAllOtherProbes()),
                   Identification.PROBE_ID))
         cls.logger.info("Sent echo to %s", action.echo)
     for probe in action.getProbeList():
         # don't re-add ourselves to the local DHT
         if probe.getId() != Identification.PROBE_ID:
             ProbeStorage.addProbe(
                 ProbeStorage.newProbe(probe.getId(), probe.getIp()))
示例#8
0
 def manageAddPrefix(cls, action):
     """Add a prefix to the DHT. A prefix is a set of addresses
     :param action: AddPrefix action
     """
     assert isinstance(action, a.AddPrefix)
     try:
         net = ip_network(action.getPrefix(), strict = False)
         hosts = net.hosts() if net.num_addresses > 1 else [net.network_address]
         for host in hosts:
             try:
                 h = str(host)
                 if not ProbeStorage.isKnownIp(h):
                     Client.send(AddToOverlay(Identification.PROBE_ID, h))
             except Exception as e:
                 cls.logger.warning("Error while adding probe %s : %s", h, e)
     except ValueError:
         cls.logger.warning("Wrong prefix given %s", action.getPrefix())
示例#9
0
    def over(self):
        """Finish testing
        - does test.doOver()
        - sends Over message to targets
        - wait for target probes to reply with Result
        """
        self.test.doOver()
        for target in self.test.getTargets():
            # this test is over!
            Client.send(Over(target, self.test.getId()))

        self.areReportsCollected.wait(self.test.resultTimeout)
        # if a timeout occurs
        if not self.areReportsCollected.is_set():
            # TODO: send abort to the probe that did answer ?
            self.testError = TestError("All probes did not give results in time")
        self.areReportsCollected.clear()
        testLogger.info("Over done, processing results")
示例#10
0
    def over(self):
        """Finish testing
        - does test.doOver()
        - sends Over message to targets
        - wait for target probes to reply with Result
        """
        self.test.doOver()
        for target in self.test.getTargets():
            # this test is over!
            Client.send(Over(target, self.test.getId()))

        self.areReportsCollected.wait(self.test.resultTimeout)
        # if a timeout occurs
        if not self.areReportsCollected.is_set():
            # TODO: send abort to the probe that did answer ?
            self.testError = TestError(
                "All probes did not give results in time")
        self.areReportsCollected.clear()
        testLogger.info("Over done, processing results")
示例#11
0
 def manageAddPrefix(cls, action):
     """Add a prefix to the DHT. A prefix is a set of addresses
     :param action: AddPrefix action
     """
     assert isinstance(action, a.AddPrefix)
     try:
         net = ip_network(action.getPrefix(), strict=False)
         hosts = net.hosts() if net.num_addresses > 1 else [
             net.network_address
         ]
         for host in hosts:
             try:
                 h = str(host)
                 if not ProbeStorage.isKnownIp(h):
                     Client.send(AddToOverlay(Identification.PROBE_ID, h))
             except Exception as e:
                 cls.logger.warning("Error while adding probe %s : %s", h,
                                    e)
     except ValueError:
         cls.logger.warning("Wrong prefix given %s", action.getPrefix())
示例#12
0
    def prepare(self):
        """Prepare for this test
        - does test.doPrepare()
        - sends prepare messages to target probes
        - waits for all targets to reply with ready
        """
        # prepare everyone
        self.test.doPrepare()
        for target in self.test.getTargets():
            ProbeStorage.connectToProbe(target)
            # prepare for the test width given id
            Client.send(Prepare(target, self.test.getId(), self.test.getName(), self.test.getOptions(),
                                Identification.PROBE_ID))

        # wait for everyone to be ready
        self.isReadyForTest.wait(self.test.prepareTimeout)
        if not self.isReadyForTest.is_set():
            # TODO: send abort ?
            self.testError = TestError("Prepare action timed out, probes did not reply in time")
        self.isReadyForTest.clear()
        if self.testError:
            raise self.testError

        testLogger.info("Prepare over, executing test")
示例#13
0
 def finish(self):
     """Clean the test and send the results"""
     if self.report is not None:
         Client.send(Result(self.sourceId, self.test.getId(), self.report))
     TestResponder.cleanTest(self.test.getId())
示例#14
0
 def replyPrepare(self):
     """Prepare for the test and send Ready when ready"""
     self.test.replyPrepare()
     Client.send(
         Ready(self.sourceId, self.test.getId(), Identification.PROBE_ID))
示例#15
0
 def finish(self):
     """Clean the test and send the results"""
     if self.report is not None:
         Client.send(Result(self.sourceId, self.test.getId(), self.report))
     TestResponder.cleanTest(self.test.getId())
示例#16
0
 def replyPrepare(self):
     """Prepare for the test and send Ready when ready"""
     self.test.replyPrepare()
     Client.send(Ready(self.sourceId, self.test.getId(), Identification.PROBE_ID))