Esempio n. 1
0
 def test_gnocchi_check_availability(self, mock_gnocchi):
     gnocchi = mock.MagicMock()
     gnocchi.status.get.return_value = True
     mock_gnocchi.return_value = gnocchi
     helper = gnocchi_helper.GnocchiHelper()
     result = helper.check_availability()
     self.assertEqual('available', result)
Esempio n. 2
0
 def test_gnocchi_list_metrics_with_failure(self, mock_gnocchi):
     cfg.CONF.set_override("query_max_retries",
                           1,
                           group='watcher_datasources')
     gnocchi = mock.MagicMock()
     gnocchi.metric.list.side_effect = Exception()
     mock_gnocchi.return_value = gnocchi
     helper = gnocchi_helper.GnocchiHelper()
     self.assertFalse(helper.list_metrics())
Esempio n. 3
0
 def test_gnocchi_list_metrics(self, mock_gnocchi):
     gnocchi = mock.MagicMock()
     metrics = [{"name": "metric1"}, {"name": "metric2"}]
     expected_metrics = set(["metric1", "metric2"])
     gnocchi.metric.list.return_value = metrics
     mock_gnocchi.return_value = gnocchi
     helper = gnocchi_helper.GnocchiHelper()
     result = helper.list_metrics()
     self.assertEqual(expected_metrics, result)
Esempio n. 4
0
 def setUp(self):
     super(TestGnocchiHelper, self).setUp()
     self.osc_mock = mock.Mock()
     self.helper = gnocchi_helper.GnocchiHelper(osc=self.osc_mock)
     stat_agg_patcher = mock.patch.object(
         self.helper,
         'statistic_aggregation',
         spec=gnocchi_helper.GnocchiHelper.statistic_aggregation)
     self.mock_aggregation = stat_agg_patcher.start()
     self.addCleanup(stat_agg_patcher.stop)
Esempio n. 5
0
    def test_gnocchi_check_availability_with_failure(self, mock_gnocchi):
        cfg.CONF.set_override("query_max_retries",
                              1,
                              group='watcher_datasources')
        gnocchi = mock.MagicMock()
        gnocchi.status.get.side_effect = Exception()
        mock_gnocchi.return_value = gnocchi
        helper = gnocchi_helper.GnocchiHelper()

        self.assertEqual('not available', helper.check_availability())
Esempio n. 6
0
    def test_gnocchi_statistic_aggregation(self, mock_gnocchi):
        gnocchi = mock.MagicMock()
        expected_result = 5.5

        expected_measures = [["2017-02-02T09:00:00.000000", 360, 5.5]]

        gnocchi.metric.get_measures.return_value = expected_measures
        mock_gnocchi.return_value = gnocchi

        helper = gnocchi_helper.GnocchiHelper()
        result = helper.statistic_aggregation(
            resource=mock.Mock(id='16a86790-327a-45f9-bc82-45839f062fdc'),
            resource_type='instance',
            meter_name='instance_cpu_usage',
            period=300,
            granularity=360,
            aggregate='mean',
        )
        self.assertEqual(expected_result, result)
Esempio n. 7
0
    def test_statistic_aggregation_metric_unavailable(self, mock_gnocchi):
        helper = gnocchi_helper.GnocchiHelper()

        # invalidate instance_cpu_usage in metric map
        original_metric_value = helper.METRIC_MAP.get('instance_cpu_usage')
        helper.METRIC_MAP.update(instance_cpu_usage=None)

        self.assertRaises(
            exception.MetricNotAvailable,
            helper.statistic_aggregation,
            resource=mock.Mock(id='16a86790-327a-45f9-bc82-45839f062fdc'),
            resource_type='instance',
            meter_name='instance_cpu_usage',
            period=300,
            granularity=360,
            aggregate='mean',
        )

        # restore the metric map as it is a static attribute that does not get
        # restored between unit tests!
        helper.METRIC_MAP.update(instance_cpu_usage=original_metric_value)
Esempio n. 8
0
 def gnocchi(self):
     if self._gnocchi is None:
         self._gnocchi = gnoc.GnocchiHelper(osc=self.osc)
     return self._gnocchi