Exemplo n.º 1
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")
Exemplo n.º 2
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")
Exemplo n.º 3
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")
Exemplo n.º 4
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")
Exemplo n.º 5
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")
Exemplo n.º 6
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")
Exemplo n.º 7
0
class _TestManager(Thread):
    """The test manager is a internal thread who runs the test independently"""
    NAME_TPL = "TestManager_%s-%s"

    def __init__(self, test, formatResult, resultCallback, errorCallback):
        super().__init__()
        self.setName(self.NAME_TPL % (test.getName(), test.getId()))
        self.readies = 0
        self.readyLock = RLock()
        self.isReadyForTest = Event()
        self.reportsLock = RLock()
        self.reports = {}
        self.areReportsCollected = Event()
        self.test = test
        self.testError = None
        self.resultCallback = resultCallback
        self.errorCallback = errorCallback
        self.formatResult = formatResult
        self.prepared = False
        self.tested = False
        self.overed = False

    def run(self):
        """Starts the process of testing"""
        testLogger.info("Starting test %s", self.test.getName())
        try:
            self.prepare()
            self.prepared = True
            self.performTest()
            self.tested = True
            self.over()
            self.overed = True
            self.result()
        except TestError as e:
            self.testError = e
        finally:
            self.finish()

    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")

    def performTest(self):
        """Perform the actual test"""
        self.test.doTest()
        testLogger.info("Actual test is done")

    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")

    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")

    def result(self):
        """Disconnect probes and compute result of the test"""
        for target in self.test.getTargets():
            ProbeStorage.disconnectFromProbe(target)
        self.test.doResult(self.reports)
        testLogger.info("Results processing over, test is done")

    ###Tools methods

    def addReady(self, message):
        """Adds a ready message from a remote probe
        :param message : a Ready message from the target probes"""
        if message.getTestId() == self.test.getId():
            with self.readyLock:
                testLogger.ddebug("Received new Ready from target probe")
                self.readies += 1
                if self.readies == self.test.getProbeNumber():
                    testLogger.info(
                        "All Readies received, proceeding with test")
                    time.sleep(0.2)
                    self.isReadyForTest.set()
                    self.readies = 0

    def addReport(self, report):
        """Adds a report from the remote probe
        :param report : Report of this probe about the test
        """
        with self.reportsLock:
            probeId = report.getProbeId()
            self.reports[probeId] = report
            testLogger.ddebug("Received new report from target probe")
            if len(self.reports) == self.test.getProbeNumber():
                testLogger.info("All reports received, proceeding with result")
                self.areReportsCollected.set()

    def finish(self):
        """Finish the _testManager, removing yourself from the index
        Sends result with callback provided on initialisation
        """
        TestManager.cleanTest(self.test.getId())
        if self.testError is not None:
            if self.formatResult:
                self.errorCallback(self.test.getName(),
                                   self.testError.getReason())
            else:
                self.errorCallback(self.test.getId(), self.testError)
            testLogger.error("An error occurred during test %s",
                             self.testError.getReason())
        else:
            if self.formatResult:
                self.resultCallback(self.test.getName(), self.test.getResult())
            else:
                self.resultCallback(self.test.getId(),
                                    self.test.getRawResult())
