def test_monasca_statistic_list_query_retry(self, mock_monasca):
        monasca = mock.MagicMock()
        expected_result = [{
            'columns': ['timestamp', 'value', 'value_meta'],
            'dimensions': {
                'hostname': 'rdev-indeedsrv001',
                'service': 'monasca'
            },
            'id':
            '0',
            'measurements': [['2016-07-29T12:54:06.000Z', 0.9, {}],
                             ['2016-07-29T12:54:36.000Z', 0.9, {}],
                             ['2016-07-29T12:55:06.000Z', 0.9, {}],
                             ['2016-07-29T12:55:36.000Z', 0.8, {}]],
            'name':
            'cpu.percent'
        }]

        monasca.metrics.list_measurements.side_effect = [
            exc.HTTPUnauthorized, expected_result
        ]
        mock_monasca.return_value = monasca
        helper = monasca_helper.MonascaHelper()
        val = helper.statistics_list(meter_name="cpu.percent", dimensions={})
        self.assertEqual(expected_result, val)
Ejemplo n.º 2
0
 def test_check_availability(self, mock_monasca):
     monasca = mock.MagicMock()
     monasca.metrics.list.return_value = True
     mock_monasca.return_value = monasca
     helper = monasca_helper.MonascaHelper()
     result = helper.check_availability()
     self.assertEqual('available', result)
    def test_monasca_statistic_aggregation(self, mock_monasca):
        monasca = mock.MagicMock()
        expected_result = [{
            'columns': ['timestamp', 'avg'],
            'dimensions': {
                'hostname': 'rdev-indeedsrv001',
                'service': 'monasca'
            },
            'id':
            '0',
            'name':
            'cpu.percent',
            'statistics': [['2016-07-29T12:45:00Z', 0.0],
                           ['2016-07-29T12:50:00Z', 0.9100000000000001],
                           ['2016-07-29T12:55:00Z', 0.9111111111111112]]
        }]

        monasca.metrics.list_statistics.return_value = expected_result
        mock_monasca.return_value = monasca

        helper = monasca_helper.MonascaHelper()
        result = helper.statistic_aggregation(
            meter_name='cpu.percent',
            dimensions={'hostname': 'NODE_UUID'},
            start_time=timeutils.parse_isotime("2016-06-06T10:33:22.063176"),
            end_time=None,
            period=7200,
            aggregate='avg',
            group_by='*',
        )
        self.assertEqual(expected_result, result)
Ejemplo n.º 4
0
    def test_monasca_statistic_aggregation(self, mock_monasca):
        monasca = mock.MagicMock()
        expected_stat = [{
            'columns': ['timestamp', 'avg'],
            'dimensions': {
                'hostname': 'rdev-indeedsrv001',
                'service': 'monasca'
            },
            'id':
            '0',
            'name':
            'cpu.percent',
            'statistics': [['2016-07-29T12:45:00Z', 0.0],
                           ['2016-07-29T12:50:00Z', 0.9],
                           ['2016-07-29T12:55:00Z', 0.9]]
        }]

        monasca.metrics.list_statistics.return_value = expected_stat
        mock_monasca.return_value = monasca

        helper = monasca_helper.MonascaHelper()
        result = helper.statistic_aggregation(
            resource_id=None,
            meter_name='cpu.percent',
            period=7200,
            granularity=300,
            dimensions={'hostname': 'NODE_UUID'},
            aggregation='avg',
            group_by='*',
        )
        self.assertEqual(0.6, result)
Ejemplo n.º 5
0
 def monasca(self):
     if self._monasca is None:
         self._monasca = mon.MonascaHelper(osc=self.osc)
     return self._monasca
Ejemplo n.º 6
0
 def test_check_availability_with_failure(self, mock_monasca):
     monasca = mock.MagicMock()
     monasca.metrics.list.side_effect = Exception()
     mock_monasca.return_value = monasca
     helper = monasca_helper.MonascaHelper()
     self.assertEqual('not available', helper.check_availability())
Ejemplo n.º 7
0
 def test_get_instance_cpu_usage(self, mock_aggregation, mock_monasca):
     mock_aggregation.return_value = 0.6
     helper = monasca_helper.MonascaHelper()
     cpu_usage = helper.get_instance_cpu_usage('vm1', 600, 'mean')
     self.assertEqual(0.6, cpu_usage)
Ejemplo n.º 8
0
 def test_get_host_cpu_usage(self, mock_aggregation, mock_monasca):
     node = "compute1_compute1"
     mock_aggregation.return_value = 0.6
     helper = monasca_helper.MonascaHelper()
     cpu_usage = helper.get_host_cpu_usage(node, 600, 'mean')
     self.assertEqual(0.6, cpu_usage)