Merge "Replace removed exceptions and prevent regression"
This commit is contained in:
commit
f8fef7d774
@ -164,7 +164,7 @@ class CeilometerHelper(base.DataSourceBase):
|
||||
|
||||
meter = self.METRIC_MAP.get(meter_name)
|
||||
if meter is None:
|
||||
raise exception.NoSuchMetric()
|
||||
raise exception.MetricNotAvailable(metric=meter_name)
|
||||
|
||||
if aggregate == 'mean':
|
||||
aggregate = 'avg'
|
||||
|
@ -75,7 +75,7 @@ class GnocchiHelper(base.DataSourceBase):
|
||||
|
||||
meter = self.METRIC_MAP.get(meter_name)
|
||||
if meter is None:
|
||||
raise exception.NoSuchMetric()
|
||||
raise exception.MetricNotAvailable(metric=meter_name)
|
||||
|
||||
if aggregate == 'count':
|
||||
aggregate = 'mean'
|
||||
|
@ -92,7 +92,7 @@ class MonascaHelper(base.DataSourceBase):
|
||||
|
||||
meter = self.METRIC_MAP.get(meter_name)
|
||||
if meter is None:
|
||||
raise exception.NoSuchMetric()
|
||||
raise exception.MetricNotAvailable(metric=meter_name)
|
||||
|
||||
if aggregate == 'mean':
|
||||
aggregate = 'avg'
|
||||
|
@ -20,6 +20,7 @@ from __future__ import unicode_literals
|
||||
import mock
|
||||
|
||||
from watcher.common import clients
|
||||
from watcher.common import exception
|
||||
from watcher.datasources import ceilometer as ceilometer_helper
|
||||
from watcher.tests import base
|
||||
|
||||
@ -70,6 +71,29 @@ class TestCeilometerHelper(base.BaseTestCase):
|
||||
)
|
||||
self.assertEqual(expected_result, val)
|
||||
|
||||
def test_statistic_aggregation_metric_unavailable(self, mock_ceilometer):
|
||||
helper = ceilometer_helper.CeilometerHelper()
|
||||
|
||||
# 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="INSTANCE_ID"),
|
||||
resource_type='instance', meter_name="instance_cpu_usage",
|
||||
period="7300",
|
||||
granularity=None
|
||||
)
|
||||
|
||||
# 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
|
||||
)
|
||||
|
||||
def test_get_host_cpu_usage(self, mock_ceilometer):
|
||||
self.helper.get_host_cpu_usage('compute1', 600, 'mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
|
@ -18,6 +18,7 @@ import mock
|
||||
from oslo_config import cfg
|
||||
|
||||
from watcher.common import clients
|
||||
from watcher.common import exception
|
||||
from watcher.datasources import gnocchi as gnocchi_helper
|
||||
from watcher.tests import base
|
||||
|
||||
@ -57,6 +58,28 @@ class TestGnocchiHelper(base.BaseTestCase):
|
||||
)
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
def test_get_host_cpu_usage(self, mock_gnocchi):
|
||||
self.helper.get_host_cpu_usage('compute1', 600, 'mean', 300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
|
@ -18,6 +18,7 @@ import mock
|
||||
from oslo_config import cfg
|
||||
|
||||
from watcher.common import clients
|
||||
from watcher.common import exception
|
||||
from watcher.datasources import monasca as monasca_helper
|
||||
from watcher.tests import base
|
||||
|
||||
@ -65,6 +66,28 @@ class TestMonascaHelper(base.BaseTestCase):
|
||||
)
|
||||
self.assertEqual(0.6, result)
|
||||
|
||||
def test_statistic_aggregation_metric_unavailable(self, mock_monasca):
|
||||
helper = monasca_helper.MonascaHelper()
|
||||
|
||||
# invalidate host_cpu_usage in metric map
|
||||
original_metric_value = helper.METRIC_MAP.get('host_cpu_usage')
|
||||
helper.METRIC_MAP.update(
|
||||
host_cpu_usage=None
|
||||
)
|
||||
|
||||
self.assertRaises(
|
||||
exception.MetricNotAvailable, helper.statistic_aggregation,
|
||||
resource=mock.Mock(id='NODE_UUID'), resource_type='compute_node',
|
||||
meter_name='host_cpu_usage', period=7200, granularity=300,
|
||||
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
|
||||
)
|
||||
|
||||
def test_check_availability(self, mock_monasca):
|
||||
monasca = mock.MagicMock()
|
||||
monasca.metrics.list.return_value = True
|
||||
|
Loading…
Reference in New Issue
Block a user