Skip to content

Commit

Permalink
Merge "alarm schema change for uve_keys field" into R3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jul 22, 2016
2 parents 44d1f55 + e6b39d8 commit 6d93f5f
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 38 deletions.
13 changes: 7 additions & 6 deletions src/opserver/alarmgen.py
Expand Up @@ -276,10 +276,10 @@ def _get_json_value(self, val):
return val
# end _get_json_value

def _get_json_vars(self, uve, exp, operand1_val,
operand2_val, is_operand2_json_val):
def _get_json_variables(self, uve, exp, operand1_val,
operand2_val, is_operand2_json_val):
json_vars = {}
for var in exp.vars:
for var in exp.variables:
# If var and operand1/operand2 are at the same hirerarchy in
# the uve struture, then get the value of var from parent_attr of
# the corresponding operand_val
Expand All @@ -295,7 +295,7 @@ def _get_json_vars(self, uve, exp, operand1_val,
var_val = self._get_operand_value(uve, var)['value']
json_vars[var] = self._get_json_value(var_val)
return json_vars
# end _get_json_vars
# end _get_json_variables

def _compare_operand_vals(self, val1, val2, operation):
try:
Expand Down Expand Up @@ -334,7 +334,7 @@ def _compare_operand_vals(self, val1, val2, operation):

def _get_alarm_match(self, uve, exp, operand1_val, operand2_val,
is_operand2_json_val):
json_vars = self._get_json_vars(uve, exp, operand1_val,
json_vars = self._get_json_variables(uve, exp, operand1_val,
operand2_val, is_operand2_json_val)
json_operand1_val = self._get_json_value(operand1_val['value'])
if not is_operand2_json_val:
Expand All @@ -352,7 +352,8 @@ def _get_alarm_condition_match(self, uve, exp, operand1_val, operand2_val,
operand2_val, is_operand2_json_val)]
return AlarmConditionMatch(
condition=AlarmCondition(operation=exp.operation,
operand1=exp.operand1, operand2=exp.operand2, vars=exp.vars),
operand1=exp.operand1, operand2=exp.operand2,
vars=exp.variables),
match=match_list)
# end _get_alarm_condition_match

Expand Down
28 changes: 15 additions & 13 deletions src/opserver/alarmgen_config_handler.py
Expand Up @@ -7,7 +7,7 @@

