Renamed Status to State

As we can see in the codebase, we have 3 "Status" enums which are
located at:

- watcher/objects/action.py
- watcher/objects/action_plan.py
- watcher/objects/audit.py

So I renamed them from "Status" to "State" to be consistent with
the DB schema.

Change-Id: If3d180c9daba6ae9083775ad6813aa4c21763dbf
Closes-Bug: #1522733
This commit is contained in:
Vincent Françoise 2016-01-19 11:52:06 +01:00
parent 43275537ea
commit 62b39fefbb
12 changed files with 77 additions and 83 deletions

View File

@ -22,7 +22,7 @@ from watcher.applier.action_plan import base
from watcher.applier import default
from watcher.applier.messaging import event_types
from watcher.common.messaging.events import event
from watcher import objects
from watcher.objects import action_plan as ap_objects
LOG = log.getLogger(__name__)
@ -35,7 +35,7 @@ class DefaultActionPlanHandler(base.BaseActionPlanHandler):
self.applier_manager = applier_manager
def notify(self, uuid, event_type, state):
action_plan = objects.ActionPlan.get_by_uuid(self.ctx, uuid)
action_plan = ap_objects.ActionPlan.get_by_uuid(self.ctx, uuid)
action_plan.state = state
action_plan.save()
ev = event.Event()
@ -51,7 +51,7 @@ class DefaultActionPlanHandler(base.BaseActionPlanHandler):
# update state
self.notify(self.action_plan_uuid,
event_types.EventTypes.LAUNCH_ACTION_PLAN,
objects.action_plan.Status.ONGOING)
ap_objects.State.ONGOING)
applier = default.DefaultApplier(self.applier_manager, self.ctx)
result = applier.execute(self.action_plan_uuid)
except Exception as e:
@ -59,9 +59,9 @@ class DefaultActionPlanHandler(base.BaseActionPlanHandler):
result = False
finally:
if result is True:
status = objects.action_plan.Status.SUCCEEDED
status = ap_objects.State.SUCCEEDED
else:
status = objects.action_plan.Status.FAILED
status = ap_objects.State.FAILED
# update state
self.notify(self.action_plan_uuid,
event_types.EventTypes.LAUNCH_ACTION_PLAN,

View File

@ -100,13 +100,13 @@ class TaskFlowActionContainer(task.Task):
def pre_execute(self):
try:
self.engine.notify(self._db_action,
obj_action.Status.ONGOING)
obj_action.State.ONGOING)
LOG.debug("Precondition action %s", self.name)
self.action.precondition()
except Exception as e:
LOG.exception(e)
self.engine.notify(self._db_action,
obj_action.Status.FAILED)
obj_action.State.FAILED)
raise
def execute(self, *args, **kwargs):
@ -117,17 +117,17 @@ class TaskFlowActionContainer(task.Task):
result = self.action.execute()
if result is not True:
self.engine.notify(self._db_action,
obj_action.Status.FAILED)
obj_action.State.FAILED)
else:
self.engine.notify(self._db_action,
obj_action.Status.SUCCEEDED)
obj_action.State.SUCCEEDED)
except Exception as e:
LOG.exception(e)
LOG.error(_LE('The WorkFlow Engine has failed '
'to execute the action %s'), self.name)
self.engine.notify(self._db_action,
obj_action.Status.FAILED)
obj_action.State.FAILED)
raise
def post_execute(self):
@ -137,7 +137,7 @@ class TaskFlowActionContainer(task.Task):
except Exception as e:
LOG.exception(e)
self.engine.notify(self._db_action,
obj_action.Status.FAILED)
obj_action.State.FAILED)
raise
def revert(self, *args, **kwargs):

View File

@ -322,7 +322,7 @@ class Connection(api.BaseConnection):
values['uuid'] = utils.generate_uuid()
if values.get('state') is None:
values['state'] = audit_objects.AuditStatus.PENDING
values['state'] = audit_objects.State.PENDING
audit = models.Audit()
audit.update(values)

View File

