add flake8 as pep8 codestyle check.
Enable test for pep8 and use flake8 as check tool. Story: 2003310 Task: 24446 Change-Id: Idf5cbde46dc1a2a579587438b83f2dcb7b9352bb Signed-off-by: chenyan <yan.chen@intel.com>
This commit is contained in:
parent
5994fbdb68
commit
7bdf6fd47c
@ -2,5 +2,9 @@
|
||||
- project:
|
||||
check:
|
||||
jobs:
|
||||
- openstack-tox-pep8
|
||||
- openstack-tox-linters:
|
||||
voting: false
|
||||
gate:
|
||||
jobs:
|
||||
- openstack-tox-pep8
|
||||
|
@ -19,6 +19,7 @@ import six
|
||||
class ClientException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
# Fields explanation:
|
||||
#
|
||||
# alarm_id: a text string of the alarm identifier
|
||||
@ -148,38 +149,39 @@ class FaultAPIs(object):
|
||||
sep = constants.FM_CLIENT_STR_SEP
|
||||
return (sep + self._check_val(data.uuid) + sep + data.alarm_id + sep +
|
||||
data.alarm_state + sep + data.entity_type_id + sep +
|
||||
data.entity_instance_id + sep + self._check_val(data.timestamp)
|
||||
+ sep + data.severity + sep + self._check_val(data.reason_text)
|
||||
+ sep + data.alarm_type + sep + data.probable_cause + sep +
|
||||
data.entity_instance_id + sep +
|
||||
self._check_val(data.timestamp) +
|
||||
sep + data.severity + sep + self._check_val(data.reason_text) +
|
||||
sep + data.alarm_type + sep + data.probable_cause + sep +
|
||||
self._check_val(data.proposed_repair_action) + sep +
|
||||
str(data.service_affecting) + sep + str(data.suppression) + sep)
|
||||
|
||||
@staticmethod
|
||||
def _str_to_alarm(alarm_str):
|
||||
l = alarm_str.split(constants.FM_CLIENT_STR_SEP)
|
||||
if len(l) < constants.MAX_ALARM_ATTRIBUTES:
|
||||
line = alarm_str.split(constants.FM_CLIENT_STR_SEP)
|
||||
if len(line) < constants.MAX_ALARM_ATTRIBUTES:
|
||||
return None
|
||||
else:
|
||||
data = Fault(l[constants.FM_ALARM_ID_INDEX],
|
||||
l[constants.FM_ALARM_STATE_INDEX],
|
||||
l[constants.FM_ENT_TYPE_ID_INDEX],
|
||||
l[constants.FM_ENT_INST_ID_INDEX],
|
||||
l[constants.FM_SEVERITY_INDEX],
|
||||
l[constants.FM_REASON_TEXT_INDEX],
|
||||
l[constants.FM_ALARM_TYPE_INDEX],
|
||||
l[constants.FM_CAUSE_INDEX],
|
||||
l[constants.FM_REPAIR_ACTION_INDEX],
|
||||
l[constants.FM_SERVICE_AFFECTING_INDEX],
|
||||
l[constants.FM_SUPPRESSION_INDEX],
|
||||
l[constants.FM_UUID_INDEX],
|
||||
l[constants.FM_TIMESTAMP_INDEX])
|
||||
data = Fault(line[constants.FM_ALARM_ID_INDEX],
|
||||
line[constants.FM_ALARM_STATE_INDEX],
|
||||
line[constants.FM_ENT_TYPE_ID_INDEX],
|
||||
line[constants.FM_ENT_INST_ID_INDEX],
|
||||
line[constants.FM_SEVERITY_INDEX],
|
||||
line[constants.FM_REASON_TEXT_INDEX],
|
||||
line[constants.FM_ALARM_TYPE_INDEX],
|
||||
line[constants.FM_CAUSE_INDEX],
|
||||
line[constants.FM_REPAIR_ACTION_INDEX],
|
||||
line[constants.FM_SERVICE_AFFECTING_INDEX],
|
||||
line[constants.FM_SUPPRESSION_INDEX],
|
||||
line[constants.FM_UUID_INDEX],
|
||||
line[constants.FM_TIMESTAMP_INDEX])
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def _run_cmd_and_get_resp(cmd):
|
||||
resp = []
|
||||
cmd = cmd.encode('utf-8')
|
||||
pro = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
|
||||
pro = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
|
||||
output = pro.communicate()[0]
|
||||
lines = output.split('\n')
|
||||
for line in lines:
|
||||
@ -217,10 +219,10 @@ class FaultAPIs(object):
|
||||
if data.severity not in constants.ALARM_SEVERITY:
|
||||
raise ClientException("Invalid Fault Severity: %s" %
|
||||
data.severity)
|
||||
if data.alarm_type not in constants.ALARM_TYPE:
|
||||
if data.alarm_type not in constants.ALARM_TYPE:
|
||||
raise ClientException("Invalid Fault Type: %s" %
|
||||
data.alarm_type)
|
||||
if data.probable_cause not in constants.ALARM_PROBABLE_CAUSE:
|
||||
if data.probable_cause not in constants.ALARM_PROBABLE_CAUSE:
|
||||
raise ClientException("Invalid Fault Probable Cause: %s" %
|
||||
data.probable_cause)
|
||||
|
||||
@ -243,5 +245,3 @@ class FaultAPIs(object):
|
||||
if given < threshold:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
@ -17,15 +17,18 @@
|
||||
# under the License.
|
||||
|
||||
import sys
|
||||
from fm_api import *
|
||||
from fm_api import Fault, FaultAPIs
|
||||
from fm_api import constants
|
||||
|
||||
|
||||
def print_alarm(alarm):
|
||||
alarm_str = "alarm_id: " + alarm.alarm_id + ", " + "uuid: " + alarm.uuid + ", "
|
||||
alarm_str = "alarm_id: " + alarm.alarm_id + ", "
|
||||
alarm_str += "uuid: " + alarm.uuid + ", "
|
||||
alarm_str += "alarm_type: " + alarm.alarm_type + "\n"
|
||||
alarm_str += "state: " + alarm.alarm_state + ", ""severity: " + alarm.severity + ", " \
|
||||
+ "entity_type_id: " + alarm.entity_type_id + ", timestamp: "+ alarm.timestamp + "\n"
|
||||
alarm_str += "state: " + alarm.alarm_state + ", "
|
||||
alarm_str += "severity: " + alarm.severity + ", "
|
||||
alarm_str += "entity_type_id: " + alarm.entity_type_id + ", "
|
||||
alarm_str += "timestamp: " + alarm.timestamp + "\n"
|
||||
alarm_str += "entity_instance_id: " + alarm.entity_instance_id + ", "
|
||||
alarm_str += "probable cause:" + alarm.probable_cause + "\n"
|
||||
print(alarm_str)
|
||||
@ -37,31 +40,31 @@ def create():
|
||||
alarm_state=constants.FM_ALARM_STATE_SET,
|
||||
entity_type_id=constants.FM_ENTITY_TYPE_INSTANCE,
|
||||
entity_instance_id=constants.FM_ENTITY_TYPE_INSTANCE + '=' + 'a4e4cdb7-2ee6-4818-84c8-5310fcd67b5d',
|
||||
severity = constants.FM_ALARM_SEVERITY_CRITICAL,
|
||||
reason_text = "Unknown",
|
||||
alarm_type = constants.FM_ALARM_TYPE_5,
|
||||
probable_cause = constants.ALARM_PROBABLE_CAUSE_8,
|
||||
proposed_repair_action = None,
|
||||
service_affecting = False,
|
||||
suppression = False)
|
||||
uuid =ser.set_fault(fault)
|
||||
severity=constants.FM_ALARM_SEVERITY_CRITICAL,
|
||||
reason_text="Unknown",
|
||||
alarm_type=constants.FM_ALARM_TYPE_5,
|
||||
probable_cause=constants.ALARM_PROBABLE_CAUSE_8,
|
||||
proposed_repair_action=None,
|
||||
service_affecting=False,
|
||||
suppression=False)
|
||||
uuid = ser.set_fault(fault)
|
||||
print(uuid)
|
||||
|
||||
|
||||
def delete(alarm_id, instance_id):
|
||||
ser=FaultAPIs()
|
||||
ret = ser.clear_fault(alarm_id,instance_id)
|
||||
ser = FaultAPIs()
|
||||
ret = ser.clear_fault(alarm_id, instance_id)
|
||||
print("Delete fault return %s" % str(ret))
|
||||
|
||||
|
||||
def del_all(instance_id):
|
||||
ser=FaultAPIs()
|
||||
ret= ser.clear_all(instance_id)
|
||||
ser = FaultAPIs()
|
||||
ret = ser.clear_all(instance_id)
|
||||
print("Delete faults return: %s" % str(ret))
|
||||
|
||||
|
||||
def get(alarm_id, instance_id):
|
||||
ser=FaultAPIs()
|
||||
ser = FaultAPIs()
|
||||
a = ser.get_fault(alarm_id, instance_id)
|
||||
if a is not None:
|
||||
print_alarm(a)
|
||||
@ -70,10 +73,11 @@ def get(alarm_id, instance_id):
|
||||
|
||||
|
||||
def get_all(instance_id):
|
||||
ser=FaultAPIs()
|
||||
ll= ser.get_faults(instance_id)
|
||||
ser = FaultAPIs()
|
||||
ll = ser.get_faults(instance_id)
|
||||
if ll is not None:
|
||||
print("Total alarm returned: %d\n" % len(ll))
|
||||
print("Total alarm returned: %d\n"
|
||||
% len(ll))
|
||||
for i in ll:
|
||||
print_alarm(i)
|
||||
else:
|
||||
@ -81,22 +85,24 @@ def get_all(instance_id):
|
||||
|
||||
|
||||
def get_list(alarm_id):
|
||||
ser=FaultAPIs()
|
||||
ll= ser.get_faults_by_id(alarm_id)
|
||||
ser = FaultAPIs()
|
||||
ll = ser.get_faults_by_id(alarm_id)
|
||||
if ll is not None:
|
||||
print("Total alarm returned: %d\n" % len(ll))
|
||||
print("Total alarm returned: %d\n"
|
||||
% len(ll))
|
||||
for i in ll:
|
||||
print_alarm(i)
|
||||
else:
|
||||
print("No alarm returned")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if sys.argv[1] == "create":
|
||||
sys.exit(create())
|
||||
elif sys.argv[1] == "del":
|
||||
sys.exit(delete(sys.argv[2],sys.argv[3]))
|
||||
sys.exit(delete(sys.argv[2], sys.argv[3]))
|
||||
elif sys.argv[1] == "get":
|
||||
sys.exit(get(sys.argv[2],sys.argv[3]))
|
||||
sys.exit(get(sys.argv[2], sys.argv[3]))
|
||||
elif sys.argv[1] == "get_all":
|
||||
sys.exit(get_all(sys.argv[2]))
|
||||
elif sys.argv[1] == "del_all":
|
||||
|
@ -53,7 +53,7 @@ class event_log(Base):
|
||||
|
||||
|
||||
def prettyDict(dict):
|
||||
output = json.dumps(dict,sort_keys=True, indent=4)
|
||||
output = json.dumps(dict, sort_keys=True, indent=4)
|
||||
return output
|
||||
|
||||
|
||||
@ -64,8 +64,8 @@ def logInfo(msg):
|
||||
caller = getframeinfo(stack()[1][0])
|
||||
line_no = str(caller.lineno)
|
||||
output = "\n" + timestamp + " " + host_name + " fmManager: info " \
|
||||
+ current_file_name + "(" + line_no + "):" + " " + msg+"\n"
|
||||
with open(FM_LOG_EVENT_LOG_FILE,"a") as logFile:
|
||||
+ current_file_name + "(" + line_no + "):" + " " + msg + "\n"
|
||||
with open(FM_LOG_EVENT_LOG_FILE, "a") as logFile:
|
||||
logFile.write(output)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@ -77,12 +77,13 @@ def get_events_yaml_filename():
|
||||
return events_yaml_name
|
||||
return "/etc/fm/events.yaml"
|
||||
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
#
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit("Postgres credentials required as argument.")
|
||||
sys.exit("Postgres credentials required as argument.")
|
||||
|
||||
postgresql_credentials = str(sys.argv[1])
|
||||
|
||||
@ -103,7 +104,7 @@ session = Session()
|
||||
EVENT_TYPES_FILE = get_events_yaml_filename()
|
||||
|
||||
if not os.path.isfile(EVENT_TYPES_FILE):
|
||||
exit (-1)
|
||||
exit(-1)
|
||||
|
||||
with open(EVENT_TYPES_FILE, 'r') as stream:
|
||||
event_types = yaml.load(stream)
|
||||
@ -132,7 +133,7 @@ for event_type in event_types:
|
||||
yaml_event_list.append(string_event_type)
|
||||
|
||||
if str(event_type) not in uneditable_descriptions:
|
||||
event_description = (event_types.get(event_type) \
|
||||
event_description = (event_types.get(event_type)
|
||||
.get('Description'))
|
||||
else:
|
||||
event_description = event_types.get(event_type).get('Description')
|
||||
@ -155,9 +156,9 @@ for event_type in event_types:
|
||||
event_supp.mgmt_affecting = event_mgmt_affecting
|
||||
event_supp.degrade_affecting = event_degrade_affecting
|
||||
else:
|
||||
event_supp = EventSuppression(created_at=event_created_at,
|
||||
uuid=event_uuid,
|
||||
alarm_id=string_event_type,
|
||||
event_supp = EventSuppression(created_at=event_created_at,
|
||||
uuid=event_uuid,
|
||||
alarm_id=string_event_type,
|
||||
description=event_description,
|
||||
suppression_status='unsuppressed',
|
||||
set_for_deletion=False,
|
||||
@ -187,15 +188,11 @@ for event_type in event_supp:
|
||||
session.delete(event_supp)
|
||||
logInfo("Deleted Event Type {} from event_suppression table.".format(event_type.alarm_id))
|
||||
else:
|
||||
event_supp.suppression_status='unsuppressed'
|
||||
event_supp.suppression_status = 'unsuppressed'
|
||||
event_supp.set_for_deletion = True
|
||||
logInfo("Event Type {} no longer in events.yaml, but still used by alarm in database.".format(event_type.alarm_id))
|
||||
logInfo("Event Type {} marked as set for deletion in event_suppression table.".format(event_type.alarm_id))
|
||||
|
||||
session.commit()
|
||||
|
||||
|
||||
session.close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -12,7 +12,8 @@ import collections
|
||||
|
||||
import constants as fm_constants
|
||||
|
||||
FM_ALARM_H="fmAlarm.h"
|
||||
FM_ALARM_H = "fmAlarm.h"
|
||||
|
||||
|
||||
def get_events_alarm_list(events):
|
||||
for alarm_id in events:
|
||||
@ -26,20 +27,21 @@ def get_events_alarm_list(events):
|
||||
|
||||
for alarm_id in events:
|
||||
if events.get(alarm_id).get('Type') == "Alarm":
|
||||
events_alarm_list.append(str(alarm_id))
|
||||
events_alarm_list.append(str(alarm_id))
|
||||
|
||||
return events_alarm_list
|
||||
|
||||
|
||||
def get_constants_alarms():
|
||||
fm_constants_raw_dict = fm_constants.__dict__
|
||||
|
||||
fm_constants_alarms_dict = {k:v for k,v in fm_constants_raw_dict.items() if 'FM_ALARM_ID' in k}
|
||||
del fm_constants_alarms_dict['FM_ALARM_ID_INDEX'] # this is not an alarm
|
||||
fm_constants_alarms_dict = {k: v for k, v in fm_constants_raw_dict.items() if 'FM_ALARM_ID' in k}
|
||||
del fm_constants_alarms_dict['FM_ALARM_ID_INDEX'] # this is not an alarm
|
||||
|
||||
fm_constants_alarms = []
|
||||
for alarm_constant_name in fm_constants_alarms_dict:
|
||||
alarm_constant_full_name = 'fm_constants.' + alarm_constant_name
|
||||
fm_constants_alarms.append(eval(alarm_constant_full_name))
|
||||
fm_constants_alarms.append(eval(alarm_constant_full_name))
|
||||
|
||||
return fm_constants_alarms
|
||||
|
||||
@ -54,27 +56,28 @@ def get_fm_alarms():
|
||||
fm_alarms_file = f.readlines()
|
||||
|
||||
fm_alarm_group_lines = [k for k in fm_alarms_file if 'define ALARM_GROUP_' in k]
|
||||
|
||||
|
||||
for line in fm_alarm_group_lines:
|
||||
group_name = line.split()[1]
|
||||
group_value = line.split()[2]
|
||||
group_value = group_value[1:-1] # remove quotes
|
||||
group_value = group_value[1:-1] # remove quotes
|
||||
fm_alarm_groups[group_name] = group_value
|
||||
|
||||
fm_alarm_lines = [k for k in fm_alarms_file if 'FM_ALARM_ID' in k]
|
||||
|
||||
for line in fm_alarm_lines:
|
||||
alarm_name = line.split()[1]
|
||||
# alarm_name = line.split()[1]
|
||||
group_name = line.split()[2]
|
||||
group_name = group_name[1:]
|
||||
alarm_right_digits_value = line.split()[3]
|
||||
alarm_right_digits_value = alarm_right_digits_value[1:-2]
|
||||
alarm_left_digits_value = fm_alarm_groups[group_name]
|
||||
alarm_value = alarm_left_digits_value + alarm_right_digits_value
|
||||
fm_alarms.append(alarm_value)
|
||||
|
||||
fm_alarms.append(alarm_value)
|
||||
|
||||
return fm_alarms
|
||||
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
@ -109,5 +112,4 @@ for alarm_id in fm_alarms:
|
||||
print("\n ERROR: fmAlarm.h alarm \'%s\' must be defined in file events.yaml.\n" % (alarm_id))
|
||||
exitValue = 1
|
||||
|
||||
exit (exitValue)
|
||||
|
||||
exit(exitValue)
|
||||
|
@ -4,18 +4,18 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# Python3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
import yaml
|
||||
import constants
|
||||
|
||||
# Python3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
# Record Format (for full description see events.yaml)
|
||||
#
|
||||
# 100.001:
|
||||
#
|
||||
# 100.001:
|
||||
# Type: Alarm
|
||||
# Description: "Degrade: <hostname> is experiencing an intermittent 'Management Network' communication failure."
|
||||
# Entity_Instance_ID: host=<hostname>
|
||||
@ -29,11 +29,11 @@ from __future__ import print_function
|
||||
# Suppression: True
|
||||
# Management_Affecting_Severity: warning
|
||||
# Degrade_Affecting_Severity: none
|
||||
#
|
||||
#
|
||||
|
||||
type_FieldName = 'Type'
|
||||
type_FieldValue_Alarm = 'Alarm'
|
||||
type_FieldValues = [ type_FieldValue_Alarm, 'Log' ]
|
||||
type_FieldValues = [type_FieldValue_Alarm, 'Log']
|
||||
|
||||
description_FieldName = 'Description'
|
||||
description_FieldValues = [] # arbitrary string
|
||||
@ -51,7 +51,7 @@ maintenanceAction_FieldName = 'Maintenance_Action'
|
||||
maintenanceAction_FieldValues = [] # arbitrary string
|
||||
|
||||
inhibitAlarms_FieldName = 'Inhibit_Alarms'
|
||||
inhibitAlarms_FieldValues = [ True, False ]
|
||||
inhibitAlarms_FieldValues = [True, False]
|
||||
|
||||
alarmType_FieldName = 'Alarm_Type'
|
||||
alarmType_FieldValues = constants.ALARM_TYPE
|
||||
@ -60,10 +60,10 @@ probableCause_FieldName = 'Probable_Cause'
|
||||
probableCause_FieldValues = constants.ALARM_PROBABLE_CAUSE
|
||||
|
||||
serviceAffecting_FieldName = 'Service_Affecting'
|
||||
serviceAffecting_FieldValues = [ True, False ]
|
||||
serviceAffecting_FieldValues = [True, False]
|
||||
|
||||
suppression_FieldName = 'Suppression'
|
||||
suppression_FieldValues = [ True, False ]
|
||||
suppression_FieldName = 'Suppression'
|
||||
suppression_FieldValues = [True, False]
|
||||
|
||||
managementAffectingSeverity_FieldName = 'Management_Affecting_Severity'
|
||||
managementAffectingSeverity_FieldValues = constants.ALARM_SEVERITY.append('none')
|
||||
@ -72,39 +72,37 @@ degradeAffecting_FieldName = 'Degrade_Affecting_Severity'
|
||||
degradeAffecting_FieldValues = constants.ALARM_SEVERITY.append('none')
|
||||
|
||||
alarmFields = {
|
||||
type_FieldName : type_FieldValues,
|
||||
description_FieldName : description_FieldValues,
|
||||
entityInstanceId_FieldName : entityInstanceId_FieldValues,
|
||||
severity_FieldName : severity_FieldValues,
|
||||
proposedRepairAction_FieldName : proposedRepairAction_FieldValues,
|
||||
maintenanceAction_FieldName : maintenanceAction_FieldValues,
|
||||
inhibitAlarms_FieldName : inhibitAlarms_FieldValues,
|
||||
alarmType_FieldName : alarmType_FieldValues,
|
||||
probableCause_FieldName : probableCause_FieldValues,
|
||||
serviceAffecting_FieldName : serviceAffecting_FieldValues,
|
||||
suppression_FieldName : suppression_FieldValues,
|
||||
managementAffectingSeverity_FieldName : managementAffectingSeverity_FieldValues,
|
||||
degradeAffecting_FieldName: degradeAffecting_FieldValues
|
||||
type_FieldName: type_FieldValues,
|
||||
description_FieldName: description_FieldValues,
|
||||
entityInstanceId_FieldName: entityInstanceId_FieldValues,
|
||||
severity_FieldName: severity_FieldValues,
|
||||
proposedRepairAction_FieldName: proposedRepairAction_FieldValues,
|
||||
maintenanceAction_FieldName: maintenanceAction_FieldValues,
|
||||
inhibitAlarms_FieldName: inhibitAlarms_FieldValues,
|
||||
alarmType_FieldName: alarmType_FieldValues,
|
||||
probableCause_FieldName: probableCause_FieldValues,
|
||||
serviceAffecting_FieldName: serviceAffecting_FieldValues,
|
||||
suppression_FieldName: suppression_FieldValues,
|
||||
managementAffectingSeverity_FieldName: managementAffectingSeverity_FieldValues,
|
||||
degradeAffecting_FieldName: degradeAffecting_FieldValues
|
||||
}
|
||||
|
||||
logFields = {
|
||||
type_FieldName : type_FieldValues,
|
||||
description_FieldName : description_FieldValues,
|
||||
entityInstanceId_FieldName : entityInstanceId_FieldValues,
|
||||
severity_FieldName : severity_FieldValues,
|
||||
alarmType_FieldName : alarmType_FieldValues,
|
||||
probableCause_FieldName : probableCause_FieldValues,
|
||||
serviceAffecting_FieldName : serviceAffecting_FieldValues
|
||||
type_FieldName: type_FieldValues,
|
||||
description_FieldName: description_FieldValues,
|
||||
entityInstanceId_FieldName: entityInstanceId_FieldValues,
|
||||
severity_FieldName: severity_FieldValues,
|
||||
alarmType_FieldName: alarmType_FieldValues,
|
||||
probableCause_FieldName: probableCause_FieldValues,
|
||||
serviceAffecting_FieldName: serviceAffecting_FieldValues
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
def checkField( fieldKey, fieldValues, key, event ):
|
||||
def checkField(fieldKey, fieldValues, key, event):
|
||||
if fieldKey not in event:
|
||||
print("\n ERROR: %s missing \'%s\' field." % (key, fieldKey))
|
||||
return False
|
||||
# print ("START: %s :END" % event[fieldKey])
|
||||
# print("START: %s :END" % event[fieldKey])
|
||||
|
||||
if type(event[fieldKey]) is str:
|
||||
if not fieldValues:
|
||||
@ -120,26 +118,26 @@ def checkField( fieldKey, fieldValues, key, event ):
|
||||
if not fieldValues:
|
||||
return True
|
||||
for listvalue in event[fieldKey]:
|
||||
if not listvalue in fieldValues:
|
||||
if listvalue not in fieldValues:
|
||||
print("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (listvalue, fieldKey))
|
||||
print(" Valid values are:", fieldValues)
|
||||
return False
|
||||
|
||||
|
||||
if type(event[fieldKey]) is dict:
|
||||
for dictKey, dictValue in event[fieldKey].items():
|
||||
if not dictKey in severity_FieldValues:
|
||||
if dictKey not in severity_FieldValues:
|
||||
print("\n ERROR: \'%s\' is not a valid \'%s\' index value." % (dictKey, fieldKey))
|
||||
print(" Valid index values are:", severity_FieldValues)
|
||||
return False
|
||||
if fieldValues:
|
||||
if not dictValue in fieldValues:
|
||||
if dictValue not in fieldValues:
|
||||
print("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (dictValue, fieldKey))
|
||||
print(" Valid values are:", fieldValues)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def checkTypeField( key, event ):
|
||||
def checkTypeField(key, event):
|
||||
if type_FieldName not in event:
|
||||
print("\n ERROR: %s missing \'%s\' field." % (key, type_FieldName))
|
||||
return False
|
||||
@ -149,21 +147,20 @@ def checkTypeField( key, event ):
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def checkFields( key, event ):
|
||||
def checkFields(key, event):
|
||||
isOk = True
|
||||
if not checkTypeField(key, event) :
|
||||
if not checkTypeField(key, event):
|
||||
return False
|
||||
isAlarm = (event[type_FieldName] == type_FieldValue_Alarm)
|
||||
eventFields = alarmFields if isAlarm else logFields
|
||||
|
||||
for fieldKey, fieldValues in eventFields.items():
|
||||
if not checkField(fieldKey, fieldValues, key, event) :
|
||||
if not checkField(fieldKey, fieldValues, key, event):
|
||||
isOk = False
|
||||
|
||||
for itemKey, itemValue in event.items():
|
||||
if itemKey not in eventFields:
|
||||
print("\n ERROR: \'%s\' is not a valid \'%s\' field." % (itemKey, ("Alarm" if isAlarm else "Log") ))
|
||||
print("\n ERROR: \'%s\' is not a valid \'%s\' field." % (itemKey, ("Alarm" if isAlarm else "Log")))
|
||||
isOk = False
|
||||
|
||||
return isOk
|
||||
@ -188,7 +185,7 @@ with open(sys.argv[1], 'r') as stream:
|
||||
|
||||
for key in events:
|
||||
print("%6.3f: checking ... " % key)
|
||||
if not checkFields( key, events[key] ):
|
||||
if not checkFields(key, events[key]):
|
||||
print()
|
||||
exitValue = 1
|
||||
else:
|
||||
@ -199,5 +196,4 @@ with open(sys.argv[1], 'r') as stream:
|
||||
except yaml.YAMLError as exc:
|
||||
print(exc)
|
||||
|
||||
exit (exitValue)
|
||||
|
||||
exit(exitValue)
|
||||
|
@ -1,3 +1,4 @@
|
||||
bashate >= 0.2
|
||||
PyYAML >= 3.1.0
|
||||
yamllint >= 0.5.2
|
||||
flake8 >= 2.5.4 # MIT
|
||||
|
20
tox.ini
20
tox.ini
@ -1,5 +1,5 @@
|
||||
[tox]
|
||||
envlist = linters
|
||||
envlist = linters,pep8
|
||||
minversion = 2.3
|
||||
skipsdist = True
|
||||
|
||||
@ -28,13 +28,21 @@ commands =
|
||||
-o -type f -name '*.yaml' \
|
||||
-print0 | xargs -0 yamllint"
|
||||
|
||||
####
|
||||
# Add flake8 as pep8 codestyle check.
|
||||
[testenv:pep8]
|
||||
usedevelop = False
|
||||
skip_install = True
|
||||
deps =
|
||||
pep8
|
||||
description =
|
||||
Run style checks.
|
||||
commands =
|
||||
pep8
|
||||
flake8
|
||||
|
||||
[flake8]
|
||||
# E123, E125 skipped as they are invalid PEP-8.
|
||||
# E501 skipped because some of the code files include templates
|
||||
# that end up quite wide
|
||||
show-source = True
|
||||
ignore = E123,E125,E501,H405
|
||||
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,release-tag-*
|
||||
|
||||
[testenv:venv]
|
||||
commands = {posargs}
|
||||
|
Loading…
Reference in New Issue
Block a user