Add a generic and extensible way to describe the flow of actions
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, ...). This patchset propose a generic and extensible way to describe the actions and his parameters that we want to add to Action Plan. It also remove the static actions because they are now deprecated. The documentation regarding strategy plugin need to be updated (plugins.rst). DocImpact Partially implements: blueprint watcher-add-actions-via-conf Change-Id: I3d641080e8ad89786abca79a942c8deb2d53355b
This commit is contained in:
@@ -83,7 +83,7 @@ def get_test_action(**kwargs):
|
||||
'id': kwargs.get('id', 1),
|
||||
'uuid': kwargs.get('uuid', '10a47dd1-4874-4298-91cf-eff046dbdb8d'),
|
||||
'action_plan_id': kwargs.get('action_plan_id', 1),
|
||||
'action_type': kwargs.get('action_type', 'COLD_MIGRATION'),
|
||||
'action_type': kwargs.get('action_type', 'nop'),
|
||||
'applies_to': kwargs.get('applies_to',
|
||||
'10a47dd1-4874-4298-91cf-eff046dbdb8d'),
|
||||
'input_parameters': kwargs.get('input_parameters', {'key1': 'val1',
|
||||
|
||||
@@ -16,19 +16,17 @@
|
||||
|
||||
import mock
|
||||
|
||||
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
|
||||
from watcher.decision_engine.planner.default import DefaultPlanner
|
||||
from watcher.decision_engine.solution.default import DefaultSolution
|
||||
from watcher.decision_engine.strategy.strategies.basic_consolidation import \
|
||||
BasicConsolidation
|
||||
from watcher.tests.db import base
|
||||
from watcher.tests.db import utils as db_utils
|
||||
from watcher.tests.decision_engine.strategy.strategies.faker_cluster_state\
|
||||
from watcher.tests.decision_engine.strategy.strategies.faker_cluster_state \
|
||||
import FakerModelCollector
|
||||
from watcher.tests.decision_engine.strategy.strategies.faker_metrics_collector\
|
||||
from watcher.tests.decision_engine.strategy.strategies.faker_metrics_collector \
|
||||
import FakerMetricsCollector
|
||||
from watcher.tests.objects import utils as obj_utils
|
||||
|
||||
@@ -39,8 +37,8 @@ class SolutionFaker(object):
|
||||
metrics = FakerMetricsCollector()
|
||||
current_state_cluster = FakerModelCollector()
|
||||
sercon = BasicConsolidation("basic", "Basic offline consolidation")
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
get_statistics=metrics.mock_get_statistics)
|
||||
sercon.ceilometer = mock.\
|
||||
MagicMock(get_statistics=metrics.mock_get_statistics)
|
||||
return sercon.execute(current_state_cluster.generate_scenario_1())
|
||||
|
||||
|
||||
@@ -50,29 +48,32 @@ class SolutionFakerSingleHyp(object):
|
||||
metrics = FakerMetricsCollector()
|
||||
current_state_cluster = FakerModelCollector()
|
||||
sercon = BasicConsolidation("basic", "Basic offline consolidation")
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
get_statistics=metrics.mock_get_statistics)
|
||||
sercon.ceilometer = \
|
||||
mock.MagicMock(get_statistics=metrics.mock_get_statistics)
|
||||
|
||||
return sercon.execute(
|
||||
current_state_cluster.generate_scenario_3_with_2_hypervisors())
|
||||
|
||||
|
||||
class TestActionScheduling(base.DbTestCase):
|
||||
scenarios = [
|
||||
(str(action_cls), {"fake_action": mock.Mock(spec=action_cls)})
|
||||
for action_cls in BaseAction.__subclasses__()]
|
||||
|
||||
def test_schedule_actions(self):
|
||||
default_planner = DefaultPlanner()
|
||||
audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
|
||||
dummy_solution = DefaultSolution()
|
||||
dummy_solution.add_change_request(self.fake_action)
|
||||
solution = DefaultSolution()
|
||||
|
||||
parameters = {
|
||||
"src_uuid_hypervisor": "server1",
|
||||
"dst_uuid_hypervisor": "server2",
|
||||
}
|
||||
solution.add_action(action_type="migrate",
|
||||
applies_to="b199db0c-1408-4d52-b5a5-5ca14de0ff36",
|
||||
input_parameters=parameters)
|
||||
|
||||
with mock.patch.object(
|
||||
DefaultPlanner, "create_action",
|
||||
wraps=default_planner.create_action) as m_create_action:
|
||||
action_plan = default_planner.schedule(
|
||||
self.context, audit.id, dummy_solution
|
||||
self.context, audit.id, solution
|
||||
)
|
||||
|
||||
self.assertIsNotNone(action_plan.uuid)
|
||||
@@ -112,14 +113,6 @@ class TestDefaultPlanner(base.DbTestCase):
|
||||
audit.id, fake_solution)
|
||||
self.assertIsNotNone(action_plan.uuid)
|
||||
|
||||
def test_schedule_raise(self):
|
||||
audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
|
||||
fake_solution = SolutionFaker.build()
|
||||
fake_solution.actions[0] = "valeur_qcq"
|
||||
self.assertRaises(exception.ActionNotFound,
|
||||
self.default_planner.schedule,
|
||||
self.context, audit.id, fake_solution)
|
||||
|
||||
def test_schedule_scheduled_empty(self):
|
||||
audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
|
||||
fake_solution = SolutionFakerSingleHyp.build()
|
||||
|
||||
0
watcher/tests/decision_engine/solution/__init__.py
Normal file
0
watcher/tests/decision_engine/solution/__init__.py
Normal file
@@ -0,0 +1,39 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 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.solution.default import DefaultSolution
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestDefaultSolution(base.BaseTestCase):
|
||||
def test_default_solution(self):
|
||||
solution = DefaultSolution()
|
||||
parameters = {
|
||||
"src_uuid_hypervisor": "server1",
|
||||
"dst_uuid_hypervisor": "server2",
|
||||
}
|
||||
solution.add_action(action_type="nop",
|
||||
applies_to="b199db0c-1408-4d52-b5a5-5ca14de0ff36",
|
||||
input_parameters=parameters)
|
||||
self.assertEqual(len(solution.actions), 1)
|
||||
expected_action_type = "nop"
|
||||
expected_applies_to = "b199db0c-1408-4d52-b5a5-5ca14de0ff36"
|
||||
expected_parameters = parameters
|
||||
self.assertEqual(solution.actions[0].get('action_type'),
|
||||
expected_action_type)
|
||||
self.assertEqual(solution.actions[0].get('applies_to'),
|
||||
expected_applies_to)
|
||||
self.assertEqual(solution.actions[0].get('input_parameters'),
|
||||
expected_parameters)
|
||||
@@ -17,15 +17,9 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
from collections import Counter
|
||||
|
||||
import mock
|
||||
from mock import MagicMock
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.decision_engine.actions.hypervisor_state import \
|
||||
ChangeHypervisorState
|
||||
from watcher.decision_engine.actions.migration import Migrate
|
||||
from watcher.decision_engine.actions.power_state import ChangePowerState
|
||||
from watcher.decision_engine.model.model_root import ModelRoot
|
||||
from watcher.decision_engine.strategy.strategies.basic_consolidation import \
|
||||
BasicConsolidation
|
||||
@@ -52,7 +46,7 @@ class TestBasicConsolidation(base.BaseTestCase):
|
||||
def test_basic_consolidation_score_hypervisor(self):
|
||||
cluster = self.fake_cluster.generate_scenario_1()
|
||||
sercon = BasicConsolidation()
|
||||
sercon.ceilometer = MagicMock(
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
|
||||
node_1_score = 0.023333333333333317
|
||||
@@ -74,7 +68,7 @@ class TestBasicConsolidation(base.BaseTestCase):
|
||||
def test_basic_consolidation_score_vm(self):
|
||||
cluster = self.fake_cluster.generate_scenario_1()
|
||||
sercon = BasicConsolidation()
|
||||
sercon.ceilometer = MagicMock(
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
vm_0 = cluster.get_vm_from_id("VM_0")
|
||||
vm_0_score = 0.023333333333333317
|
||||
@@ -97,7 +91,7 @@ class TestBasicConsolidation(base.BaseTestCase):
|
||||
def test_basic_consolidation_score_vm_disk(self):
|
||||
cluster = self.fake_cluster.generate_scenario_5_with_vm_disk_0()
|
||||
sercon = BasicConsolidation()
|
||||
sercon.ceilometer = MagicMock(
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
vm_0 = cluster.get_vm_from_id("VM_0")
|
||||
vm_0_score = 0.023333333333333355
|
||||
@@ -106,7 +100,7 @@ class TestBasicConsolidation(base.BaseTestCase):
|
||||
def test_basic_consolidation_weight(self):
|
||||
cluster = self.fake_cluster.generate_scenario_1()
|
||||
sercon = BasicConsolidation()
|
||||
sercon.ceilometer = MagicMock(
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
vm_0 = cluster.get_vm_from_id("VM_0")
|
||||
cores = 16
|
||||
@@ -138,17 +132,12 @@ class TestBasicConsolidation(base.BaseTestCase):
|
||||
metrics = FakerMetricsCollector()
|
||||
metrics.empty_one_metric("CPU_COMPUTE")
|
||||
sercon = BasicConsolidation()
|
||||
sercon.ceilometer = MagicMock(
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
|
||||
self.assertRaises(exception.ClusterStateNotDefined,
|
||||
sercon.calculate_score_vm, "VM_1", None)
|
||||
|
||||
def test_print_utilization_raise_cluster_state_not_found(self):
|
||||
sercon = BasicConsolidation()
|
||||
self.assertRaises(exception.ClusterStateNotDefined,
|
||||
sercon.print_utilization, None)
|
||||
|
||||
def test_check_migration(self):
|
||||
sercon = BasicConsolidation()
|
||||
fake_cluster = FakerModelCollector()
|
||||
@@ -182,34 +171,28 @@ class TestBasicConsolidation(base.BaseTestCase):
|
||||
|
||||
def test_basic_consolidation_migration(self):
|
||||
sercon = BasicConsolidation()
|
||||
sercon.ceilometer = MagicMock(
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
|
||||
solution = sercon.execute(
|
||||
self.fake_cluster.generate_scenario_2())
|
||||
self.fake_cluster.generate_scenario_3_with_2_hypervisors())
|
||||
|
||||
actions_counter = Counter(
|
||||
[type(action) for action in solution.actions])
|
||||
[action.get('action_type') for action in solution.actions])
|
||||
|
||||
expected_num_migrations = 0
|
||||
expected_num_migrations = 1
|
||||
expected_power_state = 0
|
||||
expected_change_hypervisor_state = 0
|
||||
|
||||
num_migrations = actions_counter.get(Migrate, 0)
|
||||
num_migrations = actions_counter.get("migrate", 0)
|
||||
num_hypervisor_state_change = actions_counter.get(
|
||||
ChangeHypervisorState, 0)
|
||||
num_power_state_change = actions_counter.get(
|
||||
ChangePowerState, 0)
|
||||
|
||||
"change_hypervisor_state", 0)
|
||||
self.assertEqual(num_migrations, expected_num_migrations)
|
||||
self.assertEqual(num_hypervisor_state_change, expected_power_state)
|
||||
self.assertEqual(num_power_state_change,
|
||||
expected_change_hypervisor_state)
|
||||
|
||||
def test_execute_cluster_empty(self):
|
||||
current_state_cluster = FakerModelCollector()
|
||||
sercon = BasicConsolidation("sercon", "Basic offline consolidation")
|
||||
sercon.ceilometer = MagicMock(
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
model = current_state_cluster.generate_random(0, 0)
|
||||
self.assertRaises(exception.ClusterEmpty, sercon.execute, model)
|
||||
@@ -217,7 +200,7 @@ class TestBasicConsolidation(base.BaseTestCase):
|
||||
# calculate_weight
|
||||
def test_execute_no_workload(self):
|
||||
sercon = BasicConsolidation()
|
||||
sercon.ceilometer = MagicMock(
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
|
||||
current_state_cluster = FakerModelCollector()
|
||||
|
||||
@@ -17,12 +17,9 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
from collections import Counter
|
||||
|
||||
from mock import MagicMock
|
||||
import mock
|
||||
|
||||
from watcher.common import exception
|
||||
|
||||
from watcher.decision_engine.actions.migration import Migrate
|
||||
from watcher.decision_engine.model.model_root import ModelRoot
|
||||
from watcher.decision_engine.model.resource import ResourceType
|
||||
from watcher.decision_engine.strategy.strategies.outlet_temp_control import \
|
||||
@@ -59,7 +56,7 @@ class TestOutletTempControl(base.BaseTestCase):
|
||||
def test_group_hosts_by_outlet_temp(self):
|
||||
model = self.fake_cluster.generate_scenario_3_with_2_hypervisors()
|
||||
strategy = OutletTempControl()
|
||||
strategy.ceilometer = MagicMock(
|
||||
strategy.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
h1, h2 = strategy.group_hosts_by_outlet_temp(model)
|
||||
self.assertEqual(h1[0]['hv'].uuid, 'Node_1')
|
||||
@@ -68,7 +65,7 @@ class TestOutletTempControl(base.BaseTestCase):
|
||||
def test_choose_vm_to_migrate(self):
|
||||
model = self.fake_cluster.generate_scenario_3_with_2_hypervisors()
|
||||
strategy = OutletTempControl()
|
||||
strategy.ceilometer = MagicMock(
|
||||
strategy.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
h1, h2 = strategy.group_hosts_by_outlet_temp(model)
|
||||
vm_to_mig = strategy.choose_vm_to_migrate(model, h1)
|
||||
@@ -78,7 +75,7 @@ class TestOutletTempControl(base.BaseTestCase):
|
||||
def test_filter_dest_servers(self):
|
||||
model = self.fake_cluster.generate_scenario_3_with_2_hypervisors()
|
||||
strategy = OutletTempControl()
|
||||
strategy.ceilometer = MagicMock(
|
||||
strategy.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
h1, h2 = strategy.group_hosts_by_outlet_temp(model)
|
||||
vm_to_mig = strategy.choose_vm_to_migrate(model, h1)
|
||||
@@ -99,14 +96,14 @@ class TestOutletTempControl(base.BaseTestCase):
|
||||
def test_execute_cluster_empty(self):
|
||||
current_state_cluster = FakerModelCollector()
|
||||
strategy = OutletTempControl()
|
||||
strategy.ceilometer = MagicMock(
|
||||
strategy.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
model = current_state_cluster.generate_random(0, 0)
|
||||
self.assertRaises(exception.ClusterEmpty, strategy.execute, model)
|
||||
|
||||
def test_execute_no_workload(self):
|
||||
strategy = OutletTempControl()
|
||||
strategy.ceilometer = MagicMock(
|
||||
strategy.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
|
||||
current_state_cluster = FakerModelCollector()
|
||||
@@ -118,12 +115,12 @@ class TestOutletTempControl(base.BaseTestCase):
|
||||
|
||||
def test_execute(self):
|
||||
strategy = OutletTempControl()
|
||||
strategy.ceilometer = MagicMock(
|
||||
strategy.ceilometer = mock.MagicMock(
|
||||
statistic_aggregation=self.fake_metrics.mock_get_statistics)
|
||||
model = self.fake_cluster.generate_scenario_3_with_2_hypervisors()
|
||||
solution = strategy.execute(model)
|
||||
actions_counter = Counter(
|
||||
[type(action) for action in solution.actions])
|
||||
[action.get('action_type') for action in solution.actions])
|
||||
|
||||
num_migrations = actions_counter.get(Migrate, 0)
|
||||
num_migrations = actions_counter.get("migrate", 0)
|
||||
self.assertEqual(num_migrations, 1)
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 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.actions.base import BaseAction
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestAction(base.TestCase):
|
||||
def test_get_priority(self):
|
||||
ma = BaseAction()
|
||||
ma.priority = 3
|
||||
self.assertEqual(ma.priority, 3)
|
||||
|
||||
def test_get_level(self):
|
||||
ma = BaseAction()
|
||||
ma.level = 5
|
||||
self.assertEqual(ma.level, 5)
|
||||
@@ -1,24 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 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.solution.default import DefaultSolution
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestDefaultSolution(base.BaseTestCase):
|
||||
def test_default_solution(self):
|
||||
solution = DefaultSolution()
|
||||
solution.add_change_request("BLA")
|
||||
self.assertEqual(solution.actions[0], "BLA")
|
||||
Reference in New Issue
Block a user