Пример #1
0
    def testProcessCollectedDataWithClearingOfCollectorError(
            self, engineMock, repoMock, *_mocks):
        # Test MetricCollector._processCollectedData with clearing of collector
        # error state
        metricID = 1

        mockMetric = _makeFreshMetricMockInstance(metricPollInterval=5,
                                                  uid=metricID)
        mockMetric.collector_error = dict(deadline=time.time(), message="Blah")

        dataCollectionResult = metric_collector._DataCollectionResult(
            metricID=metricID)
        dataCollectionResult.data = []

        metricsToUpdate = OrderedDict()
        metricsToUpdate[mockMetric.uid] = mockMetric

        collector = metric_collector.MetricCollector()
        numEmpty, numErrors = collector._processCollectedData(
            engineMock,
            metricsToUpdate=metricsToUpdate,
            collectResult=dataCollectionResult,
            modelSwapper=Mock())

        self.assertEqual(numEmpty, 1)
        self.assertEqual(numErrors, 0)
        repoMock.retryOnTransientErrors('repository.setMetricCollectorError')\
          .assert_called_once_with(
            engineMock.connect.return_value.__enter__.return_value,
            metricID,
            None)
Пример #2
0
    def testProcessCollectedDataWithGetInstanceStatusError(
            self, engineMock, *_mocks):
        # Test MetricCollector._processCollectedData with collection result
        # containing getInstanceStatus error
        metricID = 1

        mockMetric = _makeFreshMetricMockInstance(metricPollInterval=5,
                                                  uid=metricID)

        dataCollectionResult = metric_collector._DataCollectionResult(
            metricID=metricID)
        dataCollectionResult.data = []
        dataCollectionResult.resourceStatus = BotoServerError(
            500, "Fake getInstanceStatus BotoServerError")

        metricsToUpdate = OrderedDict()
        metricsToUpdate[mockMetric.uid] = mockMetric

        collector = metric_collector.MetricCollector()
        numEmpty, numErrors = collector._processCollectedData(
            engineMock,
            metricsToUpdate=metricsToUpdate,
            collectResult=dataCollectionResult,
            modelSwapper=Mock())

        self.assertEqual(numEmpty, 1)
        self.assertEqual(numErrors, 1)
Пример #3
0
 def runCollector():
     try:
         collector = metric_collector.MetricCollector()
         resultOfRunCollector["returnCode"] = collector.run()
     except:
         resultOfRunCollector["exception"] = sys.exc_info()[1]
         raise
Пример #4
0
    def testProcessCollectedDataWithEmptyNewData(self, engineMock, *_mocks):
        # Test MetricCollector._processCollectedData with collection result
        # containing empty data set
        metricID = 1
        mockMetric = _makeFreshMetricMockInstance(metricPollInterval=5,
                                                  uid=metricID)

        dataCollectionResult = metric_collector._DataCollectionResult(
            metricID=metricID)
        dataCollectionResult.data = []

        metricsToUpdate = OrderedDict()
        metricsToUpdate[mockMetric.uid] = mockMetric

        collector = metric_collector.MetricCollector()
        numEmpty, numErrors = collector._processCollectedData(
            engineMock,
            metricsToUpdate=metricsToUpdate,
            collectResult=dataCollectionResult,
            modelSwapper=Mock())

        self.assertEqual(numEmpty, 1)
        self.assertEqual(numErrors, 0)