Python 3 compatibility: use print as a function.
In Python 3 print is a function. Especially for multiple string print, need to import print_function from __future__. Story: 2003310 Task: 24265 Change-Id: I1e8f80527f9ba97093a8e753f3460110e160d1b9 Signed-off-by: chenyan <yan.chen@intel.com>
This commit is contained in:
parent
7be92d78fc
commit
4ac52a716e
|
@ -28,7 +28,7 @@ def print_alarm(alarm):
|
||||||
+ "entity_type_id: " + alarm.entity_type_id + ", timestamp: "+ alarm.timestamp + "\n"
|
+ "entity_type_id: " + alarm.entity_type_id + ", timestamp: "+ alarm.timestamp + "\n"
|
||||||
alarm_str += "entity_instance_id: " + alarm.entity_instance_id + ", "
|
alarm_str += "entity_instance_id: " + alarm.entity_instance_id + ", "
|
||||||
alarm_str += "probable cause:" + alarm.probable_cause + "\n"
|
alarm_str += "probable cause:" + alarm.probable_cause + "\n"
|
||||||
print alarm_str
|
print(alarm_str)
|
||||||
|
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
|
@ -45,19 +45,19 @@ def create():
|
||||||
service_affecting = False,
|
service_affecting = False,
|
||||||
suppression = False)
|
suppression = False)
|
||||||
uuid =ser.set_fault(fault)
|
uuid =ser.set_fault(fault)
|
||||||
print uuid
|
print(uuid)
|
||||||
|
|
||||||
|
|
||||||
def delete(alarm_id, instance_id):
|
def delete(alarm_id, instance_id):
|
||||||
ser=FaultAPIs()
|
ser=FaultAPIs()
|
||||||
ret = ser.clear_fault(alarm_id,instance_id)
|
ret = ser.clear_fault(alarm_id,instance_id)
|
||||||
print "Delete fault return %s" % str(ret)
|
print("Delete fault return %s" % str(ret))
|
||||||
|
|
||||||
|
|
||||||
def del_all(instance_id):
|
def del_all(instance_id):
|
||||||
ser=FaultAPIs()
|
ser=FaultAPIs()
|
||||||
ret= ser.clear_all(instance_id)
|
ret= ser.clear_all(instance_id)
|
||||||
print "Delete faults return: %s" % str(ret)
|
print("Delete faults return: %s" % str(ret))
|
||||||
|
|
||||||
|
|
||||||
def get(alarm_id, instance_id):
|
def get(alarm_id, instance_id):
|
||||||
|
@ -66,29 +66,29 @@ def get(alarm_id, instance_id):
|
||||||
if a is not None:
|
if a is not None:
|
||||||
print_alarm(a)
|
print_alarm(a)
|
||||||
else:
|
else:
|
||||||
print "Alarm not found"
|
print("Alarm not found")
|
||||||
|
|
||||||
|
|
||||||
def get_all(instance_id):
|
def get_all(instance_id):
|
||||||
ser=FaultAPIs()
|
ser=FaultAPIs()
|
||||||
ll= ser.get_faults(instance_id)
|
ll= ser.get_faults(instance_id)
|
||||||
if ll is not None:
|
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:
|
for i in ll:
|
||||||
print_alarm(i)
|
print_alarm(i)
|
||||||
else:
|
else:
|
||||||
print "No alarm returned"
|
print("No alarm returned")
|
||||||
|
|
||||||
|
|
||||||
def get_list(alarm_id):
|
def get_list(alarm_id):
|
||||||
ser=FaultAPIs()
|
ser=FaultAPIs()
|
||||||
ll= ser.get_faults_by_id(alarm_id)
|
ll= ser.get_faults_by_id(alarm_id)
|
||||||
if ll is not None:
|
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:
|
for i in ll:
|
||||||
print_alarm(i)
|
print_alarm(i)
|
||||||
else:
|
else:
|
||||||
print "No alarm returned"
|
print("No alarm returned")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if sys.argv[1] == "create":
|
if sys.argv[1] == "create":
|
||||||
|
|
|
@ -68,7 +68,7 @@ def logInfo(msg):
|
||||||
with open(FM_LOG_EVENT_LOG_FILE,"a") as logFile:
|
with open(FM_LOG_EVENT_LOG_FILE,"a") as logFile:
|
||||||
logFile.write(output)
|
logFile.write(output)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print e
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
def get_events_yaml_filename():
|
def get_events_yaml_filename():
|
||||||
|
|
|
@ -80,11 +80,11 @@ def get_fm_alarms():
|
||||||
#
|
#
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
print "Missing file argument.\n"
|
print("Missing file argument.\n")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if not os.path.isfile(sys.argv[1]):
|
if not os.path.isfile(sys.argv[1]):
|
||||||
print "File \'%s\' does not exist.\n" % (sys.argv[1])
|
print("File \'%s\' does not exist.\n" % (sys.argv[1]))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
exitValue = 0
|
exitValue = 0
|
||||||
|
@ -100,13 +100,13 @@ with open(sys.argv[1], 'r') as stream:
|
||||||
constants_alarms = get_constants_alarms()
|
constants_alarms = get_constants_alarms()
|
||||||
for alarm_id in constants_alarms:
|
for alarm_id in constants_alarms:
|
||||||
if alarm_id not in events_alarm_list:
|
if alarm_id not in events_alarm_list:
|
||||||
print "\n ERROR: constants.py alarm \'%s\' must be defined in file events.yaml.\n" % (alarm_id)
|
print("\n ERROR: constants.py alarm \'%s\' must be defined in file events.yaml.\n" % (alarm_id))
|
||||||
exitValue = 1
|
exitValue = 1
|
||||||
|
|
||||||
fm_alarms = get_fm_alarms()
|
fm_alarms = get_fm_alarms()
|
||||||
for alarm_id in fm_alarms:
|
for alarm_id in fm_alarms:
|
||||||
if alarm_id not in events_alarm_list:
|
if alarm_id not in events_alarm_list:
|
||||||
print "\n ERROR: fmAlarm.h alarm \'%s\' must be defined in file events.yaml.\n" % (alarm_id)
|
print("\n ERROR: fmAlarm.h alarm \'%s\' must be defined in file events.yaml.\n" % (alarm_id))
|
||||||
exitValue = 1
|
exitValue = 1
|
||||||
|
|
||||||
exit (exitValue)
|
exit (exitValue)
|
||||||
|
|
|
@ -10,6 +10,9 @@ import os
|
||||||
import yaml
|
import yaml
|
||||||
import constants
|
import constants
|
||||||
|
|
||||||
|
# Python3 compatibility
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
# Record Format (for full description see events.yaml)
|
# Record Format (for full description see events.yaml)
|
||||||
#
|
#
|
||||||
# 100.001:
|
# 100.001:
|
||||||
|
@ -99,9 +102,9 @@ serviceAffecting_FieldName : serviceAffecting_FieldValues
|
||||||
|
|
||||||
def checkField( fieldKey, fieldValues, key, event ):
|
def checkField( fieldKey, fieldValues, key, event ):
|
||||||
if not event.has_key(fieldKey):
|
if not event.has_key(fieldKey):
|
||||||
print "\n ERROR: %s missing \'%s\' field." % (key, fieldKey)
|
print("\n ERROR: %s missing \'%s\' field." % (key, fieldKey))
|
||||||
return False
|
return False
|
||||||
# print "START: %s :END" % event[fieldKey]
|
# print ("START: %s :END" % event[fieldKey])
|
||||||
|
|
||||||
if type(event[fieldKey]) is str:
|
if type(event[fieldKey]) is str:
|
||||||
if not fieldValues:
|
if not fieldValues:
|
||||||
|
@ -109,8 +112,8 @@ def checkField( fieldKey, fieldValues, key, event ):
|
||||||
if event[fieldKey] in fieldValues:
|
if event[fieldKey] in fieldValues:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print "\n ERROR: \'%s\' is not a valid \'%s\' field value." % (event[fieldKey], fieldKey)
|
print("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (event[fieldKey], fieldKey))
|
||||||
print " Valid values are:", fieldValues
|
print(" Valid values are:", fieldValues)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if type(event[fieldKey]) is list:
|
if type(event[fieldKey]) is list:
|
||||||
|
@ -118,31 +121,31 @@ def checkField( fieldKey, fieldValues, key, event ):
|
||||||
return True
|
return True
|
||||||
for listvalue in event[fieldKey]:
|
for listvalue in event[fieldKey]:
|
||||||
if not listvalue in fieldValues:
|
if not listvalue in fieldValues:
|
||||||
print "\n ERROR: \'%s\' is not a valid \'%s\' field value." % (listvalue, fieldKey)
|
print("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (listvalue, fieldKey))
|
||||||
print " Valid values are:", fieldValues
|
print(" Valid values are:", fieldValues)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if type(event[fieldKey]) is dict:
|
if type(event[fieldKey]) is dict:
|
||||||
for dictKey, dictValue in event[fieldKey].iteritems():
|
for dictKey, dictValue in event[fieldKey].iteritems():
|
||||||
if not dictKey in severity_FieldValues:
|
if not dictKey in severity_FieldValues:
|
||||||
print "\n ERROR: \'%s\' is not a valid \'%s\' index value." % (dictKey, fieldKey)
|
print("\n ERROR: \'%s\' is not a valid \'%s\' index value." % (dictKey, fieldKey))
|
||||||
print " Valid index values are:", severity_FieldValues
|
print(" Valid index values are:", severity_FieldValues)
|
||||||
return False
|
return False
|
||||||
if fieldValues:
|
if fieldValues:
|
||||||
if not dictValue in fieldValues:
|
if not dictValue in fieldValues:
|
||||||
print "\n ERROR: \'%s\' is not a valid \'%s\' field value." % (dictValue, fieldKey)
|
print("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (dictValue, fieldKey))
|
||||||
print " Valid values are:", fieldValues
|
print(" Valid values are:", fieldValues)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def checkTypeField( key, event ):
|
def checkTypeField( key, event ):
|
||||||
if not event.has_key(type_FieldName):
|
if not event.has_key(type_FieldName):
|
||||||
print "\n ERROR: %s missing \'%s\' field." % (key, type_FieldName)
|
print("\n ERROR: %s missing \'%s\' field." % (key, type_FieldName))
|
||||||
return False
|
return False
|
||||||
if event[type_FieldName] in type_FieldValues:
|
if event[type_FieldName] in type_FieldValues:
|
||||||
return True
|
return True
|
||||||
print "\n ERROR: \'%s\' is not a valid \'%s\' field value." % (event[type_FieldName], type_FieldName)
|
print("\n ERROR: \'%s\' is not a valid \'%s\' field value." % (event[type_FieldName], type_FieldName))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,7 +163,7 @@ def checkFields( key, event ):
|
||||||
|
|
||||||
for itemKey, itemValue in event.iteritems():
|
for itemKey, itemValue in event.iteritems():
|
||||||
if not eventFields.has_key(itemKey):
|
if not eventFields.has_key(itemKey):
|
||||||
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
|
isOk = False
|
||||||
|
|
||||||
return isOk
|
return isOk
|
||||||
|
@ -171,11 +174,11 @@ def checkFields( key, event ):
|
||||||
#
|
#
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
print "Missing file argument.\n"
|
print("Missing file argument.\n")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if not os.path.isfile(sys.argv[1]):
|
if not os.path.isfile(sys.argv[1]):
|
||||||
print "File \'%s\' does not exist.\n" % (sys.argv[1])
|
print("File \'%s\' does not exist.\n" % (sys.argv[1]))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
with open(sys.argv[1], 'r') as stream:
|
with open(sys.argv[1], 'r') as stream:
|
||||||
|
@ -184,14 +187,14 @@ with open(sys.argv[1], 'r') as stream:
|
||||||
exitValue = 0
|
exitValue = 0
|
||||||
|
|
||||||
for key in events:
|
for key in events:
|
||||||
print "%6.3f: checking ... " % key,
|
print("%6.3f: checking ... " % key)
|
||||||
if not checkFields( key, events[key] ):
|
if not checkFields( key, events[key] ):
|
||||||
print
|
print()
|
||||||
exitValue = 1
|
exitValue = 1
|
||||||
else:
|
else:
|
||||||
print 'OK.'
|
print('OK.')
|
||||||
|
|
||||||
print 'Done.'
|
print('Done.')
|
||||||
|
|
||||||
except yaml.YAMLError as exc:
|
except yaml.YAMLError as exc:
|
||||||
print(exc)
|
print(exc)
|
||||||
|
|
Loading…
Reference in New Issue