Exemple #1
0
    def _doDiskPoller(self, thresholdToTest, level, config, expected = 0):
        poller = DiskSpacePoller(config, self.generator)
        # inject own input sample data provider
        poller.sample = lambda: self._dfCommandOutputGenerator(thresholdToTest,
                                                               thresholdToTest + 10)
        handler, receiver = utils.setUpReceiver(self.generator.config.Alert.address,
                                                self.generator.config.Alert.controlAddr)    
        proc = multiprocessing.Process(target = poller.poll, args = ())
        proc.start()
        self.assertTrue(proc.is_alive())

        # wait to poller to work now ... wait for alert to arrive
        if expected != 0:
            # #2238 AlertGenerator test can take 1 hour+ (and fail)
            # fail 2mins anyway if alert is not received
            timeLimitExceeded = False
            startTime = datetime.datetime.now()
            limitTime = 2 * 60 # seconds
            while len(handler.queue) == 0:
                time.sleep(config.pollInterval / 5)
                if (datetime.datetime.now() - startTime).seconds > limitTime:
                    timeLimitExceeded = True
                    break
        else:
            time.sleep(config.pollInterval * 2)

        proc.terminate()
        poller.shutdown()
        receiver.shutdown()
        self.assertFalse(proc.is_alive())
        
        if expected != 0:
            # #2238 AlertGenerator test can take 1 hour+ (and fail)
            # temporary measure from above loop:
            if timeLimitExceeded:
                self.fail("No alert received in %s seconds." % limitTime)
            # there should be just one alert received, poller should have the
            # change to send a second
            self.assertEqual(len(handler.queue), expected)
            a = handler.queue[0]
            # soft threshold - alert should have soft level
            self.assertEqual(a["Level"], level)
            self.assertEqual(a["Component"], self.generator.__class__.__name__)
            self.assertEqual(a["Source"], poller.__class__.__name__)
            d = a["Details"]
            self.assertEqual(d["mountPoint"], "/data")
            self.assertEqual(d["threshold"], "%s%%" % thresholdToTest)
        else:
            self.assertEqual(len(handler.queue), 0)
Exemple #2
0
    def _doDiskPoller(self, thresholdToTest, level, config, expected=0):
        poller = DiskSpacePoller(config, self.generator)
        # inject own input sample data provider
        poller.sample = lambda: self._dfCommandOutputGenerator(
            thresholdToTest, thresholdToTest + 10)
        handler, receiver = utils.setUpReceiver(
            self.generator.config.Alert.address,
            self.generator.config.Alert.controlAddr)
        poller.start()
        self.assertTrue(poller.is_alive())

        # wait to poller to work now ... wait for alert to arrive
        if expected != 0:
            # #2238 AlertGenerator test can take 1 hour+ (and fail)
            # fail 2mins anyway if alert is not received
            timeLimitExceeded = False
            startTime = datetime.datetime.now()
            limitTime = 2 * 60  # seconds
            while len(handler.queue) == 0:
                time.sleep(config.pollInterval / 5)
                if (datetime.datetime.now() - startTime).seconds > limitTime:
                    timeLimitExceeded = True
                    break
        else:
            time.sleep(config.pollInterval * 2)

        poller.terminate()
        receiver.shutdown()
        self.assertFalse(poller.is_alive())

        if expected != 0:
            # #2238 AlertGenerator test can take 1 hour+ (and fail)
            # temporary measure from above loop:
            if timeLimitExceeded:
                self.fail("No alert received in %s seconds." % limitTime)
            # there should be just one alert received, poller should have the
            # change to send a second
            self.assertEqual(len(handler.queue), expected)
            a = handler.queue[0]
            # soft threshold - alert should have soft level
            self.assertEqual(a["Level"], level)
            self.assertEqual(a["Component"], self.generator.__class__.__name__)
            self.assertEqual(a["Source"], poller.__class__.__name__)
            d = a["Details"]
            self.assertEqual(d["mountPoint"], "/data")
            self.assertEqual(d["threshold"], "%s%%" % thresholdToTest)
        else:
            self.assertEqual(len(handler.queue), 0)
Exemple #3
0
 def testDiskSpacePollerBasic(self):
     self.config.AlertGenerator.diskSpacePoller.soft = 60
     self.config.AlertGenerator.diskSpacePoller.critical = 90
     self.config.AlertGenerator.diskSpacePoller.pollInterval = 0.2
     poller = DiskSpacePoller(self.config.AlertGenerator.diskSpacePoller,
                              self.generator)
     poller.sample()
     # this may send an alert, provide sender
     poller.sender = utils.SenderMock()
     poller.check()
Exemple #4
0
 def testDiskSpacePollerBasic(self):
     self.config.AlertGenerator.diskSpacePoller.soft = 60
     self.config.AlertGenerator.diskSpacePoller.critical = 90
     self.config.AlertGenerator.diskSpacePoller.pollInterval = 0.2
     poller = DiskSpacePoller(self.config.AlertGenerator.diskSpacePoller, self.generator)
     poller.sample()
     # this may send an alert, provide sender
     poller.sender = utils.SenderMock()
     poller.check()