Merge "Add category validation for action add_causal_relationship
"
This commit is contained in:
commit
9f8c040336
@ -73,5 +73,6 @@ status_msgs = {
|
||||
'in target_action block.',
|
||||
131: 'mark_down action must contain \'target\' field in'
|
||||
' \'target_action\' block.',
|
||||
132: 'add_causal_relationship action requires action_target to be ALARM'
|
||||
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
from oslo_log import log
|
||||
from six.moves import reduce
|
||||
from vitrage.common.constants import EntityCategory
|
||||
from vitrage.evaluator.actions.base import ActionType
|
||||
from vitrage.evaluator.template_data import TemplateData
|
||||
from vitrage.evaluator.template_fields import TemplateFields
|
||||
@ -241,6 +242,11 @@ def validate_add_causal_relationship_action(action, definitions_index):
|
||||
if not result.is_valid:
|
||||
return result
|
||||
|
||||
entity = definitions_index[template_id]
|
||||
result = _validate_entity_category(entity, EntityCategory.ALARM)
|
||||
if not result.is_valid:
|
||||
return result
|
||||
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
@ -263,3 +269,15 @@ def _validate_template_id(definitions_index, id_to_check):
|
||||
return get_fault_result(RESULT_DESCRIPTION, 3, msg)
|
||||
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
def _validate_entity_category(entity_to_check, category):
|
||||
|
||||
if TemplateFields.CATEGORY not in entity_to_check \
|
||||
or entity_to_check[TemplateFields.CATEGORY] != category:
|
||||
msg = status_msgs[132] + ' expect %s to be %s' \
|
||||
% (entity_to_check, category)
|
||||
LOG.error('%s status code: %s' % (msg, 132))
|
||||
return get_fault_result(RESULT_DESCRIPTION, 132, msg)
|
||||
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
@ -16,7 +16,9 @@ import logging
|
||||
|
||||
from oslo_log import log
|
||||
|
||||
from vitrage.common.constants import EntityCategory
|
||||
from vitrage.common import file_utils
|
||||
|
||||
from vitrage.evaluator.actions.base import ActionType
|
||||
from vitrage.evaluator.template_fields import TemplateFields
|
||||
from vitrage.evaluator.template_validation.status_messages import status_msgs
|
||||
@ -30,7 +32,13 @@ LOG = log.getLogger(__name__)
|
||||
DEFINITIONS_INDEX_MOCK = {
|
||||
'123': {},
|
||||
'456': {},
|
||||
'789': {}
|
||||
'789': {},
|
||||
'a1': {
|
||||
TemplateFields.CATEGORY: EntityCategory.ALARM
|
||||
},
|
||||
'a2': {
|
||||
TemplateFields.CATEGORY: EntityCategory.ALARM
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -275,7 +283,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
|
||||
# Test setup
|
||||
idx = DEFINITIONS_INDEX_MOCK.copy()
|
||||
action = self._create_add_causal_relationship_action('456', '123')
|
||||
action = self._create_add_causal_relationship_action('a1', 'a2')
|
||||
|
||||
# Test action and assertions
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
@ -287,7 +295,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
|
||||
# Test setup
|
||||
idx = DEFINITIONS_INDEX_MOCK.copy()
|
||||
action = self._create_add_causal_relationship_action('unknown', '123')
|
||||
action = self._create_add_causal_relationship_action('unknown', 'a1')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
@ -299,7 +307,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
|
||||
# Test setup
|
||||
idx = DEFINITIONS_INDEX_MOCK.copy()
|
||||
action = self._create_add_causal_relationship_action('456', '123')
|
||||
action = self._create_add_causal_relationship_action('a1', 'a2')
|
||||
action[TemplateFields.ACTION_TARGET].pop(TemplateFields.TARGET, None)
|
||||
|
||||
# Test action
|
||||
@ -312,7 +320,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
|
||||
# Test setup
|
||||
idx = DEFINITIONS_INDEX_MOCK.copy()
|
||||
action = self._create_add_causal_relationship_action('456', 'unknown')
|
||||
action = self._create_add_causal_relationship_action('a1', 'unknown')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
@ -324,7 +332,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
|
||||
# Test setup
|
||||
idx = DEFINITIONS_INDEX_MOCK.copy()
|
||||
action = self._create_add_causal_relationship_action('456', '123')
|
||||
action = self._create_add_causal_relationship_action('a1', 'a2')
|
||||
action[TemplateFields.ACTION_TARGET].pop(TemplateFields.SOURCE, None)
|
||||
|
||||
# Test action
|
||||
@ -333,6 +341,30 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
# Test assertion
|
||||
self._test_assert_with_fault_result(result, 130)
|
||||
|
||||
def test_validate_add_causal_relationship_action_wrong_src_category(self):
|
||||
|
||||
# Test setup
|
||||
idx = DEFINITIONS_INDEX_MOCK.copy()
|
||||
action = self._create_add_causal_relationship_action('a1', '123')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
|
||||
# Test assertion
|
||||
self._test_assert_with_fault_result(result, 132)
|
||||
|
||||
def test_validate_add_causal_relationship_action_wrong_tgt_category(self):
|
||||
|
||||
# Test setup
|
||||
idx = DEFINITIONS_INDEX_MOCK.copy()
|
||||
action = self._create_add_causal_relationship_action('123', 'a1')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
|
||||
# Test assertion
|
||||
self._test_assert_with_fault_result(result, 132)
|
||||
|
||||
def _test_execute_and_assert_with_fault_result(self,
|
||||
template,
|
||||
status_code):
|
||||
|
Loading…
Reference in New Issue
Block a user