from vnc_api.gen.resource_client import Alarm
from vnc_api.gen.resource_xsd import IdPermsType, AlarmExpression, \
AlarmAndList, AlarmOrList
AlarmAndList, AlarmOrList, UveKeysType
from pysandesh.gen_py.sandesh.ttypes import SandeshLevel
from config_handler import ConfigHandler
from opserver_util import camel_case_to_hyphen, inverse_dict
Expand Down Expand Up @@ -90,7 +90,7 @@ def _create_inbuilt_alarms_config(self):
extn.obj.__class__.__name__)
if self._inbuilt_alarms.has_key(alarm_name):
uve_keys = self._inbuilt_alarms[alarm_name].get_uve_keys()
uve_keys.append(_INVERSE_UVE_MAP[table])
uve_keys.uve_key.append(_INVERSE_UVE_MAP[table])
self._inbuilt_alarms[alarm_name].set_uve_keys(uve_keys)
else:
alarm_or_list = None
Expand All @@ -103,7 +103,7 @@ def _create_inbuilt_alarms_config(self):
operation=exp['operation'],
operand1=exp['operand1'],
operand2=exp['operand2'],
vars=exp.get('vars')))
variables=exp.get('variables')))
alarm_or_list.append(AlarmAndList(alarm_and_list))
desc = ' '.join([l.strip() \
for l in extn.obj.__doc__.splitlines()])
Expand All @@ -112,7 +112,7 @@ def _create_inbuilt_alarms_config(self):
'fq_name': ['default-global-system-config',
alarm_name]}
self._inbuilt_alarms[alarm_name] = Alarm(name=alarm_name,
uve_keys=[_INVERSE_UVE_MAP[table]],
uve_keys=UveKeysType([_INVERSE_UVE_MAP[table]]),
alarm_severity=extn.obj.severity(),
alarm_rules=AlarmOrList(alarm_or_list),
id_perms=id_perms, **kwargs)
Expand All @@ -139,25 +139,27 @@ def _handle_config_update(self, config_type, fq_name, config_obj,
alarm_config = self._config_db[config_type].get(fq_name)
if alarm_config is None:
alarm_config_change_map = self._update_alarm_config_table(
fq_name, config_obj, config_obj.uve_keys, 'CREATE')
fq_name, config_obj, config_obj.uve_keys.uve_key,
'CREATE')
else:
# If the alarm config already exists, then check for
# addition/deletion of elements from uve_keys[] and
# addition/deletion of elements from uve_keys and
# update the alarm_config_db appropriately.
add_uve_keys = set(config_obj.uve_keys) - \
set(alarm_config.uve_keys)
add_uve_keys = set(config_obj.uve_keys.uve_key) - \
set(alarm_config.uve_keys.uve_key)
if add_uve_keys:
alarm_config_change_map.update(
self._update_alarm_config_table(
fq_name, config_obj, add_uve_keys, 'CREATE'))
del_uve_keys = set(alarm_config.uve_keys) - \
set(config_obj.uve_keys)
del_uve_keys = set(alarm_config.uve_keys.uve_key) - \
set(config_obj.uve_keys.uve_key)
if del_uve_keys:
alarm_config_change_map.update(
self._update_alarm_config_table(
fq_name, None, del_uve_keys, 'DELETE'))
upd_uve_keys = set(config_obj.uve_keys).intersection(
set(alarm_config.uve_keys))
upd_uve_keys = \
set(config_obj.uve_keys.uve_key).intersection(
set(alarm_config.uve_keys.uve_key))
if upd_uve_keys:
alarm_config_change_map.update(
self._update_alarm_config_table(
Expand All @@ -168,7 +170,7 @@ def _handle_config_update(self, config_type, fq_name, config_obj,
if config_obj is not None:
if config_type == 'alarm':
alarm_config_change_map = self._update_alarm_config_table(
fq_name, None, config_obj.uve_keys, 'DELETE')
fq_name, None, config_obj.uve_keys.uve_key, 'DELETE')
del self._config_db[config_type][fq_name]
if not len(self._config_db[config_type]):
del self._config_db[config_type]
Expand Down
3 changes: 2 additions & 1 deletion src/opserver/plugins/alarm_disk_usage/main.py
Expand Up @@ -14,7 +14,8 @@ class DiskUsage(AlarmBase):
'percentage_partition_space_used',
'operation': '>=',
'operand2': '90',
'vars': ['NodeStatus.disk_usage_info.partition_name']
'variables': \
['NodeStatus.disk_usage_info.partition_name']
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion src/opserver/plugins/alarm_process_connectivity/main.py
Expand Up @@ -22,7 +22,7 @@ class ProcessConnectivity(AlarmBase):
'operand1': 'NodeStatus.process_status.state',
'operation': '!=',
'operand2': '"Functional"',
'vars': ['NodeStatus.process_status.module_id',
'variables': ['NodeStatus.process_status.module_id',
'NodeStatus.process_status.instance_id']
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/opserver/plugins/alarm_process_status/main.py
Expand Up @@ -22,7 +22,7 @@ class ProcessStatus(AlarmBase):
'operand1': 'NodeStatus.process_info.process_state',
'operation': '!=',
'operand2': '"PROCESS_STATE_RUNNING"',
'vars': ['NodeStatus.process_info.process_name']
'variables': ['NodeStatus.process_info.process_name']
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion src/opserver/plugins/alarm_storage/main.py
Expand Up @@ -13,7 +13,8 @@ class StorageClusterState(AlarmBase):
'operand1': 'StorageCluster.info_stats.status',
'operation': '!=',
'operand2': '0',
'vars': ['StorageCluster.info_stats.health_summary']
'variables': \
['StorageCluster.info_stats.health_summary']
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions src/opserver/plugins/alarm_vrouter_interface/main.py
Expand Up @@ -13,8 +13,8 @@ class VrouterInterface(AlarmBase):
'operand1': 'VrouterAgent.down_interface_count',
'operation': '>=',
'operand2': '1',
'vars': ['VrouterAgent.error_intf_list', \
'VrouterAgent.no_config_intf_list']
'variables': ['VrouterAgent.error_intf_list', \
'VrouterAgent.no_config_intf_list']
},
]
}
Expand Down
12 changes: 6 additions & 6 deletions src/opserver/test/test_alarm.py
Expand Up @@ -20,7 +20,7 @@