@ -15,26 +15,23 @@
# limitations under the License.
from oslo_log import log
from watcher.common.messaging.events.event import Event
from watcher.decision_engine.audit.base import \
BaseAuditHandler
from watcher.decision_engine.messaging.events import Events
from watcher.decision_engine.planner.manager import PlannerManager
from watcher.decision_engine.strategy.context.default import \
DefaultStrategyContext
from watcher.objects.audit import Audit
from watcher.objects.audit import AuditStatus
from watcher.common.messaging.events import event as watcher_event
from watcher.decision_engine.audit import base
from watcher.decision_engine.messaging import events as de_events
from watcher.decision_engine.planner import manager as planner_manager
from watcher.decision_engine.strategy.context import default as default_context
from watcher.objects import audit as audit_objects
LOG = log.getLogger(__name__)
class DefaultAuditHandler(BaseAuditHandler):
class DefaultAuditHandler(base.BaseAuditHandler):
def __init__(self, messaging):
super(DefaultAuditHandler, self).__init__()
self._messaging = messaging
self._strategy_context = DefaultStrategyContext()
self._planner_manager = PlannerManager()
self._strategy_context = default_context.DefaultStrategyContext()
self._planner_manager = planner_manager.PlannerManager()
self._planner = None
@property
@ -52,7 +49,7 @@ class DefaultAuditHandler(BaseAuditHandler):
return self._strategy_context
def notify(self, audit_uuid, event_type, status):
event = Event()
event = watcher_event.Event()
event.type = event_type
event.data = {}
payload = {'audit_uuid': audit_uuid,
@ -61,20 +58,19 @@ class DefaultAuditHandler(BaseAuditHandler):
payload)
def update_audit_state(self, request_context, audit_uuid, state):
LOG.debug("Update audit state:{0} ".format(state))
audit = Audit.get_by_uuid(request_context, audit_uuid)
LOG.debug("Update audit state: %s", state)
audit = audit_objects.Audit.get_by_uuid(request_context, audit_uuid)
audit.state = state
audit.save()
self.notify(audit_uuid, Events.TRIGGER_AUDIT, state)
self.notify(audit_uuid, de_events.Events.TRIGGER_AUDIT, state)
return audit
def execute(self, audit_uuid, request_context):
try:
LOG.debug("Trigger audit %s" % audit_uuid)
LOG.debug("Trigger audit %s", audit_uuid)
# change state of the audit to ONGOING
audit = self.update_audit_state(request_context, audit_uuid,
AuditStatus.ONGOING)
audit_objects.State.ONGOING)
# execute the strategy
solution = self.strategy_context.execute_strategy(audit_uuid,
@ -84,8 +80,8 @@ class DefaultAuditHandler(BaseAuditHandler):
# change state of the audit to SUCCEEDED
self.update_audit_state(request_context, audit_uuid,
AuditStatus.SUCCEEDED)
audit_objects.State.SUCCEEDED)
except Exception as e:
LOG.exception(e)
self.update_audit_state(request_context, audit_uuid,
AuditStatus.FAILED)
audit_objects.State.FAILED)

View File

@ -47,7 +47,7 @@ class DefaultPlanner(base.BasePlanner):
'action_type': action_type,
'applies_to': applies_to,
'input_parameters': input_parameters,
'state': objects.action.Status.PENDING,
'state': objects.action.State.PENDING,
'alarm': None,
'next': None,
}
@ -99,7 +99,7 @@ class DefaultPlanner(base.BasePlanner):
'uuid': utils.generate_uuid(),
'audit_id': audit_id,
'first_action_id': None,
'state': objects.action_plan.Status.RECOMMENDED
'state': objects.action_plan.State.RECOMMENDED
}
new_action_plan = objects.ActionPlan(context, **action_plan_dict)

View File

@ -22,7 +22,7 @@ from watcher.objects import base
from watcher.objects import utils as obj_utils
class Status(object):
class State(object):
PENDING = 'PENDING'
ONGOING = 'ONGOING'
FAILED = 'FAILED'

View File

@ -75,7 +75,7 @@ from watcher.objects import base
from watcher.objects import utils as obj_utils
class Status(object):
class State(object):
RECOMMENDED = 'RECOMMENDED'
ONGOING = 'ONGOING'
FAILED = 'FAILED'

View File

@ -55,7 +55,7 @@ from watcher.objects import base
from watcher.objects import utils as obj_utils
class AuditStatus(object):
class State(object):
ONGOING = 'ONGOING'
SUCCEEDED = 'SUCCEEDED'
SUBMITTED = 'SUBMITTED'

View File

