Merge "template not condition validation"
This commit is contained in:
commit
1c1fbb4cc7
@ -192,6 +192,7 @@ class TemplateData(object):
|
||||
condition_str = condition_str.replace(' and ', '&')
|
||||
condition_str = condition_str.replace(' or ', '|')
|
||||
condition_str = condition_str.replace(' not ', '~')
|
||||
condition_str = condition_str.replace('not ', '~')
|
||||
|
||||
return sympy_to_dfn(condition_str)
|
||||
|
||||
|
@ -47,6 +47,7 @@ status_msgs = {
|
||||
83: 'Entity definition must contain condition field.',
|
||||
84: 'Entity definition must contain actions field.',
|
||||
85: 'Failed to convert condition.',
|
||||
86: 'Not operator can be used only on relationships.',
|
||||
|
||||
# relationships status messages 100-119
|
||||
100: 'Invalid relation type. Relation type must be from types: '
|
||||
|
@ -12,8 +12,13 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sympy.logic.boolalg import Not
|
||||
from sympy import Symbol
|
||||
|
||||
from oslo_log import log
|
||||
from six.moves import reduce
|
||||
|
||||
from vitrage.common.constants import EdgeProperties as EProps
|
||||
from vitrage.common.constants import EntityCategory
|
||||
from vitrage.evaluator.actions.base import ActionType
|
||||
from vitrage.evaluator.template_data import TemplateData
|
||||
@ -34,7 +39,7 @@ def content_validation(template):
|
||||
|
||||
entities_index = {}
|
||||
entities = template_definitions[TemplateFields.ENTITIES]
|
||||
result = validate_entities_definition(entities, entities_index)
|
||||
result = _validate_entities_definition(entities, entities_index)
|
||||
|
||||
relationships_index = {}
|
||||
|
||||
@ -42,24 +47,24 @@ def content_validation(template):
|
||||
TemplateFields.RELATIONSHIPS in template_definitions:
|
||||
|
||||
relationships = template_definitions[TemplateFields.RELATIONSHIPS]
|
||||
result = validate_relationships_definitions(relationships,
|
||||
relationships_index,
|
||||
entities_index)
|
||||
result = _validate_relationships_definitions(relationships,
|
||||
relationships_index,
|
||||
entities_index)
|
||||
if result.is_valid_config:
|
||||
scenarios = template[TemplateFields.SCENARIOS]
|
||||
definitions_index = entities_index.copy()
|
||||
definitions_index.update(relationships_index)
|
||||
result = validate_scenarios(scenarios, definitions_index)
|
||||
result = _validate_scenarios(scenarios, definitions_index)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_entities_definition(entities, entities_index):
|
||||
def _validate_entities_definition(entities, entities_index):
|
||||
|
||||
for entity in entities:
|
||||
|
||||
entity_dict = entity[TemplateFields.ENTITY]
|
||||
result = validate_entity_definition(entity_dict, entities_index)
|
||||
result = _validate_entity_definition(entity_dict, entities_index)
|
||||
|
||||
if not result.is_valid_config:
|
||||
return result
|
||||
@ -69,7 +74,7 @@ def validate_entities_definition(entities, entities_index):
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
def validate_entity_definition(entity_dict, entities_index):
|
||||
def _validate_entity_definition(entity_dict, entities_index):
|
||||
|
||||
template_id = entity_dict[TemplateFields.TEMPLATE_ID]
|
||||
if template_id in entities_index:
|
||||
@ -79,16 +84,16 @@ def validate_entity_definition(entity_dict, entities_index):
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
def validate_relationships_definitions(relationships,
|
||||
relationships_index,
|
||||
entities_index):
|
||||
def _validate_relationships_definitions(relationships,
|
||||
relationships_index,
|
||||
entities_index):
|
||||
|
||||
for relationship in relationships:
|
||||
|
||||
relationship_dict = relationship[TemplateFields.RELATIONSHIP]
|
||||
result = validate_relationship(relationship_dict,
|
||||
relationships_index,
|
||||
entities_index)
|
||||
result = _validate_relationship(relationship_dict,
|
||||
relationships_index,
|
||||
entities_index)
|
||||
if not result.is_valid_config:
|
||||
return result
|
||||
|
||||
@ -97,7 +102,7 @@ def validate_relationships_definitions(relationships,
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
def validate_relationship(relationship, relationships_index, entities_index):
|
||||
def _validate_relationship(relationship, relationships_index, entities_index):
|
||||
|
||||
template_id = relationship[TemplateFields.TEMPLATE_ID]
|
||||
if template_id in relationships_index or template_id in entities_index:
|
||||
@ -114,20 +119,20 @@ def validate_relationship(relationship, relationships_index, entities_index):
|
||||
return result
|
||||
|
||||
|
||||
def validate_scenarios(scenarios, definitions_index):
|
||||
def _validate_scenarios(scenarios, definitions_index):
|
||||
|
||||
for scenario in scenarios:
|
||||
|
||||
scenario_values = scenario[TemplateFields.SCENARIO]
|
||||
|
||||
condition = scenario_values[TemplateFields.CONDITION]
|
||||
result = validate_scenario_condition(condition, definitions_index)
|
||||
result = _validate_scenario_condition(condition, definitions_index)
|
||||
|
||||
if not result.is_valid_config:
|
||||
return result
|
||||
|
||||
actions = scenario_values[TemplateFields.ACTIONS]
|
||||
result = validate_scenario_actions(actions, definitions_index)
|
||||
result = _validate_scenario_actions(actions, definitions_index)
|
||||
|
||||
if not result.is_valid_config:
|
||||
return result
|
||||
@ -135,15 +140,21 @@ def validate_scenarios(scenarios, definitions_index):
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
def validate_scenario_condition(condition, definitions_index):
|
||||
|
||||
def _validate_scenario_condition(condition, definitions_index):
|
||||
try:
|
||||
TemplateData.convert_to_dnf_format(condition)
|
||||
dnf_result = TemplateData.convert_to_dnf_format(condition)
|
||||
except Exception:
|
||||
LOG.error('%s status code: %s' % (status_msgs[85], 85))
|
||||
return get_fault_result(RESULT_DESCRIPTION, 85)
|
||||
|
||||
values_to_replace = ' and ', ' or ', ' not ', '(', ')'
|
||||
# not condition validation
|
||||
not_condition_result = \
|
||||
_validate_not_condition(dnf_result, definitions_index)
|
||||
if not not_condition_result.is_valid_config:
|
||||
return not_condition_result
|
||||
|
||||
# template id validation
|
||||
values_to_replace = ' and ', ' or ', ' not ', 'not ', '(', ')'
|
||||
condition = reduce(lambda cond, v: cond.replace(v, ' '),
|
||||
values_to_replace,
|
||||
condition)
|
||||
@ -160,26 +171,60 @@ def validate_scenario_condition(condition, definitions_index):
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
def validate_scenario_actions(actions, definitions_index):
|
||||
def _validate_not_condition(dnf_result, definitions_index):
|
||||
"""Not operator validation
|
||||
|
||||
Not operator can appear only on edges.
|
||||
|
||||
:param dnf_result:
|
||||
:param definitions_index:
|
||||
:return:
|
||||
"""
|
||||
|
||||
if isinstance(dnf_result, Not):
|
||||
for arg in dnf_result.args:
|
||||
if isinstance(arg, Symbol):
|
||||
definition = definitions_index.get(str(arg), None)
|
||||
if not (definition and
|
||||
definition.get(EProps.RELATIONSHIP_TYPE)):
|
||||
msg = status_msgs[86] + ' template id: %s' % arg
|
||||
LOG.error('%s status code: %s' % (msg, 86))
|
||||
return get_fault_result(RESULT_DESCRIPTION, 86, msg)
|
||||
else:
|
||||
res = _validate_not_condition(arg, definitions_index)
|
||||
if not res.is_valid_config:
|
||||
return res
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
for arg in dnf_result.args:
|
||||
if not isinstance(arg, Symbol):
|
||||
res = _validate_not_condition(arg, definitions_index)
|
||||
if not res.is_valid_config:
|
||||
return res
|
||||
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
def _validate_scenario_actions(actions, definitions_index):
|
||||
|
||||
for action in actions:
|
||||
result = validate_scenario_action(action[TemplateFields.ACTION],
|
||||
definitions_index)
|
||||
result = _validate_scenario_action(action[TemplateFields.ACTION],
|
||||
definitions_index)
|
||||
if not result.is_valid_config:
|
||||
return result
|
||||
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
def validate_scenario_action(action, definitions_index):
|
||||
def _validate_scenario_action(action, definitions_index):
|
||||
|
||||
action_type = action[TemplateFields.ACTION_TYPE]
|
||||
actions = {
|
||||
ActionType.RAISE_ALARM: validate_raise_alarm_action,
|
||||
ActionType.SET_STATE: validate_set_state_action,
|
||||
ActionType.RAISE_ALARM: _validate_raise_alarm_action,
|
||||
ActionType.SET_STATE: _validate_set_state_action,
|
||||
ActionType.ADD_CAUSAL_RELATIONSHIP:
|
||||
validate_add_causal_relationship_action,
|
||||
ActionType.MARK_DOWN: validate_mark_down_action,
|
||||
_validate_add_causal_relationship_action,
|
||||
ActionType.MARK_DOWN: _validate_mark_down_action,
|
||||
}
|
||||
|
||||
if action_type not in actions.keys():
|
||||
@ -189,7 +234,7 @@ def validate_scenario_action(action, definitions_index):
|
||||
return actions[action_type](action, definitions_index)
|
||||
|
||||
|
||||
def validate_raise_alarm_action(action, definitions_index):
|
||||
def _validate_raise_alarm_action(action, definitions_index):
|
||||
|
||||
properties = action[TemplateFields.PROPERTIES]
|
||||
|
||||
@ -210,7 +255,7 @@ def validate_raise_alarm_action(action, definitions_index):
|
||||
return _validate_template_id(definitions_index, target)
|
||||
|
||||
|
||||
def validate_set_state_action(action, definitions_index):
|
||||
def _validate_set_state_action(action, definitions_index):
|
||||
|
||||
properties = action[TemplateFields.PROPERTIES]
|
||||
|
||||
@ -227,7 +272,7 @@ def validate_set_state_action(action, definitions_index):
|
||||
return _validate_template_id(definitions_index, target)
|
||||
|
||||
|
||||
def validate_add_causal_relationship_action(action, definitions_index):
|
||||
def _validate_add_causal_relationship_action(action, definitions_index):
|
||||
|
||||
action_target = action[TemplateFields.ACTION_TARGET]
|
||||
|
||||
@ -250,7 +295,7 @@ def validate_add_causal_relationship_action(action, definitions_index):
|
||||
return get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
|
||||
def validate_mark_down_action(action, definitions_index):
|
||||
def _validate_mark_down_action(action, definitions_index):
|
||||
|
||||
action_target = action[TemplateFields.ACTION_TARGET]
|
||||
if TemplateFields.TARGET not in action_target:
|
||||
|
@ -38,24 +38,24 @@ RESULT_DESCRIPTION = 'Template syntax validation'
|
||||
|
||||
def syntax_validation(template_conf):
|
||||
|
||||
result = validate_template_sections(template_conf)
|
||||
result = _validate_template_sections(template_conf)
|
||||
|
||||
if result.is_valid_config:
|
||||
metadata = template_conf[TemplateFields.METADATA]
|
||||
result = validate_metadata_section(metadata)
|
||||
result = _validate_metadata_section(metadata)
|
||||
|
||||
if result.is_valid_config:
|
||||
definitions = template_conf[TemplateFields.DEFINITIONS]
|
||||
result = validate_definitions_section(definitions)
|
||||
result = _validate_definitions_section(definitions)
|
||||
|
||||
if result.is_valid_config:
|
||||
scenarios = template_conf[TemplateFields.SCENARIOS]
|
||||
result = validate_scenarios_section(scenarios)
|
||||
result = _validate_scenarios_section(scenarios)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_template_sections(template_conf):
|
||||
def _validate_template_sections(template_conf):
|
||||
|
||||
schema = Schema({
|
||||
Required(TemplateFields.DEFINITIONS, msg=21): dict,
|
||||
@ -65,7 +65,7 @@ def validate_template_sections(template_conf):
|
||||
return _validate_dict_schema(schema, template_conf)
|
||||
|
||||
|
||||
def validate_metadata_section(metadata):
|
||||
def _validate_metadata_section(metadata):
|
||||
|
||||
any_str = Any(str, six.text_type)
|
||||
|
||||
@ -76,10 +76,10 @@ def validate_metadata_section(metadata):
|
||||
return _validate_dict_schema(schema, metadata)
|
||||
|
||||
|
||||
def validate_definitions_section(definitions):
|
||||
def _validate_definitions_section(definitions):
|
||||
|
||||
if TemplateFields.RELATIONSHIPS not in definitions or \
|
||||
definitions[TemplateFields.RELATIONSHIPS] != '':
|
||||
definitions[TemplateFields.RELATIONSHIPS] != '':
|
||||
schema = Schema({
|
||||
Required(TemplateFields.ENTITIES, msg=20): list,
|
||||
TemplateFields.RELATIONSHIPS: list
|
||||
@ -90,16 +90,16 @@ def validate_definitions_section(definitions):
|
||||
result = get_correct_result(RESULT_DESCRIPTION)
|
||||
|
||||
if result.is_valid_config:
|
||||
result = validate_entities(definitions[TemplateFields.ENTITIES])
|
||||
result = _validate_entities(definitions[TemplateFields.ENTITIES])
|
||||
|
||||
relationships = definitions.get(TemplateFields.RELATIONSHIPS, None)
|
||||
if result.is_valid_config and relationships:
|
||||
return validate_relationships(relationships)
|
||||
return _validate_relationships(relationships)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_entities(entities):
|
||||
def _validate_entities(entities):
|
||||
|
||||
if not entities:
|
||||
LOG.error('%s status code: %s' % (status_msgs[43], 43))
|
||||
@ -113,7 +113,7 @@ def validate_entities(entities):
|
||||
result = _validate_dict_schema(schema, entity)
|
||||
|
||||
if result.is_valid_config:
|
||||
result = validate_entity_dict(entity[TemplateFields.ENTITY])
|
||||
result = _validate_entity_dict(entity[TemplateFields.ENTITY])
|
||||
|
||||
if not result.is_valid_config:
|
||||
return result
|
||||
@ -121,7 +121,7 @@ def validate_entities(entities):
|
||||
return result
|
||||
|
||||
|
||||
def validate_entity_dict(entity_dict):
|
||||
def _validate_entity_dict(entity_dict):
|
||||
|
||||
any_str = Any(str, six.text_type)
|
||||
schema = Schema({
|
||||
@ -135,7 +135,7 @@ def validate_entity_dict(entity_dict):
|
||||
return _validate_dict_schema(schema, entity_dict)
|
||||
|
||||
|
||||
def validate_relationships(relationships):
|
||||
def _validate_relationships(relationships):
|
||||
|
||||
for relationship in relationships:
|
||||
|
||||
@ -146,14 +146,14 @@ def validate_relationships(relationships):
|
||||
|
||||
if result.is_valid_config:
|
||||
relationship_dict = relationship[TemplateFields.RELATIONSHIP]
|
||||
result = validate_relationship_dict(relationship_dict)
|
||||
result = _validate_relationship_dict(relationship_dict)
|
||||
|
||||
if not result.is_valid_config:
|
||||
return result
|
||||
return result
|
||||
|
||||
|
||||
def validate_relationship_dict(relationship_dict):
|
||||
def _validate_relationship_dict(relationship_dict):
|
||||
|
||||
any_str = Any(str, six.text_type)
|
||||
schema = Schema({
|
||||
@ -166,7 +166,7 @@ def validate_relationship_dict(relationship_dict):
|
||||
return _validate_dict_schema(schema, relationship_dict)
|
||||
|
||||
|
||||
def validate_scenarios_section(scenarios):
|
||||
def _validate_scenarios_section(scenarios):
|
||||
|
||||
if not scenarios:
|
||||
LOG.error('%s status code: %s' % (status_msgs[81], 81))
|
||||
@ -180,7 +180,7 @@ def validate_scenarios_section(scenarios):
|
||||
result = _validate_dict_schema(schema, scenario)
|
||||
|
||||
if result.is_valid_config:
|
||||
result = validate_scenario(scenario[TemplateFields.SCENARIO])
|
||||
result = _validate_scenario(scenario[TemplateFields.SCENARIO])
|
||||
|
||||
if not result.is_valid_config:
|
||||
return result
|
||||
@ -188,7 +188,7 @@ def validate_scenarios_section(scenarios):
|
||||
return result
|
||||
|
||||
|
||||
def validate_scenario(scenario):
|
||||
def _validate_scenario(scenario):
|
||||
|
||||
any_str = Any(str, six.text_type)
|
||||
schema = Schema({
|
||||
@ -198,12 +198,12 @@ def validate_scenario(scenario):
|
||||
result = _validate_dict_schema(schema, scenario)
|
||||
|
||||
if result.is_valid_config:
|
||||
return validate_actions_schema(scenario[TemplateFields.ACTIONS])
|
||||
return _validate_actions_schema(scenario[TemplateFields.ACTIONS])
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def validate_actions_schema(actions):
|
||||
def _validate_actions_schema(actions):
|
||||
|
||||
if not actions:
|
||||
LOG.error('%s status code: %s' % (status_msgs[121], 121))
|
||||
@ -217,7 +217,7 @@ def validate_actions_schema(actions):
|
||||
result = _validate_dict_schema(schema, action)
|
||||
|
||||
if result.is_valid_config:
|
||||
result = validate_action_schema(action[TemplateFields.ACTION])
|
||||
result = _validate_action_schema(action[TemplateFields.ACTION])
|
||||
|
||||
if not result.is_valid_config:
|
||||
return result
|
||||
@ -225,7 +225,7 @@ def validate_actions_schema(actions):
|
||||
return result
|
||||
|
||||
|
||||
def validate_action_schema(action):
|
||||
def _validate_action_schema(action):
|
||||
|
||||
schema = Schema({
|
||||
Required(TemplateFields.ACTION_TYPE, msg=123):
|
||||
|
@ -0,0 +1,30 @@
|
||||
metadata:
|
||||
name: basic_correct_not_condition_template
|
||||
description: basic not condition template for general tests
|
||||
definitions:
|
||||
entities:
|
||||
- entity:
|
||||
category: ALARM
|
||||
type: nagios
|
||||
name: HOST_HIGH_CPU_LOAD
|
||||
template_id: alarm
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: nova.host
|
||||
template_id: resource
|
||||
relationships:
|
||||
- relationship:
|
||||
source: alarm
|
||||
target: resource
|
||||
relationship_type: on
|
||||
template_id : alarm_on_host
|
||||
scenarios:
|
||||
- scenario:
|
||||
condition: not alarm_on_host
|
||||
actions:
|
||||
- action:
|
||||
action_type: set_state
|
||||
properties:
|
||||
state: SUBOPTIMAL
|
||||
action_target:
|
||||
target: resource
|
@ -0,0 +1,30 @@
|
||||
metadata:
|
||||
name: basic_incorrect_not_condition_template
|
||||
description: basic not condition template for general tests
|
||||
definitions:
|
||||
entities:
|
||||
- entity:
|
||||
category: ALARM
|
||||
type: nagios
|
||||
name: HOST_HIGH_CPU_LOAD
|
||||
template_id: alarm
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: nova.host
|
||||
template_id: resource
|
||||
relationships:
|
||||
- relationship:
|
||||
source: alarm
|
||||
target: resource
|
||||
relationship_type: on
|
||||
template_id : alarm_on_host
|
||||
scenarios:
|
||||
- scenario:
|
||||
condition: not resource
|
||||
actions:
|
||||
- action:
|
||||
action_type: set_state
|
||||
properties:
|
||||
state: SUBOPTIMAL
|
||||
action_target:
|
||||
target: resource
|
@ -0,0 +1,57 @@
|
||||
metadata:
|
||||
name: complicated_correct_not_condition_template
|
||||
description: basic not condition template for general tests
|
||||
definitions:
|
||||
entities:
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: neutron.port
|
||||
template_id: port
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: nova.zone
|
||||
template_id: zone
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: nova.host
|
||||
template_id: host
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: nova.instance
|
||||
template_id: instance
|
||||
- entity:
|
||||
category: ALARM
|
||||
type: nova.host
|
||||
name: HOST_HIGH_CPU_LOAD
|
||||
template_id: alarm
|
||||
relationships:
|
||||
- relationship:
|
||||
source: zone
|
||||
target: host
|
||||
relationship_type: contains
|
||||
template_id : zone_contains_host
|
||||
- relationship:
|
||||
source: host
|
||||
target: instance
|
||||
relationship_type: contains
|
||||
template_id : host_contains_instance
|
||||
- relationship:
|
||||
source: port
|
||||
target: instance
|
||||
relationship_type: attached
|
||||
template_id : port_attached_instance
|
||||
- relationship:
|
||||
source: alarm
|
||||
target: instance
|
||||
relationship_type: on
|
||||
template_id : alarm_on_instance
|
||||
scenarios:
|
||||
- scenario:
|
||||
condition: zone_contains_host or host_contains_instance and not host_contains_instance or not port_attached_instance
|
||||
actions:
|
||||
- action:
|
||||
action_type: set_state
|
||||
properties:
|
||||
state: SUBOPTIMAL
|
||||
action_target:
|
||||
target: host
|
@ -0,0 +1,57 @@
|
||||
metadata:
|
||||
name: complicated_incorrect_not_condition_template
|
||||
description: basic not condition template for general tests
|
||||
definitions:
|
||||
entities:
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: neutron.port
|
||||
template_id: port
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: nova.zone
|
||||
template_id: zone
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: nova.host
|
||||
template_id: host
|
||||
- entity:
|
||||
category: RESOURCE
|
||||
type: nova.instance
|
||||
template_id: instance
|
||||
- entity:
|
||||
category: ALARM
|
||||
type: nova.host
|
||||
name: HOST_HIGH_CPU_LOAD
|
||||
template_id: alarm
|
||||
relationships:
|
||||
- relationship:
|
||||
source: zone
|
||||
target: host
|
||||
relationship_type: contains
|
||||
template_id : zone_contains_host
|
||||
- relationship:
|
||||
source: host
|
||||
target: instance
|
||||
relationship_type: contains
|
||||
template_id : host_contains_instance
|
||||
- relationship:
|
||||
source: port
|
||||
target: instance
|
||||
relationship_type: attached
|
||||
template_id : port_attached_instance
|
||||
- relationship:
|
||||
source: alarm
|
||||
target: instance
|
||||
relationship_type: on
|
||||
template_id : alarm_on_instance
|
||||
scenarios:
|
||||
- scenario:
|
||||
condition: zone_contains_host or host_contains_instance and not port or not host_contains_instance
|
||||
actions:
|
||||
- action:
|
||||
action_type: set_state
|
||||
properties:
|
||||
state: SUBOPTIMAL
|
||||
action_target:
|
||||
target: host
|
@ -11,6 +11,7 @@
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import logging
|
||||
|
||||
@ -57,6 +58,43 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
for template in self.templates:
|
||||
self._test_execute_and_assert_with_correct_result(template)
|
||||
|
||||
def test_not_operator(self):
|
||||
basic_correct_not_condition_path = \
|
||||
'%s/templates/not_operator/basic_correct_not_condition.yaml' % \
|
||||
utils.get_resources_dir()
|
||||
basic_correct_not_condition_template = \
|
||||
file_utils.load_yaml_file(basic_correct_not_condition_path)
|
||||
self._test_execute_and_assert_with_correct_result(
|
||||
basic_correct_not_condition_template)
|
||||
|
||||
basic_incorrect_not_condition_path = \
|
||||
'%s/templates/not_operator/basic_incorrect_not_condition.yaml' % \
|
||||
utils.get_resources_dir()
|
||||
basic_incorrect_not_condition_template = \
|
||||
file_utils.load_yaml_file(basic_incorrect_not_condition_path)
|
||||
self._test_execute_and_assert_with_fault_result(
|
||||
basic_incorrect_not_condition_template,
|
||||
86)
|
||||
|
||||
complicated_correct_not_condition_path = \
|
||||
'%s/templates/not_operator/' \
|
||||
'complicated_correct_not_condition.yaml' % \
|
||||
utils.get_resources_dir()
|
||||
complicated_correct_not_condition_template = \
|
||||
file_utils.load_yaml_file(complicated_correct_not_condition_path)
|
||||
self._test_execute_and_assert_with_correct_result(
|
||||
complicated_correct_not_condition_template)
|
||||
|
||||
complicated_incorrect_not_condition_path = \
|
||||
'%s/templates/not_operator/' \
|
||||
'complicated_incorrect_not_condition.yaml' % \
|
||||
utils.get_resources_dir()
|
||||
complicated_incorrect_not_condition_template = \
|
||||
file_utils.load_yaml_file(complicated_incorrect_not_condition_path)
|
||||
self._test_execute_and_assert_with_fault_result(
|
||||
complicated_incorrect_not_condition_template,
|
||||
86)
|
||||
|
||||
def test_validate_entity_definition_with_no_unique_template_id(self):
|
||||
|
||||
template = self.clone_template
|
||||
@ -131,7 +169,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_raise_alarm_action('123')
|
||||
|
||||
# Test action and assertions
|
||||
result = validator.validate_raise_alarm_action(action, idx)
|
||||
result = validator._validate_raise_alarm_action(action, idx)
|
||||
|
||||
# Test Assertions
|
||||
self._test_assert_with_correct_result(result)
|
||||
@ -143,7 +181,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_raise_alarm_action('unknown')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_raise_alarm_action(action, idx)
|
||||
result = validator._validate_raise_alarm_action(action, idx)
|
||||
|
||||
# Test assertions
|
||||
self._test_assert_with_fault_result(result, 3)
|
||||
@ -156,7 +194,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action[TemplateFields.ACTION_TARGET].pop(TemplateFields.TARGET)
|
||||
|
||||
# Test action
|
||||
result = validator.validate_raise_alarm_action(action, idx)
|
||||
result = validator._validate_raise_alarm_action(action, idx)
|
||||
|
||||
# Test assertions
|
||||
self._test_assert_with_fault_result(result, 127)
|
||||
@ -169,7 +207,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action[TemplateFields.PROPERTIES].pop(TemplateFields.SEVERITY)
|
||||
|
||||
# Test action
|
||||
result = validator.validate_raise_alarm_action(action, idx)
|
||||
result = validator._validate_raise_alarm_action(action, idx)
|
||||
|
||||
# Test assertions
|
||||
self._test_assert_with_fault_result(result, 126)
|
||||
@ -182,7 +220,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action[TemplateFields.PROPERTIES].pop(TemplateFields.ALARM_NAME)
|
||||
|
||||
# Test action
|
||||
result = validator.validate_raise_alarm_action(action, idx)
|
||||
result = validator._validate_raise_alarm_action(action, idx)
|
||||
|
||||
# Test assertions
|
||||
self._test_assert_with_fault_result(result, 125)
|
||||
@ -194,7 +232,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_set_state_action('123')
|
||||
|
||||
# Test action and assertions
|
||||
result = validator.validate_set_state_action(action, idx)
|
||||
result = validator._validate_set_state_action(action, idx)
|
||||
|
||||
# Test Assertions
|
||||
self._test_assert_with_correct_result(result)
|
||||
@ -206,7 +244,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_set_state_action('unknown')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_set_state_action(action, idx)
|
||||
result = validator._validate_set_state_action(action, idx)
|
||||
|
||||
# Test assertions
|
||||
self._test_assert_with_fault_result(result, 3)
|
||||
@ -219,7 +257,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action[TemplateFields.ACTION_TARGET].pop(TemplateFields.TARGET)
|
||||
|
||||
# Test action
|
||||
result = validator.validate_set_state_action(action, idx)
|
||||
result = validator._validate_set_state_action(action, idx)
|
||||
|
||||
# Test assertions
|
||||
self._test_assert_with_fault_result(result, 129)
|
||||
@ -232,7 +270,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action[TemplateFields.PROPERTIES].pop(TemplateFields.STATE, None)
|
||||
|
||||
# Test action
|
||||
result = validator.validate_set_state_action(action, idx)
|
||||
result = validator._validate_set_state_action(action, idx)
|
||||
|
||||
# Test assertions
|
||||
self._test_assert_with_fault_result(result, 128)
|
||||
@ -244,7 +282,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_mark_down_action('123')
|
||||
|
||||
# Test action and assertions
|
||||
result = validator.validate_mark_down_action(action, idx)
|
||||
result = validator._validate_mark_down_action(action, idx)
|
||||
|
||||
# Test Assertions
|
||||
self._test_assert_with_correct_result(result)
|
||||
@ -256,7 +294,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_mark_down_action('unknown')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_mark_down_action(action, idx)
|
||||
result = validator._validate_mark_down_action(action, idx)
|
||||
|
||||
# Test assertions
|
||||
self._test_assert_with_fault_result(result, 3)
|
||||
@ -269,7 +307,7 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action[TemplateFields.ACTION_TARGET].pop(TemplateFields.TARGET)
|
||||
|
||||
# Test action
|
||||
result = validator.validate_mark_down_action(action, idx)
|
||||
result = validator._validate_mark_down_action(action, idx)
|
||||
|
||||
# Test assertions
|
||||
self._test_assert_with_fault_result(result, 131)
|
||||
@ -281,7 +319,8 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_add_causal_relationship_action('a1', 'a2')
|
||||
|
||||
# Test action and assertions
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
result = \
|
||||
validator._validate_add_causal_relationship_action(action, idx)
|
||||
|
||||
# Test action and assertions
|
||||
self._test_assert_with_correct_result(result)
|
||||
@ -293,7 +332,8 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_add_causal_relationship_action('unknown', 'a1')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
result = \
|
||||
validator._validate_add_causal_relationship_action(action, idx)
|
||||
|
||||
# Test assertion
|
||||
self._test_assert_with_fault_result(result, 3)
|
||||
@ -306,7 +346,8 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action[TemplateFields.ACTION_TARGET].pop(TemplateFields.TARGET, None)
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
result = \
|
||||
validator._validate_add_causal_relationship_action(action, idx)
|
||||
|
||||
# Test assertion
|
||||
self._test_assert_with_fault_result(result, 130)
|
||||
@ -318,7 +359,8 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_add_causal_relationship_action('a1', 'unknown')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
result = \
|
||||
validator._validate_add_causal_relationship_action(action, idx)
|
||||
|
||||
# Test assertion
|
||||
self._test_assert_with_fault_result(result, 3)
|
||||
@ -331,7 +373,8 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action[TemplateFields.ACTION_TARGET].pop(TemplateFields.SOURCE, None)
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
result = \
|
||||
validator._validate_add_causal_relationship_action(action, idx)
|
||||
|
||||
# Test assertion
|
||||
self._test_assert_with_fault_result(result, 130)
|
||||
@ -343,7 +386,8 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_add_causal_relationship_action('a1', '123')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
result = \
|
||||
validator._validate_add_causal_relationship_action(action, idx)
|
||||
|
||||
# Test assertion
|
||||
self._test_assert_with_fault_result(result, 132)
|
||||
@ -355,7 +399,8 @@ class TemplateContentValidatorTest(base.BaseTest):
|
||||
action = self._create_add_causal_relationship_action('123', 'a1')
|
||||
|
||||
# Test action
|
||||
result = validator.validate_add_causal_relationship_action(action, idx)
|
||||
result = \
|
||||
validator._validate_add_causal_relationship_action(action, idx)
|
||||
|
||||
# Test assertion
|
||||
self._test_assert_with_fault_result(result, 132)
|
||||
|
Loading…
Reference in New Issue
Block a user