from vnc_api.gen.resource_client import Alarm
from vnc_api.gen.resource_xsd import AlarmExpression, AlarmAndList, \
AlarmOrList
AlarmOrList, UveKeysType
from pysandesh.util import UTCTimestampUsec
from pysandesh.gen_py.sandesh_alarm.ttypes import SandeshAlarmAckRequest, \
SandeshAlarmAckResponseCode
Expand Down Expand Up @@ -321,10 +321,10 @@ def get_alarm_config_object(self, config_dict):
operation=exp['operation'],
operand1=exp['operand1'],
operand2=exp['operand2'],
vars=exp.get('vars')))
variables=exp.get('variables')))
alarm_or_list.append(AlarmAndList(alarm_and_list))
return Alarm(name=config_dict['name'],
uve_keys=config_dict['uve_keys'],
uve_keys=UveKeysType(config_dict['uve_keys']),
alarm_severity=config_dict['alarm_severity'],
alarm_rules=AlarmOrList(alarm_or_list),
**config_dict['kwargs'])
Expand Down Expand Up @@ -877,7 +877,7 @@ def test_05_evaluate_uve_for_alarms(self):
'operand1': 'A.B',
'operation': '<=',
'operand2': 'A.C.D',
'vars': ['A.C.N']
'variables': ['A.C.N']
}
]
}
Expand All @@ -903,13 +903,13 @@ def test_05_evaluate_uve_for_alarms(self):
'operand1': 'A.B',
'operation': '<=',
'operand2': 'A.C.D',
'vars': ['A.C.N']
'variables': ['A.C.N']
},
{
'operand1': 'A.B',
'operation': '>=',
'operand2': 'A.C.E',
'vars': ['A.C.N']
'variables': ['A.C.N']
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion src/opserver/test/test_alarm_plugins.py
Expand Up @@ -58,7 +58,8 @@ def get_alarm_config(self, plugin):
for exp in and_list['and_list']:
alarm_and_list.append(AlarmExpression(
operation=exp['operation'], operand1=exp['operand1'],
operand2=exp['operand2'], vars=exp.get('vars')))
operand2=exp['operand2'],
variables=exp.get('variables')))
alarm_or_list.append(AlarmAndList(alarm_and_list))
alarm_name = camel_case_to_hyphen(plugin.__class__.__name__)
kwargs = {'parent_type': 'global-system-config',
Expand Down
6 changes: 3 additions & 3 deletions src/opserver/test/test_alarmgen_config_handler.py
Expand Up @@ -12,7 +12,7 @@

from vnc_api.gen.resource_client import GlobalSystemConfig, Alarm
from vnc_api.gen.resource_xsd import AlarmExpression, \
AlarmAndList, AlarmOrList
AlarmAndList, AlarmOrList, UveKeysType
from pysandesh.sandesh_logger import SandeshLogger
from opserver.plugins.alarm_base import AlarmBase
from opserver.alarmgen_config_handler import AlarmGenConfigHandler
Expand Down Expand Up @@ -48,10 +48,10 @@ def _get_config_object(self, config_type, config_dict):
operation=exp['operation'],
operand1=exp['operand1'],
operand2=exp['operand2'],
vars=exp.get('vars')))
variables=exp.get('variables')))
alarm_or_list.append(AlarmAndList(alarm_and_list))
return Alarm(name=config_dict['name'],
uve_keys=config_dict['uve_keys'],
uve_keys=UveKeysType(config_dict['uve_keys']),
alarm_severity=config_dict['alarm_severity'],
alarm_rules=AlarmOrList(alarm_or_list),
**config_dict['kwargs'])
Expand Down
12 changes: 9 additions & 3 deletions src/schema/alarm.xsd
Expand Up @@ -22,7 +22,7 @@
<xsd:element name="operation" type="AlarmOperation" required="true" description="operation to compare operand1 and operand2"/>
<xsd:element name="operand1" type="xsd:string" required="true" description="UVE attribute specified in the dotted format. Example: NodeStatus.process_info.process_state"/>
<xsd:element name="operand2" type="xsd:string" required="true" description="UVE attribute or a json value to compare with the UVE attribute in operand1. null value can be specified to check if operand1 exists using the operator != or =="/>
<xsd:element name="vars" type="xsd:string" required="optional" maxOccurs="unbounded" description="List of UVE attributes that would be useful when the alarm is raised. For example, user may want to raise an alarm if the NodeStatus.process_info.process_state != PROCESS_STATE_RUNNING. But, it would be useful to know the process_name whose state != PROCESS_STATE_RUNNING. This UVE attribute which is neither part of operand1 nor operand2 may be specified in vars"/>
<xsd:element name="variables" type="xsd:string" required="optional" maxOccurs="unbounded" description="List of UVE attributes that would be useful when the alarm is raised. For example, user may want to raise an alarm if the NodeStatus.process_info.process_state != PROCESS_STATE_RUNNING. But, it would be useful to know the process_name whose state != PROCESS_STATE_RUNNING. This UVE attribute which is neither part of operand1 nor operand2 may be specified in variables"/>
</xsd:all>
</xsd:complexType>

