From c8e4efcd0bab637ee0e84dd6269c8ae09db5214a Mon Sep 17 00:00:00 2001 From: Dantali0n Date: Tue, 26 Mar 2019 08:53:25 +0100 Subject: [PATCH] Make datasource methods match names of metrics Metrics for datasources now match the name of their corresponding abstract methods. This ensures that developers know how the method is named if they know the name of the metric and vice versa. Change-Id: I0f9d400432d8182b3f10a0da97155e6cb786690e --- watcher/datasource/base.py | 66 +++++++++---------- watcher/datasource/ceilometer.py | 16 ++--- watcher/datasource/gnocchi.py | 16 ++--- watcher/datasource/monasca.py | 18 ++--- .../strategies/vm_workload_consolidation.py | 4 +- .../datasource/test_ceilometer_helper.py | 8 +-- .../tests/datasource/test_gnocchi_helper.py | 16 ++--- .../test_vm_workload_consolidation.py | 4 +- 8 files changed, 74 insertions(+), 74 deletions(-) diff --git a/watcher/datasource/base.py b/watcher/datasource/base.py index 4a920d0a8..08c75851b 100644 --- a/watcher/datasource/base.py +++ b/watcher/datasource/base.py @@ -19,16 +19,16 @@ import abc class DataSourceBase(object): METRIC_MAP = dict(host_cpu_usage=None, - instance_cpu_usage=None, - instance_l3_cache_usage=None, + host_memory_usage=None, host_outlet_temp=None, - host_airflow=None, host_inlet_temp=None, + host_airflow=None, host_power=None, + instance_cpu_usage=None, instance_ram_usage=None, instance_ram_allocated=None, + instance_l3_cache_usage=None, instance_root_disk_size=None, - host_memory_usage=None ) @abc.abstractmethod @@ -50,44 +50,19 @@ class DataSourceBase(object): granularity=None): pass - @abc.abstractmethod - def get_instance_cpu_usage(self, resource_id, period, aggregate, - granularity=None): - pass - @abc.abstractmethod def get_host_memory_usage(self, resource_id, period, aggregate, granularity=None): pass @abc.abstractmethod - def get_instance_memory_usage(self, resource_id, period, aggregate, - granularity=None): + def get_host_outlet_temp(self, resource_id, period, aggregate, + granularity=None): pass @abc.abstractmethod - def get_instance_l3_cache_usage(self, resource_id, period, aggregate, - granularity=None): - pass - - @abc.abstractmethod - def get_instance_ram_allocated(self, resource_id, period, aggregate, - granularity=None): - pass - - @abc.abstractmethod - def get_instance_root_disk_allocated(self, resource_id, period, aggregate, - granularity=None): - pass - - @abc.abstractmethod - def get_host_outlet_temperature(self, resource_id, period, aggregate, - granularity=None): - pass - - @abc.abstractmethod - def get_host_inlet_temperature(self, resource_id, period, aggregate, - granularity=None): + def get_host_inlet_temp(self, resource_id, period, aggregate, + granularity=None): pass @abc.abstractmethod @@ -98,3 +73,28 @@ class DataSourceBase(object): @abc.abstractmethod def get_host_power(self, resource_id, period, aggregate, granularity=None): pass + + @abc.abstractmethod + def get_instance_cpu_usage(self, resource_id, period, aggregate, + granularity=None): + pass + + @abc.abstractmethod + def get_instance_ram_usage(self, resource_id, period, aggregate, + granularity=None): + pass + + @abc.abstractmethod + def get_instance_ram_allocated(self, resource_id, period, aggregate, + granularity=None): + pass + + @abc.abstractmethod + def get_instance_l3_cache_usage(self, resource_id, period, aggregate, + granularity=None): + pass + + @abc.abstractmethod + def get_instance_root_disk_size(self, resource_id, period, aggregate, + granularity=None): + pass diff --git a/watcher/datasource/ceilometer.py b/watcher/datasource/ceilometer.py index eb08f7fe5..f774ef8c2 100644 --- a/watcher/datasource/ceilometer.py +++ b/watcher/datasource/ceilometer.py @@ -240,8 +240,8 @@ class CeilometerHelper(base.DataSourceBase): return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregate=aggregate) - def get_instance_memory_usage(self, resource_id, period, aggregate, - granularity=None): + def get_instance_ram_usage(self, resource_id, period, aggregate, + granularity=None): meter_name = self.METRIC_MAP.get('instance_ram_usage') return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregate=aggregate) @@ -258,20 +258,20 @@ class CeilometerHelper(base.DataSourceBase): return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregate=aggregate) - def get_instance_root_disk_allocated(self, resource_id, period, aggregate, - granularity=None): + def get_instance_root_disk_size(self, resource_id, period, aggregate, + granularity=None): meter_name = self.METRIC_MAP.get('instance_root_disk_size') return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregate=aggregate) - def get_host_outlet_temperature(self, resource_id, period, aggregate, - granularity=None): + def get_host_outlet_temp(self, resource_id, period, aggregate, + granularity=None): meter_name = self.METRIC_MAP.get('host_outlet_temp') return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregate=aggregate) - def get_host_inlet_temperature(self, resource_id, period, aggregate, - granularity=None): + def get_host_inlet_temp(self, resource_id, period, aggregate, + granularity=None): meter_name = self.METRIC_MAP.get('host_inlet_temp') return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregate=aggregate) diff --git a/watcher/datasource/gnocchi.py b/watcher/datasource/gnocchi.py index a41f79277..b60607009 100644 --- a/watcher/datasource/gnocchi.py +++ b/watcher/datasource/gnocchi.py @@ -148,8 +148,8 @@ class GnocchiHelper(base.DataSourceBase): return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregation=aggregate) - def get_instance_memory_usage(self, resource_id, period, aggregate, - granularity=300): + def get_instance_ram_usage(self, resource_id, period, aggregate, + granularity=300): meter_name = self.METRIC_MAP.get('instance_ram_usage') return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregation=aggregate) @@ -166,20 +166,20 @@ class GnocchiHelper(base.DataSourceBase): return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregation=aggregate) - def get_instance_root_disk_allocated(self, resource_id, period, aggregate, - granularity=300): + def get_instance_root_disk_size(self, resource_id, period, aggregate, + granularity=300): meter_name = self.METRIC_MAP.get('instance_root_disk_size') return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregation=aggregate) - def get_host_outlet_temperature(self, resource_id, period, aggregate, - granularity=300): + def get_host_outlet_temp(self, resource_id, period, aggregate, + granularity=300): meter_name = self.METRIC_MAP.get('host_outlet_temp') return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregation=aggregate) - def get_host_inlet_temperature(self, resource_id, period, aggregate, - granularity=300): + def get_host_inlet_temp(self, resource_id, period, aggregate, + granularity=300): meter_name = self.METRIC_MAP.get('host_inlet_temp') return self.statistic_aggregation(resource_id, meter_name, period, granularity, aggregation=aggregate) diff --git a/watcher/datasource/monasca.py b/watcher/datasource/monasca.py index 2847cc73f..6b02419ef 100644 --- a/watcher/datasource/monasca.py +++ b/watcher/datasource/monasca.py @@ -188,8 +188,8 @@ class MonascaHelper(base.DataSourceBase): granularity=None): raise NotImplementedError - def get_instance_memory_usage(self, resource_id, period, aggregate, - granularity=None): + def get_instance_ram_usage(self, resource_id, period, aggregate, + granularity=None): raise NotImplementedError def get_instance_l3_cache_usage(self, resource_id, period, aggregate, @@ -200,16 +200,16 @@ class MonascaHelper(base.DataSourceBase): granularity=None): raise NotImplementedError - def get_instance_root_disk_allocated(self, resource_id, period, aggregate, - granularity=None): - raise NotImplementedError - - def get_host_outlet_temperature(self, resource_id, period, aggregate, + def get_instance_root_disk_size(self, resource_id, period, aggregate, granularity=None): raise NotImplementedError - def get_host_inlet_temperature(self, resource_id, period, aggregate, - granularity=None): + def get_host_outlet_temp(self, resource_id, period, aggregate, + granularity=None): + raise NotImplementedError + + def get_host_inlet_temp(self, resource_id, period, aggregate, + granularity=None): raise NotImplementedError def get_host_airflow(self, resource_id, period, aggregate, diff --git a/watcher/decision_engine/strategy/strategies/vm_workload_consolidation.py b/watcher/decision_engine/strategy/strategies/vm_workload_consolidation.py index 28aa86940..06928d558 100644 --- a/watcher/decision_engine/strategy/strategies/vm_workload_consolidation.py +++ b/watcher/decision_engine/strategy/strategies/vm_workload_consolidation.py @@ -291,7 +291,7 @@ class VMWorkloadConsolidation(base.ServerConsolidationBaseStrategy): self.period, self.AGGREGATION, granularity=self.granularity) - instance_ram_util = self.datasource_backend.get_instance_memory_usage( + instance_ram_util = self.datasource_backend.get_instance_ram_usage( instance.uuid, self.period, self.AGGREGATION, @@ -304,7 +304,7 @@ class VMWorkloadConsolidation(base.ServerConsolidationBaseStrategy): self.AGGREGATION, granularity=self.granularity)) instance_disk_util = ( - self.datasource_backend.get_instance_root_disk_allocated( + self.datasource_backend.get_instance_root_disk_size( instance.uuid, self.period, self.AGGREGATION, diff --git a/watcher/tests/datasource/test_ceilometer_helper.py b/watcher/tests/datasource/test_ceilometer_helper.py index c1113ca56..cc79f53bd 100644 --- a/watcher/tests/datasource/test_ceilometer_helper.py +++ b/watcher/tests/datasource/test_ceilometer_helper.py @@ -127,7 +127,7 @@ class TestCeilometerHelper(base.BaseTestCase): def test_get_instance_memory_usage(self, mock_aggregation, mock_ceilometer): helper = ceilometer_helper.CeilometerHelper() - helper.get_instance_memory_usage('compute1', 600, 'mean') + helper.get_instance_ram_usage('compute1', 600, 'mean') mock_aggregation.assert_called_once_with( 'compute1', helper.METRIC_MAP['instance_ram_usage'], 600, None, aggregate='mean') @@ -157,7 +157,7 @@ class TestCeilometerHelper(base.BaseTestCase): def test_get_instance_root_disk_allocated(self, mock_aggregation, mock_ceilometer): helper = ceilometer_helper.CeilometerHelper() - helper.get_instance_root_disk_allocated('compute1', 600, 'mean') + helper.get_instance_root_disk_size('compute1', 600, 'mean') mock_aggregation.assert_called_once_with( 'compute1', helper.METRIC_MAP['instance_root_disk_size'], 600, None, aggregate='mean') @@ -167,7 +167,7 @@ class TestCeilometerHelper(base.BaseTestCase): def test_get_host_outlet_temperature(self, mock_aggregation, mock_ceilometer): helper = ceilometer_helper.CeilometerHelper() - helper.get_host_outlet_temperature('compute1', 600, 'mean') + helper.get_host_outlet_temp('compute1', 600, 'mean') mock_aggregation.assert_called_once_with( 'compute1', helper.METRIC_MAP['host_outlet_temp'], 600, None, aggregate='mean') @@ -177,7 +177,7 @@ class TestCeilometerHelper(base.BaseTestCase): def test_get_host_inlet_temperature(self, mock_aggregation, mock_ceilometer): helper = ceilometer_helper.CeilometerHelper() - helper.get_host_inlet_temperature('compute1', 600, 'mean') + helper.get_host_inlet_temp('compute1', 600, 'mean') mock_aggregation.assert_called_once_with( 'compute1', helper.METRIC_MAP['host_inlet_temp'], 600, None, aggregate='mean') diff --git a/watcher/tests/datasource/test_gnocchi_helper.py b/watcher/tests/datasource/test_gnocchi_helper.py index be156ba5e..f3f1227a7 100644 --- a/watcher/tests/datasource/test_gnocchi_helper.py +++ b/watcher/tests/datasource/test_gnocchi_helper.py @@ -75,8 +75,8 @@ class TestGnocchiHelper(base.BaseTestCase): @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_memory_usage('compute1', 600, 'mean', - granularity=300) + 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') @@ -94,8 +94,8 @@ class TestGnocchiHelper(base.BaseTestCase): def test_get_instance_root_disk_allocated(self, mock_aggregation, mock_gnocchi): helper = gnocchi_helper.GnocchiHelper() - helper.get_instance_root_disk_allocated('compute1', 600, 'mean', - granularity=300) + 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, 300, aggregation='mean') @@ -103,8 +103,8 @@ class TestGnocchiHelper(base.BaseTestCase): @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_temperature('compute1', 600, 'mean', - granularity=300) + 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') @@ -112,8 +112,8 @@ class TestGnocchiHelper(base.BaseTestCase): @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_temperature('compute1', 600, 'mean', - granularity=300) + helper.get_host_inlet_temp('compute1', 600, 'mean', + granularity=300) mock_aggregation.assert_called_once_with( 'compute1', helper.METRIC_MAP['host_inlet_temp'], 600, 300, aggregation='mean') diff --git a/watcher/tests/decision_engine/strategy/strategies/test_vm_workload_consolidation.py b/watcher/tests/decision_engine/strategy/strategies/test_vm_workload_consolidation.py index 020fd30d3..370938fc6 100644 --- a/watcher/tests/decision_engine/strategy/strategies/test_vm_workload_consolidation.py +++ b/watcher/tests/decision_engine/strategy/strategies/test_vm_workload_consolidation.py @@ -60,9 +60,9 @@ class TestVMWorkloadConsolidation(TestBaseStrategy): self.m_datasource.return_value = mock.Mock( get_instance_cpu_usage=( self.fake_metrics.get_instance_cpu_util), - get_instance_memory_usage=( + get_instance_ram_usage=( self.fake_metrics.get_instance_ram_util), - get_instance_root_disk_allocated=( + get_instance_root_disk_size=( self.fake_metrics.get_instance_disk_root_size), ) self.strategy = strategies.VMWorkloadConsolidation(