Add a dynamic loading of the Watcher Planner implementation

In watcher, an audit generates a set of actions which
aims at achieving a given goal (lower energy consumption, ...).
It is possible to configure different strategies in order to achieve
each goal. Each strategy is written as a Python class which produces
a set of actions. Today, the set of possible actions is fixed for a
given version of Watcher and enables optimization algorithms to
include actions such as instance migration, changing hypervisor state,
changing power state (ACPI level, ...).

The objective of this patchset is to give the ability to extend the
default set of planner algorithms currently available in Watcher
using Stevedore.

The doc need to explain how create a new planner.

DocImpact
Partially implements: blueprint watcher-add-actions-via-conf

Change-Id: I2fd73f8c4a457ee391d764a7a3f494deecd2634f
This commit is contained in:
Jean-Emile DARTOIS
2016-01-07 16:54:15 +01:00
parent c0306ea8f4
commit 47759202a8
11 changed files with 157 additions and 32 deletions

View File

@@ -15,9 +15,8 @@
# limitations under the License.
import mock
from mock import MagicMock
from watcher.common.exception import ActionNotFound
from watcher.common import exception
from watcher.common import utils
from watcher.db import api as db_api
from watcher.decision_engine.actions.base import BaseAction
@@ -40,7 +39,7 @@ class SolutionFaker(object):
metrics = FakerMetricsCollector()
current_state_cluster = FakerModelCollector()
sercon = BasicConsolidation("basic", "Basic offline consolidation")
sercon.ceilometer = MagicMock(
sercon.ceilometer = mock.MagicMock(
get_statistics=metrics.mock_get_statistics)
return sercon.execute(current_state_cluster.generate_scenario_1())
@@ -51,7 +50,7 @@ class SolutionFakerSingleHyp(object):
metrics = FakerMetricsCollector()
current_state_cluster = FakerModelCollector()
sercon = BasicConsolidation("basic", "Basic offline consolidation")
sercon.ceilometer = MagicMock(
sercon.ceilometer = mock.MagicMock(
get_statistics=metrics.mock_get_statistics)
return sercon.execute(
@@ -117,7 +116,8 @@ class TestDefaultPlanner(base.DbTestCase):
audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
fake_solution = SolutionFaker.build()
fake_solution.actions[0] = "valeur_qcq"
self.assertRaises(ActionNotFound, self.default_planner.schedule,
self.assertRaises(exception.ActionNotFound,
self.default_planner.schedule,
self.context, audit.id, fake_solution)
def test_schedule_scheduled_empty(self):

View File

@@ -0,0 +1,29 @@
# -*- encoding: utf-8 -*-
# Copyright (c) 2016 b<>com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from watcher.decision_engine.planner import base as planner
from watcher.decision_engine.planner.loading import default
from watcher.tests import base
class TestDefaultPlannerLoader(base.TestCase):
loader = default.DefaultPlannerLoader()
def test_endpoints(self):
for endpoint in self.loader.list_available():
loaded = self.loader.load(endpoint)
self.assertIsNotNone(loaded)
self.assertIsInstance(loaded, planner.BasePlanner)

View File

@@ -0,0 +1,28 @@
# -*- encoding: utf-8 -*-
# Copyright (c) 2016 b<>com
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from oslo_config import cfg
from watcher.decision_engine.planner.default import DefaultPlanner
from watcher.decision_engine.planner.manager import PlannerManager
from watcher.tests import base
class TestPlannerManager(base.TestCase):
def test_load(self):
cfg.CONF.set_override('planner', "default", group='watcher_planner')
manager = PlannerManager()
self.assertIsInstance(manager.load(), DefaultPlanner)

View File

@@ -70,3 +70,7 @@ class TestDefaultStrategyLoader(TestCase):
strategy_loader = DefaultStrategyLoader()
loaded_strategy = strategy_loader.load("dummy")
self.assertIsInstance(loaded_strategy, DummyStrategy)
def test_endpoints(self):
for endpoint in self.strategy_loader.list_available():
self.assertIsNotNone(self.strategy_loader.load(endpoint))