Merge " evaluator - bugs fixing: 1. adding state to deduced alarms 2. handle datetime in action executor"

This commit is contained in:
Jenkins 2016-03-13 12:49:00 +00:00 committed by Gerrit Code Review
commit 5968842a5a
5 changed files with 23 additions and 6 deletions

View File

@ -15,9 +15,9 @@ from datetime import datetime
from oslo_utils import timeutils
def utcnow():
def utcnow(with_timezone=True):
"""Better version of utcnow() that returns utcnow with a correct TZ."""
return timeutils.utcnow(True)
return timeutils.utcnow(with_timezone)
def change_time_str_format(timestamp_str, old_format, new_format):

View File

@ -112,7 +112,7 @@ class ActionExecutor(object):
event[SyncProps.SYNC_MODE] = SyncMode.UPDATE
event[SyncProps.SYNC_TYPE] = EntityType.VITRAGE
event[EProps.UPDATE_TIMESTAMP] = str(datetime_utils.utcnow())
event[EProps.UPDATE_TIMESTAMP] = str(datetime_utils.utcnow(False))
@staticmethod
def _register_action_recipes():

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_log import log as logging
from vitrage.common import datetime_utils
from vitrage.common.constants import EdgeLabels
from vitrage.common.constants import EdgeProperties as EProps
@ -46,10 +47,15 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
event_type = event[EVALUATOR_EVENT_TYPE]
timestamp = datetime_utils.change_time_str_format(
event[VProps.UPDATE_TIMESTAMP],
'%Y-%m-%d %H:%M:%S.%f',
transformer_base.TIMESTAMP_FORMAT)
if event_type == UPDATE_VERTEX:
properties = {
VProps.VITRAGE_STATE: event[VProps.VITRAGE_STATE],
VProps.UPDATE_TIMESTAMP: event[VProps.UPDATE_TIMESTAMP]
VProps.UPDATE_TIMESTAMP: timestamp
}
return Vertex(event[VProps.VITRAGE_ID], properties)
@ -58,7 +64,8 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
metadata = {
VProps.UPDATE_TIMESTAMP: event[VProps.UPDATE_TIMESTAMP],
VProps.NAME: event[TFields.ALARM_NAME],
VProps.SEVERITY: event[TFields.SEVERITY]
VProps.SEVERITY: event[TFields.SEVERITY],
VProps.STATE: event[VProps.STATE]
}
return graph_utils.create_vertex(
self.extract_key(event),

View File

@ -12,11 +12,14 @@
# License for the specific language governing permissions and limitations
# under the License.
from vitrage.common.constants import VertexProperties as VProps
from vitrage.evaluator.actions.recipes.action_steps import ADD_VERTEX
from vitrage.evaluator.actions.recipes.action_steps import NOTIFY
from vitrage.evaluator.actions.recipes.action_steps import REMOVE_VERTEX
from vitrage.evaluator.actions.recipes import base
from vitrage.evaluator.actions.recipes.base import ActionStepWrapper
from vitrage.synchronizer.plugins.base.alarm.properties \
import AlarmProperties as AlarmProps
class RaiseAlarm(base.Recipe):
@ -24,6 +27,9 @@ class RaiseAlarm(base.Recipe):
@staticmethod
def get_do_recipe(action_spec):
params = RaiseAlarm._get_vertex_params(action_spec)
params[VProps.STATE] = AlarmProps.ALARM_STATE
add_vertex_step = ActionStepWrapper(
ADD_VERTEX, RaiseAlarm._get_vertex_params(action_spec))

View File

@ -27,9 +27,12 @@ from vitrage.evaluator.actions.base import ActionType
from vitrage.evaluator.template import ActionSpecs
from vitrage.evaluator.template_fields import TemplateFields as TFields
from vitrage.service import load_plugin
from vitrage.synchronizer.plugins.base.alarm.properties \
import AlarmProperties as AlarmProps
from vitrage.tests.functional.entity_graph.base import \
TestEntityGraphFunctionalBase
LOG = logging.getLogger(__name__)
@ -155,7 +158,8 @@ class TestActionExecutor(TestEntityGraphFunctionalBase):
targets = {TFields.TARGET: host.vertex_id}
props = {
TFields.ALARM_NAME: 'VM_CPU_SUBOPTIMAL_PERFORMANCE',
TFields.SEVERITY: 'critical'
TFields.SEVERITY: 'critical',
VProps.STATE: AlarmProps.ALARM_STATE
}
action_spec = ActionSpecs(ActionType.RAISE_ALARM, targets, props)