diff --git a/watcher/decision_engine/strategy/strategies/uniform_airflow.py b/watcher/decision_engine/strategy/strategies/uniform_airflow.py index 5ac13fe37..ac27ff3d0 100644 --- a/watcher/decision_engine/strategy/strategies/uniform_airflow.py +++ b/watcher/decision_engine/strategy/strategies/uniform_airflow.py @@ -90,12 +90,6 @@ class UniformAirflow(base.BaseStrategy): super(UniformAirflow, self).__init__(config, osc) # The migration plan will be triggered when the airflow reaches # threshold - self.meter_name_airflow = self.METRIC_NAMES[ - self.config.datasource]['host_airflow'] - self.meter_name_inlet_t = self.METRIC_NAMES[ - self.config.datasource]['host_inlet_temp'] - self.meter_name_power = self.METRIC_NAMES[ - self.config.datasource]['host_power'] self._period = self.PERIOD @classmethod @@ -158,11 +152,14 @@ class UniformAirflow(base.BaseStrategy): @classmethod def get_config_opts(cls): return [ - cfg.StrOpt( - "datasource", - help="Data source to use in order to query the needed metrics", - default="gnocchi", - choices=["ceilometer", "gnocchi"]) + cfg.ListOpt( + "datasources", + help="Datasources to use in order to query the needed metrics." + " If one of strategy metric isn't available in the first" + " datasource, the next datasource will be chosen.", + item_type=cfg.types.String(choices=['gnocchi', 'ceilometer', + 'monasca']), + default=['gnocchi', 'ceilometer', 'monasca']), ] def get_available_compute_nodes(self): @@ -317,6 +314,13 @@ class UniformAirflow(base.BaseStrategy): if self.compute_model.stale: raise wexc.ClusterStateStale() + self.meter_name_airflow = self.METRIC_NAMES[ + self.datasource_backend.NAME]['host_airflow'] + self.meter_name_inlet_t = self.METRIC_NAMES[ + self.datasource_backend.NAME]['host_inlet_temp'] + self.meter_name_power = self.METRIC_NAMES[ + self.datasource_backend.NAME]['host_power'] + LOG.debug(self.compute_model.to_string()) def do_execute(self): diff --git a/watcher/tests/decision_engine/model/ceilometer_metrics.py b/watcher/tests/decision_engine/model/ceilometer_metrics.py index 6fc4f5545..64aeb80bd 100644 --- a/watcher/tests/decision_engine/model/ceilometer_metrics.py +++ b/watcher/tests/decision_engine/model/ceilometer_metrics.py @@ -20,6 +20,8 @@ import oslo_utils class FakeCeilometerMetrics(object): + NAME = 'ceilometer' + def __init__(self): self.emptytype = "" diff --git a/watcher/tests/decision_engine/model/gnocchi_metrics.py b/watcher/tests/decision_engine/model/gnocchi_metrics.py index a340f7a3b..817e4636d 100644 --- a/watcher/tests/decision_engine/model/gnocchi_metrics.py +++ b/watcher/tests/decision_engine/model/gnocchi_metrics.py @@ -15,6 +15,8 @@ import oslo_utils class FakeGnocchiMetrics(object): + NAME = 'gnocchi' + def __init__(self): self.emptytype = "" diff --git a/watcher/tests/decision_engine/strategy/strategies/test_uniform_airflow.py b/watcher/tests/decision_engine/strategy/strategies/test_uniform_airflow.py index 42f76ec15..39a04fc10 100644 --- a/watcher/tests/decision_engine/strategy/strategies/test_uniform_airflow.py +++ b/watcher/tests/decision_engine/strategy/strategies/test_uniform_airflow.py @@ -71,7 +71,8 @@ class TestUniformAirflow(base.TestCase): self.m_model.return_value = model_root.ModelRoot() self.m_datasource.return_value = mock.Mock( - statistic_aggregation=self.fake_metrics.mock_get_statistics) + statistic_aggregation=self.fake_metrics.mock_get_statistics, + NAME=self.fake_metrics.NAME) self.strategy = strategies.UniformAirflow( config=mock.Mock(datasource=self.datasource)) self.strategy.input_parameters = utils.Struct() @@ -83,6 +84,7 @@ class TestUniformAirflow(base.TestCase): self.strategy.threshold_inlet_t = 28 self.strategy.threshold_power = 350 self._period = 300 + self.strategy.pre_execute() def test_calc_used_resource(self): model = self.fake_cluster.generate_scenario_7_with_2_nodes()