Merge "Improve Gnocchi and Monasca datasource tests"
This commit is contained in:
@@ -27,6 +27,16 @@ CONF = cfg.CONF
|
||||
@mock.patch.object(clients.OpenStackClients, 'gnocchi')
|
||||
class TestGnocchiHelper(base.BaseTestCase):
|
||||
|
||||
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)
|
||||
|
||||
def test_gnocchi_statistic_aggregation(self, mock_gnocchi):
|
||||
gnocchi = mock.MagicMock()
|
||||
expected_result = 5.5
|
||||
@@ -48,91 +58,75 @@ class TestGnocchiHelper(base.BaseTestCase):
|
||||
)
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
def test_get_host_cpu_usage(self, mock_aggregation, mock_gnocchi):
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
helper.get_host_cpu_usage('compute1', 600, 'mean', granularity=300)
|
||||
mock_aggregation.assert_called_once_with(
|
||||
'compute1', helper.METRIC_MAP['host_cpu_usage'], 600, 300,
|
||||
aggregation='mean')
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
def test_get_instance_cpu_usage(self, mock_aggregation, mock_gnocchi):
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
helper.get_instance_cpu_usage('compute1', 600, 'mean', granularity=300)
|
||||
mock_aggregation.assert_called_once_with(
|
||||
'compute1', helper.METRIC_MAP['instance_cpu_usage'], 600, 300,
|
||||
aggregation='mean')
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
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')
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
def test_get_instance_memory_usage(self, mock_aggregation, mock_gnocchi):
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
helper.get_instance_ram_usage('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
mock_aggregation.assert_called_once_with(
|
||||
'compute1', helper.METRIC_MAP['instance_ram_usage'], 600, 300,
|
||||
aggregation='mean')
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
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')
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
def test_get_instance_root_disk_allocated(self, mock_aggregation,
|
||||
mock_gnocchi):
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
helper.get_instance_root_disk_size('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
mock_aggregation.assert_called_once_with(
|
||||
'compute1', helper.METRIC_MAP['instance_root_disk_size'], 600,
|
||||
def test_get_host_cpu_usage(self, mock_gnocchi):
|
||||
self.helper.get_host_cpu_usage('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_cpu_usage'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
def test_get_host_outlet_temperature(self, mock_aggregation, mock_gnocchi):
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
helper.get_host_outlet_temp('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
mock_aggregation.assert_called_once_with(
|
||||
'compute1', helper.METRIC_MAP['host_outlet_temp'], 600, 300,
|
||||
aggregation='mean')
|
||||
def test_get_instance_cpu_usage(self, mock_gnocchi):
|
||||
self.helper.get_instance_cpu_usage('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_cpu_usage'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
def test_get_host_inlet_temperature(self, mock_aggregation, mock_gnocchi):
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
helper.get_host_inlet_temp('compute1', 600, 'mean',
|
||||
def test_get_host_memory_usage(self, mock_gnocchi):
|
||||
self.helper.get_host_memory_usage('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_memory_usage'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_instance_memory_usage(self, mock_gnocchi):
|
||||
self.helper.get_instance_ram_usage('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_ram_usage'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_instance_ram_allocated(self, mock_gnocchi):
|
||||
self.helper.get_instance_ram_allocated('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_ram_allocated'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_instance_root_disk_allocated(self, mock_gnocchi):
|
||||
self.helper.get_instance_root_disk_size('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['instance_root_disk_size'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_host_outlet_temperature(self, mock_gnocchi):
|
||||
self.helper.get_host_outlet_temp('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_outlet_temp'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_host_inlet_temperature(self, mock_gnocchi):
|
||||
self.helper.get_host_inlet_temp('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_inlet_temp'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_host_airflow(self, mock_gnocchi):
|
||||
self.helper.get_host_airflow('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_airflow'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_get_host_power(self, mock_gnocchi):
|
||||
self.helper.get_host_power('compute1', 600, 'mean',
|
||||
granularity=300)
|
||||
mock_aggregation.assert_called_once_with(
|
||||
'compute1', helper.METRIC_MAP['host_inlet_temp'], 600, 300,
|
||||
aggregation='mean')
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
def test_get_host_airflow(self, mock_aggregation, mock_gnocchi):
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
helper.get_host_airflow('compute1', 600, 'mean', granularity=300)
|
||||
mock_aggregation.assert_called_once_with(
|
||||
'compute1', helper.METRIC_MAP['host_airflow'], 600, 300,
|
||||
aggregation='mean')
|
||||
|
||||
@mock.patch.object(gnocchi_helper.GnocchiHelper, 'statistic_aggregation')
|
||||
def test_get_host_power(self, mock_aggregation, mock_gnocchi):
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
helper.get_host_power('compute1', 600, 'mean', granularity=300)
|
||||
mock_aggregation.assert_called_once_with(
|
||||
'compute1', helper.METRIC_MAP['host_power'], 600, 300,
|
||||
aggregation='mean')
|
||||
self.mock_aggregation.assert_called_once_with(
|
||||
'compute1', self.helper.METRIC_MAP['host_power'], 600,
|
||||
300, aggregation='mean')
|
||||
|
||||
def test_gnocchi_check_availability(self, mock_gnocchi):
|
||||
gnocchi = mock.MagicMock()
|
||||
|
||||
@@ -27,6 +27,16 @@ CONF = cfg.CONF
|
||||
@mock.patch.object(clients.OpenStackClients, 'monasca')
|
||||
class TestMonascaHelper(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestMonascaHelper, self).setUp()
|
||||
self.osc_mock = mock.Mock()
|
||||
self.helper = monasca_helper.MonascaHelper(osc=self.osc_mock)
|
||||
stat_agg_patcher = mock.patch.object(
|
||||
self.helper, 'statistic_aggregation',
|
||||
spec=monasca_helper.MonascaHelper.statistic_aggregation)
|
||||
self.mock_aggregation = stat_agg_patcher.start()
|
||||
self.addCleanup(stat_agg_patcher.stop)
|
||||
|
||||
def test_monasca_statistic_aggregation(self, mock_monasca):
|
||||
monasca = mock.MagicMock()
|
||||
expected_stat = [{
|
||||
@@ -113,17 +123,13 @@ class TestMonascaHelper(base.BaseTestCase):
|
||||
val = helper.statistics_list(meter_name="cpu.percent", dimensions={})
|
||||
self.assertEqual(expected_result, val)
|
||||
|
||||
@mock.patch.object(monasca_helper.MonascaHelper, 'statistic_aggregation')
|
||||
def test_get_host_cpu_usage(self, mock_aggregation, mock_monasca):
|
||||
def test_get_host_cpu_usage(self, 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.mock_aggregation.return_value = 0.6
|
||||
cpu_usage = self.helper.get_host_cpu_usage(node, 600, 'mean')
|
||||
self.assertEqual(0.6, cpu_usage)
|
||||
|
||||
@mock.patch.object(monasca_helper.MonascaHelper, 'statistic_aggregation')
|
||||
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')
|
||||
def test_get_instance_cpu_usage(self, mock_monasca):
|
||||
self.mock_aggregation.return_value = 0.6
|
||||
cpu_usage = self.helper.get_instance_cpu_usage('vm1', 600, 'mean')
|
||||
self.assertEqual(0.6, cpu_usage)
|
||||
|
||||
Reference in New Issue
Block a user