Skip to content

Commit

Permalink
Fix validation of alarm rules
Browse files Browse the repository at this point in the history
Alarm config validation code should handle the case when both
"uve_attribute" and "json_value" are passed in AlarmOperand2, but one of
these values is None

Change-Id: Iebee9d8f7f4a6e308d9be8993ed0f78a74a3754c
Closes-Bug: #1610661
(cherry picked from commit c2d5a98)
  • Loading branch information
Sundaresan Rajangam committed Aug 10, 2016
1 parent 4cb1544 commit a55ab2c
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/config/api-server/vnc_cfg_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2135,19 +2135,26 @@ def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, **kwargs):

@classmethod
def _check_alarm_rules(cls, alarm_rules):
operand2_fields = ['uve_attribute', 'json_value']
try:
for and_list in alarm_rules['or_list']:
for and_cond in and_list['and_list']:
if 'json_value' in and_cond['operand2']:
if 'uve_attribute' in and_cond['operand2']:
return (False, (400, 'operand2 should have either '
'"uve_attribute" or "json_value", not both'))
try:
json.loads(and_cond['operand2']['json_value'])
except ValueError:
return (False, (400, 'Invalid json_value %s '
'specified in alarm_rules' %
(and_cond['operand2']['json_value'])))
if any(k in and_cond['operand2'] for k in operand2_fields):
uve_attr = and_cond['operand2'].get('uve_attribute')
json_val = and_cond['operand2'].get('json_value')
if uve_attr is not None and json_val is not None:
return (False, (400, 'operand2 should have '
'either "uve_attribute" or "json_value", '
'not both'))
if json_val is not None:
try:
json.loads(json_val)
except ValueError:
return (False, (400, 'Invalid json_value %s '
'specified in alarm_rules' % (json_val)))
else:
return (False, (400, 'operand2 should have '
'"uve_attribute" or "json_value"'))
except Exception as e:
return (False, (400, 'Invalid alarm_rules'))
return (True, '')
Expand Down

0 comments on commit a55ab2c

Please sign in to comment.