@ -443,7 +443,7 @@ class TestPost(api_base.FunctionalTest):
self.assertEqual(urlparse.urlparse(response.location).path,
expected_location)
self.assertEqual(audit_dict['uuid'], response.json['uuid'])
self.assertEqual(objects.audit.AuditStatus.PENDING,
self.assertEqual(objects.audit.State.PENDING,
response.json['state'])
self.assertNotIn('updated_at', response.json.keys)
self.assertNotIn('deleted_at', response.json.keys)
@ -492,7 +492,7 @@ class TestPost(api_base.FunctionalTest):
response = self.post_json('/audits', audit_dict)
self.assertEqual('application/json', response.content_type)
self.assertEqual(201, response.status_int)
self.assertEqual(objects.audit.AuditStatus.PENDING,
self.assertEqual(objects.audit.State.PENDING,
response.json['state'])
self.assertTrue(utils.is_uuid_like(response.json['uuid']))

View File

@ -21,7 +21,7 @@ from mock import MagicMock
from watcher.applier.action_plan.default import DefaultActionPlanHandler
from watcher.applier.messaging.event_types import EventTypes
from watcher.objects.action_plan import Status
from watcher.objects import action_plan as ap_objects
from watcher.objects import ActionPlan
from watcher.tests.db.base import DbTestCase
from watcher.tests.objects import utils as obj_utils
@ -39,7 +39,7 @@ class TestDefaultActionPlanHandler(DbTestCase):
command.execute()
action_plan = ActionPlan.get_by_uuid(self.context,
self.action_plan.uuid)
self.assertEqual(Status.SUCCEEDED, action_plan.state)
self.assertEqual(ap_objects.State.SUCCEEDED, action_plan.state)
def test_trigger_audit_send_notification(self):
messaging = MagicMock()
@ -48,10 +48,10 @@ class TestDefaultActionPlanHandler(DbTestCase):
command.execute()
call_on_going = call(EventTypes.LAUNCH_ACTION_PLAN.name, {
'action_plan_status': Status.ONGOING,
'action_plan_state': ap_objects.State.ONGOING,
'action_plan__uuid': self.action_plan.uuid})
call_succeeded = call(EventTypes.LAUNCH_ACTION_PLAN.name, {
'action_plan_status': Status.SUCCEEDED,
'action_plan_state': ap_objects.State.SUCCEEDED,
'action_plan__uuid': self.action_plan.uuid})
calls = [call_on_going, call_succeeded]

View File

@ -69,7 +69,7 @@ class TestDefaultWorkFlowEngine(base.DbTestCase):
'action_type': action_type,
'applies_to': applies_to,
'input_parameters': parameters,
'state': objects.action.Status.PENDING,
'state': objects.action.State.PENDING,
'alarm': None,
'next': next,
}
@ -95,7 +95,7 @@ class TestDefaultWorkFlowEngine(base.DbTestCase):
actions = [self.create_action("nop", "", {'message': 'test'}, None)]
result = self.engine.execute(actions)
self.assertEqual(result, True)
self.check_actions_state(actions, objects.action.Status.SUCCEEDED)
self.check_actions_state(actions, objects.action.State.SUCCEEDED)
def test_execute_with_two_actions(self):
actions = []
@ -107,16 +107,16 @@ class TestDefaultWorkFlowEngine(base.DbTestCase):
result = self.engine.execute(actions)
self.assertEqual(result, True)
self.check_actions_state(actions, objects.action.Status.SUCCEEDED)
self.check_actions_state(actions, objects.action.State.SUCCEEDED)
def test_execute_with_three_actions(self):
actions = []
next2 = self.create_action("nop", "vm1", {'message': 'next'}, None)
next = self.create_action("sleep", "vm1", {'duration': '0'}, next2.id)
first = self.create_action("nop", "vm1", {'message': 'hello'}, next.id)
self.check_action_state(first, objects.action.Status.PENDING)
self.check_action_state(next, objects.action.Status.PENDING)
self.check_action_state(next2, objects.action.Status.PENDING)
self.check_action_state(first, objects.action.State.PENDING)
self.check_action_state(next, objects.action.State.PENDING)
self.check_action_state(next2, objects.action.State.PENDING)
actions.append(first)
actions.append(next)
@ -124,7 +124,7 @@ class TestDefaultWorkFlowEngine(base.DbTestCase):
result = self.engine.execute(actions)
self.assertEqual(result, True)
self.check_actions_state(actions, objects.action.Status.SUCCEEDED)
self.check_actions_state(actions, objects.action.State.SUCCEEDED)
def test_execute_with_exception(self):
actions = []
@ -135,18 +135,18 @@ class TestDefaultWorkFlowEngine(base.DbTestCase):
first = self.create_action("nop", "vm1",
{'message': 'hello'}, next.id)
self.check_action_state(first, objects.action.Status.PENDING)
self.check_action_state(next, objects.action.Status.PENDING)
self.check_action_state(next2, objects.action.Status.PENDING)
self.check_action_state(first, objects.action.State.PENDING)
self.check_action_state(next, objects.action.State.PENDING)
self.check_action_state(next2, objects.action.State.PENDING)
actions.append(first)
actions.append(next)
actions.append(next2)
result = self.engine.execute(actions)
self.assertEqual(result, False)
self.check_action_state(first, objects.action.Status.SUCCEEDED)
self.check_action_state(next, objects.action.Status.SUCCEEDED)
self.check_action_state(next2, objects.action.Status.FAILED)
self.check_action_state(first, objects.action.State.SUCCEEDED)
self.check_action_state(next, objects.action.State.SUCCEEDED)
self.check_action_state(next2, objects.action.State.FAILED)
@mock.patch("watcher.common.loader.default.DriverManager")
def test_execute_with_action_exception(self, m_driver):
@ -161,4 +161,4 @@ class TestDefaultWorkFlowEngine(base.DbTestCase):
actions = [self.create_action("dontcare", "vm1", {}, None)]
result = self.engine.execute(actions)
self.assertEqual(result, False)
self.check_action_state(actions[0], objects.action.Status.FAILED)
self.check_action_state(actions[0], objects.action.State.FAILED)

View File

@ -15,19 +15,17 @@
# limitations under the License.
import mock
from watcher.decision_engine.audit.default import DefaultAuditHandler
from watcher.decision_engine.messaging.events import Events
from watcher.metrics_engine.cluster_model_collector.manager import \
CollectorManager
from watcher.objects.audit import Audit
from watcher.objects.audit import AuditStatus
from watcher.tests.db.base import DbTestCase
from watcher.tests.decision_engine.strategy.strategies.faker_cluster_state \
import FakerModelCollector
from watcher.decision_engine.audit import default as default
from watcher.decision_engine.messaging import events
from watcher.metrics_engine.cluster_model_collector import manager
from watcher.objects import audit as audit_objects
from watcher.tests.db import base
from watcher.tests.decision_engine.strategy.strategies import \
faker_cluster_state as faker
from watcher.tests.objects import utils as obj_utils
class TestDefaultAuditHandler(DbTestCase):
class TestDefaultAuditHandler(base.DbTestCase):
def setUp(self):
super(TestDefaultAuditHandler, self).setUp()
self.audit_template = obj_utils.create_test_audit_template(
@ -36,32 +34,32 @@ class TestDefaultAuditHandler(DbTestCase):
self.context,
audit_template_id=self.audit_template.id)
@mock.patch.object(CollectorManager, "get_cluster_model_collector")
@mock.patch.object(manager.CollectorManager, "get_cluster_model_collector")
def test_trigger_audit_without_errors(self, mock_collector):
mock_collector.return_value = FakerModelCollector()
audit_handler = DefaultAuditHandler(mock.MagicMock())
mock_collector.return_value = faker.FakerModelCollector()
audit_handler = default.DefaultAuditHandler(mock.MagicMock())
audit_handler.execute(self.audit.uuid, self.context)
@mock.patch.object(CollectorManager, "get_cluster_model_collector")
@mock.patch.object(manager.CollectorManager, "get_cluster_model_collector")
def test_trigger_audit_state_success(self, mock_collector):
mock_collector.return_value = FakerModelCollector()
audit_handler = DefaultAuditHandler(mock.MagicMock())
mock_collector.return_value = faker.FakerModelCollector()
audit_handler = default.DefaultAuditHandler(mock.MagicMock())
audit_handler.execute(self.audit.uuid, self.context)
audit = Audit.get_by_uuid(self.context, self.audit.uuid)
self.assertEqual(AuditStatus.SUCCEEDED, audit.state)
audit = audit_objects.Audit.get_by_uuid(self.context, self.audit.uuid)
self.assertEqual(audit_objects.State.SUCCEEDED, audit.state)
@mock.patch.object(CollectorManager, "get_cluster_model_collector")
@mock.patch.object(manager.CollectorManager, "get_cluster_model_collector")
def test_trigger_audit_send_notification(self, mock_collector):
messaging = mock.MagicMock()
mock_collector.return_value = FakerModelCollector()
audit_handler = DefaultAuditHandler(messaging)
mock_collector.return_value = faker.FakerModelCollector()
audit_handler = default.DefaultAuditHandler(messaging)
audit_handler.execute(self.audit.uuid, self.context)
call_on_going = mock.call(Events.TRIGGER_AUDIT.name, {
'audit_status': AuditStatus.ONGOING,
call_on_going = mock.call(events.Events.TRIGGER_AUDIT.name, {
'audit_status': audit_objects.State.ONGOING,
'audit_uuid': self.audit.uuid})
call_succeeded = mock.call(Events.TRIGGER_AUDIT.name, {
'audit_status': AuditStatus.SUCCEEDED,
call_succeeded = mock.call(events.Events.TRIGGER_AUDIT.name, {
'audit_status': audit_objects.State.SUCCEEDED,
'audit_uuid': self.audit.uuid})
calls = [call_on_going, call_succeeded]