Added efficacy indicators to /action_plans
I this changeset, I added the efficacy indicators both at the DB and at the API level alongside the associated logic. Partially Implements: blueprint efficacy-indicator Change-Id: I824553637621da67966103c1b0c01348b09bd836
This commit is contained in:
@@ -13,13 +13,14 @@
|
||||
import datetime
|
||||
import itertools
|
||||
import mock
|
||||
|
||||
import pecan
|
||||
|
||||
from oslo_config import cfg
|
||||
from wsme import types as wtypes
|
||||
|
||||
from watcher.api.controllers.v1 import action_plan as api_action_plan
|
||||
from watcher.applier import rpcapi as aapi
|
||||
from watcher.common import context
|
||||
from watcher.common import utils
|
||||
from watcher.db import api as db_api
|
||||
from watcher import objects
|
||||
@@ -31,7 +32,11 @@ from watcher.tests.objects import utils as obj_utils
|
||||
|
||||
class TestActionPlanObject(base.TestCase):
|
||||
|
||||
def test_action_plan_init(self):
|
||||
@mock.patch.object(objects.EfficacyIndicator,
|
||||
'list', mock.Mock(return_value=[]))
|
||||
@mock.patch.object(pecan, 'request')
|
||||
def test_action_plan_init(self, m_request):
|
||||
m_request.context = context.make_context()
|
||||
act_plan_dict = api_utils.action_plan_post_data()
|
||||
del act_plan_dict['state']
|
||||
del act_plan_dict['audit_id']
|
||||
@@ -47,7 +52,8 @@ class TestListActionPlan(api_base.FunctionalTest):
|
||||
self.assertEqual([], response['action_plans'])
|
||||
|
||||
def _assert_action_plans_fields(self, action_plan):
|
||||
action_plan_fields = ['state']
|
||||
action_plan_fields = ['uuid', 'audit_uuid', 'state', 'global_efficacy',
|
||||
'efficacy_indicators']
|
||||
for field in action_plan_fields:
|
||||
self.assertIn(field, action_plan)
|
||||
|
||||
@@ -71,10 +77,18 @@ class TestListActionPlan(api_base.FunctionalTest):
|
||||
self.assertEqual([], response['action_plans'])
|
||||
|
||||
def test_get_one_ok(self):
|
||||
action_plan = obj_utils.create_action_plan_without_audit(self.context)
|
||||
action_plan = obj_utils.create_test_action_plan(self.context)
|
||||
obj_utils.create_test_efficacy_indicator(
|
||||
self.context, action_plan_id=action_plan['id'])
|
||||
response = self.get_json('/action_plans/%s' % action_plan['uuid'])
|
||||
self.assertEqual(action_plan.uuid, response['uuid'])
|
||||
self._assert_action_plans_fields(response)
|
||||
self.assertEqual(
|
||||
[{'description': 'Test indicator',
|
||||
'name': 'test_indicator',
|
||||
'value': 0.0,
|
||||
'unit': '%'}],
|
||||
response['efficacy_indicators'])
|
||||
|
||||
def test_get_one_with_first_action(self):
|
||||
action_plan = obj_utils.create_test_action_plan(self.context)
|
||||
|
||||
@@ -120,6 +120,7 @@ def get_test_action_plan(**kwargs):
|
||||
'uuid': kwargs.get('uuid', '76be87bd-3422-43f9-93a0-e85a577e3061'),
|
||||
'state': kwargs.get('state', 'ONGOING'),
|
||||
'audit_id': kwargs.get('audit_id', 1),
|
||||
'global_efficacy': kwargs.get('global_efficacy', {}),
|
||||
'first_action_id': kwargs.get('first_action_id', 1),
|
||||
'created_at': kwargs.get('created_at'),
|
||||
'updated_at': kwargs.get('updated_at'),
|
||||
|
||||
@@ -47,7 +47,13 @@ class FakeStrategy(base_strategy.BaseStrategy):
|
||||
def get_config_opts(cls):
|
||||
return []
|
||||
|
||||
def execute(self, original_model):
|
||||
def pre_execute(self):
|
||||
pass
|
||||
|
||||
def do_execute(self):
|
||||
pass
|
||||
|
||||
def post_execute(self):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -53,14 +53,17 @@ class SolutionFakerSingleHyp(object):
|
||||
current_state_cluster.generate_scenario_3_with_2_hypervisors())
|
||||
sercon.ceilometer = mock.MagicMock(
|
||||
get_statistics=metrics.mock_get_statistics)
|
||||
|
||||
return sercon.execute()
|
||||
|
||||
|
||||
class TestActionScheduling(base.DbTestCase):
|
||||
|
||||
def test_schedule_actions(self):
|
||||
default_planner = pbase.DefaultPlanner(mock.Mock())
|
||||
audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
|
||||
solution = dsol.DefaultSolution()
|
||||
solution = dsol.DefaultSolution(
|
||||
goal=mock.Mock(), strategy=mock.Mock())
|
||||
|
||||
parameters = {
|
||||
"src_uuid_hypervisor": "server1",
|
||||
@@ -86,7 +89,8 @@ class TestActionScheduling(base.DbTestCase):
|
||||
def test_schedule_two_actions(self):
|
||||
default_planner = pbase.DefaultPlanner(mock.Mock())
|
||||
audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
|
||||
solution = dsol.DefaultSolution()
|
||||
solution = dsol.DefaultSolution(
|
||||
goal=mock.Mock(), strategy=mock.Mock())
|
||||
|
||||
parameters = {
|
||||
"src_uuid_hypervisor": "server1",
|
||||
|
||||
@@ -14,13 +14,16 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from watcher.decision_engine.solution import default
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestDefaultSolution(base.BaseTestCase):
|
||||
def test_default_solution(self):
|
||||
solution = default.DefaultSolution()
|
||||
solution = default.DefaultSolution(
|
||||
goal=mock.Mock(), strategy=mock.Mock())
|
||||
parameters = {
|
||||
"src_uuid_hypervisor": "server1",
|
||||
"dst_uuid_hypervisor": "server2",
|
||||
|
||||
@@ -60,7 +60,6 @@ class TestStrategySelector(base.TestCase):
|
||||
@mock.patch.object(default_loader.DefaultStrategyLoader, 'list_available')
|
||||
def test_select_no_available_strategy_for_goal(self, m_list_available):
|
||||
m_list_available.return_value = {}
|
||||
strategy_selector = default_selector.DefaultStrategySelector(
|
||||
"dummy")
|
||||
strategy_selector = default_selector.DefaultStrategySelector("dummy")
|
||||
self.assertRaises(exception.NoAvailableStrategyForGoal,
|
||||
strategy_selector.select)
|
||||
|
||||
@@ -180,7 +180,7 @@ class TestBasicConsolidation(base.BaseTestCase):
|
||||
) as mock_score_call:
|
||||
mock_score_call.return_value = 0
|
||||
solution = self.strategy.execute()
|
||||
self.assertEqual(0, solution.efficacy)
|
||||
self.assertEqual(0, solution.efficacy.global_efficacy.value)
|
||||
|
||||
def test_check_parameters(self):
|
||||
model = self.fake_cluster.generate_scenario_3_with_2_hypervisors()
|
||||
|
||||
@@ -37,7 +37,6 @@ class TestOutletTempControl(base.BaseTestCase):
|
||||
super(TestOutletTempControl, self).setUp()
|
||||
# fake metrics
|
||||
self.fake_metrics = faker_metrics_collector.FakerMetricsCollector()
|
||||
|
||||
# fake cluster
|
||||
self.fake_cluster = faker_cluster_state.FakerModelCollector()
|
||||
|
||||
|
||||
@@ -74,19 +74,69 @@ class TestActionPlanObject(base.DbTestCase):
|
||||
self.assertEqual(self.context, action_plan._context)
|
||||
|
||||
def test_destroy(self):
|
||||
efficacy_indicator = utils.get_test_efficacy_indicator(
|
||||
action_plan_id=self.fake_action_plan['id'])
|
||||
uuid = self.fake_action_plan['uuid']
|
||||
with mock.patch.object(self.dbapi, 'get_action_plan_by_uuid',
|
||||
autospec=True) as mock_get_action_plan:
|
||||
mock_get_action_plan.return_value = self.fake_action_plan
|
||||
with mock.patch.object(self.dbapi, 'destroy_action_plan',
|
||||
autospec=True) as mock_destroy_action_plan:
|
||||
action_plan = objects.ActionPlan.get_by_uuid(
|
||||
self.context, uuid)
|
||||
action_plan.destroy()
|
||||
mock_get_action_plan.assert_called_once_with(
|
||||
self.context, uuid)
|
||||
mock_destroy_action_plan.assert_called_once_with(uuid)
|
||||
self.assertEqual(self.context, action_plan._context)
|
||||
|
||||
with mock.patch.multiple(
|
||||
self.dbapi, autospec=True,
|
||||
get_action_plan_by_uuid=mock.DEFAULT,
|
||||
destroy_action_plan=mock.DEFAULT,
|
||||
get_efficacy_indicator_list=mock.DEFAULT,
|
||||
destroy_efficacy_indicator=mock.DEFAULT,
|
||||
) as m_dict:
|
||||
m_get_action_plan = m_dict['get_action_plan_by_uuid']
|
||||
m_destroy_action_plan = m_dict['destroy_action_plan']
|
||||
m_get_efficacy_indicator_list = (
|
||||
m_dict['get_efficacy_indicator_list'])
|
||||
m_destroy_efficacy_indicator = m_dict['destroy_efficacy_indicator']
|
||||
m_get_action_plan.return_value = self.fake_action_plan
|
||||
m_get_efficacy_indicator_list.return_value = [efficacy_indicator]
|
||||
action_plan = objects.ActionPlan.get_by_uuid(self.context, uuid)
|
||||
action_plan.destroy()
|
||||
m_get_action_plan.assert_called_once_with(self.context, uuid)
|
||||
m_get_efficacy_indicator_list.assert_called_once_with(
|
||||
self.context, filters={"action_plan_uuid": uuid},
|
||||
limit=None, marker=None, sort_dir=None, sort_key=None)
|
||||
m_destroy_action_plan.assert_called_once_with(uuid)
|
||||
m_destroy_efficacy_indicator.assert_called_once_with(
|
||||
efficacy_indicator['uuid'])
|
||||
self.assertEqual(self.context, action_plan._context)
|
||||
|
||||
def test_soft_delete(self):
|
||||
efficacy_indicator = utils.get_test_efficacy_indicator(
|
||||
action_plan_id=self.fake_action_plan['id'])
|
||||
uuid = self.fake_action_plan['uuid']
|
||||
|
||||
with mock.patch.multiple(
|
||||
self.dbapi, autospec=True,
|
||||
get_action_plan_by_uuid=mock.DEFAULT,
|
||||
soft_delete_action_plan=mock.DEFAULT,
|
||||
update_action_plan=mock.DEFAULT,
|
||||
get_efficacy_indicator_list=mock.DEFAULT,
|
||||
soft_delete_efficacy_indicator=mock.DEFAULT,
|
||||
) as m_dict:
|
||||
m_get_action_plan = m_dict['get_action_plan_by_uuid']
|
||||
m_soft_delete_action_plan = m_dict['soft_delete_action_plan']
|
||||
m_get_efficacy_indicator_list = (
|
||||
m_dict['get_efficacy_indicator_list'])
|
||||
m_soft_delete_efficacy_indicator = (
|
||||
m_dict['soft_delete_efficacy_indicator'])
|
||||
m_update_action_plan = m_dict['update_action_plan']
|
||||
m_get_action_plan.return_value = self.fake_action_plan
|
||||
m_get_efficacy_indicator_list.return_value = [efficacy_indicator]
|
||||
action_plan = objects.ActionPlan.get_by_uuid(self.context, uuid)
|
||||
action_plan.soft_delete()
|
||||
m_get_action_plan.assert_called_once_with(self.context, uuid)
|
||||
m_get_efficacy_indicator_list.assert_called_once_with(
|
||||
self.context, filters={"action_plan_uuid": uuid},
|
||||
limit=None, marker=None, sort_dir=None, sort_key=None)
|
||||
m_soft_delete_action_plan.assert_called_once_with(uuid)
|
||||
m_soft_delete_efficacy_indicator.assert_called_once_with(
|
||||
efficacy_indicator['uuid'])
|
||||
m_update_action_plan.assert_called_once_with(
|
||||
uuid, {'state': 'DELETED'})
|
||||
self.assertEqual(self.context, action_plan._context)
|
||||
|
||||
def test_save(self):
|
||||
uuid = self.fake_action_plan['uuid']
|
||||
|
||||
@@ -189,3 +189,30 @@ def create_test_strategy(context, **kw):
|
||||
strategy = get_test_strategy(context, **kw)
|
||||
strategy.create()
|
||||
return strategy
|
||||
|
||||
|
||||
def get_test_efficacy_indicator(context, **kw):
|
||||
"""Return a EfficacyIndicator object with appropriate attributes.
|
||||
|
||||
NOTE: The object leaves the attributes marked as changed, such
|
||||
that a create() could be used to commit it to the DB.
|
||||
"""
|
||||
db_efficacy_indicator = db_utils.get_test_efficacy_indicator(**kw)
|
||||
# Let DB generate ID if it isn't specified explicitly
|
||||
if 'id' not in kw:
|
||||
del db_efficacy_indicator['id']
|
||||
efficacy_indicator = objects.EfficacyIndicator(context)
|
||||
for key in db_efficacy_indicator:
|
||||
setattr(efficacy_indicator, key, db_efficacy_indicator[key])
|
||||
return efficacy_indicator
|
||||
|
||||
|
||||
def create_test_efficacy_indicator(context, **kw):
|
||||
"""Create and return a test efficacy indicator object.
|
||||
|
||||
Create a efficacy indicator in the DB and return a EfficacyIndicator object
|
||||
with appropriate attributes.
|
||||
"""
|
||||
efficacy_indicator = get_test_efficacy_indicator(context, **kw)
|
||||
efficacy_indicator.create()
|
||||
return efficacy_indicator
|
||||
|
||||
Reference in New Issue
Block a user