Exemple #1
0
 def test_gnocchi_list_metrics_with_failure(self, mock_gnocchi):
     cfg.CONF.set_override("query_max_retries", 1, group='gnocchi_client')
     gnocchi = mock.MagicMock()
     gnocchi.metric.list.side_effect = Exception()
     mock_gnocchi.return_value = gnocchi
     helper = gnocchi_helper.GnocchiHelper()
     self.assertFalse(helper.list_metrics())
Exemple #2
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)
Exemple #3
0
    def test_gnocchi_check_availability_with_failure(self, mock_gnocchi):
        cfg.CONF.set_override("query_max_retries", 1, group='gnocchi_client')
        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())
Exemple #4
0
 def test_get_host_memory_usage(self, mock_aggregation, mock_gnocchi):
     helper = gnocchi_helper.GnocchiHelper()
     helper.get_host_memory_usage('compute1', 600, 'mean', granularity=300)
     mock_aggregation.assert_called_once_with(
         'compute1',
         helper.METRIC_MAP['host_memory_usage'],
         600,
         300,
         aggregation='mean')
Exemple #5
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)
Exemple #6
0
 def test_get_instance_ram_allocated(self, mock_aggregation, mock_gnocchi):
     helper = gnocchi_helper.GnocchiHelper()
     helper.get_instance_ram_allocated('compute1',
                                       600,
                                       'mean',
                                       granularity=300)
     mock_aggregation.assert_called_once_with(
         'compute1',
         helper.METRIC_MAP['instance_ram_allocated'],
         600,
         300,
         aggregation='mean')
Exemple #7
0
    def test_gnocchi_wrong_datetime(self, mock_gnocchi):
        gnocchi = mock.MagicMock()

        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()
        self.assertRaises(
            exception.InvalidParameter, helper.statistic_aggregation,
            resource_id='16a86790-327a-45f9-bc82-45839f062fdc',
            metric='cpu_util',
            granularity=360,
            start_time="2017-02-02T09:00:00.000000",
            stop_time=timeutils.parse_isotime("2017-02-02T10:00:00.000000"),
            aggregation='mean')
Exemple #8
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_id='16a86790-327a-45f9-bc82-45839f062fdc',
            meter_name='cpu_util',
            period=300,
            granularity=360,
            dimensions=None,
            aggregation='mean',
            group_by='*')
        self.assertEqual(expected_result, result)
Exemple #9
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_id='16a86790-327a-45f9-bc82-45839f062fdc',
            metric='cpu_util',
            granularity=360,
            start_time=timeutils.parse_isotime("2017-02-02T09:00:00.000000"),
            stop_time=timeutils.parse_isotime("2017-02-02T10:00:00.000000"),
            aggregation='mean'
        )
        self.assertEqual(expected_result, result)
Exemple #10
0
 def gnocchi(self):
     if self._gnocchi is None:
         self.gnocchi = gnoc.GnocchiHelper(osc=self.osc)
     return self._gnocchi