Exemplo n.º 8
0
class _TestManager(Thread):
    """The test manager is a internal thread who runs the test independently"""
    NAME_TPL = "TestManager_%s-%s"

    def __init__(self, test, formatResult, resultCallback, errorCallback):
        super().__init__()
        self.setName(self.NAME_TPL % (test.getName(), test.getId()))
        self.readies = 0
        self.readyLock = RLock()
        self.isReadyForTest = Event()
        self.reportsLock = RLock()
        self.reports = {}
        self.areReportsCollected = Event()
        self.test = test
        self.testError = None
        self.resultCallback = resultCallback
        self.errorCallback = errorCallback
        self.formatResult = formatResult
        self.prepared = False
        self.tested = False
        self.overed = False


    def run(self):
        """Starts the process of testing"""
        testLogger.info("Starting test %s", self.test.getName())
        try:
            self.prepare()
            self.prepared = True
            self.performTest()
            self.tested = True
            self.over()
            self.overed = True
            self.result()
        except TestError as e:
            self.testError = e
        finally:
            self.finish()


    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")

    def performTest(self):
        """Perform the actual test"""
        self.test.doTest()
        testLogger.info("Actual test is done")


    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")

    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")

    def result(self):
        """Disconnect probes and compute result of the test"""
        for target in self.test.getTargets():
            ProbeStorage.disconnectFromProbe(target)
        self.test.doResult(self.reports)
        testLogger.info("Results processing over, test is done")


    ###Tools methods

    def addReady(self, message):
        """Adds a ready message from a remote probe
        :param message : a Ready message from the target probes"""
        if message.getTestId() == self.test.getId():
            with self.readyLock:
                testLogger.ddebug("Received new Ready from target probe")
                self.readies += 1
                if self.readies == self.test.getProbeNumber():
                    testLogger.info("All Readies received, proceeding with test")
                    time.sleep(0.2)
                    self.isReadyForTest.set()
                    self.readies = 0


    def addReport(self, report):
        """Adds a report from the remote probe
        :param report : Report of this probe about the test
        """
        with self.reportsLock:
            probeId = report.getProbeId()
            self.reports[probeId] = report
            testLogger.ddebug("Received new report from target probe")
            if len(self.reports) == self.test.getProbeNumber():
                testLogger.info("All reports received, proceeding with result")
                self.areReportsCollected.set()

    def finish(self):
        """Finish the _testManager, removing yourself from the index
        Sends result with callback provided on initialisation
        """
        TestManager.cleanTest(self.test.getId())
        if self.testError is not None:
            if self.formatResult:
                self.errorCallback(self.test.getName(), self.testError.getReason())
            else:
                self.errorCallback(self.test.getId(), self.testError)
            testLogger.error("An error occurred during test %s", self.testError.getReason())
        else:
            if self.formatResult:
                self.resultCallback(self.test.getName(), self.test.getResult())
            else:
                self.resultCallback(self.test.getId(), self.test.getRawResult())
Exemplo n.º 9
0
 def abort(self):
     """End the test early"""
     if not self.overed:
         self.test.doOver()
     self.testError = TestAborted("Test aborted early.")
     testLogger.info("Test cancelled")
Exemplo n.º 10
0
class _TestManager(Thread):
    """A tread to manage a test"""

    NAME_TPL = "TestManager_%s-%s"

    def __init__(self, test, formatResult, resultCallback, errorCallback):
        super().__init__()
        self.setName(self.NAME_TPL % (test.getName(), test.getId()))
        self.test = test
        self.testError = None
        self.resultCallback = resultCallback
        self.errorCallback = errorCallback
        self.formatResult = formatResult
        self.prepared = False
        self.tested = False
        self.overed = False

    def run(self):
        """Starts the process of testing"""
        testLogger.info("Starting test %s", self.test.getName())
        try:
            self.prepare()
            self.prepared = True
            self.performTest()
            self.tested = True
            self.over()
            self.overed = True
            self.result()
        except TestError as e:
            self.testError = e
        finally:
            self.finish()

    def prepare(self):
        """Prepare for the test"""
        self.test.doPrepare()
        testLogger.info("Prepare over, executing test")

    def performTest(self):
        """Do the actual test"""
        self.test.doTest()
        testLogger.info("Actual test is done")

    def over(self):
        """End the test"""
        self.test.doOver()
        testLogger.info("Over done, processing results")

    def abort(self):
        """End the test early"""
        if not self.overed:
            self.test.doOver()
        self.testError = TestAborted("Test aborted early.")
        testLogger.info("Test cancelled")

    def result(self):
        """Compute results for this test"""
        self.test.doResult()
        testLogger.info("Results processing over, test is done")

    def finish(self):
        """Clean everything and write results using callbacks"""
        TestManager.cleanTest(self.test.getId())
        if self.testError is not None:
            if self.formatResult:
                self.errorCallback(self.test.getName(), self.testError.getReason())
            else:
                self.errorCallback(self.test.getId(), self.testError)
            testLogger.error("An error occurred during test %s", self.testError.getReason())
        else:
            if self.formatResult:
                self.resultCallback(self.test.getName(), self.test.getResult())
            else:
                self.resultCallback(self.test.getId(), self.test.getRawResult())