Expand All @@ -45,6 +45,12 @@
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="UveKeysType">
<xsd:all>
<xsd:element name="uve-key" type="xsd:string" required="true" maxOccurs="unbounded" description="List of UVE tables where this alarm config should be applied"/>
</xsd:all>
</xsd:complexType>

<xsd:element name="alarm-enable" type="xsd:boolean"/>
<!--#IFMAP-SEMANTICS-IDL
Property('alarm-enable', 'global-system-config', 'optional', 'CRUD',
Expand All @@ -64,10 +70,10 @@
Link('project-alarm', 'project', 'alarm', ['has'], 'optional', 'CRUD',
'List of alarms that are applicable to objects anchored under the project.') -->

<xsd:element name="uve-keys" type="xsd:string" maxOccurs="unbounded"/>
<xsd:element name="uve-keys" type="UveKeysType"/>
<!--#IFMAP-SEMANTICS-IDL
Property('uve-keys', 'alarm', 'required', 'CRUD',
'List of UVE tables or UVE objects where this alarm config should be applied. For example, rules based on NodeStatus UVE can be applied to multiple object types such as analytics-node, config-node, control-node, etc., Alarm config may also be applied to specific objects that can be specified as <uve-table-name>.<uve-name>') -->
'List of UVE tables where this alarm config should be applied. For example, rules based on NodeStatus UVE can be applied to multiple object types such as analytics-node, config-node, control-node, etc.,') -->
<xsd:element name="alarm-severity" type="AlarmSeverity"/>
<!--#IFMAP-SEMANTICS-IDL
Property('alarm-severity', 'alarm', 'required', 'CRUD',
Expand Down

0 comments on commit 6d93f5f

Please sign in to comment.